Silverfrost Forums

Welcome to our forums

Confirm_exit

18 Sep 2010 4:53 #6963

When i exit the code with Esc or Alt+x or other ways, to close all running processes, files and windows i do final closures which do a lot and lot of different things with the commands like this

       i = winio@('%ac[Alt+X]&', 
     *  '+','SET', kFrwdial_SettingsRd_D01, 1,
     *  '+','SET', k_Brahms_GoPauseStop012, 2,
     *  '+', Save_Code_Settings,
     *  '+', Close_AllCode_Files,
     *  '+', BringInitialTextWindowToTheTop,
     *  'exit' )

But ideal would be to have the functionality of 'confirm_exit' which asks you before if you really want to close window ( or do that by mistake ). So when you click Alt+X/Esc for example the window will ask you this question, and then if you say 'YES' it will do all the final SETs before the exit above and do the exit itself. But if you say NO - no action will be performed.

Any ideas how to make that functionality?

18 Sep 2010 6:21 #6964

Does %cc do what you want?

18 Sep 2010 9:56 #6965

Thanks for one more (already uncountable) good suggestion, Paul. I suppose you mean %cc? Most probably that's what does the trick, will doublecheck, because making search over my older codes i see that I've used %cc in numerous cases 10 years ago but by some reason stopped. Is %cc a newer addition?

18 Sep 2010 7:08 #6966

Hi Dan,

I stumbled over this too. The answer is that 'Exit' is for a REALLY quick hack, and 'Confirm_Exit' is for a nearly as quick hack. For real work, you have to do it yourself.

The problem is that there are several ways to close a window, including the File / Exit route, the close box on the window, Exit Windows, Alt-F4 etc. They can't all be 'Exit'. If in addition you use %cc, you have to think carefully or you get asked twice, or not at all, whether you want to save the file befoe exitting.

I do this in the main window:

       IA = WINIO@('%cc&', EndExit_FUNCTION)
       IA = WINIO@('%ew&', EndExit_FUNCTION)
       IA = WINIO@('%mn[[|,E&xit]]&',                EndExit_FUNCTION)

The End_Exit function looks like this:

      INTEGER FUNCTION EndExit_FUNCTION()
C      -----------------------------------
C
C      call back function for CLOSE. Clears graphics area, and re-sets 
C      permission to OPEN file or have NEW file
C
C      -----------------------------------------------------------------
       INCLUDE <WINDOWS.INS>
       EXTERNAL       File_FUNCTION

       COMMON/GREYS/  IGR(10),JGR(10),KGR(10),LGR(10),MGR(10),NGR(10)
C                                                                      .
       CHARACTER*(129)      FILENM
       COMMON  /FILES/      FILENM

       CHARACTER*(129)      PATH(4) 
       COMMON/PATHS/        PATH

       CHARACTER*(20)       FLTN(2), FLTS(2), CAPT
       SAVE
       INTEGER File_FUNCTION
       COMMON/EXITCODE/     INHIBIT_EXIT
C      ... second pass through this function? Always quit.
       EndExit_FUNCTION = 1
       IF (INHIBIT_EXIT .EQ. 0) THEN
           EndExit_FUNCTION = 0
           RETURN
           ENDIF
C      ... anything worth saving? I this case give option to save.
       IF (MGR(3) .NE. 0 .OR. MGR(4) .NE. 0) THEN
       IA=WINIO@('%ca[Quit using Program]&')
       IA=WINIO@('%si?   Do you want to save your data first?   &')
       IA=WINIO@('%ff%nl%cn%6`bt[Yes]     %6bt[No]     %6bt[Cancel]')
C      ... Cancelled or Close box - return, keeping main window open
       IF (IA .EQ. 0  .OR.  IA .EQ. 3) RETURN
C      ... Don't save. In this case go on to exit. Be aware that this 
C          could lead to a second pass through this callback function
       IF (IA. EQ. 2) THEN
           EndExit_FUNCTION = 0
           RETURN
           ENDIF
C      ... Save file - at least, give the option to save. User can still 
C          decide not to save. This can't be done with callback on the 
C          button.  Be aware that this 
C          could lead to a second pass through this callback function
       IF (IA .EQ. 1) THEN
            CAPT = 'File to save to'
            FLTN(1) = 'WSX files'
            FLTN(1) = 'All files'
            FLTS(1) = '*.wsx'
            FLTS(2) = '*.*'
            CALL GET_FILTERED_FILE@ (CAPT,FILEnm,PATH(1),FLTN,FLTS,2,0)
            CALL CORRECT_NAME(FILEnm,'.wsx')
            IJ = File_FUNCTION()                ! This is in this file
            INHIBIT_EXIT = 0
            ENDIF
       EndExit_FUNCTION = 0

C      ... If the user closes a window without a current file, we need  
C          to close the main window. Just in case this leads to a second 
C          pass, then set INHIBIT_EXIT to 0 (no), although it will be 
C          caught here the second time round. INHIBIT_EXIT is cleaner. 

       ELSE                  ! This is ELSE to the IF about MGR 3 and 4.
       INHIBIT_EXIT = 0
       EndExit_FUNCTION = 0
       ENDIF
       RETURN
       END 

In the context of my program, you can only save if MGR(3) or (4) is set appropriately - and these are also grey-out codes for something or other, probably saying that SAVE and SAVE_AS are available. File_FUNCTION contains the Fortran writes to actually save the file. Inhibit_Exit is set to 1 when a datafile is created or opened. I have afeeling that the above has 'belt and braces' code in it - I make no claims that it is either elegant or foolproof!

You may have to program more to have an 'Are you sure?' - but then how many chances do you give the user?

Eddie

20 Sep 2010 5:30 #6967

You've done nice trick with that, Litus! Will add to my weaponry with reference on you. This is a must for all programs. And i also missed %ew format which you use, that's together with %`cc looks like a later years additions, i do not see them in Clearwin older then circa 2000-2004. Lots of good new stuff. Thanks 😃

29 May 2013 12:23 #12289

i think %cc does not work together with 'confirm_exit', works only with plain 'exit' ....

Please login to reply.