Skip to content

Commit 83683c0

Browse files
authored
Merge pull request #29 from ukos-git/add_all_modules
Add all modules
2 parents 4ac3d4c + 68220cc commit 83683c0

File tree

2 files changed

+127
-48
lines changed

2 files changed

+127
-48
lines changed

procedures/CodeBrowser.ipf

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,10 @@ Function KillStorage()
892892
killGlobalvar("parsingTime")
893893
End
894894

895-
// Returns a list with the following optional suffixes removed:
896-
// -Module " [.*]"
897-
// -Ending ".ipf"
898-
// -Both ".ipf [.*]"
899-
Function/S nicifyProcedureList(list)
895+
/// @brief Return a list of procedures with the module suffix " [.*]" removed
896+
//
897+
/// @see ProcedureListRemoveEnding
898+
Function/S ProcedureListRemoveModule(list)
900899
string list
901900

902901
variable i, idx
@@ -905,6 +904,23 @@ Function/S nicifyProcedureList(list)
905904
for(i = 0; i < ItemsInList(list); i += 1)
906905
item = StringFromList(i, list)
907906
item = RemoveEverythingAfter(item, " [")
907+
niceList = AddListItem(item, niceList, ";", inf)
908+
endfor
909+
910+
return niceList
911+
End
912+
913+
/// @brief Return a list of procedures with the ending ".ipf" removed
914+
//
915+
/// @see ProcedureListRemoveModule
916+
Function/S ProcedureListRemoveEnding(list)
917+
string list
918+
919+
variable i, idx
920+
string item, niceList=""
921+
922+
for(i = 0; i < ItemsInList(list); i += 1)
923+
item = StringFromList(i, list)
908924
item = RemoveEverythingAfter(item, ".ipf")
909925
niceList = AddListItem(item, niceList, ";", inf)
910926
endfor
@@ -977,10 +993,10 @@ Function updateListBoxHook()
977993
Wave/I lines = getLineWave()
978994

979995
// get procedure information
980-
procedure.name = getCurrentItem(procedureWithoutModule = 1)
981-
procedure.module = getCurrentItem(module = 1)
982-
procedure.fullName = getCurrentItem(procedure = 1) // remove this if maclist is removed
983-
procedure.id = procedure.module + "#" + procedure.name
996+
procedure.fullName = getCurrentItem(procedure = 1)
997+
procedure.name = ProcedureWithoutModule(procedure.fullName)
998+
procedure.module = ModuleWithoutProcedure(procedure.fullName)
999+
procedure.id = procedure.module + "#" + RemoveEverythingAfter(procedure.name, ".ipf")
9841000
procedure.row = getSaveRow(procedure.id)
9851001

9861002
// load procedure
@@ -1189,15 +1205,32 @@ static Function/Wave getSaveVariables()
11891205
return wv
11901206
End
11911207

1192-
// Returns a list of all procedure files of the given independent module/ProcGlobal
1193-
Function/S getProcList(module)
1194-
String module
1208+
// Get a list of all procedure files of the given independent module/ProcGlobal
1209+
//
1210+
// @param module Independent Module or ProcGlobal Namespace
1211+
// @param addModule [optional, default 0] add the module to the list
1212+
// Module is added as Module#Procedure in a way similar to Module#Function()
1213+
Function/S getProcList(module, [addModule])
1214+
string module
1215+
variable addModule
1216+
1217+
string procedures
1218+
1219+
addModule = ParamIsDefault(addModule) ? 0 : !!addModule
11951220

1196-
if( isProcGlobal(module) )
1197-
return getGlobalProcWindows()
1221+
if(isProcGlobal(module))
1222+
module = "ProcGlobal"
1223+
procedures = getGlobalProcWindows()
11981224
else
1199-
return getIMProcWindows(module)
1225+
procedures = getIMProcWindows(module)
1226+
endif
1227+
1228+
if(addModule)
1229+
procedures = ProcedureListRemoveEnding(procedures)
1230+
module = module + "#"
1231+
procedures = AddToItemsInList(procedures, prefix=module)
12001232
endif
1233+
return procedures
12011234
End
12021235

12031236
static Function getParsingTime()

procedures/CodeBrowser_gui.ipf

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static StrConstant userDataNiceList = "niceList"
2828

2929
static StrConstant oneTimeInitUserData = "oneTimeInit"
3030

31+
static StrConstant selectAll = "<ALL>"
32+
3133
Function/S GetPanel()
3234
return panel
3335
End
@@ -135,6 +137,7 @@ Function/S generateModuleList()
135137
debugPrint("called")
136138

137139
string niceList = getModuleList()
140+
niceList = AddListItem(selectAll, niceList)
138141

139142
PopupMenu $moduleCtrl, win=$panel, userData($userDataNiceList)=niceList
140143

@@ -144,11 +147,30 @@ End
144147
// Callback for the procedure popup, returns a nicified list
145148
// Stores both the nicified list and the raw list as user data
146149
Function/S generateProcedureList()
147-
debugPrint("called")
148-
149-
string module = getCurrentItem(module=1)
150-
string procList = getProcList(module)
151-
string niceList = nicifyProcedureList(procList)
150+
string module, modules, procList, niceList
151+
variable numModules, i
152+
153+
module = getCurrentItem(module = 1)
154+
if(!cmpstr(module, selectAll))
155+
procList = ""
156+
niceList = ""
157+
modules = getModuleList()
158+
numModules = ItemsInList(modules)
159+
for(i = 0; i < numModules; i += 1)
160+
module = StringFromList(i, modules)
161+
procList += getProcList(module)
162+
if(isProcGlobal(module))
163+
niceList += getProcList(module)
164+
else
165+
niceList += getProcList(module, addModule = 1)
166+
endif
167+
endfor
168+
else
169+
procList = getProcList(module)
170+
niceList = procList
171+
endif
172+
niceList = ProcedureListRemoveModule(niceList)
173+
niceList = ProcedureListRemoveEnding(niceList)
152174

