diff --git a/src/core/controllers/bridge_controller.py b/src/core/controllers/bridge_controller.py index 79735ca..4affce8 100644 --- a/src/core/controllers/bridge_controller.py +++ b/src/core/controllers/bridge_controller.py @@ -33,6 +33,8 @@ class BridgeController: event_system.emit(f"handle_file_event_{event.originator}", (event,)) case "load_file": event_system.emit(f"handle_file_event_{event.originator}", (event,)) + case "open_file": + event_system.emit(f"handle_file_event_{event.originator}", (event,)) case "error": content = base64.b64decode( event.content.encode() ).decode("utf-8") logger.info(content) diff --git a/src/core/controllers/files_controller.py b/src/core/controllers/files_controller.py index 3870995..7ea1ba1 100644 --- a/src/core/controllers/files_controller.py +++ b/src/core/controllers/files_controller.py @@ -88,6 +88,8 @@ class FilesController: case "load_file": content = base64.b64decode( event.content.encode() ).decode("utf-8") # event_system.emit(f"add_tab_with_name_{event.originator}", (event.fhash, content,)) + case "open_file": + event_system.emit(f"open_files", (None, None, self.INDEX,)) case _: return diff --git a/src/core/widgets/controls/open_file_button.py b/src/core/widgets/controls/open_file_button.py index 3b98d65..e60e1f4 100644 --- a/src/core/widgets/controls/open_file_button.py +++ b/src/core/widgets/controls/open_file_button.py @@ -41,7 +41,7 @@ class OpenFileButton(Gtk.Button): def _load_widgets(self): ... - def _open_files(self, widget = None, eve = None): + def _open_files(self, widget = None, eve = None, widget_index = None): chooser = Gtk.FileChooserDialog("Open File...", None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, @@ -54,11 +54,24 @@ class OpenFileButton(Gtk.Button): ... response = chooser.run() - if response == Gtk.ResponseType.OK: - filename = chooser.get_filename() - if filename: - path = filename if os.path.isabs(filename) else os.path.abspath(filename) - _gfile = Gio.File.new_for_path(path) - event_system.emit("keyboard_open_file", (_gfile,)) + if not response == Gtk.ResponseType.OK: + chooser.destroy() + return - chooser.destroy() \ No newline at end of file + filename = chooser.get_filename() + if not filename: + chooser.destroy() + return + + + path = filename if os.path.isabs(filename) else os.path.abspath(filename) + _gfile = Gio.File.new_for_path(path) + + event_system.emit( + f"set_pre_drop_dnd_{widget_index}" if widget_index else "keyboard_open_file", + ( + [_gfile], + ) + ) + + chooser.destroy() diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/events.js b/user_config/usr/share/newton/context_path/resources/js/newton/events.js index 379c637..7021508 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/events.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/events.js @@ -44,7 +44,14 @@ document.addEventListener("keyup", (eve) => { isControlDown = false; case "b": if (isControlDown) { - $('#buffers-modal').modal("toggle"); + if ( isNotNullOrUndefined(previewSel) ) { + clearChildNodes(previewSel.parentElement); + $('#buffers-modal').modal("toggle"); + previewSel = null; + editor.focus(); + } else { + listOpenBuffers(); + } } break; default: diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js index f8c5272..5c06ca0 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js @@ -18,10 +18,10 @@ const editorCommands = [ }) } }, { - name: "listBuffers", - bindKey: {win: "ctrl-b", mac: "ctrl-b"}, + name: "openFile", + bindKey: {win: "ctrl-o", mac: "ctrl-o"}, exec: function(editor) { - listOpenBuffers(); + sendMessage("open_file", "", "", "", ""); }, readOnly: true }, { diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js index 3ac9885..cd81962 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js @@ -125,13 +125,12 @@ const saveSession = (fhash) => { const listOpenBuffers = () => { - $('#buffers-modal').modal("toggle"); + $('#buffers-modal').modal("toggle"); let ulElm = document.getElementById('buffers-selection'); let keys = Object.keys(aceSessions); - clearChildNodes(ulElm); - for (var i = 0; i < keys.length; i++) { + for (let i = 0; i < keys.length; i++) { let session = aceSessions[keys[i]]; let liElm = document.createElement("li"); let fname = aceSessions[keys[i]]["fname"]; @@ -148,13 +147,15 @@ const listOpenBuffers = () => { } - liElm.addEventListener("click", (elm) => { + liElm.addEventListener("click", (eve) => { + if ( !isNotNullOrUndefined(previewSel) ) return; + previewSel.classList.remove("bg-info"); - let fhash = elm.target.getAttribute("fhash"); + let fhash = eve.target.getAttribute("fhash"); let ftype = aceSessions[fhash]["ftype"]; let session = aceSessions[fhash]["session"]; - previewSel = elm.target; + previewSel = eve.target; previewEditor.setSession(session); @@ -165,19 +166,21 @@ const listOpenBuffers = () => { previewSel.classList.add("bg-info"); }) - liElm.addEventListener("dblclick", (elm) => { - let fhash = elm.target.getAttribute("fhash"); + liElm.addEventListener("dblclick", (eve) => { + let fhash = eve.target.getAttribute("fhash"); let ftype = aceSessions[fhash]["ftype"]; let session = aceSessions[fhash]["session"]; - previewSel = null; + clearChildNodes(previewSel.parentElement); + + previewSel = null; setSession(ftype, fhash, session); $('#buffers-modal').modal("toggle"); + editor.focus(); }) ulElm.appendChild(liElm); } - }