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

mMainWindow main topLevel

  mMenuBar menu_bar main
    mPulldownMenu mp1 menu_bar unmanaged
      mPushButton Quit mp1 \
	activateCallback quit
    mCascadeButton Exit menu_bar \
	subMenuId mp1

    mPulldownMenu mp2 menu_bar unmanaged
      mPushButton Help mp2 \
	activateCallback "manageChild helpbox"
      mPushButton Version mp2 \
	activateCallback "manageChild versionbox"
    mCascadeButton Help menu_bar \
	subMenuId mp2

  mBulletinBoard bboard main
    mLabelGadget labelg bboard \
	x 10 y 10 labelString "Enter Directory Here"
    mTextField textf bboard \
	x 10 y 40 columns 50 activateCallback textActivate

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

  mForm form1 main height 70
    mLabelGadget errmsg_box form1 \
	topAttachment ATTACH_FORM leftAttachment ATTACH_FORM \
	labelString "ErrorMessage Window" 
    mPushButtonGadget 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}

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

mMessageDialog 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 \
	versionbox.[mMessageBoxGetChild versionbox DIALOG_CANCEL_BUTTON] \
	versionbox.[mMessageBoxGetChild versionbox DIALOG_HELP_BUTTON] \
	helpbox.[mMessageBoxGetChild helpbox DIALOG_CANCEL_BUTTON] \
	helpbox.[mMessageBoxGetChild helpbox DIALOG_HELP_BUTTON]

proc dlog {title t} { 
    mFormDialog dlog$t rowcol unmanaged 
    sV [parent dlog$t] title $title
    mScrolledText 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
    }
    mSeparatorGadget sep$t dlog$t {
	topOffset 10 
	topWidget scroll_text$t topAttachment ATTACH_WIDGET
    }
    mPushButtonGadget button$t dlog$t {
	leftOffset 210 topOffset 10 topWidget sep$t 
	leftAttachment ATTACH_FORM topAttachment ATTACH_WIDGET 
	labelString Close showAsDefault True 
	height 30 width 80
    }
    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

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

realize
