-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeWindow.qml
More file actions
499 lines (458 loc) · 16.5 KB
/
CodeWindow.qml
File metadata and controls
499 lines (458 loc) · 16.5 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.2
import Qt.labs.folderlistmodel 2.2
import CodeWindow 1.0
Item {
anchors.fill: parent
property string prjPath: ""
property variant _exist_projects_name: []
property string _defaultPrjPath: "SixR_Projects"
property string _current_prj_name: ""
property bool _have_active_prj: false
property bool _is_started_prj: false
FileIO{
id: fileio
}
Component.onCompleted: {
console.log("*********************")
// if(fileio.currentProject!="")
// {
// console.log("**************** in if")
// openPrj(fileio.currentProject)
// }
// openPrj("SixR_Projects/temp2/final.code")
// console.log(fileio.getCurrentProject())
openPrj(fileio.currentProject)
console.log(fileio.currentProject)
}
function urlExists(testUrl) {
var request = new XMLHttpRequest();
request.open("GET", testUrl, false);
request.send(null);
return request.status==200;
}
function openPrjFromPath(path){
if(urlExists(path)){
projectEditor.open(path)
}
}
function openPrj(f_path){
// fileDialogLoad.nameFilters= [ "SixR files (*.six)", "All files (*)" ]
// fileDialogLoad.cb = function() {
// var xhr = new XMLHttpRequest;
// prjPath =fileDialogLoad.fileUrl
// xhr.open("GET", fileDialogLoad.fileUrl);
// //var path ="/"+fileDialogLoad.folder.toLocaleString().replace("file:///","")+"/"
// xhr.onreadystatechange = function() {
// if (xhr.readyState == XMLHttpRequest.DONE) {
// var response = xhr.responseText;
// var files = response.split(("\n"))
// for(var i in files){
// if(files[i]){
// var newCodeEditor = Qt.createQmlObject("import QtQuick 2.7; CodeEditor { }", stackLayout);
// var newTabButton = Qt.createQmlObject("import QtQuick 2.7; import QtQuick.Controls 2.0; CodeEditorTabButton { }", tabBar);
// newTabButton.codeEditor = newCodeEditor
// newCodeEditor.open(files[i])//path+files[i])
// newCodeEditor.changedSinceLastSave = false
// tabBar.setCurrentIndex(tabBar.count-1)
// newTabButton.color = "#fff" // Hack since focus isn't set correctly when it's the first tab?
// }
// }
// }
// };
// xhr.send();
// openPrjFromPath(prjPath+".mnr")
// }
// fileDialogLoad.visible = true
projectEditor.open(f_path)
}
function playProject(){
projectEditor.play(runFromLine.textInput.text)
}
function puaseCurrentTab(){
projectEditor.pause()
}
function stopCurrentTab(){
projectEditor.stop()
}
function getExistProjectsName()
{
return fileio.getExistProjectList(_defaultPrjPath)
}
ColumnLayout {
anchors.fill: parent
spacing: 2
Row {
Layout.fillWidth: true
spacing: 3
MButton {
_width: 60
_height: 35
id: openPrjButton
_text: "Open"
onBtnClick: {
var res=getExistProjectsName()
_exist_projects_name=res.split('#')
openExistProjectPopUp.open()
}
}
MButton {
_width: 60
_height: 35
id: playCurrentTabButton
_text: "Start"
enabled: _have_active_prj
onBtnClick: {
//if(text: "Play")
if(pauseCurrentTabButton._text == "Run"){
stopCurrentTab()
var times = new Date().getTime()
while(new Date().getTime() - times<500);
pauseCurrentTabButton._text="Pause"
pauseCurrentTabButton._background.color = "white"
}
playProject()
_is_started_prj=true
}
}
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("From Line")
color: "#EFECCA"
}
MTextField{
_width:60
id: runFromLine
_text:"-1"
}
MButton {
_width: 60
_height: 35
id: pauseCurrentTabButton
_text: "Pause"
enabled: _is_started_prj
onBtnClick: {
if(_text== "Pause"){
_background.color = "red"
_text="Run"
}
else{
_background.color = "white"
_text = "Pause"
}
puaseCurrentTab()
}
}
MButton {
_width: 60
_height: 35
id: stopCurrentTabButton
_text: "Stop"
enabled: _is_started_prj
onBtnClick: {
pauseCurrentTabButton._text="Pause"
pauseCurrentTabButton._background.color = "white"
//if(text: "Play")
stopCurrentTab()
}
}
MButton {
_width: 60
_height: 35
id: refreshButton
_text: "Refresh"
onBtnClick: {
openPrj(fileio.currentProject)
_have_active_prj=true
}
}
}
StackLayout {
id:stackLayout
Layout.fillWidth: true
Layout.fillHeight: true
CodeEditor {
id: projectEditor
Component.onCompleted: {
changedSinceLastSave = false
textArea.readOnly=true
}
}
}
}
FileDialog {
id: fileDialogLoad
selectExisting : true
//selectFolder: true
nameFilters: [ "SixR files (*.six)", "All files (*)" ]
property var cb
title: "Please choose project"
onAccepted: {
cb()
cb = undefined
}
}
//********************************************************
//********************************************************
Popup
{
id: openExistProjectPopUp
anchors.centerIn: parent
width: 450
height: 200
modal: true
focus: true
closePolicy: Popup.NoAutoClose // change closePolicy when write done
background: Rectangle {
visible: true
color: "#002F2F"
}
MFrame
{
anchors.fill: parent
Grid
{
anchors.fill: parent
rows: 3
Grid
{
width: parent.width
height: parent.height * 1/3
spacing: 5
columns: 2
Rectangle
{
width: parent.width * 2/5
height: parent.height
color: "transparent"
Label
{
anchors.centerIn: parent
text: qsTr("Project Name")
color: "#EFECCA"
}
}
//***************************************************
//***************************************************
ComboBox {
id: cmb_openExistProjectPopUp
height: parent.height
width: parent.width * 3/5
model: _exist_projects_name
displayText: cmb_openExistProjectPopUp.currentText
delegate: ItemDelegate {
width: cmb_openExistProjectPopUp.width
contentItem: Text {
text: modelData
color: "#EFECCA"
font: cmb_openExistProjectPopUp.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: cmb_openExistProjectPopUp.highlightedIndex === index
}
indicator: Canvas {
id: cmb_openExistProjectPopUp_canvas
x: cmb_openExistProjectPopUp.width - width - cmb_openExistProjectPopUp.rightPadding
y: cmb_openExistProjectPopUp.topPadding + (cmb_openExistProjectPopUp.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
Connections {
target: cmb_openExistProjectPopUp
onPressedChanged: cmb_openExistProjectPopUp_canvas.requestPaint()
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = cmb_openExistProjectPopUp.pressed ? "#046380" : "#EFECCA";
context.fill();
}
}
contentItem: Text {
leftPadding: 10
rightPadding: cmb_openExistProjectPopUp.indicator.width + cmb_openExistProjectPopUp.spacing
text: cmb_openExistProjectPopUp.displayText
font: cmb_openExistProjectPopUp.font
color: cmb_openExistProjectPopUp.pressed ? "#046380" : "#EFECCA"
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 120
implicitHeight: 40
border.color: cmb_openExistProjectPopUp.pressed ? "#046380" : "#EFECCA"
border.width: cmb_openExistProjectPopUp.visualFocus ? 2 : 1
color: "#046380"
radius: 2
}
popup: Popup {
y: cmb_openExistProjectPopUp.height - 1
width: cmb_openExistProjectPopUp.width
implicitHeight: contentItem.implicitHeight
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: cmb_openExistProjectPopUp.popup.visible ? cmb_openExistProjectPopUp.delegateModel : null
currentIndex: cmb_openExistProjectPopUp.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
border.color: "#EFECCA"
color: "#046380"
radius: 5
}
}
onActivated:{
}
}
}
Rectangle
{
width: parent.width
height: parent.height * 1/3 - 10
color: "transparent"
}
Grid
{
width: parent.width
height: parent.height * 1/3
columns: 3
spacing: 5
Rectangle
{
width: parent.width * 1/2 - 10
height: parent.height
color: "transparent"
}
MButton {
_text: "cancle"
_width:parent.width * 1/4
height: parent.height
onBtnClick:
{
openExistProjectPopUp.close()
}
}
MButton {
_text: "Open"
_width:parent.width * 1/4
height: parent.height
onBtnClick:
{
_current_prj_name=cmb_openExistProjectPopUp.currentText
openPrj(_defaultPrjPath+"/"+_current_prj_name+"/final.code")
_have_active_prj=true
openExistProjectPopUp.close()
}
}
}
}
}
}
Item {
id: shortcuts
Shortcut {
sequence: "Ctrl+1"
onActivated: {
if(editorCount >= 1) tabBar.setCurrentIndex(0)
}
}
Shortcut {
sequence: "Ctrl+2"
onActivated: {
if(editorCount >= 2) tabBar.setCurrentIndex(1)
}
}
Shortcut {
sequence: "Ctrl+3"
onActivated: {
if(editorCount >= 3) tabBar.setCurrentIndex(2)
}
}
Shortcut {
sequence: "Ctrl+4"
onActivated: {
if(editorCount >= 4) tabBar.setCurrentIndex(3)
}
}
Shortcut {
sequence: "Ctrl+5"
onActivated: {
if(editorCount >= 5) tabBar.setCurrentIndex(4)
}
}
Shortcut {
sequence: "Ctrl+6"
onActivated: {
if(editorCount >= 6) tabBar.setCurrentIndex(5)
}
}
Shortcut {
sequence: "Ctrl+7"
onActivated: {
if(editorCount >= 7) tabBar.setCurrentIndex(6)
}
}
Shortcut {
sequence: "Ctrl+8"
onActivated: {
if(editorCount >= 8) tabBar.setCurrentIndex(7)
}
}
Shortcut {
sequence: "Ctrl+9"
onActivated: {
if(editorCount >= 9) tabBar.setCurrentIndex(8)
}
}
Shortcut {
sequence: "Ctrl+0"
onActivated: {
if(editorCount >= 10) tabBar.setCurrentIndex(9)
}
}
Shortcut {
sequence: StandardKey.New
onActivated: {
newTab()
}
}
Shortcut {
sequence: StandardKey.AddTab
onActivated: {
newTab()
}
}
Shortcut {
sequence: StandardKey.Open
onActivated: {
openTab()
}
}
Shortcut {
sequence: StandardKey.Save
onActivated: {
currentEditor.save()
}
}
Shortcut {
sequence: StandardKey.Close
onActivated: {
closeTab()
}
}
Shortcut {
sequence: StandardKey.SaveAs
onActivated: {
currentEditor.saveAs()
}
}
}
}