8000 WIP: new file from editor. · arduino/lab-micropython-editor@e2784f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2784f4

Browse files
committed
WIP: new file from editor.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent 8d7586a commit e2784f4

File tree

8 files changed

+71
-20
lines changed

8 files changed

+71
-20
lines changed

ui/arduino/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<!-- Components -->
2626
<script type="text/javascript" src="views/components/code-editor.js" charset="utf-8"></script>
2727
<script type="text/javascript" src="views/components/connection-dialog.js" charset="utf-8"></script>
28+
<script type="text/javascript" src="views/components/new-file-destination-dialog.js" charset="utf-8"></script>
2829
<script type="text/javascript" src="views/components/file-actions.js" charset="utf-8"></script>
2930
<script type="text/javascript" src="views/components/file-list.js" charset="utf-8"></script>
3031
<script type="text/javascript" src="views/components/repl-panel.js" charset="utf-8"></script>

ui/arduino/main.css

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ button.small .icon {
330330
opacity: 0.5;
331331
}
332332

333-
#dialog {
333+
.dialog {
334334
display: flex;
335335
flex-direction: column;
336336
justify-content: center;
@@ -350,13 +350,16 @@ button.small .icon {
350350
line-height: normal;
351351
background: rgba(236, 241, 241, 0.50);
352352
}
353-
#dialog.open {
353+
354+
.dialog.open {
354355
opacity: 1;
355356
pointer-events: inherit;
356357
transition: opacity 0.15s;
357358
}
358359

359-
#dialog .dialog-content {
360+
361+
362+
.dialog .dialog-content {
360363
display: flex;
361364
width: 576px;
362365
padding: 36px;
@@ -372,16 +375,16 @@ button.small .icon {
372375
transition: transform 0.15s;
373376
}
374377

375-
#dialog.open .dialog-content {
378+
.dialog.open .dialog-content {
376379
transform: translateY(0px);
377380
transition: transform 0.15s;
378381
}
379382

380-
#dialog .dialog-content > * {
383+
.dialog .dialog-content > * {
381384
width: 100%;
382385
}
383386

384-
#dialog .dialog-content .item {
387+
.dialog .dialog-content .item {
385388
border-radius: 4.5px;
386389
display: flex;
387390
padding: 10px;
@@ -391,7 +394,7 @@ button.small .icon {
391394
cursor: pointer;
392395
}
393396

394-
#dialog .dialog-content .item:hover {
397+
.dialog .dialog-content .item:hover {
395398
background: #008184;
396399
color: #ffffff;
397400
}

ui/arduino/store.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ A92E -49,6 +49,8 @@ async function store(state, emitter) {
4949
state.isConnected = false
5050
state.connectedPort = null
5151

52+
state.isNewFileDialogOpen = false
53+
5254
state.isSaving = false
5355
state.savingProgress = 0
5456
state.isTransferring = false
@@ -295,7 +297,17 @@ async function store(state, emitter) {
295297
window.removeEventListener('mousemove', state.resizePanel)
296298
})
297299

298-
// SAVING
300+
// NEW FILE AND SAVING
301+
emitter.on('create-new-file', () => {
302+
log('create-new-file')
303+
state.isNewFileDialogOpen = true
304+
emitter.emit('render')
305+
})
306+
emitter.on('close-new-file-dialog', () => {
307+
state.isNewFileDialogOpen = false
308+
emitter.emit('render')
309+
})
310+
299311
emitter.on('save', async () => {
300312
log('save')
301313
let response = canSave({
@@ -514,18 +526,22 @@ async function store(state, emitter) {
514526
emitter.emit('render')
515527
})
516528

517-
emitter.on('create-file', (device) => {
529+
emitter.on('create-file', (device, fileName = null) => {
518530
log('create-file', device)
519531
if (state.creatingFile !== null) return
520532
state.creatingFile = device
521533
state.creatingFolder = null
534+
if (fileName != null) {
535+
emitter.emit('finish-creating-file', fileName)
536+
}
522537
emitter.emit('render')
523538
})
524-
emitter.on('finish-creating-file', async (value) => {
525-
log('finish-creating', value)
539+
540+
emitter.on('finish-creating-file', async (fileNameParameter) => {
541+
log('finish-creating', fileNameParameter)
526542
if (!state.creatingFile) return
527543

528-
if (!value) {
544+
if (!fileNameParameter) {
529545
state.creatingFile = null
530546
emitter.emit('render')
531547
return
@@ -535,10 +551,10 @@ async function store(state, emitter) {
535551
let willOverwrite = await checkBoardFile({
536552
root: state.boardNavigationRoot,
537553
parentFolder: state.boardNavigationPath,
538-
fileName: value
554+
fileName: fileNameParameter
539555
})
540556
if (willOverwrite) {
541-
const confirmAction = await confirm(`You are about to overwrite the file ${value} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
557+
const confirmAction = await confirm(`You are about to overwrite the file ${fileNameParameter} on your board.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
542558
if (!confirmAction) {
543559
state.creatingFile = null
544560
emitter.emit('render')
@@ -550,18 +566,18 @@ async function store(state, emitter) {
550566
serialBridge.getFullPath(
551567
'/',
552568
state.boardNavigationPath,
553-
value
569+
fileNameParameter
554570
),
555571
newFileContent
556572
)
557573
} else if (state.creatingFile == 'disk') {
558574
let willOverwrite = await checkDiskFile({
559575
root: state.diskNavigationRoot,
560576
parentFolder: state.diskNavigationPath,
561-
fileName: value
577+
fileName: fileNameParameter
562578
})
563579
if (willOverwrite) {
564-
const confirmAction = await confirm(`You are about to overwrite the file ${value} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
580+
const confirmAction = await confirm(`You are about to overwrite the file ${fileNameParameter} on your disk.\n\nAre you sure you want to proceed?`, 'Cancel', 'Yes')
565581
if (!confirmAction) {
566582
state.creatingFile = null
567583
emitter.emit('render')
@@ -573,7 +589,7 @@ async function store(state, emitter) {
573589
disk.getFullPath(
574590
state.diskNavigationRoot,
575591
state.diskNavigationPath,
576-
value
592+
fileNameParameter
577593
),
578594
newFileContent
579595
)

ui/arduino/views/components/connection-dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function ConnectionDialog(state, emit) {
22
const stateClass = state.isConnectionDialogOpen ? 'open' : 'closed'
33
function onClick(e) {
4-
if (e.target.id == 'dialog') {
4+
if (e.target.id == 'dialog-connection') {
55
emit('close-connection-dialog')
66
}
77
}
88

99
return html`
10-
<div id="dialog" class="${stateClass}" onclick=${< EED3 span class="pl-s1">onClick}>
10+
<div id="dialog-connection" class="dialog ${stateClass}" onclick=${onClick}>
1111
<div class="dialog-content">
1212
${state.availablePorts.map(
1313
(port) => html`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function NewFileDestinationDialog(state, emit) {
2+
const stateClass = state.isNewFileDialogOpen ? 'open' : 'closed'
3+
function onClick(e) {
4+
if (e.target.id == 'dialog-new-file') {
5+
emit('close-new-file-dialog')
6+
}
7+
}
8+
let boardOption = ''
9+
if (state.isConnected) {
10+
boardOption = html`
11+
<div class="item" onclick=${() => {emit('create-file','board', 'board_capocchia.py')}}>Board</div>
12+
`
13+
}
14+
return html`
15+
<div id="dialog-new-file" class="dialog ${stateClass}" onclick=${onClick}>
16+
<div class="dialog-content">
17+
${boardOption}
18+
<div class="item" onclick=${() => {emit('create-file', 'disk', 'disk_capocchia.py')}}>Computer</div>
19+
</div>
20+
</div>
21+
`
22+
}

ui/arduino/views/components/toolbar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ function Toolbar(state, emit) {
4949
5050
<div class="separator"></div>
5151
52+
${Button({
53+
icon: 'new-file.svg',
54+
tooltip: `New (${metaKeyString}+N)`,
55+
disabled: state.view != 'editor',
56+
onClick: () => emit('create-new-file')
57+
})}
58+
5259
${Button({
5360
icon: 'save.svg',
5461
tooltip: `Save (${metaKeyString}+S)`,

ui/arduino/views/editor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ function EditorView(state, emit) {
77
${ReplPanel(state, emit)}
88
</div>
99
${ConnectionDialog(state, emit)}
10+
${NewFileDestinationDialog(state, emit)}
1011
`
1112
}

ui/arduino/views/file-manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ function FileManagerView(state, emit) {
4444
</div>
4545
</div>
4646
${ConnectionDialog(state, emit)}
47+
${NewFileDestinationDialog(state, emit)}
4748
`
4849
}

0 commit comments

Comments
 (0)
0