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

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

  
/*
GUIBEGIN
WINDOW , 33, 94, 216, 138, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , Editor
	FONT 8, 400, MS Shell Dlg
	MENU
	ENTRY 0, 0, 32, 12, MULTI|V_AUTO|H_AUTO|RETURN, , TEXT
DEND

MENU
	HEADING File
		ITEM New
		ITEM Open
		ITEM
		ITEM Save
		ITEM Save as
		ITEM
		ITEM Exit
	<
	HEADING Edit
		ITEM Cut, , CTRL "X"
		ITEM Copy, , CTRL "C"
		ITEM Paste, , CTRL "V"
	<
	HEADING REXX
		ITEM &Run as script, , CTRL "R"
	<
DEND
GUIEND
*/

/* An example of a simple text editor.
 *
 * We create a main window. In it, we place one ENTRY control. It has the
 * MULTI style so the user can enter numerous lines of text.
 *
 * We also have a menu. It has a File->Load item whereby we use GuiFile()
 * to pick out the name of the text file to load. (ASCII format only).
 *
 * We also have a "Rexx->Run as script" menu item to run the text as a script.
 */

/* Load the REXX GUI functions. */
LIBRARY rexxgui

/* Let REXX GUI raise SYNTAX for errors. */
guierr = "SYNTAX"
guiheading = 1

/* Store the filename in the variable FN */
fn = ''

/* Default contents is an empty file. If the user supplied a text file
 * name on the command line when running this script, let's load that
 * file into TEXT
 */
text = ''

/* Create our main window. */
guicreatewindow('NORMAL')

/* Resize our ENTRY to fill the inner window. */
guigetctlplacement(, , , 'Width', 'Height')
guisetctlplacement('TEXT', , , width, height)

/* Main message loop */
again:
DO FOREVER

	guigetmsg()

	CATCH SYNTAX
		CONDITION('M')
		SIGNAL again

	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN

checkifsaved:
	/* See if the contents of the ENTRY were altered. */
	guisendmsg('TEXT', 'GETMODIFY')
	IF guisignal == 1 THEN DO

		/* Contents were changed. Ask if he wants to save. */
		err = guisay('Save the current changes?', 'YESCANCEL|INFO')
		IF err == 'CANCEL' THEN RETURN -1
		IF err == 'YES' THEN RETURN filesave()
	END
	RETURN 0

/* ================== "New" menu item ====================== */
filenew:
	/* See if the contents need to be saved. */
	IF checkifsaved() \== 0 THEN RETURN

	/* Blank the Window title bar */
	guiaddctltext(guiwindow)

	/* Empty the contents */
	text.0 = 0
	guisetctlvalue('TEXT')

	/* Text is not modified yet. */
	guisendmsg('TEXT', 'SETMODIFY', 0)

	RETURN

