File: FilePlusGUI.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (44 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
+ File {
	*openDialog { arg prompt, successFunc, cancelFunc;
		var gui = GUI.current,
			dialogClass = GUI.dialog,
			dialogMetaClass;

		/*
			Older versions of SwingOSC have an older argument, maxSize,
			that disagrees with CocoaDialog and QDialog. Newer versions
			of SwingOSC have the same arguments. So it isn't enough to
			check GUI.id -- we have to detect which argument name is there.

			Then, findRespondingMethodFor searches a class's methods.
			But getPaths is a class method -- of the metaclass -- and,
			Class provides no easy way to navigate from a class
			to its metaclass.

			So it's rather more complex than I suppose it really needs to be.
			Backward compatibility is not always pain-free.
		*/

		dialogMetaClass = ("Meta_" ++ dialogClass.name).asSymbol.asClass;

		if(dialogMetaClass.findRespondingMethodFor(\getPaths).argNames.includes(\maxSize)) {
			dialogClass.getPaths(
				{ arg paths; GUI.use( gui, { successFunc.value( paths.first )})},
				{ if(cancelFunc.notNil){ GUI.use( gui, cancelFunc )}}, 3 );
		} {
			dialogClass.getPaths(
				{ arg paths; GUI.use( gui, { successFunc.value( paths.first )})},
				{ if(cancelFunc.notNil){ GUI.use( gui, cancelFunc )}}, true );
		};
	}

	*saveDialog { arg prompt, defaultName, successFunc, cancelFunc;
		var gui;
		gui = GUI.current;
		// no prompts or defaultNames in cocoa
		gui.dialog.savePanel({ arg args;
			GUI.use( gui, { successFunc.value( args )})}, {
			if(cancelFunc.notNil){GUI.use( gui, cancelFunc )}}
		);
	}
}