153175
PopupMenu $procCtrl, win=$panel, userData($userDataRawList)=procList, userData($userDataNiceList)=niceList
154176

@@ -208,25 +230,26 @@ Function isInitialized()
208230
return getGlobalVar("initialized") == 1
209231
End
210232

211-
// Returns the currently selected item from the panel defined by the optional arguments.
212-
// Exactly one optional argument must be given.
213-
//
214-
// module: Module from ProcGlobal/Independent Module list
215-
// procedure: "myProcedure.ipf [moduleName]"
216-
// procedureWithModule: "myProcedure.ipf"
217-
// index: Zero-based index into main listbox
218-
Function/S getCurrentItem([module, procedure,procedureWithoutModule, index])
219-
variable module, procedureWithoutModule, procedure, index
233+
/// Returns the currently selected item from the panel defined by the optional arguments.
234+
///
235+
/// Exactly one optional argument must be given.
236+
///
237+
/// @param module [optional] Module from ProcGlobal/Independent Module list
238+
/// @param procedure [optional] "myProcedure.ipf [moduleName]"
239+
/// @param index [optional] Zero-based index into main listbox
240+
///
241+
/// @returns the currently selected item
242+
Function/S getCurrentItem([module, procedure, index])
243+
variable module, procedure, index
220244

221-
string procName
245+
string procName, rawList
222246

223-
module = ParamIsDefault(module) ? 0 : 1
224-
procedureWithoutModule = ParamIsDefault(procedureWithoutModule) ? 0 : 1
225-
procedure = ParamIsDefault(procedure) ? 0 : 1
226-
index = ParamIsDefault(index) ? 0 : 1
247+
module = ParamIsDefault(module) ? 0 : 1
248+
procedure = ParamIsDefault(procedure) ? 0 : 1
249+
index = ParamIsDefault(index) ? 0 : 1
227250

228251
// only one optional argument allowed
229-
if(module + procedure + procedureWithoutModule + index != 1)
252+
if(module + procedure + index != 1)
230253
return "_error_"
231254
endif
232255

@@ -242,28 +265,51 @@ Function/S getCurrentItem([module, procedure,procedureWithoutModule, index])
242265
if(V_Value >= 0)
243266
return num2str(V_Value)
244267
endif
245-
elseif(procedure || procedureWithoutModule)
246-
268+
elseif(procedure)
247269
ControlInfo/W=$panel $procCtrl
248270
V_Value -= 1 // 1-based index
249-
string rawList = GetUserData(panel,procCtrl,userDataRawList)
250271

272+
rawList = GetUserData(panel, procCtrl, userDataRawList)
251273
if(V_Value < 0 || V_Value >= ItemsInList(rawList))
252274
return "_error_"
253275
endif
254276

255-
procName = StringFromList(V_Value,rawList)
256-
257-
if(procedureWithoutModule)
258-
return RemoveEverythingAfter(procName," [")
259-
endif
260-
277+
procName = StringFromList(V_Value, rawList)
261278
return procName
262279
endif
263280

264281
return "_error_"
265282
End
266283

284+
/// Get the basic procedure name from a full procedure name
285+
///
286+
/// @param fullName "myProcedure.ipf [moduleName]"
287+
///
288+
/// @returns myProcedure.ipf without module definition
289+
Function/S ProcedureWithoutModule(fullName)
290+
string fullName
291+
292+
return RemoveEverythingAfter(fullName, " [")
293+
End
294+
295+
/// Get the module name from a full procedure name
296+
///
297+
/// @param fullName "myProcedure.ipf [moduleName]"
298+
///
299+
/// @returns moduleName without procedure specification
300+
Function/S ModuleWithoutProcedure(fullName)
301+
string fullName
302+
303+
string module, procedure
304+
305+
SplitString/E="(.*)\ \[(\w+)\]" fullName, procedure, module
306+
if(V_flag != 2)
307+
return ""
308+
endif
309+
310+
return module
311+
End
312+
267313
// Returns the currently selected item from the panel defined by the optional arguments.
268314
// Argument is returned as number in current list
269315
// Exactly one optional argument must be given.
@@ -304,7 +350,7 @@ Function getCurrentItemAsNumeric([module, procedure, index, indexTop])
304350
return -1 // error
305351
End
306352

307-
// Updates the the given popup menu
353+
// Updates the given popup menu
308354
// Tries to preserve the currently selected item
309355
Function updatePopup(ctrlName)
310356
string ctrlName
@@ -320,7 +366,7 @@ Function updatePopup(ctrlName)
320366

321367
ControlUpdate/W=$panel $ctrlName
322368

323-
list = GetUserData(panel,procCtrl,userDataNiceList)
369+
list = GetUserData(panel, procCtrl, userDataNiceList)
324370

325371
if(ItemsInList(list) == 1)
326372
PopupMenu $ctrlName win=$panel, disable=2
@@ -329,10 +375,10 @@ Function updatePopup(ctrlName)
329375
endif
330376

331377
// try to restore the previously selected item if it differs from the current one
332-
variable newIndex = WhichListItem(itemText,list) + 1
378+
variable newIndex = WhichListItem(itemText, list) + 1
333379

334380
if(newIndex != index) // only update if required, as the update triggers the list generating function
335-
if( newIndex > 0)
381+
if(newIndex > 0)
336382
PopupMenu $ctrlName win=$panel, mode=newIndex
337383
else
338384
PopupMenu $ctrlName win=$panel, mode=1

0 commit comments

Comments
 (0)