-
Notifications
You must be signed in to change notification settings - Fork 0
/
nimride.nim
171 lines (119 loc) · 4.11 KB
/
nimride.nim
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
import iup38
import strutils
import os
import encodings
var
doctabs:PIhandle #tabs control for each document
proc onCmdNew(ih:PIhandle):cint {.cdecl.}
proc onCmdExit(ih:PIhandle):cint {.cdecl.}
proc onCmdOpen(ih:PIhandle):cint {.cdecl.}
var noname_counter=1 #used to create indexed NONMAEx.nim name for new drawings
proc newToolButton(title,cmdname:string,image:string=nil):PIHandle=
var btn=button("",cmdname)
if image!=nil:
setAttribute(btn,"IMAGE",image)
else:
setAttribute(btn,"TITLE",title)
if title!=nil:
setAttribute(btn,"TOOLTIP",title)
setAttribute(btn,"CANFOCUS","NO")
return btn
proc createMainWindow():PIhandle =
doctabs=Tabs(nil)
var mainwindow=Dialog(
vbox(
hbox( #toolbar
newToolButton("","NEW","IUP_FileNew"),
newToolButton("","OPEN","IUP_FileOpen"),
newToolButton("X","EXIT"),
nil
),
doctabs,
nil
)
)
setAttribute(mainwindow,"TITLE","Nimride")
setFunction("NEW",onCmdNew)
setFunction("EXIT",onCmdExit)
setFunction("OPEN",onCmdOpen)
#create one document from scratch
discard onCmdNew(nil)
return mainwindow
proc createNimrodScintilla():PIhandle=
## creates an iup scintilla control initialized for nimrod
var ed=scintilla()
SetAttribute(ed, "LEXERLANGUAGE", "nimrod");
SetAttribute(ed, "KEYWORDS0", "proc var method")
#SetAttribute(ed, "STYLECLEARALL", "YES") # sets all styles to have the same attributes as 32
SetAttribute(ed, "STYLEFONT32", "Consolas")
#SetAttribute(ed, "STYLEFONTSIZE32", "12")
SetAttribute(ed, "STYLEFGCOLOR1", "0 128 0") # 1-C comment
SetAttribute(ed, "STYLEFGCOLOR2", "0 128 0") # 2-C++ comment line
SetAttribute(ed, "STYLEFGCOLOR4", "128 0 0") # 4-Number
SetAttribute(ed, "STYLEFGCOLOR5", "0 0 255") # 5-Keyword
SetAttribute(ed, "STYLEFGCOLOR6", "160 20 20") # 6-String
SetAttribute(ed, "STYLEFGCOLOR7", "128 0 0") # 7-Character
SetAttribute(ed, "STYLEFGCOLOR9", "0 0 255") # 9-Preprocessor block
SetAttribute(ed, "STYLEFGCOLOR10", "255 0 255") # 10-Operator
SetAttribute(ed, "STYLEBOLD10", "YES")
SetAttribute(ed,"USETABS","NO")
SetAttribute(ed,"TABSIZE","2")
ed.setAttribute("EXPAND","YES")
return ed
proc createNewEditor(filename:string):PIhandle=
## Creates a new editor document
## If filename is not nil this file is loaded
var ed=createNimrodScintilla()
if filename!=nil:
setAttribute(ed,"VALUE",readFile(filename))
echo filename
echo extractFileName(filename)
ed.setAttribute("TABTITLE",extractFileName(filename))
else:
ed.setAttribute("TABTITLE","NONAME"& $noname_counter&".nim")
inc noname_counter
append(doctabs,ed)
var stridx= $(getChildCount(doctabs)-1)
setAttribute(doctabs,"VALUEPOS",stridx)
ed.Map()
ed.Refresh()
return ed
proc onCmdNew(ih:PIhandle):cint =
discard createNewEditor(nil)
result=IUP_DEFAULT
proc onCmdExit(ih:PIhandle):cint=
#TODO: check for unsaved files
result=IUP_CLOSE
proc ASCIIToUtf8(asc:string):string=
var ce=getCurrentEncoding()
return encodings.convert(asc,"utf-8",ce)
proc onCmdOpen(ih:PIhandle):cint=
var fd=FileDlg()
setAttribute(fd,"FILTER","*.nim")
setAttribute(fd,"FILTERINFO","Nimrod sources (*.nim)")
setAttribute(fd,"MULTIPLEFILES","YES")
fd.popup(IUP_CENTER,IUP_CENTER)
if fd.GetInt("STATUS")==0: #normal existing file selected
var fname= $fd.getAttribute("VALUE")
if fname.contains('|'): #Multiple files selcted
var parts=fname.split('|')
var dir=parts[0]
for fnidx in 1.. <high(parts): #skip last since we always have an empty | last
var fn=dir & dirsep & parts[fnidx]
#discard createNewEditor(dir & dirsep & parts[fnidx])
echo(fn)
echo(ASCIIToUtf8(fn))
else: #only one file selected
#discard createNewEditor(fname)
echo(fname)
echo(ASCIIToUtf8(fname))
#discard createNewEditor($fname)
fd.destroy()
result=IUP_DEFAULT
when isMainModule:
iup38.open(nil,nil)
scintillaOpen()
imageLibOpen()
var mainwin=createMainWindow()
mainwin.show()
mainLoop()