Guidance
指路人
g.yi.org
Software / Reginald / Examples / html.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*
GUIBEGIN
WINDOW , 146, 188, 241, 138, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , HTML Processor
	FONT 8, 400, MS Shell Dlg
	PUSH 4, 121, 40, 14, TABSTOP, , Search, ALT "S", &Search
	PUSH 51, 121, 40, 14, TABSTOP, , Process, ALT "P", &Process
	LIST 0, 16, 241, 97, NOTIFY|MULTI|BORDER|VSCROLL|HSCROLL|TABSTOP, , MyList, ALT "H"
	TEXT 2, 4, 45, 8, GROUP, , , , &HTML Files
DEND
GUIEND
*/

/* Searches for all .HTM and .HTML files under a directory tree,
 * displays the names in a list box for the user to select, and
 * then performs an operation upon the selected names.
 */

LIBRARY rexxgui
guierr = "SYNTAX"
guiheading = 1
guicreatewindow('NORMAL')

/* We aren't doing a search/process yet */
processing = 0

again:
DO FOREVER
	guigetmsg()
	CATCH SYNTAX
			CONDITION('M')
			SIGNAL again
	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN





/* Called by Reginald when the user clicks on our "Search" button */
wm_click_search:

/* Are we processing HTML files, or searching for HTML files? */
IF processing == 1 THEN DO

	/* This button was clicked while we were either searching
	 * for HTML files below (ie, filling the listbox) or
	 * processing files (in WM_CLICK_Process). In that case,
	 * this is really the "Stop" button. Call GuiWake with
	 * "ABORT", so the next call to GuiGetMsg() will return
	 * with GuiSignal set to "ABORT"
	 */
	guiwake("ABORT")

	/* Disable the Stop button. This is just to prevent him
	 * from clicking it again, and causing another GuiWake
	 * above. We only need to GuiWake once
	 */
	guisetctlplacement("Search", , , , , "DISABLE")

	RETURN
END

/* Start searching for HTML files */

/* Store the directory in the variable directoryName. */
directoryname = ''

DO
   /* Present the dialog. */
   err = guifile('directoryName', 'BROWSE|DRIVES', 'Where to find HTML files:')

   CATCH SYNTAX
      /* Get the error message. */
      err = CONDITION('D')
END

/* Check for an error. */
SELECT err

   WHEN "" THEN DO

		/* Change the "Search" button to "Stop" */
		guiaddctltext("Search", "&Stop")

		/* Indicate that we're searching HTML files */
		processing = 1

		/* Populate the list box with the names of whatever HTML files we find */
		count = 0
		err = gethtmlnames(directoryname, 1)

		/* Done searching for HTML files */
		processing = 0

		/* Change the "Search" button back to "Search" */
		guiaddctltext("Search", "&Search")
		guisetctlplacement("Search", , , , , "ENABLE")

		/* If an error, display an error message */
		IF err \== "" & err \== "ABORT" THEN guisay(err)
   END

   WHEN 'DLL function "GUIFILE" reported "Cancel"' THEN NOP /* Ignore CANCEL. Note we assume GuiHeading = 1. */

   OTHERWISE
      /* Some other error, so display it. */
      CONDITION('M')
END

RETURN





/* Populates a list box with the names of all files that end in extensions
 * of .HTM and .HTML. It does a recursive directory search from the passed
 * directory name. 'Count' contains a count of the collected names. (This
 * must be set to 0 before this function is called). Each name is fully
 * qualified.
 *
 * Returns an empty string if successful, or an error message.
 *
 * Count = 0
 * error = GetHtmlNames(directoryName, 1)
 * IF error \== "" THEN SAY error
 *
 * NOTE: Because we call GuiGetMsg(), that means that any of our
 * event handlers can be called by GetHtmlNames(). And because we
 * have used a PROCEDURE on GetHtmlNames(), that means we have to
 * EXPOSE any main level variables that our event handlers need
 * to access. The one exception is "GuiWindow".
 */

gethtmlnames: PROCEDURE EXPOSE count processing

/* DO UNTIL no more items or an error */
DO UNTIL err \== ""

	/* Get the name of the next item inside of this dir */
	err = MATCHNAME(ARG(2), 'name', ARG(1) || '\*.*', 'DSNHCRAT', 'NS')

	/* No error? */
	IF err == "" THEN DO

		/* Call GuiGetMsg to allow us to check if the user has interacted
		 * with the window. But use a "CLEAR" operation, so GuiGetMsg doesn't
		 * pause our script if he hasn't done anything. NOTE: If the user
		 * clicks on the "Stop" button, GuiGetMsg will call WM_CLICK_Search()
		 * right here.
		 */
		guigetmsg("CLEAR")

		/* Did he click on the "Stop" button? If so, WM_CLICK_Search
		 * called GuiWake, and GuiSignal was set to "ABORT".
		 */
		IF EXISTS(guisignal) THEN IF guisignal == "ABORT" THEN RETURN 'ABORT'

		/* Is this a sub-dir? If so, its size will be an empty string */
		IF name.0 == "" THEN DO

			/* Enumerate all items in this sub-dir */
			err = gethtmlnames(ARG(1) || '\' || NAME, ARG(2) + 1)
			IF err \== "" THEN RETURN err

		END

		/* It's a file. Check its extension for HTM or HTML */
		ELSE DO
			ext = TRANSLATE(FILESPEC('E', name))
			IF ext == ".HTM" | ext == ".HTML" THEN DO

				/* Increment count of files */
				count = count + 1
	
				/* Add the full pathname to the list */
				guisendmsg("MyList", "ADDSTRING", , ARG(1) || '\' || name)
			END
		END
	END
END

/* If we enumerated all items successfully, return an empty string */
IF err == 'DONE' THEN err = ""

/* Return an empty string if success, or an error message */
RETURN err





/* Called by Reginald when the user clicks on our "Process" button */
wm_click_process:

	/* Get the selections in the listbox */
	guigetctlvalue("MyList")

	/* Change the "Search" button to "Stop" */
	guiaddctltext("Search", "Stop")

	/* Indicate that we're processing HTML files */
	processing = 1

	/* Do as many items as the user selected */
	DO index = 1 TO mylist.0

		/* Call GuiGetMsg to allow us to check if the user has interacted
		 * with the window. But use a "CLEAR" operation, so GuiGetMsg doesn't
		 * pause our script if he hasn't done anything
		 */
		guigetmsg("CLEAR")

		/* Did he click on the "Stop" button? If so, WM_CLICK_Search
		 * called GuiWake, and GuiSignal was set to "ABORT".
		 */
		IF EXISTS(guisignal) THEN IF guisignal == "ABORT" THEN RETURN

		/* Here, you would add whatever code you wish to operate upon this one file. The file's
		 * name is STRS.0.index
	 	*/
		SAY mylist.index
	END

	/* Done processing HTML files */
	processing = 0

	/* Change the "Search" button back to "Search" */
	guiaddctltext("Search", "&Search")
	guisetctlplacement("Search", , , , , "ENABLE")

	RETURN
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-4-26  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:23