-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.xojo_code
250 lines (196 loc) · 6.13 KB
/
App.xojo_code
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#tag Class
Protected Class App
Inherits Application
#tag Event
Sub EnableMenuItems()
//
// FileClose
//
if Keyboard.AsyncOptionKey then
FileClose.Text = "Close All"
FileClose.KeyboardShortcut = "cmd-opt-W"
else
FileClose.Text = "Close"
FileClose.KeyboardShortcut = "cmd-W"
end if
FileSaveWithIndents.Checked = Prefs.SaveWithIndents
End Sub
#tag EndEvent
#tag Event
Function HandleAppleEvent(theEvent As AppleEvent, eventClass As String, eventID As String) As Boolean
#pragma unused theEvent
#if not TargetMacOS
#pragma unused eventClass
#pragma unused eventID
#else
if StrComp( eventClass, "aevt", 0 ) = 0 and StrComp( eventID, "rapp", 0 ) = 0 then
dim isVisibleWindow as boolean
dim lastWindowIndex as integer = WindowCount - 1
for i as integer = 0 to lastWindowIndex
if Window( i ).Visible then
isVisibleWindow = true
exit
end if
next
if not isVisibleWindow then
NewDocument
end if
return true
end if
#endif
End Function
#tag EndEvent
#tag Event
Sub NewDocument()
dim w as new WndEditor
w.Show
End Sub
#tag EndEvent
#tag Event
Sub OpenDocument(item As FolderItem)
dim editor as WndEditor
//
// See if the first window is available
//
for i as integer = 0 to WindowCount - 1
dim wnd as Window = Window( i )
if wnd IsA WndEditor then
dim maybe as WndEditor = WndEditor( wnd )
if editor is nil and maybe.MyDocument is nil and not maybe.ContentsChanged then
editor = maybe
//
// But keep going to see if the document is open elsewhere
//
elseif maybe.MyDocument IsA FolderItem and maybe.MyDocument.NativePath = item.NativePath then
//
// It's already open
//
maybe.Show
return // Early exit
end if
end if
next i
if editor is nil then
editor = new WndEditor
else
editor.Show
end if
editor.OpenDocument item
End Sub
#tag EndEvent
#tag MenuHandler
Function EditPreferences() As Boolean Handles EditPreferences.Action
WndPreferences.ShowModal
Return True
End Function
#tag EndMenuHandler
#tag MenuHandler
Function FileNew() As Boolean Handles FileNew.Action
NewDocument
Return True
End Function
#tag EndMenuHandler
#tag MenuHandler
Function FileOpen() As Boolean Handles FileOpen.Action
dim dlg as new OpenDialog
dlg.PromptText = "Select a XojoScript document:"
dlg.Filter = DocumentTypes.XojoScript
dim f as FolderItem = dlg.ShowModal
if f IsA FolderItem then
OpenDocument f
end if
Return True
End Function
#tag EndMenuHandler
#tag MenuHandler
Function FileSaveWithIndents() As Boolean Handles FileSaveWithIndents.Action
Prefs.SaveWithIndents = not Prefs.SaveWithIndents
Return True
End Function
#tag EndMenuHandler
#tag MenuHandler
Function HelpAbout() As Boolean Handles HelpAbout.Action
WndAbout.Show
Return True
End Function
#tag EndMenuHandler
#tag MenuHandler
Function HelpXojoScriptingLanguageDocs() As Boolean Handles HelpXojoScriptingLanguageDocs.Action
ShowURL "http://docs.xojo.com/index.php/Scripting_Language"
Return True
End Function
#tag EndMenuHandler
#tag Method, Flags = &h0
Sub CloseAllWindows()
for i as integer = WindowCount - 1 downto 0
Window( i ).Close
next
End Sub
#tag EndMethod
#tag Property, Flags = &h21
Private mPrefs As XsEditPreferences
#tag EndProperty
#tag ComputedProperty, Flags = &h0
#tag Getter
Get
if mPrefs is nil then
mPrefs = new XsEditPreferences( "com.mactechnologiesconsulting.xsedit" )
end if
return mPrefs
End Get
#tag EndGetter
Prefs As XsEditPreferences
#tag EndComputedProperty
#tag ComputedProperty, Flags = &h0
#tag Getter
Get
dim p as FolderItem = App.ExecutableFile.Parent
dim f as FolderItem
#if TargetMacOS then
f = p.Parent.Child( "Resources" )
#else
f = p.Child( "Resources" )
if not f.Exists then
dim appName as string = App.ExecutableFile.Name
if appName.Right( 4 ) = ".exe" then
appName = appName.Left( appName.Len - 4 )
end if
f = p.Child( appName + " Resources" )
end if
#endif
return f
End Get
#tag EndGetter
ResourcesFolder As FolderItem
#tag EndComputedProperty
#tag ComputedProperty, Flags = &h0
#tag Getter
Get
return ResourcesFolder.Child( "Syntax Definitions" ).Child( "XojoScript.xml" )
End Get
#tag EndGetter
SyntaxDefinitionFile As FolderItem
#tag EndComputedProperty
#tag Constant, Name = kEditClear, Type = String, Dynamic = False, Default = \"&Delete", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"&Delete"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"&Delete"
#tag EndConstant
#tag Constant, Name = kEditComment, Type = String, Dynamic = False, Default = \"Co&mment", Scope = Public
#tag EndConstant
#tag Constant, Name = kEditUncomment, Type = String, Dynamic = False, Default = \"Unco&mment", Scope = Public
#tag EndConstant
#tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"E&xit"
#tag EndConstant
#tag Constant, Name = kFileQuitShortcut, Type = String, Dynamic = False, Default = \"", Scope = Public
#Tag Instance, Platform = Mac OS, Language = Default, Definition = \"Cmd+Q"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"Ctrl+Q"
#tag EndConstant
#tag Constant, Name = kViewHideToolbar, Type = String, Dynamic = False, Default = \"Hide &Toolbar", Scope = Public
#tag EndConstant
#tag Constant, Name = kViewShowToolbar, Type = String, Dynamic = False, Default = \"Show &Toolbar", Scope = Public
#tag EndConstant
#tag ViewBehavior
#tag EndViewBehavior
End Class
#tag EndClass