Skip to content

Commit 7a1b2d1

Browse files
author
Matthias Kastner
committed
restructure Functions Before and After panel closing
Add two new Functions: BeforPanelClose and AfterPanelClose. This gives a better overview to which part of the CodeBrowser the associated Functions belong: * The hook as to be unbound from the panel. * Panel Variables and Waves (only killed if panel was killed prior) * Package Pref Variables (killed after Syncing PackagePrefs at Program Quit. * Storage Variables and Waves (can be killed at any time after unbinding the hook
1 parent a64891c commit 7a1b2d1

File tree

3 files changed

+63
-35
lines changed

3 files changed

+63
-35
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_hooks.ipf

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ static Function IgorBeforeQuitHook(unsavedExp, unsavedNotebooks, unsavedProcedur
1313

1414
debugprint("called")
1515

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

1920
if(unsavedExp || unsavedNotebooks || unsavedProcedures)
2021
return 0
2122
endif
2223

2324
expName = IgorInfo(1)
24-
2525
if(!cmpstr(expName, "Untitled"))
2626
return 0
2727
endif
@@ -40,7 +40,9 @@ End
4040
static Function IgorBeforeNewHook(igorApplicationNameStr)
4141
string igorApplicationNameStr
4242

43-
preparePanelClose()
43+
debugPrint("called")
44+
BeforePanelClose()
45+
4446
return 0
4547
End
4648

@@ -66,38 +68,52 @@ Function initializePanel()
6668
setGlobalStr("search", "")
6769
End
6870

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

7589
if(!existsPanel())
7690
return 0
7791
endif
7892

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")
93+
cleanOnExit = !!getGlobalVar("cleanOnExit")
94+
QuitPackagePrefs()
95+
if(cleanOnExit)
96+
KillStorage()
97+
KillPanelObjects()
98+
DeletePKGfolder()
9399
endif
94100
End
95101

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

112+
// reset
113+
setGlobalStr("search","")
114+
setGlobalVar("initialized", 0)
115+
116+
// kill
101117
KillWaves/Z decl, line
102118
killGlobalStr("search")
103119
killGlobalVar("initialized")
@@ -117,9 +133,8 @@ Function panelHook(s)
117133
markAsInitialized()
118134
break
119135
case 2: // kill
120-
preparePanelClose()
121-
killPanelRelatedObjects()
122-
DeletePKGfolder()
136+
BeforePanelClose()
137+
AfterPanelClose()
123138
hookResult = 1
124139
break
125140
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)