File: FileDialog.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (108 lines) | stat: -rw-r--r-- 3,133 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
TITLE:: FileDialog
summary:: Operating system interface for Open file, save file, select directory dialogs
categories:: GUI>Accessories
related:: Classes/Dialog, Classes/File

DESCRIPTION::
This is the interface for your standard operating system modal file dialogs to open files, save files and select directories.

link::Classes/Dialog:: has functions built on top of FileDialog that may be more convenient to use.
However, selecting a directory is only possible with FileDialog.

CLASSMETHODS::

PRIVATE:: qtClass

METHOD:: new
Create and display a dialog.

ARGUMENT:: okFunc
Handler function evaluated when the user clicks "Open" or "Save".
This function receives different arguments depending on the value of code::stripResult::. By default
(code::stripResult: false::), code::okFunc:: is passed an array of selected paths. Otherwise, the
paths are passed as separate arguments, one for each path.

ARGUMENT:: cancelFunc
Handler function evaluated when the user clicks "Cancel". Receives no arguments.

ARGUMENT:: fileMode
An integer that determines the type of dialog.

These values correspond directly to values of QFileDialog\::FileMode in the Qt class.

list::
## 0 The name of a file, whether it exists or not.
## 1 The name of a single existing file.
## 2 The name of a directory. Both files and directories are displayed.
## 3 The names of zero or more existing files.
::

0 or 3 implies that the user can type in a new file name.

ARGUMENT:: acceptMode
An integer that determines whether the dialog is for opening or saving files. Note that this doesn't
actually open or save a file; you'll need to do that in your code::okFunc::. This only affects
appearance of the dialog.

These values correspond directly to values of QFileDialog\::AcceptMode in the Qt class.

list::
## 0 Opening
## 1 Saving
::

ARGUMENT:: stripResult
A boolean. If code::true::, selected paths are passed individually as arguments to code::okFunc::.
Otherwise, they are passed as an array in a single argument (the default).

list::
## false: okFunc(paths)
## true: okFunc(path1, path2, path3)
::

ARGUMENT:: path
A string. The dialog will initially display the contents of this path. The default is the current
user's home directory.

returns:: a FileDialog

EXAMPLES::

code::
// By default, the selected paths are passed to okFunc as an array.
(
FileDialog({ |paths|
	postln("Selected path:" + paths[0]);
	}, {
	postln("Dialog was cancelled. Try again.");
	});
)

// You can change this by passing `stripResult: true`
(
FileDialog({ |path|
	postln("Selected path:" + path);
	}, {
	postln("Dialog was cancelled. Try again.");
	}, stripResult: true);
)

// Passing `fileMode: 3` makes it possible to select multiple files.
(
FileDialog({ |paths|
	postln("Selected paths:");
	paths.do(_.postln);
	}, fileMode: 3);
)

// Passing `fileMode: 0` allows selecting any kind of file.
// You can start the dialog in a directory other than home by passing `path: "/some/path/"`
(
FileDialog({ |path|
	postln("Selected file:" + path);
	postln("File type is:" + File.type(path)); },
	fileMode: 0,
	stripResult: true,
	path: Platform.userAppSupportDir);
)
::