forked from ChrisS85/CGUI
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCFileDialog.ahk
92 lines (80 loc) · 2.92 KB
/
CFileDialog.ahk
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
/*
Class: CFileDialog
This class is used for open/save file dialogs.
*/
Class CFileDialog
{
/*
Property: Mode
Possible values:
- Open: Shows a dialog to select a file which is opened.
- Save: Shows a dialog to select a file which is saved.
*/
;Property: Multi
;If true, multiple files can be selected.
;Property: FileMustExist
;If true, the dialog requires that the file exists. Often used to open files.
;Property: PathMustExist
;If true, the dialog requires that the path exists.
;Property: CreateNewFilePrompt
;If true, the dialog will ask the user to create a new file if it does not exist.
;Property: OverwriteFilePrompt
;If true, the dialog asks the user to overwrite an existing file.
;Property: FollowShortcuts
;If true(default), shortcuts are followed. Otherwise the shortcut file itself will be used.
;Property: InitialDirectory
;Initial directory of the dialog.
;Property: Filename
;Initial filename in the filename edit field. If the dialog was confirmed, this property contains the selected path & filename. If multiple files are selected, this property will be an array.
;Property: Title
;Title of the dialog window.
;Property: Filter
;File extension filter. AHK only supports a single user defined entry, but it may have different file extensions. An example would be "Audio files (*.mp3;*.wav)".
/*
Constructor: __New
Creates the instance but does not show the dialog. It can be used to store a configuration of the dialog that can be reused.
Parameters:
Mode - Possible values:
- Open: Shows a dialog to select a file which is opened.
- Save: Shows a dialog to select a file which is saved.
Returns:
An instance of the <CFileDialog> class.
*/
__New(Mode="")
{
this.Mode := Mode ? Mode : "Open"
this.Multi := 0
this.FileMustExist := 0
this.PathMustExist := 0
this.CreateNewFilePrompt := 0
this.OverwriteFilePrompt := 0
this.FollowShortcuts := 1
this.InitialDirectory := ""
this.Filename := ""
this.Title := ""
this.Filter := ""
}
__Delete()
{
}
/*
Function: Show
Shows a file dialog window. To show a modal window, set OwnDialogs := 1 for the GUI thread that calls this.
The path & filename of the selected file will be stored under the key "Filename". If multiple files are selected, this property will be an array.
Returns:
1 if the user confirmed the selection and pressed OK, 0 if the file selection was cancelled.
*/
Show()
{
FileSelectFile, result, % (this.Multi ? "M" : "" ) (this.Mode = "Open" ? "" : "S") ((this.FileMustExist > 0) + (this.PathMustExist>0) * 2 + (this.CreateNewFilePrompt > 0) * 8 + (this.OverwriteFilePrompt > 0) * 16 + (this.FollowShortcuts = 0) * 32), % this.InitialDirectory (this.InitialDirectory && this.Filename ? "\" : "") this.Filename, % this.Title, % this.Filter
if(Multi)
{
this.Filenames := Array()
Loop, Parse, result, `n
this.Filenames.Insert(A_LoopField)
}
else
this.Filename := result
return result != ""
}
}