/* ================== "Open" menu item ====================== */
fileopen:
	/* See if the contents need to be saved. */
	IF checkifsaved() \== 0 THEN RETURN

	DO
		/* Here are our file extensions that we filter -- .rex, .txt, and all files */
		extensions = 'REXX scripts (*.rex) | *.rex | Text files (*.txt) | *.txt | All files (*.*) | *.*'
	
		/* Do the File Dialog */
		guifile('FN', 'HIDEREADONLY|PATH|DIR', 'Pick out a text file', extensions)

		/* If he cancels or there is an error, we CATCH here. */
		CATCH SYNTAX
			RETURN
	END

	DO
		/* Load the file into the 'TEXT.' stem variable */
		LOADTEXT('TEXT', fn)

		/* Put the file contents into our ENTRY */
		guisetctlvalue('TEXT')
		DROP text.

		/* Set the Window title bar with our filename. Replace \ chars with / because
		 * REXX GUI uses these chars for \t (TAB) and \n (new line)
		 */
		guiaddctltext(guiwindow, TRANSLATE(fn, '/', '\'))

		CATCH NOTREADY
			CONDITION('M')
	END

	/* Text is not modified yet. */
	guisendmsg('TEXT', 'SETMODIFY', 0)

	/* Done */
	RETURN

/* ================== "Save As" menu item ====================== */
filesaveas:
	DO
		/* Here are our file extensions that we filter -- .rex, .txt, and all files */
		extensions = 'REXX scripts (*.rex) | *.rex | Text files (*.txt) | *.txt | All files (*.*) | *.*'
	
		/* Do the File Dialog */
		guifile('FN', 'HIDEREADONLY|OVERWRITE|SAVE|PATH|DIR', 'Save a text file', extensions)

		/* If he cancels or there is an error, we CATCH here. */
		CATCH SYNTAX
			RETURN -1
	END

	/* Drop down into the "Save" code */

/* ================== "Save" menu item ====================== */
filesave:
	/* Make sure that we don't have an empty file name. If so,
	 * force him to pick a name now.
	 */
	IF fn = "" THEN SIGNAL filesaveas

	/* Get the contents of our ENTRY into the variable 'GuiSignal' as one string. */
	guisendmsg('TEXT', 'GETTEXT')

	DO
		/* Open the file, overwriting any previous contents. */
		STREAM(fn, 'C', 'OPEN WRITE REPLACE')

		/* Write the contents out to the file. */
		CHAROUT(fn, guisignal)

		CATCH NOTREADY
			CONDITION('M')
		FINALLY
			/* Close the file */
			STREAM(fn, 'C', 'CLOSE')
	END

	/* Success. */
	RETURN 0

/* ================== "Exit" menu item ====================== */
fileexit:
	/* Post a WM_CLOSE message to our main window. */
	guisendmsg(, 'POST CLOSE')

	RETURN

/* =================== "Cut" menu item ====================== */
editcut:
   /* To cut an ENTRY's currently selected text to the clipboard,
    * we call GuiRemoveCtlText() and omit the second arg.
    */
	guiremovectltext('TEXT')
	RETURN


/* ================== "Copy" menu item ====================== */
editcopy:
   /* To copy an ENTRY's currently selected text to the clipboard,
    * we send it a COPY message.
    */
	guisendmsg('TEXT', 'COPY')
	RETURN

/* ================== "Paste" menu item ===================== */
editpaste:
   /* To paste the clipboard over an ENTRY's current selection,
    * we call GuiAddCtlText, and omit the second arg.
    */
	guiaddctltext("TEXT")
	RETURN

/* =================== "Run as script" menu item ====================== */
rexxrunasscript: PROCEDURE
	/* Get whether the ENTRY's contents have been modified
	 * without yet being returned to us (ie, without us
	 * saving the modified contents to disk).
	 */
	guisendmsg('TEXT', 'GETMODIFY')
	flag = guisignal

	/* Get the contents of our ENTRY into the variable 'GuiSignal' as one string. */
	guisendmsg('TEXT', 'GETTEXT')

	/* Run it as a REXX script, passing it no args. */
	INTERPRET guisignal

	/* Reset the state prior to our fetching the contents */
	guisendmsg('TEXT', 'SETMODIFY', flag)

	/* Return to main */
	RETURN

/* ====================== WM_SIZE ==========================
 * This is our window's SIZE event handler. It is called by
 * Reginald when the user finishes sizing the window.
 *
 * ARG(1) =		The new inner width of the window (ie, the
 *				client area -- not including borders, title
 *				bar, and menu.
 * ARG(2) =		The new inner height.
 */

wm_size:
	/* The first time this event happens, our ENTRY has not
	 * yet been created. So, GuiSetCtlPlacement will cause
	 * a SYNTAX error. Let's trap that here, and just ignore
	 * it.
	 */
	DO
		/* Resize our ENTRY to fill the inner window. */
		guisetctlplacement('TEXT', , , ARG(3), ARG(4))

		CATCH SYNTAX
	END

	/* Don't let REXX GUI handle this message. */
	RETURN ""

/* ====================== WM_CLOSE ==========================
 * This is our window's CLOSE event handler. It is called by
 * Reginald when the user wants to close the window, or
 * someone has sent our window a CLOSE message (like we do
 * when the user selects the File->Exit menu item).
 */

wm_close:
	/* See if the contents need to be saved. If a problem or he cancels,
	 * then return 0 to prevent our window from closing.
	 */
/* 
	IF CheckIfSaved() \== 0 THEN RETURN 0
*/
	/* Don't return anything so that REXX GUI allows the window
	 * to be closed.
	 */
	RETURN
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-4-26  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:02