Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Method help re-ordering utility
name
code content
( Dialog.openPanel { |path| var f = File(path, "r"); protect { if(f.isOpen) { m = f.readAllString; } { "Couldn't read %".format(path).warn; }; } { f.close }; }; ) ( var split, sorted, w, list, upBtn, dnBtn, printBtn, printFunc, centerX = Window.screenBounds.center.x; split = m.findRegexp("METHOD:: *([A-Za-z0-9_]+)"); split = split.separate { |a, b| b[1].contains("METHOD::") }; sorted = split.copy.sort { |a, b| a.last[1] < b.last[1] }; w = Window("Methods", Rect(centerX - 150, 0, 300, Window.screenBounds.height)); w.layout = HLayout( list = ListView(), VLayout( nil, upBtn = Button().fixedSize_(Size(30, 20)), dnBtn = Button().fixedSize_(Size(30, 20)), printBtn = Button().fixedSize_(Size(30, 20)), nil ) ); list.items_(sorted.collect { |pair| pair.last[1] }) .keyDownAction_({ |view, char| switch(char) { $a } { upBtn.doAction; true // do not do normal item matching } { $z } { dnBtn.doAction; true } }); upBtn.states_([["^"]]) .action_({ |view| var items = list.items, i = list.value; if(i > 0) { items = items.swap(i - 1, i); sorted = sorted.swap(i - 1, i); list.items = items; list.value = i - 1; }; }); dnBtn.states_([["v"]]) .action_({ |view| var items = list.items, i = list.value; if(i < (items.size - 1)) { items = items.swap(i, i + 1); sorted = sorted.swap(i, i + 1); list.items = items; list.value = i + 1; }; }); printBtn.states_([["P"]]) .action_({ printFunc.value }); printFunc = { sorted.do { |pair| var j = split.detectIndex { |item| item == pair }; if(j.isNil) { "FAILURE: %\n".postf(pair); } { if(j == (split.size - 1)) { m[pair[0][0]..].postln; } { m[split[j][0][0] .. split[j+1][0][0] - 1].postln; }; } }; }; w.front; w.onClose = printFunc; )
code description
If you have a large class with a lot of methods, you probably want to sort the methods in the auto-generated SCDoc template into an order that's meaningful for the end user (related methods grouped together, more important methods toward the top). But SCDoc syntax, with method::, argument:: and returns:: tags, makes it a bit harder to see where entries begin and end, and provides no overview of the list of methods. This GUI reads the METHOD:: sections from the auto-generated template and presents a list box containing the method names. 1. Get the list of METHOD:: sections, as a string, into the variable 'm'. If the string is in a disk file, use the upper code block to read it. 2. Run the second block. 3. Initially, the methods are sorted in ASCII order. The ^/v buttons allow you to change the order, or use "a" and "z" keys while focusing on the list box. 4. Close the window or click the "P" button to reprint the full templates, in the new order. Then you can copy/paste these back into the schelp file.
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change