Skip to content

Commit a152ca1

Browse files
committed
As "PopupMenu value=#localList" is limited to 400 characters we use generation functions.
Properly handle pxp-local procedure files. This also required a to store the complete popup menu lists in raw and nice form as userData in the control.
1 parent 99b306b commit a152ca1

6 files changed

Lines changed: 311 additions & 105 deletions

File tree

procedures/CodeBrowser.ipf

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,47 @@ Function/S parseAllProcedureWindows()
395395

396396
string options, funcList, macList, list=""
397397
string module = getCurrentItem(module=1)
398-
string procedureWithModule = getCurrentItem(procedureWithModule=1)
399-
string procedureWithSuffix = getCurrentItem(procedureWithSuffix=1)
398+
string procedure = getCurrentItem(procedure=1)
399+
string procedureWithoutModule = getCurrentItem(procedureWithoutModule=1)
400400

401401
// list normal, userdefined, override and static functions
402-
options = "KIND:18,WIN:" + procedureWithModule
402+
options = "KIND:18,WIN:" + procedure
403403
funcList = FunctionList("*",";",options)
404-
macList = getDecoratedMacroList(procedureWithSuffix)
404+
405+
macList = getDecoratedMacroList(procedureWithoutModule)
405406

406407
list = SortList(funcList + macList,";",4)
407408

408409
Wave/T decls = getDeclWave()
409410
Wave/D lines = getLineWave()
410-
decorateFunctionNames(module, list, procedureWithModule, decls, lines)
411+
decorateFunctionNames(module, list, procedure, decls, lines)
412+
End
413+
414+
// Returns a list with the following optional suffixes removed:
415+
// -Module " [.*]"
416+
// -Ending ".ipf"
417+
// -Both ".ipf [.*]"
418+
Function/S nicifyProcedureList(list)
419+
string list
420+
421+
variable i, idx
422+
string item, niceList=""
423+
424+
for(i=0; i < ItemsInList(list);i+=1)
425+
item = StringFromList(i,list)
426+
item = RemoveEverythingAfter(item," [")
427+
item = RemoveEverythingAfter(item,".ipf")
428+
niceList = AddListItem(item,niceList,";",inf)
429+
endfor
430+
431+
return niceList
411432
End
412433

413434
// Returns a list of all procedures windows in ProcGlobal context
414435
Function/S getGlobalProcWindows()
415-
return getProcWindows("*","INDEPENDENTMODULE:0")
436+
string procList = getProcWindows("*","INDEPENDENTMODULE:0")
437+
438+
return AddToItemsInList(procList, suffix=" [ProcGlobal]")
416439
End
417440

418441
// Returns a list of all procedures windows in the given independent module
@@ -428,23 +451,8 @@ End
428451
Function/S getProcWindows(regexp,options)
429452
string regexp, options
430453

431-
string procList, procListClean = "", procedure
432-
variable i, endIdx
433-
434-
procList = WinList(regexp,";",options)
435-
436-
for(i=0; i < ItemsInList(procList); i+=1)
437-
// remove the ".ipf *" suffix
438-
procedure = StringFromList(i,procList)
439-
endIdx = strsearch(procedure,".ipf",0)
440-
if(endIdx > 0)
441-
procListClean = AddListItem(procedure[0,endIdx-1],procListClean)
442-
else
443-
procListClean = AddListItem(procedure,procListClean)
444-
endif
445-
endfor
446-
447-
return SortList(procListClean,";",4)
454+
string procList = WinList(regexp,";",options)
455+
return SortList(procList,";",4)
448456
End
449457

450458
// Returns a list of independent modules
@@ -527,7 +535,7 @@ Function showCode(procedure,[index])
527535
endif
528536
End
529537

530-
// Returns a list of all procedure files of the given indepenent module/ProcGlobal
538+
// Returns a list of all procedure files of the given independent module/ProcGlobal
531539
Function/S getProcList(module)
532540
string module
533541

procedures/CodeBrowser_gui.ipf

Lines changed: 84 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static StrConstant panel = "CodeBrowser"
1616
static StrConstant moduleCtrl = "popupNamespace"
1717
static StrConstant procCtrl = "popupProcedure"
1818
static StrConstant listCtrl = "list1"
19+
static StrConstant userDataRawList = "rawList"
20+
static StrConstant userDataNiceList = "niceList"
1921

2022
static 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()
6567
End
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
6896
Function 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_"
209224
End
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
240260
End
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

Comments
 (0)