@@ -16,6 +16,8 @@ static StrConstant panel = "CodeBrowser"
1616static StrConstant moduleCtrl = "popupNamespace"
1717static StrConstant procCtrl = "popupProcedure"
1818static StrConstant listCtrl = "list1"
19+ static StrConstant userDataRawList = "rawList"
20+ static StrConstant userDataNiceList = "niceList"
1921
2022static StrConstant oneTimeInitUserData = "oneTimeInit"
2123
@@ -46,11 +48,11 @@ Function createPanel()
4648
4749 PopupMenu $ moduleCtrl, win=$ panel, pos= { 30, moduleCtrlTop} , size= { popupLength,20 } , bodywidth=200
4850 PopupMenu $ moduleCtrl, win=$ panel, title= "Namespace"
49- PopupMenu $ moduleCtrl, win=$ panel, proc=$ ( module + "#popupModules" )
51+ PopupMenu $ moduleCtrl, win=$ panel, proc=$ ( module + "#popupModules" ) , value =# module + "#generateModuleList()"
5052
5153 PopupMenu $ procCtrl, win=$ panel, pos= { 30, procCtrlTop} , size= { popupLength,20 } , bodywidth=200
5254 PopupMenu $ procCtrl, win=$ panel, title= "Procedure"
53- PopupMenu $ procCtrl, win=$ panel, proc=$ ( module + "#popupProcedures" )
55+ PopupMenu $ procCtrl, win=$ panel, proc=$ ( module + "#popupProcedures" ) , value =# module + "#generateProcedureList()"
5456
5557 ListBox $ listCtrl, win=$ panel, pos= { border, topSpaceList} , size= { 300,800 }
5658 ListBox $ listCtrl, win=$ panel, proc=$ ( module + "#ListBoxProc" )
@@ -64,6 +66,32 @@ Function createPanel()
6466 resizePanel ()
6567End
6668
69+ // Callback for the modules popup
70+ // Stores the raw list as user data
71+ Function /S generateModuleList ()
72+ debugPrint ( "called" )
73+
74+ string niceList = getModuleList ()
75+
76+ PopupMenu $ moduleCtrl, win=$ panel, userData ( $ userDataNiceList) = niceList
77+
78+ return niceList
79+ End
80+
81+ // Callback for the procedure popup, returns a nicified list
82+ // Stores both the nicified list and the raw list as user data
83+ Function /S generateProcedureList ()
84+ debugPrint ( "called" )
85+
86+ string module = getCurrentItem ( module=1 )
87+ string procList = getProcList ( module)
88+ string niceList = nicifyProcedureList ( procList)
89+
90+ PopupMenu $ procCtrl, win=$ panel, userData ( $ userDataRawList) = procList, userData ( $ userDataNiceList) = niceList
91+
92+ return niceList
93+ End
94+
6795// Resize the panel controls
6896Function resizePanel ()
6997
@@ -101,16 +129,9 @@ Function updatePanel()
101129 return 0
102130 endif
103131
104- updatePopup ( moduleCtrl , getModuleList () )
132+ debugPrint ( "panel exists" )
105133
106- ControlInfo / W=$ panel $ moduleCtrl
107- if ( V_Value == 0 )
108- debugPrint ( "unknown GUI element: " + moduleCtrl)
109- return 0
110- endif
111-
112- string module = S_value
113- updatePopup ( procCtrl, getProcList ( module))
134+ ControlUpdate / A/ W=$ panel
114135 updateListBoxHook ()
115136
116137 return 0
@@ -149,22 +170,22 @@ End
149170// Returns the currently selected item from the panel defined by the optional arguments.
150171// Exactly one optional argument must be given.
151172//
152- // module: Module from ProcGlobal/Independent Module list
153- // procedure: Procedure name as shown in the panel, "myProcedure"
154- // procedureWithSuffix : "myProcedure.ipf"
155- // procedureWithModule: "myProcedure.ipf [moduleName]", except for the main procedure window which just returns "myProcedure [ProcGlobal]"
156- // index: Zero-based index into main listbox
157- Function /S getCurrentItem ( [ module, procedure, procedureWithSuffix, procedureWithModule, index] )
158- variable module , procedure , procedureWithSuffix , procedureWithModule , index
159-
160- module = ParamIsDefault ( module ) ? 0 : 1
161- procedure = ParamIsDefault ( procedure ) ? 0 : 1
162- procedureWithSuffix = ParamIsDefault ( procedureWithSuffix ) ? 0 : 1
163- procedureWithModule = ParamIsDefault ( procedureWithModule ) ? 0 : 1
164- index = ParamIsDefault ( index) ? 0 : 1
173+ // module: Module from ProcGlobal/Independent Module list
174+ // procedure: "myProcedure.ipf [moduleName] "
175+ // procedureWithModule : "myProcedure.ipf"
176+ // index: Zero-based index into main listbox
177+ Function /S getCurrentItem ( [ module, procedure,procedureWithoutModule, index] )
178+ variable module, procedureWithoutModule , procedure , index
179+
180+ string procName
181+
182+ module = ParamIsDefault ( module ) ? 0 : 1
183+ procedureWithoutModule = ParamIsDefault ( procedureWithoutModule ) ? 0 : 1
184+ procedure = ParamIsDefault ( procedure ) ? 0 : 1
185+ index = ParamIsDefault ( index) ? 0 : 1
165186
166187 // only one optional argument allowed
167- if ( module + procedure + procedureWithSuffix + procedureWithModule + index != 1 )
188+ if ( module + procedure + procedureWithoutModule + index != 1 )
168189 return "_error_"
169190 endif
170191
@@ -180,62 +201,61 @@ Function/S getCurrentItem([module, procedure, procedureWithSuffix, procedureWith
180201 if ( V_Value >= 0 )
181202 return num2str ( V_Value)
182203 endif
183- elseif ( procedure || procedureWithModule || procedureWithSuffix )
204+ elseif ( procedure || procedureWithoutModule )
184205
185206 ControlInfo / W=$ panel $ procCtrl
207+ V_Value -= 1 // 1-based index
208+ string rawList = GetUserData ( panel, procCtrl, userDataRawList)
186209
187- if ( V_Value <= 0 )
210+ if ( V_Value < 0 || V_Value >= ItemsInList ( rawList ) )
188211 return "_error_"
189212 endif
190213
191- string windowName = S_value
214+ procName = StringFromList ( V_Value , rawList )
192215
193- if ( procedureWithModule)
194- string moduleName = getCurrentItem ( module=1 )
195- // work around FunctionList not accepting Procedure.ipf [ProcGlobal]
196- if ( isProcGlobal ( "ProcGlobal" ) && cmpstr ( windowName, "Procedure" ) == 0 )
197- return windowName + " [" + moduleName + "]"
198- else
199- return windowName + ".ipf [" + moduleName + "]"
200- endif
201- elseif ( procedureWithSuffix)
202- return windowName + ".ipf"
203- else
204- return windowName
216+ if ( procedureWithoutModule)
217+ return RemoveEverythingAfter ( procName, " [" )
205218 endif
219+
220+ return procName
206221 endif
207222
208223 return "_error_"
209224End
210225
211- // Updates the list of the given popup menu
226+ // Updates the the given popup menu
212227// Tries to preserve the currently selected item
213- Function updatePopup ( ctrlName,list )
214- string ctrlName, list
228+ Function updatePopup ( ctrlName)
229+ string ctrlName
215230
216- string quotedList
231+ string itemText = "" , list
232+ variable index
217233
218234 ControlInfo / W=$ panel $ ctrlName
219- variable index = V_Value - 1
220- string itemText = ""
221-
235+ index = V_Value
222236 if ( ! isEmpty ( S_Value))
223237 itemText = S_Value
224238 endif
225239
240+ ControlUpdate / W=$ panel $ ctrlName
241+
242+ list = GetUserData ( panel, procCtrl, userDataNiceList)
243+
226244 if ( ItemsInList ( list) == 1 )
227- quotedList = quoteString ( list)
228- PopupMenu $ ctrlName win=$ panel, disable=2, value=# quotedList
245+ PopupMenu $ ctrlName win=$ panel, disable=2
229246 else
230- quotedList = quoteString ( list)
231- PopupMenu $ ctrlName win=$ panel, disable=0, value=# quotedList
247+ PopupMenu $ ctrlName win=$ panel, disable=0
232248 endif
233249
234- // choose the first element if we can't restore or would restore to the wrong argument
235- if ( ! ( index > 0 ) || index >= ItemsInList ( list) || cmpstr ( itemText, StringFromList ( index, list)) != 0 )
236- PopupMenu $ ctrlName win=$ panel, mode=1
237- else
238- PopupMenu $ ctrlName win=$ panel, mode= ( index+1 )
250+ // try to restore the previously selected item if it differs from the current one
251+ variable newIndex = WhichListItem ( itemText, list) + 1
252+
253+ if ( newIndex != index) // only update if required, as the update triggers the list generating function
254+ if ( newIndex > 0 )
255+ PopupMenu $ ctrlName win=$ panel, mode= newIndex
256+ else
257+ PopupMenu $ ctrlName win=$ panel, mode=1
258+ endif
239259 endif
240260End
241261
@@ -244,17 +264,18 @@ Function popupModules(pa) : PopupMenuControl
244264
245265 switch ( pa. eventCode )
246266 case 2: // mouse up
267+ debugprint ( "mouse up" )
247268
248269 string module = pa. popStr
249270
250271 if ( isEmpty ( module) )
251272 break
252273 endif
253274
254- updatePopup ( procCtrl, getProcList ( module ) )
275+ updatePopup ( procCtrl)
255276
256277 if ( updateListBoxHook () == 0 )
257- showCode ( getCurrentItem ( procedureWithModule =1 ))
278+ showCode ( getCurrentItem ( procedure =1 ))
258279 endif
259280 break
260281 endswitch
@@ -267,7 +288,9 @@ Function popupProcedures(pa) : PopupMenuControl
267288
268289 switch ( pa. eventCode )
269290 case 2: // mouse up
270- string procedure = getCurrentItem ( procedure=1 )
291+ debugprint ( "mouse up" )
292+
293+ string procedure = pa. popStr
271294
272295 if ( isEmpty ( procedure) )
273296 break
@@ -302,7 +325,7 @@ Function listBoxProc(lba) : ListBoxControl
302325 return 0
303326 endif
304327
305- procedure = getCurrentItem ( procedureWithModule =1 )
328+ procedure = getCurrentItem ( procedure =1 )
306329 showCode ( procedure, index= row)
307330 break
308331 case 4: // cell selection
@@ -318,14 +341,8 @@ Function listBoxProc(lba) : ListBoxControl
318341 return 0
319342 endif
320343
321- if ( debuggingEnabled)
322- string str
323- sprintf str, "keycode=%d,char=%s\r " , row, num2char ( row)
324- debugprint ( str)
325- endif
326-
327344 if ( row == openkey)
328- procedure = getCurrentItem ( procedureWithModule =1 )
345+ procedure = getCurrentItem ( procedure =1 )
329346 variable listIndex = str2num ( getCurrentItem ( index=1 ))
330347 showCode ( procedure, index= listIndex)
331348 endif
0 commit comments