Skip to content

Commit e365ed7

Browse files
authored
Merge pull request #15 from ukos-git/fix_BeforeQuitHook
Fix before quit hook
2 parents a64891c + 061d83c commit e365ed7

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

procedures/CodeBrowser.ipf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,13 +765,15 @@ Function saveReParse()
765765
savedVariables[][0] = 0
766766
End
767767

768-
Function saveResetStorage()
768+
// Kill all storage objects
769+
//
770+
// note: if objects are in use they can not be killed.
771+
// therefore the function resets all variables before killing
772+
Function KillStorage()
769773
Wave savedVariablesWave = getSaveVariables()
770774
Wave/T SavedStringsWave = getSaveStrings()
771775
Wave/WAVE SavedWavesWave = getSaveWaves()
772776

773-
// if objects are in use they can not be killed. reset before killing
774-
775777
// reset
776778
saveReParse()
777779
setGlobalStr("parsingChecksum", "")
@@ -892,10 +894,6 @@ Function searchAndDelete(decls, lines, searchString)
892894
endif
893895
End
894896

895-
Function searchReset()
896-
setGlobalStr("search","")
897-
End
898-
899897
Function DeletePKGfolder()
900898
if(CountObjects(pkgFolder, 1) + CountObjects(pkgFolder, 2) + CountObjects(pkgFolder, 3) == 0)
901899
KillDataFolder/Z $pkgFolder

procedures/CodeBrowser_gui.ipf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ End
175175
Function existsPanel()
176176
DoWindow $panel
177177
if(V_flag == 0)
178+
debugPrint("panel does not exist")
178179
return 0
179180
endif
180181
debugPrint("panel exists")

procedures/CodeBrowser_hooks.ipf

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ static Function IgorBeforeQuitHook(unsavedExp, unsavedNotebooks, unsavedProcedur
1111

1212
string expName
1313

14-
debugprint("called")
14+
debugPrint("called")
15+
debugPrint("unsavedExp: " + num2str(unsavedExp))
1516

16-
preparePanelClose()
17-
markAsUnInitialized()
17+
BeforePanelClose()
18+
DoWindow/K CodeBrowser
19+
AfterPanelClose()
1820

1921
if(unsavedExp || unsavedNotebooks || unsavedProcedures)
2022
return 0
2123
endif
2224

2325
expName = IgorInfo(1)
24-
2526
if(!cmpstr(expName, "Untitled"))
2627
return 0
2728
endif
@@ -40,7 +41,9 @@ End
4041
static Function IgorBeforeNewHook(igorApplicationNameStr)
4142
string igorApplicationNameStr
4243

43-
preparePanelClose()
44+
debugPrint("called")
45+
BeforePanelClose()
46+
4447
return 0
4548
End
4649

@@ -66,38 +69,52 @@ Function initializePanel()
6669
setGlobalStr("search", "")
6770
End
6871

69-
// Prepare for panel closing, must be called before the panel is killed or the experiment closed
70-
Function preparePanelClose()
71-
72+
// Prepare for panel closing.
73+
//
74+
// note: Must be called before the panel is killed or the experiment is closed.
75+
Function BeforePanelClose()
7276
SetIgorHook/K AfterCompiledHook=updatePanel
73-
debugPrint("AfterCompiledHook: " + S_info)
77+
if(strlen(S_info) > 0)
78+
debugPrint("registered hooks with hookType=AfterCompiledHook: " + S_info)
79+
else
80+
debugPrint("all hookType=AfterCompiledHook deleted")
81+
endif
82+
End
83+
84+
// Clean up after closing panel
85+
//
86+
// note: Must be called after the panel was closed
87+
Function AfterPanelClose()
88+
variable cleanOnExit
7489

7590
if(!existsPanel())
7691
return 0
7792
endif
7893

79-
// save panel coordinates to disk
80-
STRUCT CodeBrowserPrefs prefs
81-
FillPackagePrefsStruct(prefs)
82-
SavePackagePrefsToDisk(prefs)
83-
84-
// reset global gui variables
85-
searchReset()
86-
87-
// delete CodeBrowser related data
88-
if(prefs.configCleanOnExit)
89-
// storage data will not be saved in experiment
90-
saveResetStorage()
91-
killGlobalVar("cleanOnExit")
92-
killGlobalVar("debuggingEnabled")
94+
cleanOnExit = !!getGlobalVar("cleanOnExit")
95+
QuitPackagePrefs()
96+
if(cleanOnExit)
97+
KillStorage()
98+
KillPanelObjects()
99+
DeletePKGfolder()
93100
endif
94101
End
95102

96-
// if panel does not exist, delete panel-bound var/wave/dfr
97-
Function killPanelRelatedObjects()
103+
// Kill panel-bound variables and waves
104+
//
105+
// @see KillStorage
106+
//
107+
// note: if the waves and variables are still bound to a panel, this function
108+
// will only reset them.
109+
Function KillPanelObjects()
98110
Wave/T decl = getDeclWave()
99111
Wave/I line = getLineWave()
100112

113+
// reset
114+
setGlobalStr("search","")
115+
setGlobalVar("initialized", 0)
116+
117+
// kill
101118
KillWaves/Z decl, line
102119
killGlobalStr("search")
103120
killGlobalVar("initialized")
@@ -117,9 +134,8 @@ Function panelHook(s)
117134
markAsInitialized()
118135
break
119136
case 2: // kill
120-
preparePanelClose()
121-
killPanelRelatedObjects()
122-
DeletePKGfolder()
137+
BeforePanelClose()
138+
AfterPanelClose()
123139
hookResult = 1
124140
break
125141
case 6: // resize

procedures/CodeBrowser_preferences.ipf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,23 @@ Function SavePackagePrefsToDisk(prefs)
145145
SavePackagePreferences kPackageName, kPrefsFileName, kPrefsRecordID, prefs
146146
End
147147

148+
// Sync all package preferences to disk and kill global variables that were
149+
// used.
150+
Function QuitPackagePrefs()
151+
// sync
152+
STRUCT CodeBrowserPrefs prefs
153+
FillPackagePrefsStruct(prefs)
154+
SavePackagePrefsToDisk(prefs)
155+
156+
// kill
157+
if(!!prefs.configCleanOnExit)
158+
killGlobalVar("cleanOnExit")
159+
killGlobalVar("debuggingEnabled")
160+
endif
161+
End
162+
148163
// Used to test SavePackagePreferences /KILL flag added in Igor Pro 6.10B04.
149-
Function KillPackagePrefs()
164+
Function ResetPackagePrefs()
150165
STRUCT CodeBrowserPrefs prefs
151166
SavePackagePreferences /KILL kPackageName, kPrefsFileName, kPrefsRecordID, prefs
152167
End

0 commit comments

Comments
 (0)