Skip to content

Commit 088a088

Browse files
authored
Merge pull request #437 from makermelissa/beta
Change text input to custom dialog
2 parents ef6f1d7 + 6f94f20 commit 088a088

5 files changed

Lines changed: 56 additions & 28 deletions

File tree

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@
199199
<button class="purple-button ok-button">Ok</button>
200200
</div>
201201
</div>
202+
<div class="popup-modal shadow prompt" data-popup-modal="input">
203+
<div id="message"></div>
204+
<input type="text" id="inputvalue" />
205+
<div class="buttons centered">
206+
<button class="purple-button ok-button">Ok</button>
207+
<button class="purple-button cancel-button">Cancel</button>
208+
</div>
209+
</div>
202210
<div class="popup-modal shadow prompt" data-popup-modal="progress" data-tabbable="false">
203211
<div class="label centered" id="status"></div>
204212
<div class="label centered" id="percentage"></div>

js/common/dialogs.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ class MessageModal extends GenericModal {
241241
}
242242
}
243243

244+
class InputModal extends GenericModal {
245+
_handleOkButton(event) {
246+
this._returnValue(this._getElement('inputValueField').value);
247+
}
248+
249+
async open(message, defaultValue="") {
250+
let p = super.open();
251+
const cancelButton = this._currentModal.querySelector("button.cancel-button");
252+
this._addDialogElement('cancelButton', cancelButton, 'click', this._closeModal);
253+
const okButton = this._currentModal.querySelector("button.ok-button");
254+
this._addDialogElement('okButton', okButton, 'click', this._handleOkButton);
255+
const inputValueField = this._currentModal.querySelector("#inputvalue");
256+
this._addDialogElement('inputValueField', inputValueField);
257+
this._setElementValue('inputValueField', defaultValue);
258+
this._currentModal.querySelector("#message").innerHTML = message;
259+
260+
return p;
261+
}
262+
}
263+
244264
class ProgressDialog extends GenericModal {
245265
async open() {
246266
let p = super.open();
@@ -424,5 +444,6 @@ export {
424444
UnsavedDialog,
425445
DiscoveryModal,
426446
ProgressDialog,
427-
DeviceInfoModal
447+
DeviceInfoModal,
448+
InputModal
428449
};

js/common/file_dialog.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {GenericModal, ProgressDialog, ButtonValueDialog} from './dialogs.js';
1+
import {GenericModal, ProgressDialog, ButtonValueDialog, InputModal} from './dialogs.js';
22
import {readUploadedFileAsArrayBuffer} from './utilities.js';
33
import {saveAs} from 'file-saver';
44
import JSZip from 'jszip';
@@ -321,6 +321,11 @@ class FileDialog extends GenericModal {
321321
return selectedItems > 1;
322322
}
323323

324+
async _prompt(message, defaultValue="") {
325+
const inputModal = new InputModal("input");
326+
return await inputModal.open(message, defaultValue);
327+
}
328+
324329
_updateToolbar() {
325330
this._setElementEnabled('delButton', this._canPerformWritableFileOperation());
326331
this._setElementEnabled('renameButton', !this._multipleItemsSelected() && this._canPerformWritableFileOperation());
@@ -653,7 +658,8 @@ class FileDialog extends GenericModal {
653658
return;
654659
}
655660
oldName = oldName[0];
656-
let newName = prompt("Enter a new folder name", oldName);
661+
let newName = await this._prompt("Enter a new name", oldName);
662+
657663
// If cancelled, do nothing
658664
if (!newName) {
659665
return;
@@ -688,7 +694,7 @@ class FileDialog extends GenericModal {
688694
async _handleNewFolderButton() {
689695
if (this._readOnlyMode) return;
690696
// prompt for new folder name
691-
let folderName = prompt("Enter a new folder name");
697+
let folderName = await this._prompt("Enter a new folder name");
692698
// If cancelled, do nothing
693699
if (!folderName) {
694700
return;

package-lock.json

Lines changed: 14 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
},
1616
"dependencies": {
1717
"@adafruit/ble-file-transfer-js": "adafruit/ble-file-transfer-js#1.0.4",
18-
"@adafruit/circuitpython-repl-js": "adafruit/circuitpython-repl-js#3.2.4",
18+
"@adafruit/circuitpython-repl-js": "adafruit/circuitpython-repl-js#3.2.5",
1919
"@codemirror/lang-python": "^6.2.1",
2020
"@fortawesome/fontawesome-free": "^7.1.0",
21-
"@xterm/addon-fit": "^0.10.0",
22-
"@xterm/addon-web-links": "^0.11.0",
21+
"@xterm/addon-fit": "^0.11.0",
22+
"@xterm/addon-web-links": "^0.12.0",
2323
"@xterm/xterm": "^5.5.0",
2424
"chart.js": "^4.5.1",
2525
"codemirror": "^6.0.2",

0 commit comments

Comments
 (0)