/****************************** Module Header ******************************* * * Module Name: select.e * * 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. * ****************************************************************************/ ; SELECT.E Bryan Lewis 1/2/89 ; ; This DEFSELECT event is automatically triggered whenever the current file ; after an action is different from the one before the action. It never ; needs to be (and can't be) explicitly called. ; ; This is triggered after all command processing is done, if the then-current ; file is different from the one before the command. If a command switches ; to a temporary file but switches back to the original file before ending, ; this event will not be triggered. ; ; Because of other improvements -- keyset, tabs and margins are bound to ; the file now, and are selected at load time in a DEFLOAD event -- there's ; not much work to be done here. ; --------------------------------------------------------------------------- defselect universal selectdisabled universal loadstate getfileid fid dprintf( 'SELECT', .filename', fid = 'fid', loadstate = 'loadstate) if not .visible then -- process following only if file is visible return endif if selectdisabled <> 1 then 'ProcessSelect' endif ; --------------------------------------------------------------------------- ; defselect is processed after defmodify. Therefore lastselectedfid can be ; used to get the previous fid in InfoLineModify. For RefreshFormatMenu, ; prevselectedfid is saved additionally. ; Bugs in EPM: ; o The load event for the automatically first loaded file '.Untitled' is ; not executed. It is now executed in ProcessPostMain instead. ; o The select event for the automatically first loaded file '.Untitled' is ; executed too early, before ProcessLoad. That is suppressed here and ; ProcessSelect is executed in ProcessPostMain instead, too. defc ProcessSelect universal mainstate universal loadstate universal lastselectedfid universal lastcommand universal datetimecheckdisabled universal prevselectedfid getfileid fid if mainstate = 1 then mainstate = 2 endif lastcommand = '' -- Suppress too early select event for the automaticallay loaded file if loadstate = '' then dprintf( 'SELECT', 'suppress ProcessSelect for '.filename', fid = 'fid', loadstate = 'loadstate' (initial file)') return endif SetFileAVar( 'reflowmode', ReflowGetSelectedMode()) fFileSwitched = (fid <> lastselectedfid) if fFileSwitched then prevselectedfid = lastselectedfid endif lastselectedfid = fid if loadstate = 1 then -- if a defload was processed before loadstate = 2 'ProcessFilesLoaded' -- executes multiple ring commands that sometimes -- left the wrong file on top 'PostMe ProcessPostFilesLoaded' -- final processing, therefore posted datetimecheckdisabled = 1 loadstate = 0 endif if fFileSwitched then 'ProcessFileSwitched' endif -- mainstate is set to 0 by ProcessPostSelect, after the initial file loading 'PostMe ProcessPostSelect' datetimecheckdisabled = 0 ; --------------------------------------------------------------------------- ; This cmd is called once by defselect after all files were loaded. defc ProcessFilesLoaded universal mainstate universal loadstate universal lastfilesinring dprintf( 'FILESLOADED', '........ '.filename', mainstate = 'mainstate', loadstate = 'loadstate) -- Write name of all files in the ring to NEPMD.INI. -- Do this only for single files, not for wildcards in filespec. if lastfilesinring = '' then lastfilesinring = 0 endif ; --------------------------------------------------------------------------- ; This cmd is posted once by defselect after all files are loaded. defc ProcessPostFilesLoaded universal firstinringfid universal vepm_pointer universal edithistorydisabled universal loadhistorydisabled -- Set firstinringfid if unset if firstinringfid = '' then getfileid fid firstinringfid = fid endif dprintf( 'FILESLOADED', 'PostFilesLoaded for '.filename) -- Reset the mouse pointer, set by MAIN.E:defmain to WAIT_POINTER mouse_setpointer vepm_pointer -- Workaround. Sometimes the initial font for just 1 loaded file was the -- default PM font (9.Warp Sans), but had the metrics of the correct -- TextFont (12.System VIO). if filesinring() = 1 then KeyPath = '\NEPMD\User\Fonts\Text' TextFont = QueryConfigKey( KeyPath) 'ProcessFontRequest' ConvertToEFont( TextFont) endif -- Query type and change to dir of type 1 'ChangeWorkDirLast' -- Type 0 is handled by the program object -- Type 2 is handled in ProcessFileSwitched and PostProcessMouse dprintf( 'FILESLOADED', 'HookExecute postfilesloaded: 'HookGet( 'postfilesloaded')) 'HookExecute postfilesloaded' dprintf( 'FILESLOADED', 'HookExecuteOnce postfilesloadedonce: 'HookGet( 'postfilesloadedonce')) 'HookExecuteOnce postfilesloadedonce' if HookIsDefined( 'postpostfilesloadedonce') then 'PostMe HookExecuteOnce postpostfilesloadedonce' dprintf( 'FILESLOADED', 'HookExecuteOnce postpostfilesloadedonce: 'HookGet( 'postpostfilesloadedonce')) endif -- Always (re-)enable Edit and Load history after startup edithistorydisabled = 0 loadhistorydisabled = 0 -- Another try to work around the strange font bug. 'PostMe Refresh' ; --------------------------------------------------------------------------- ; Change to dir of set type 0 defc ChangeWorkDirProgram KeyPath = '\NEPMD\User\StartDir\WorkDir\Type' WorkDirType = QueryConfigKey( KeyPath) KeyPath = '\NEPMD\User\ProgramObjects\StartupDir' StartupDir = ExpandEnvVars( QueryConfigKey( KeyPath)) if WorkDirType = 0 then call Directory2( StartupDir) endif ; --------------------------------------------------------------------------- ; Change to dir of set type 1 defc ChangeWorkDirLast KeyPath = '\NEPMD\User\StartDir\WorkDir\Type' WorkDirType = QueryConfigKey( KeyPath) KeyPath = '\NEPMD\User\StartDir\WorkDir\Last' LastWorkDir = QueryConfigKey( KeyPath) if WorkDirType = 1 then if NepmdDirExists( LastWorkDir) = 1 then call Directory2( LastWorkDir) endif endif ; --------------------------------------------------------------------------- ; Change to dir of set type 2 defc ChangeWorkDirSelected KeyPath = '\NEPMD\User\StartDir\WorkDir\Type' WorkDirType = QueryConfigKey( KeyPath) KeyPath = '\NEPMD\User\ProgramObjects\StartupDir' StartupDir = ExpandEnvVars( QueryConfigKey( KeyPath)) if WorkDirType = 2 then Filename = .filename if pos( ':\', Filename) then call Directory2( Filename'\..') else call Directory2( StartupDir) endif endif ; --------------------------------------------------------------------------- ; Executed by defselect once after all file loading has been processed. defc ProcessFileSwitched universal prevselectedfid -- lastselectedfid may be eqal to current fid. E.g. a select event can -- happen for the same file again. prevselectedfid is only changed if -- lastselcetedfid is different from current fid. dprintf( 'SELECT', 'FileSwitched for '.filename) -- Query type and change to dir of type 2 'ChangeWorkDirSelected' -- Types 0 and 1 are handled in PostProcessFilesLoaded -- and PostProcessMouse -- Determine modechanged event and process hook Mode = GetMode() PrevMode = '' if prevselectedfid <> '' then PrevMode = GetAVar( prevselectedfid'.mode') endif if Mode <> PrevMode | prevselectedfid = '' then 'HookExecute modechanged' endif -- Determine expandmodechanged event ExpandMode = GetExpandMode() PrevExpandMode = '' if prevselectedfid <> '' then -- .expandmode is saved by MODEEXEC.E:"defc SetExpandMode" PrevExpandMode = GetAVar( prevselectedfid'.expandmode') endif if ExpandMode <> PrevExpandMode | prevselectedfid = '' then -- Process hook 'HookExecute expandmodechanged' endif -- Refresh the coding style file array var CodingStyle = QueryModeKey( Mode, 'CodingStyle') if GetFileAVar( 'codingstyle') <> CodingStyle then SetFileAVar( 'codingstyle', CodingStyle) endif -- Store FileAVar with some of 'I B P K' 'SetExpandOverrides' -- Process fileswitched hooks -- o Use the 'fileswiched' hooks for settings, that you want to change on -- every defselect event. That should be only stuff, that doesn't stick -- with the file. If your stuff sticks, better use the 'load' hook to -- avoid loss of performance and stability. 'HookExecute fileswitched' -- usually contains ProcessSelectSettings, -- to be used for user additions as well 'HookExecuteOnce fileswitchedonce' -- user additions, deleted after execution 'HookExecute postfileswitched' -- usually contains ProcessSelectRefresh ; --------------------------------------------------------------------------- ; In contrast to ProcessFilesLoaded, this is also called on quitting a file. defc ProcessPostSelect universal mainstate universal lastfilesinring universal firstinringfid universal loaddisabledfid universal lastselectedreflowmode universal savelastringdisabled dprintf( 'SELECT', 'PostSelect for '.filename) if mainstate <> 0 then dprintf( 'SELECT', 'PostSelect: mainstate before = 'mainstate', reset to 0') endif -- Reset mainstate here, after the initial file loading mainstate = 0 -- Reset firstinringfid if that file is not in ring anymore if not validatefileid( firstinringfid) then firstinringfid = '' endif -- Get line end char for current file if unset LineEndType = GetFileAVar( 'lineend') if not LineEndType then FileLineEnd = QueryFileLineEnd() SetFileAVar( 'lineend', FileLineEnd) LineEndType = FileLineEnd endif getfileid startfid fNumberOfFilesAltered = (lastfilesinring <> filesinring()) fFileNumberAlreadySet = (IsNum( GetFileNumber( startfid))) -- If number of files in ring has changed or -- if FileNumber of current file is not set if fNumberOfFilesAltered | not fFileNumberAlreadySet then -- Write number for all files in the ring to an array var -- See FILELIST.E call RingSetFileNumber() getfileid fid if fid <> startfid then call pActivateFile( startfid) endif if fNumberOfFilesAltered then -- savelastringdisabled is set by RestoreLastRing and reset here. -- Check if locally disabled if savelastringdisabled then -- Enable it for after that savelastringdisabled = 0 else -- Don't overwrite saved last rings when opening a virtual file if leftstr( .filename, 1) <> '.' then if Exist( .filename) then -- Write position and name of all files in the ring to NEPMD.INI -- See FILELIST.E 'RefreshLastRing' endif endif endif getfileid fid if fid <> startfid then call pActivateFile( startfid) endif -- Save value as universal lastfilesinring = filesinring() endif endif 'PostMe HighlightLast' 'HookExecute postselect' 'HookExecuteOnce postselectonce' dprintf( 'SELECT', 'PostSelect ended for '.filename) ; --------------------------------------------------------------------------- ; For call with PostMe. Determines highlight type at execution time from ; lastcommand. Then either HighlightMatch or HighlightCursor is executed. defc HighlightLast universal lastcommand parse value lastcommand with CmdWrd CmdArgs fHighlighted = (lowcase( CmdWrd) = 'highlightmatch') if fHighlighted then 'HighlightMatch' CmdArgs else 'HighlightCursor' endif ; --------------------------------------------------------------------------- ; Suppress select processing. Used for temporary .filename changes and to ; avoid a load and select triggering, that otherwise would be executed on ; canceling the action. Even executing .filename = newname triggers a load ; and a followed select event. ; 'DisableSelect' Disable select processing for all files (e.g. ; before a Name or SaveAs command). ; 'EnableSelect' Enable select processsing for all files (e.g. ; after a Name or SaveAs command was successful. ; The load and select events are internally posted, ; so that the EnableSelect command will reset the ; flag before it's been executed. ; 'PostMe EnableSelect' Enable select processsing for all files after ; current command (e.g. Name or SaveAs) was ; completely executed. That triggers defload and ; after that, defselect before the disable flag ; was reset. As a result, defselect will work ; normally from the next processed file on. defc DisableSelect universal selectdisabled selectdisabled = 1 defc EnableSelect universal selectdisabled selectdisabled = 0 ; --------------------------------------------------------------------------- ; Dummy proc for compatibility. Select_edit_keys() isn't used any more. /* defproc select_edit_keys() */