/****************************** Module Header ******************************* * * Module Name: omitopenbox.erx * * Syntax: rx omitopenbox * * with * = query | toggle | 1 | 0 | on | off | yes | no * (query retrieves the object settings for object \1.) * * This EPM REXX file is used for the setting * Programm objects -> File open selection: Omit open box. * * When activated, the EPM parameter /o is added to the program objects. Then * the opening of the additional EPM open box is bypassed and the file dialog * is opened directly. * * The open box has the advantage that it provides a history list with * previously selected files. * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ /* ----------------- Standard ERX initialization follows ----------------- */ SIGNAL ON HALT NAME Halt SIGNAL ON ERROR NAME Error SIGNAL ON SYNTAX NAME Error SIGNAL ON NOVALUE NAME Error SIGNAL ON FAILURE NAME Error SIGNAL ON NOTREADY NAME Error env = 'OS2ENVIRONMENT' TRUE = (1 = 1) FALSE = (0 = 1) CrLf = '0d0a'x Redirection = '>NUL 2>&1' PARSE SOURCE . . ThisFile GlobalVars = 'env TRUE FALSE Redirection ERROR. ThisFile' GlobalVars = GlobalVars 'ErrorQueueName ErrorMessage' /* some OS/2 Error codes */ ERROR.NO_ERROR = 0 ERROR.INVALID_FUNCTION = 1 ERROR.FILE_NOT_FOUND = 2 ERROR.PATH_NOT_FOUND = 3 ERROR.ACCESS_DENIED = 5 ERROR.NOT_ENOUGH_MEMORY = 8 ERROR.INVALID_FORMAT = 11 ERROR.INVALID_DATA = 13 ERROR.NO_MORE_FILES = 18 ERROR.WRITE_FAULT = 29 ERROR.READ_FAULT = 30 ERROR.SHARING_VIOLATION = 32 ERROR.GEN_FAILURE = 31 ERROR.INVALID_PARAMETER = 87 ERROR.ENVVAR_NOT_FOUND = 204 rc = ERROR.NO_ERROR ErrorQueueName = VALUE( 'NEPMD_RXQUEUE',, env) ErrorMessage = '' CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' CALL SysLoadFuncs /* ----------------- Standard ERX initialization ends -------------------- */ /* ------------- Configuration ---------------- */ UserDir = VALUE( 'NEPMD_USERDIR',, env) Ini._Filename = UserDir'\bin\nepmd.ini' Ini._RegKeys = 'RegKeys' Ini._RegContainer = 'RegContainer' Ini._RegDefaults = 'RegDefaults' Key._MainPath = '\NEPMD\User\ProgramObjects\OmitOpenBox' /* -------------------------------------------- */ GlobalVars = GlobalVars 'Ini. Key.' CALL RxFuncAdd 'WPToolsLoadFuncs', 'WPTOOLS', 'WPToolsLoadFuncs' CALL WPToolsLoadFuncs DO 1 PARSE ARG Args Args = TRANSLATE( STRIP( Args)) SELECT WHEN (POS( Args, 'ON') = 1 | POS( Args, 'YES') = 1 | Args = 1) THEN Action = 'ON' WHEN (POS( Args, 'OFF') = 1 | POS( Args, 'NO') = 1 | Args = 0) THEN Action = 'OFF' WHEN (POS( Args, 'TOGGLE') = 1) THEN Action = 'TOGGLE' WHEN (POS( Args, 'QUERY') = 1) THEN Action = 'QUERY' OTHERWISE rc = ERROR.INVALID_PARAMETER ErrorMessage = 'Error: No action specified. Parameter' ||, ' for OMITOPENBOX.ERX is missing.' LEAVE END /* Init stem var */ Obj. = '' Obj.0 = 0 /* Get user sub keys from RegContainer */ UserSubKeys = '' next = SysIni( Ini._Filename, Ini._RegContainer, Key._MainPath) next = STRIP( next, 'T', '00'x) IF \(next = '' | next = 'ERROR:') THEN UserSubKeys = next /* Add user objects to Obj. */ rest = UserSubKeys DO FOREVER PARSE VAR rest SubKey'00'x''rest IF SubKey = '' THEN LEAVE /* Check items for integer > 0 */ IF VERIFY( SubKey, '0123456789') <> 0 THEN ITERATE IF SubKey = 0 THEN ITERATE /* Query key */ next = SysIni( Ini._Filename, Ini._RegKeys, Key._MainPath'\'SubKey) next = STRIP( next, 'T', '00'x) IF \(next = '' | next = 'ERROR:') THEN DO /* Add next to Obj. */ n = Obj.0 + 1 Obj.n = next Obj.0 = n END END IF Obj.0 = 0 THEN DO /* Get all default keys */ DefaultKey. = '' DefaultKey.0 = '' next = SysIni( Ini._Filename, Ini._RegDefaults, 'ALL:', 'DefaultKey.') SearchKey = Key._MainPath'\' SearchLen = LENGTH( SearchKey) DO k = 1 TO DefaultKey.0 /* Find keys that start with SearchKey */ IF LEFT( DefaultKey.k, SearchLen) = SearchKey THEN DO /* Get reamaining key string */ SubKey = SUBSTR( DefaultKey.k, SearchLen + 1) /* Get first path segment */ PARSE VAR SubKey SubKey'\'. /* Check items for integer > 0 */ IF VERIFY( SubKey, '0123456789') <> 0 THEN ITERATE IF SubKey = 0 THEN ITERATE /* Query key */ next = SysIni( Ini._Filename, Ini._RegDefaults, DefaultKey.k) next = STRIP( next, 'T', '00'x) IF \(next = '' | next = 'ERROR:') THEN DO /* Add next to Obj. */ n = Obj.0 + 1 Obj.n = next Obj.0 = n END END END END /* Query current setting from first object */ Obj = Obj.1 rcx = WPToolsQueryObject( Obj, 'Class', 'Title', 'Setup', 'Location') IF (rcx = 1) THEN fOldO = CheckO( Setup) ELSE DO ErrorMessage = 'Error: Setup string couldn''t be queried from 'Obj'.' rc = ERROR.FILE_NOT_FOUND LEAVE END IF (Action = 'QUERY') THEN EXIT( fOldO) OldState = WORD( 'OFF ON', fOldO + 1) /* 'DPrintf Current state of parameter "/o" is: 'OldState */ IF Action = OldState THEN DO CALL SayText 'No changes.' LEAVE END /* Toggle presence of /o */ fNewO = \fOldO i = 0 DO n = 1 to Obj.0 IF Obj.n = '' THEN ITERATE rcx = ToggleO( Obj.n, fNewO) IF (rcx = 1) THEN i = i + 1 END CALL SayText 'Changed 'i' object(s). Restart all EPM windows to make' ||, ' the changes take effect.' END CALL SayErrorMessage EXIT( rc) /* ----------------------------------------------------------------------- */ CheckO: PROCEDURE PARSE ARG Setup PARSE VAR Setup First'PARAMETERS='Params';'Rest wp = WORDPOS( '/O', TRANSLATE( Params)) RETURN( wp > 0) /* ----------------------------------------------------------------------- */ ToggleO: PROCEDURE EXPOSE (GlobalVars) PARSE ARG Obj, fAddO rcx = WPToolsQueryObject( Obj, 'Class', 'Title', 'Setup', 'Location') IF (rcx = 1) THEN DO PARSE VAR Setup First'PARAMETERS='Params';'Rest wp = WORDPOS( '/O', TRANSLATE( Params)) SELECT WHEN (fAddO & wp = 0) THEN Params = '/o 'Params WHEN (\fAddO & wp > 0) THEN Params = DELWORD( Params, wp, 1) OTHERWISE NOP END /* Remove trailing "%*" */ IF (WORD( Params, WORDS( Params)) = '"%*"') THEN Params = STRIP( DELWORD( Params, WORDS( Params)), 'T') /* Setting an empty parameter doesn't work */ /* The doublequotes are required for filenames with spaces */ IF Params = '' THEN Params = '"%*"' Setup = First'PARAMETERS='Params';'Rest /* 'DPrintf' Obj 'PARAMETERS='Params';' */ rcx = SysSetObjectData( Obj, Setup) rc2 = SysSaveObject( Obj, 0) END RETURN( rcx) /* --------------------- Standard ERX macros follow ---------------------- */ /* ----------------------------------------------------------------------- */ SayText: PROCEDURE EXPOSE (GlobalVars) PARSE ARG Message SELECT WHEN ADDRESS() = 'EPM' THEN 'sayerror' Message OTHERWISE SAY Message END RETURN( '') /* ----------------------------------------------------------------------- */ SayErrorMessage: PROCEDURE EXPOSE (GlobalVars) SELECT WHEN (ErrorMessage = '') THEN NOP /* Called by frame program: insert error */ /* message into private queue */ WHEN (ErrorQueueName <> '') THEN DO rcx = RXQUEUE( 'SET', ErrorQueueName) PUSH ErrorMessage END /* Called directly */ WHEN ADDRESS() = 'EPM' THEN DO /*'sayerror' ErrorMessage*/ ThisFileName = SUBSTR( ThisFile, LASTPOS( '\', ThisFile) + 1) rcx = RxMessageBox( ErrorMessage, TRANSLATE( ThisFileName),, 'OK', 'ERROR') END /* Called directly */ OTHERWISE DO SAY ErrorMessage 'PAUSE' END END RETURN( '') /* ----------------------------------------------------------------------- */ Halt: ErrorMessage = 'Interrupted by user.' CALL SayErrorMessage EXIT( ERROR.GEN_FAILURE) /* ----------------------------------------------------------------------- */ /* Give a standard REXX error message and jump to the error line */ Error: /* sigl must be saved to not get overwritten by SayErrorMessage call */ ErrorLine = sigl /* As an extension to the standard REXX error messages, */ /* the error condition will be appended to the error text. */ ConditionText = 'Condition: 'CONDITION( 'C') ConditionDescription = CONDITION( 'D') IF ConditionDescription <> '' THEN ConditionText = ConditionText', Reason: 'ConditionDescription ErrText = ERRORTEXT( rc) IF ErrText = '' THEN ErrText = ConditionText ELSE ErrText = ErrText', 'ConditionText ErrorMessage = 'REX'RIGHT( rc, 4, 0)': Error 'rc' running 'ThisFile',' ||, ' line 'sigl': 'ErrText CALL SayErrorMessage IF ADDRESS() = 'EPM' THEN "e "ThisFile" 'postme "ErrorLine"'" /* Ensure that rc <> 0 is returned */ IF rc = 0 THEN rc = ERROR.GEN_FAILURE EXIT( rc)