// // EVENT-MAC.VDM Christian Ziemski 07.02.2003 // 17.03.2003 // // Test-macro for the File_Event_Macros. // // Simply execute it and then open/close a file with or without altering it. // To deactivate it: There is a {Tools} menu entry for this. // // requires 6.10.2 03/15/03 ! // //-------------------------------------------------------------------------- // // Comments about the behavior: // // // 1) if file was altered and manually saved before close: // Is_Altered=0 // Is_Altered_File=16 // That's correct. // // 2) [ >>> still a problem! But a workaround is possible. See below.] // If file was altered and user chooses "save=yes" upon close: // After 111 both Is_Altered and Is_Altered_File are reset. // So 113 can't say if the file has been altered. // It should be like in 1): Is_Altered_File should remain set! // // 4) [ >>> only optical? ] // If file was not altered and then closed: // it's still visible in step 113: shouldn't be. // (Not important, but not consistent.) // (Perhaps a Clear-Screen or so missing after 111? ) // //----------- // 3) [ >>> solved via new Is_Altered_NoSave() in 6.10.2 03/15/03] // // If file was altered and then closed and user chooses "save=no": // Both Is_Altered* are correctly set first but remain SET *up_to_the_end* // So 111 and 113 can't decide by themself what they should do. // Is_Altered should be reset at least after 111. // // Perhaps Is_Altered should be reset in this case just *before* 111? // I'm not exactly sure here, since the buffer IS altered (but user wanted not to save it). // 111 should be able to decide whether the buffers content will be saved just after it. // (That means: whether the buffers content is valid or not.) // // And: like 4) // //-------------------------------------------------------------------------- #99=Dialog_Input_1(99,"`Test Event Macros`, `This demo macro shows the behavior and usage of the file event macros.`, `After choosing 'ok' below it will put some dialogs into the event macros. To show the effects please load/[edit]/[don't] save some files.`, `If you wish to stop the demo choose the additional {Tools} menu entry 'Deactivate EVENT-MAC'`, `[&OK]`, `[&Cancel]`",SET+APP+CENTER,0,0) if (#99 != 1) { return } // Put an entry in the {Tools} menu to disable this demo again #104=Buf_Num Buf_Switch(Buf_Free) Reg_Ins(123) Search('Deactivate EVENT-MAC', BEGIN+NOERR) if (EM) { Reg_Set(123,%128 Deactivate EVENT-MAC RS(106, `RE(110) RE(111) RE(112) RE(113) #104=Buf_Num Buf_Switch(Buf_Free) Reg_Ins(123) Search('Deactivate EVENT-MAC', BEGIN+NOERR) if (!EM) {Line(2) Del_Line(-3)} Reg_Copy_Block(123, 0, File_Size) Buf_Quit(OK) Buf_Switch(#104) Return(0, DELETE)`) Call(106) %, APPEND) } Buf_Quit(OK) Buf_Switch(#104) // Enable the event macros Config(F_E_F_Macro, 1) // The Pre-Open event-macro Reg_Set(112, % Num_Str(Is_Altered, 11) Num_Str(Is_Altered_File, 12) Num_Str(Buf_Num, 13) Update #99=Dialog_Input_1(99,"`Test Event Macros`, `Now in Pre-Open 112`, `.\PATHNAME = |(PATHNAME)`, `Is_Altered \t\t = |@(11) \nIs_Altered_File \t\t = |@(12) \nBuf_Num \t\t = |@(13)`, `e.g. File RCS-Check-Out`, `The buffer is already created.`, `[&OK]`",SET+APP+CENTER,0,0) %) // The File-Open event-macro Reg_Set(110, % Num_Str(Is_Altered, 11) Num_Str(Is_Altered_File, 12) Num_Str(Buf_Num, 13) Update #99=Dialog_Input_1(99,"`Test Event Macros`, `Now in File-Open 110`, `.\PATHNAME = |(PATHNAME)`, `Is_Altered \t\t = |@(11) \nIs_Altered_File \t\t = |@(12) \nBuf_Num \t\t = |@(13)`, `The file is opened in the buffer.`, `[&OK]`",SET+APP+CENTER,0,0) %) // The File-Close event-macro Reg_Set(111, % Num_Str(Is_Altered, 11) Num_Str(Is_Altered_File, 12) Num_Str(Is_Altered_NoSave, 14) Num_Str(Buf_Num, 13) Reg_Empty(15) if (Is_Altered) { if (Is_Altered_Nosave) { Reg_Set(15, "File is altered since last save but will NOT be saved to disk due to user's choice.") } else { Reg_Set(15, "The file will be saved to disk just after this dialog.") } } else { Reg_Set(15, "The file will not be saved to disk due to no changes since last save.") } #80 = Is_Altered_File // Workaround for incorrectly reset flag, desribed at top Update Reg_Copy_Block(30, 0,20) #99=Dialog_Input_1(99,"`Test Event Macros`, `Now in File-Close 111`, `.\PATHNAME = |(PATHNAME)`, `Is_Altered \t\t = |@(11) \nIs_Altered_File \t\t = |@(12) \nIs_Altered_NoSave \t = |@(14) \nBuf_Num \t\t = |@(13)`, `|@(15)`, `First 20 bytes of buffer:`, `|@(30)`, `[&OK]`",SET+APP+CENTER,0,0) %) // The Post-Close event-macro Reg_Set(113, % Num_Str(Is_Altered, 11) Num_Str(Is_Altered_File, 12) Num_Str(Buf_Num, 13) Reg_Load_Part(30, PATHNAME, 0,20) Reg_Empty(15) if (Is_Altered) { if (Is_Altered_Nosave) { Reg_Set(15, "File was altered since last save but was NOT saved to disk due to user's choice.") } else { Reg_Set(15, "The file was saved to disk just before this dialog.") } } else { Reg_Empty(15) } Reg_Empty(16) if (Is_Altered_File) { Reg_Set(16, "File was altered since last open: e.g. RCS-Check-In") } else { if (#80) { Reg_Set(16, "Problem: File was altered since last open, but Is_Altered_File() is incorrectly reset. \nCan't officially say whether file has been altered. :-(") } } Update #99=Dialog_Input_1(99,"`Test Event Macros`, `Now in Post-Close 113`, `.\PATHNAME = |(PATHNAME)`, `Is_Altered \t\t = |@(11) \nIs_Altered_File \t\t = |@(12) \nIs_Altered_NoSave \t = |@(14) \nBuf_Num \t\t = |@(13)`, `|@(15)`, `|@(16)`, `The buffer is still existing, but file assignment is gone.`, `First 20 bytes of file on disk:`, `|@(30)`, `[&OK]`",SET+APP+CENTER,0,0) %)