/****************************** Module Header ******************************* * * Module Name: modify.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. * ****************************************************************************/ ; MODIFY.E Bryan Lewis 12/31/88 ; ; New in EPM. This DEFMODIFY event is triggered when a file's number of ; modifications (.modify): ; - goes from zero to nonzero (first modification, so we can change the ; textcolor or title to indicate that the file needs to be saved; ; - goes from nonzero to zero (so we can return to the safe textcolor, ; usually after a save); ; - goes from less than .autosave to greater than or equal to .autosave. ; ; ; Note: .modify does not always increase smoothly, one increment at a time. ; For instance, changing a line and hitting Enter increases .modify by 2, ; because it registers the change to the previous line as well as the new ; line. So we can't expect .modify to be exactly 1; we have to look for ; a transition from zero to nonzero. ; ; Note 2: E will not retrigger this event while the event is in ; progress, to protect against infinite recursion. So if you make a lot ; of changes to a file in the process of autosaving it, it won't get autosaved ; twice. ; ; We've provided three methods of showing the modified status. ; 1. The COLOR method changes the window color, for a very obvious indicator. ; 2. The FKTEXTCOLOR method changes the color of the bottom line of the ; screen, for EOS2 only. ; 3. The TITLE method does one of two things. For EOS2 it changes the color ; of the filename. For EPM it adds the string " (mod)" to the title bar. ; This isn't as obvious as COLOR, but you can check it even when the file ; is shrunk to an icon by clicking on the icon. ; ; You, the macro writer, can add to or replace this behavior. ; 1. You can write defmodify procedures anywhere in your MYSTUFF.E or ; MYKEYS.E files. All defmodify procedures will be executed in sequence, ; just as definit preocedures are. The pieces can be anywhere. ; 2. Or you can write a DEFMODIFY event in a linked module, and it will ; replace this one entirely. For example, create a file NEWMOD.E with ; your defmodify proc; compile it separately (ETPM NEWMOD); add a link ; statement (link 'newmod') to your MYKEYS.E or MYSTUFF.E file. ; --------------------------------------------------------------------------- defc DiscardChanges .modify = 0 .autosave = 0 -- Sometimes the status bar color is not reset after resetting .modify. -- Ensure that it's renewed. 'SetStatusLine' ; --------------------------------------------------------------------------- ; This is commonly used for to reset .modify of vitual and shell files. defproc FileShouldBeDiscarded Filename = arg( 1) if Filename = '' then Filename = .filename endif fVirtual = IsVirtual( Filename) fShell = IsAShell() KeyPath = '\NEPMD\User\Modify\DiscardChanges' fDiscardChanges = 0 if not .visible then -- Not visible files: always reset fDiscardChanges = 1 elseif Filename = GetUnnamedFilename() then -- .Untitled files fDiscardChanges = QueryConfigKey( KeyPath'\Untitled') elseif fShell then -- Shell files if fVirtual then -- New shell files fDiscardChanges = QueryConfigKey( KeyPath'\NewShells') else -- Restored shell files fDiscardChanges = QueryConfigKey( KeyPath'\RestoredShells') endif elseif fVirtual then -- Other virtual files fDiscardChanges = QueryConfigKey( KeyPath'\OtherVirtual') endif return fDiscardChanges ; --------------------------------------------------------------------------- defc RestoreModify ModifyNum = strip( arg( 1)) .modify = ModifyNum ; --------------------------------------------------------------------------- ; Not used. Was added for a test in INFOLINE.E. ; Can be used to disable defmodify processing. Since defmodify code is used ; at several places, the execution of the defmodify code has also be checked ; for this universal var at all these places to disable them all. ;defc DisableModify ; universal modifydisabled ; modifydisabled = 1 ; ; --------------------------------------------------------------------------- ;defc EnableModify ; universal modifydisabled ; modifydisabled = 0 ; ; --------------------------------------------------------------------------- ; defmodify is triggered ; 1) when .modify changes from 0 to > 0 ; 2) when .modify changes from < .autosave to >= .autosave ; 3) when .modify changes from > 0 to 0 ; 4) when a modified file is selected after a non-modified file ; 5) when a non-modified file is selected after a modified file ; Changing .modify causes a new undo state, except for the following: ; If .modify is set from 0 to 1, no new undo state is created. defmodify fFileDiscarded = 0 if .modify then -- This ensures that special files can be closed without -- popping up a message box that asks "Are you sure?" if FileShouldBeDiscarded() then 'DiscardChanges' fFileDiscarded = 1 endif endif if not fFileDiscarded then -- Lock on modify 'LockOnModify ?' -- Update info lines if required 'InfolineModify' -- Do autosave on case 2) if .autosave and .modify >= .autosave then call MakeAutoSave() endif endif -- Execute user macros 'HookExecute modify' 'HookExecuteOnce modifyonce'