/****************************** Module Header ******************************* * * Module Name: toolbar.erx * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id: toolbar.erx 4480 2021-04-30 16:31:27Z aschn $ * * =========================================================================== * * 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. * ****************************************************************************/ /* EPM REXX */ /* This helper macro meets the limitation of E strings, whose maximum */ /* length is 1600 chars only. Paths from bitmap filenames are stripped. */ /* Therefore im- and export with this macros works properly compared with */ /* EPM's standard actions via the settings dialog. */ /* */ /* Toolbar export: */ /* */ /* Syntax: */ /* rx toolbar EXPORT IniFile IniAppl ToolbarName [TmpToolbarName] */ /* */ /* ToolbarName = Name of active toolbar, saved to ini. */ /* TmpToolbarName = Name to which current toolbar is saved first */ /* in order to compare it with CurToolbar and ask */ /* user if it shall be saved. */ /* If omitted, no temporary toolbar is created and */ /* toolbar is saved directly to ToolBarName. */ /* */ /* Returns: */ /* 0 on success */ /* 1 canceled by user */ /* 13 data not found in ini */ /* */ /* Toolbar import: */ /* */ /* Syntax: */ /* rx toolbar IMPORT IniFile IniAppl ToolbarName BarFile */ /* */ /* Returns: */ /* 0 on success */ /* 1 on error (data not written) */ env = 'OS2ENVIRONMENT' ret = 1 call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs parse arg Action . if Action = 'EXPORT' then do parse arg Action IniFile IniAppl ToolbarName TmpToolbarName . /* Query toolbar from ini */ next = SysIni( IniFile, IniAppl, ToolbarName) if next = 'ERROR:' then return 13 else CurToolbar = strip( next, 't', '00'x) if CurToolbar = '' then return 13 /* Remove paths from bitmaps */ CurToolbar = StripBmpPaths( CurToolbar) /* Write CurToolbar back to ini */ next = SysIni( IniFile, IniAppl, ToolbarName, CurToolbar) ExportToolbar = CurToolbar fUseTmpBar = 0 if TmpToolbarName <> '' then fUseTmpBar = 1 if fUseTmpBar then do /* Query toolbar from ini */ next = SysIni( IniFile, IniAppl, TmpToolbarName) if next = 'ERROR:' then return 13 else TmpToolbar = strip( next, 't', '00'x) /* Remove paths from bitmaps */ TmpToolbar = StripBmpPaths( TmpToolbar) /* Check if equal */ if CurToolbar <> TmpToolbar then do /* Ask if toolbar shall be saved */ MsgText = 'Current toolbar is modified. Save it first?' MsgTitle = 'Modified toolbar "'ToolbarName'"' MsgButtons = 'YESNOCANCEL' MsgBitmap = 'QUESTION' ret = RxMessageBox( MsgText, MsgTitle, MsgButtons, MsgBitmap) /* If answer = yes, save it to ini */ if ret = 6 then /* YES */ next = SysIni( IniFile, IniAppl, ToolbarName, TmpToolbar'00'x) else if ret = 2 then /* CANCEL */ return 1 ExportToolbar = TmpToolbar end end /* Build .bar filename */ UserDir = strip( value( 'NEPMD_USERDIR', , env), 't', '\') BarFile = UserDir'\bar\'ToolbarName'.bar' if fUseTmpBar then do /* Selct a filename. Default is BarFile */ 'SaveUserstring' 'FileDlg Select a filename for toolbar export, SetUserstring,' BarFile 'extract /userstring' if Userstring.1 = '' then /* CANCEL */ return 1 else BarFile = Userstring.1 'RestoreUserstring' end /* Write BarFile to UserDir without check if exists */ call SysFileDelete BarFile call charout BarFile, ExportToolbar call stream BarFile, 'c', 'close' 'SayError Toolbar exported to' BarFile ret = 0 end if action = 'IMPORT' then do parse arg Action IniFile IniAppl ToolbarName BarFile BarFile = strip( BarFile) if left( BarFile, 1) = '"' & right( BarFile, 1) = '"' then BarFile = substr( BarFile, 2, length( BarFile) - 2) /* Read toolbar from file */ call stream BarFile, 'c', 'open read' BarLength = stream( BarFile, 'c', 'query size') ImportToolbar = charin( BarFile, 1, BarLength) call stream BarFile, 'c', 'close' /* Remove paths from bitmaps */ ImportToolbar = StripBmpPaths( ImportToolbar) /* Write toolbar to ini */ next = SysIni( IniFile, IniAppl, ToolbarName, ImportToolbar'00'x) if next = 'ERROR:' then ret = 1 else ret = 0 end return ret /**************************************************************************** * Remove all paths from toolbar data. EPM saves a toolbar with paths for * its bitmaps. That leads to problems for exporting toolbars to other * systems. ****************************************************************************/ StripBmpPaths: procedure Toolbar = arg(1) startpos = 1 endpos = length( Toolbar) NewToolbar = '' Sep = '09'x /* .bmp filenames are enclosed in tab chars */ do while startpos < endpos new = '' bmppos = pos( '.BMP'Sep, translate( Toolbar), startpos ) if bmppos > 0 then do /* next = chars until next occurence of ".BMP"\9, including ".BMP" */ /* new = next without path */ next = substr( Toolbar, startpos, bmppos + 3 - startpos + 1) startpos = startpos + length( next) seppos = lastpos( Sep, next) lbslpos = lastpos( '\', next) if lbslpos > seppos then do new = substr( next, 1, seppos)''substr( next, lbslpos + 1) /*say substr( next, seppos + 1)' --> 'substr( next, lbslpos + 1)*/ end else do new = next /*say substr( next, seppos + 1 )*/ end end else do /* new = rest, end of loop */ new = substr( Toolbar, startpos) startpos = endpos + 1 end /* append new to NewToolbar */ NewToolbar = NewToolbar''new end return NewToolbar