Skip to content

Commit 6a66d10

Browse files
committed
rework and fix panel initialization
1 parent 1c04106 commit 6a66d10

2 files changed

Lines changed: 56 additions & 20 deletions

File tree

procedures/CodeBrowser_gui.ipf

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ static StrConstant moduleCtrl = "popupNamespace"
1717
static StrConstant procCtrl = "popupProcedure"
1818
static StrConstant listCtrl = "list1"
1919

20+
static StrConstant oneTimeInitUserData = "oneTimeInit"
21+
2022
Function/S GetPanel()
2123
return panel
2224
End
@@ -58,7 +60,7 @@ Function createPanel()
5860
SetWindow $panel, hook(mainHook)=$(module + "#panelHook")
5961
DoUpdate/W=$panel
6062

61-
setHooksAndUpdate()
63+
initializePanel()
6264
resizePanel()
6365
End
6466

@@ -96,7 +98,6 @@ Function updatePanel()
9698

9799
DoWindow $panel
98100
if(V_flag == 0)
99-
debugPrint("Main panel does not exist")
100101
return 0
101102
endif
102103

@@ -110,12 +111,41 @@ Function updatePanel()
110111

111112
string module = S_value
112113
updatePopup(procCtrl,getProcList(module))
113-
114114
updateListBoxHook()
115115

116116
return 0
117117
End
118118

119+
Function markAsUnInitialized()
120+
121+
DoWindow $panel
122+
if(V_flag == 0)
123+
return 0
124+
endif
125+
126+
SetWindow $panel, userdata($oneTimeInitUserData)=""
127+
End
128+
129+
Function markAsInitialized()
130+
131+
DoWindow $panel
132+
if(V_flag == 0)
133+
return 0
134+
endif
135+
136+
SetWindow $panel, userdata($oneTimeInitUserData)="1"
137+
End
138+
139+
Function isInitialized()
140+
141+
DoWindow $panel
142+
if(V_flag == 0)
143+
return 0
144+
endif
145+
146+
return cmpstr(GetUserData(panel,"",oneTimeInitUserData),"1") == 0
147+
End
148+
119149
// Returns the currently selected item from the panel defined by the optional arguments.
120150
// Exactly one optional argument must be given.
121151
//
@@ -283,10 +313,6 @@ Function listBoxProc(lba) : ListBoxControl
283313
ListBox $listCtrl, win=$panel, selCol=1
284314
endif
285315
break
286-
case 6: // begin edit
287-
// break
288-
case 7: // finish edit
289-
break
290316
case 12: // keystroke
291317
if(!WaveExists(listWave))
292318
return 0

procedures/CodeBrowser_hooks.ipf

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,44 @@
66
// This file was created by () byte physics Thomas Braun, support@byte-physics.de
77
// (c) 2013
88

9-
static Function IgorStartOrNewHook(igorApplicationNameStr)
9+
static Function IgorBeforeQuitHook(igorApplicationNameStr)
1010
string igorApplicationNameStr
1111

12-
setHooksAndUpdate()
12+
preparePanelClose()
1313
return 0
1414
End
1515

16-
static Function IgorQuitHook(igorApplicationNameStr)
16+
static Function IgorBeforeNewHook(igorApplicationNameStr)
1717
string igorApplicationNameStr
1818

1919
preparePanelClose()
2020
return 0
2121
End
2222

23-
static Function IgorBeforeNewHook(igorApplicationNameStr)
24-
string igorApplicationNameStr
23+
static Function BeforeExperimentSaveHook(rN,fileName,path,type,creator,kind)
24+
Variable rN,kind
25+
String fileName,path,type,creator
2526

26-
preparePanelClose()
27+
markAsUnInitialized()
2728
return 0
2829
End
2930

30-
Function setHooksAndUpdate()
31-
Execute/Q "SetIgorOption IndependentModuleDev=1"
31+
Function initializePanel()
3232

33-
// prevent multiple hooks of the same function
34-
SetIgorHook/K AfterCompiledHook=updatePanel
33+
debugprint("called")
34+
35+
Execute/Q "SetIgorOption IndependentModuleDev=1"
3536

36-
SetIgorHook AfterCompiledHook=updatePanel
37-
debugprint("SetIgorHook AfterCompiledHook: " + S_info)
37+
SetIgorHook AfterCompiledHook=updatePanel
38+
debugprint("AfterCompiledHook: " + S_info)
3839
updatePanel()
3940
End
4041

4142
// Prepare for panel closing, must be called before the panel is killed or the experiment closed
4243
Function preparePanelClose()
44+
4345
SetIgorHook/K AfterCompiledHook=updatePanel
44-
debugprint("SetIgorHook AfterCompiledHook: " + S_info)
46+
debugprint("AfterCompiledHook: " + S_info)
4547

4648
DoWindow $GetPanel()
4749
if(V_flag == 0)
@@ -60,6 +62,14 @@ Function panelHook(s)
6062
Variable hookResult = 0
6163

6264
switch(s.eventCode)
65+
case 0: // activate
66+
if(isInitialized())
67+
break
68+
endif
69+
initializePanel()
70+
markAsUnInitialized()
71+
hookResult = 1
72+
break
6373
case 2: // kill
6474
preparePanelClose()
6575
hookResult = 1

0 commit comments

Comments
 (0)