-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_CDialogs.ahk
96 lines (82 loc) · 2.71 KB
/
class_CDialogs.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
93
94
95
96
/*
This file contains standard dialog classes like CFileDialog
*/
/*
Class: CFileDialog
This class is used for open/save file dialogs.
*/
Class CFileDialog
{
/*
Variable: 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.
*/
;Variable: Multi
;If true, multiple files can be selected.
;Variable: FileMustExist
;If true, the dialog requires that the file exists. Often used to open files.
;Variable: PathMustExist
;If true, the dialog requires that the path exists.
;Variable: CreateNewFilePrompt
;If true, the dialog will ask the user to create a new file if it does not exist.
;Variable: OverwriteFilePrompt
;If true, the dialog asks the user to overwrite an existing file.
;Variable: FollowShortcuts
;If true(default), shortcuts are followed. Otherwise the shortcut file itself will be used.
;Variable: InitialDirectory
;Initial directory of the dialog.
;Variable: Filename
;Initial filename in the filename edit field.
;Variable: Title
;Title of the dialog window.
;Variable: 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.
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 != ""
}
}