#! ../mofe --f
mergeResources topLevel *background gray

XmMainWindow main topLevel

  XmMenuBar menu_bar main
    XmPulldownMenu mp1 menu_bar unmanaged
      XmPushButton Quit mp1 \
	activateCallback quit
    XmCascadeButton Exit menu_bar \
	subMenuId mp1

    XmPulldownMenu mp2 menu_bar unmanaged
      XmPushButton Help mp2 \
	activateCallback "manageChild helpbox"
      XmPushButton Version mp2 \
	activateCallback "manageChild versionbox"
    XmCascadeButton Help menu_bar \
	subMenuId mp2

  XmBulletinBoard bboard main
    XmLabelGadget labelg bboard \
	x 10 y 10 labelString "Enter Directory Here"
    XmTextField textf bboard \
	x 10 y 40 columns 50 activateCallback textActivate

  XmRowColumn rowcol main \
	packing PACK_COLUMN numColumns 1
    XmPushButton pbutton1 rowcol \
	labelString "Home Directory Usage" \
	armCallback "execdu %w $env(HOME)"
    XmPushButton pbutton2 rowcol \
	labelString "Current Directory Usage" \
	armCallback "execdu %w ."

  XmForm form1 main height 70
    XmLabelGadget errmsg_box form1 \
	topAttachment ATTACH_FORM leftAttachment ATTACH_FORM \
	labelString "ErrorMessage Window" 
    XmPushButtonGadget pbg form1 unmanaged \
	topAttachment ATTACH_WIDGET topOffset 20 topWidget errmsg_box \
	leftAttachment ATTACH_FORM leftOffset 210 \
	bottomAttachment ATTACH_FORM \
	labelString Continue \
	activateCallback {sV errmsg_box labelString {Message Area}; \
		unmanageChild pbg}

XmMessageDialog versionbox Version unmanaged \
	dialogTitle "Diskuse Version" \
	okLabelString "Close" \
	messageString "This is m-du"

XmMessageDialog helpbox Help unmanaged \
	dialogTitle "Diskuse Help" \
	okLabelString "Close" \
	messageString "\
This program provides a quick means of finding the disk space used \n\
by a particular directory.  You can enter a specific directory path \n\
in the text field widget labeled 'Enter Directory Here' and press \n\
Return or move the pointer to one of the buttons and click button 1.  \n\
Another window will appear with a scrolled text containing the \n\
information you want.  There may be a slight time delay before this \n\
window appears.  To remove this window, move the pointer to the \n\
Close button and click button 1 to close that window.  To exit the \n\
program, move the pointer to the Exit button and click button 1.  A Quit \n\
button then appears and you move the pointer into it and again click \n\
button 1.  There is a time delay before the program is terminated."

unmanageChild \
	[XmMessageBoxGetChild versionbox DIALOG_CANCEL_BUTTON] \
	[XmMessageBoxGetChild versionbox DIALOG_HELP_BUTTON] 
unmanageChild \
	[XmMessageBoxGetChild helpbox DIALOG_CANCEL_BUTTON] \
	[XmMessageBoxGetChild helpbox DIALOG_HELP_BUTTON]

proc dlog {title t} { 
    XmFormDialog dlog$t rowcol unmanaged 
    sV [parent dlog$t] title $title
    XmScrolledText scroll_text$t dlog$t {
	topOffset 10 leftOffset 10 rightOffset 10 
	height 150 width 400
	topAttachment ATTACH_FORM leftAttachment ATTACH_FORM 
	rightAttachment ATTACH_FORM 
	editMode MULTI_LINE_EDIT editable False
    }
    XmSeparatorGadget sep$t dlog$t {
        topOffset 10  width 450
	topWidget scroll_text$t topAttachment ATTACH_WIDGET
    }
    XmPushButtonGadget button$t dlog$t {
	leftOffset 210 topOffset 10 topWidget sep$t 
	leftAttachment ATTACH_FORM topAttachment ATTACH_WIDGET 
	labelString Close showAsDefault True 
    }
    sV dlog$t defaultButton button$t 
}

proc execdu {t dir} {
    manageChild dlog$t
    sV scroll_text$t value [exec du $dir] 
}

proc textActivate {} {
    set dir [gV textf value]
    if [file isdirectory $dir] {execdu textf $dir} {
	manageChild pbg; 
	sV errmsg_box labelString \
	    "Error! $dir is not an existing directory."
    } 
}

dlog "Home Directory Usage" pbutton1
dlog "Current Directory Usage" pbutton2
dlog "User Specified Directory" textf

XmMainWindowSetAreas main menu_bar bboard NULL NULL rowcol
sV menu_bar menuHelpWidget Help
sV main messageWindow form1

realize
