-
Notifications
You must be signed in to change notification settings - Fork 3
/
AceEditorDemo.sb
137 lines (91 loc) · 4.12 KB
/
AceEditorDemo.sb
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
XIncludeFile "AceEditor.sbi"
EnableExplicit
Enumeration
#Window
#Toolbar
#Toolbar_New
#Toolbar_Open
#Toolbar_Save
#Toolbar_Search
#AceEditor
EndEnumeration
#dijitEditorIconNewPage = "dijitEditorIcon dijitEditorIconNewPage"
#dijitIconFolderOpen = "dijitIconFolderOpen"
#dijitIconSave = "dijitIconSave"
#dijitIconSearch = "dijitIconSearch"
Procedure.s GetTestSource()
Protected TestSource.s
TestSource = "function ValidFunction() {" + #CRLF$ + #CRLF$ +
" alert('Hello World');" + #CRLF$ + #CRLF$ +
"}" + #CRLF$ + #CRLF$ +
"function InvalidFunction( {" + #CRLF$ + #CRLF$ +
"}" + #CRLF$
ProcedureReturn TestSource
EndProcedure
Procedure ToolBarStandardButton(Button, ButtonIcon.s, Mode = #PB_ToolBar_Normal, Text.s = "")
; see: http://forums.spiderbasic.com/viewtopic.php?p=3581#p3581
ToolBarImageButton(Button, 0, Mode)
! var b = spider.toolbar.current.buttons[v_button];
! var i = $(b.domNode).find(".dijitIcon");
! i.addClass(v_buttonicon);
If Text <> ""
! var s = $(b.domNode).find(".dijitButtonText");
! s.removeClass("dijitDisplayNone");
! s.text(v_text);
EndIf
EndProcedure
Procedure MenuEvent()
Select EventMenu()
Case #Toolbar_New
AceEditor::SetValue(#AceEditor, "")
Case #Toolbar_Open
! alert("not implemented");
Case #Toolbar_Save
! alert("not implemented");
Case #Toolbar_Search
Protected SearchString.s = "World"
Protected SearchObject
! v_searchobject = {
! backwards : false, // Whether to search backwards from where cursor currently is. Defaults to false.
! wrap : false, // Whether to wrap the search back to the beginning when it hits the end. Defaults to false.
! caseSensitive : false, // Whether the search ought to be case-sensitive. Defaults to false.
! wholeWord : false, // Whether the search matches only on whole words. Defaults to false.
! range : null, // The Range to search within. Set this to null for the whole document
! regExp : false, // Whether the search is a regular expression or not. Defaults to false.
! start : 0, // The starting Range or cursor position to begin the search
! skipCurrent : false // Whether or not to include the current line in the search. Default to false.
! }
AceEditor::Find(#AceEditor, SearchString, SearchObject)
AceEditor::FindNext(#AceEditor)
AceEditor::FindPrevious(#AceEditor)
AceEditor::Focus(#AceEditor)
EndSelect
EndProcedure
Procedure SizeWindowEvent()
ResizeGadget(#AceEditor, #PB_Ignore, #PB_Ignore, WindowWidth(#Window), WindowHeight(#Window) - ToolBarHeight(#Toolbar))
EndProcedure
Procedure Main()
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 800, 600, "AceEditorDemo", #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
CreateToolBar(#Toolbar, WindowID(#Window))
ToolBarStandardButton(#Toolbar_New, #dijitEditorIconNewPage)
ToolBarToolTip(#Toolbar, #Toolbar_New, "New")
ToolBarStandardButton(#Toolbar_Open, #dijitIconFolderOpen)
ToolBarToolTip(#Toolbar, #Toolbar_Open, "Open...")
ToolBarStandardButton(#Toolbar_Save, #dijitIconSave)
ToolBarToolTip(#Toolbar, #Toolbar_Save, "Save...")
ToolBarSeparator()
ToolBarStandardButton(#Toolbar_Search, #dijitIconSearch)
ToolBarToolTip(#Toolbar, #Toolbar_Search, "Search 'World'")
ContainerGadget(#AceEditor, 0, 0, WindowWidth(#Window), WindowHeight(#Window) - ToolBarHeight(#Toolbar))
CloseGadgetList()
AceEditor::BindGadget(#AceEditor)
AceEditor::SetTheme(#AceEditor, "chrome")
AceEditor::SetMode (#AceEditor, "javascript")
; (Overview of themes and modes: https://ace.c9.io/build/kitchen-sink.html)
AceEditor::SetValue(#AceEditor, GetTestSource())
AceEditor::Focus(#AceEditor)
AceEditor::GotoLine(#AceEditor, 2, 2)
BindEvent(#PB_Event_Menu, @MenuEvent())
BindEvent(#PB_Event_SizeWindow, @SizeWindowEvent())
EndProcedure
AceEditor::Init(@Main())