Fixed switching buffers; setup open file key binding

This commit is contained in:
itdominator 2024-02-15 17:48:50 -06:00
parent 35a461ff68
commit f17e92d148
6 changed files with 49 additions and 22 deletions

View File

@ -33,6 +33,8 @@ class BridgeController:
event_system.emit(f"handle_file_event_{event.originator}", (event,)) event_system.emit(f"handle_file_event_{event.originator}", (event,))
case "load_file": case "load_file":
event_system.emit(f"handle_file_event_{event.originator}", (event,)) 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": case "error":
content = base64.b64decode( event.content.encode() ).decode("utf-8") content = base64.b64decode( event.content.encode() ).decode("utf-8")
logger.info(content) logger.info(content)

View File

@ -88,6 +88,8 @@ class FilesController:
case "load_file": case "load_file":
content = base64.b64decode( event.content.encode() ).decode("utf-8") content = base64.b64decode( event.content.encode() ).decode("utf-8")
# event_system.emit(f"add_tab_with_name_{event.originator}", (event.fhash, content,)) # 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 _: case _:
return return

View File

@ -41,7 +41,7 @@ class OpenFileButton(Gtk.Button):
def _load_widgets(self): 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, chooser = Gtk.FileChooserDialog("Open File...", None,
Gtk.FileChooserAction.OPEN, Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
@ -54,11 +54,24 @@ class OpenFileButton(Gtk.Button):
... ...
response = chooser.run() response = chooser.run()
if response == Gtk.ResponseType.OK: if not response == Gtk.ResponseType.OK:
filename = chooser.get_filename() chooser.destroy()
if filename: return
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,))
chooser.destroy() 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()

View File

@ -44,7 +44,14 @@ document.addEventListener("keyup", (eve) => {
isControlDown = false; isControlDown = false;
case "b": case "b":
if (isControlDown) { if (isControlDown) {
$('#buffers-modal').modal("toggle"); if ( isNotNullOrUndefined(previewSel) ) {
clearChildNodes(previewSel.parentElement);
$('#buffers-modal').modal("toggle");
previewSel = null;
editor.focus();
} else {
listOpenBuffers();
}
} }
break; break;
default: default:

View File

@ -18,10 +18,10 @@ const editorCommands = [
}) })
} }
}, { }, {
name: "listBuffers", name: "openFile",
bindKey: {win: "ctrl-b", mac: "ctrl-b"}, bindKey: {win: "ctrl-o", mac: "ctrl-o"},
exec: function(editor) { exec: function(editor) {
listOpenBuffers(); sendMessage("open_file", "", "", "", "");
}, },
readOnly: true readOnly: true
}, { }, {

View File

@ -125,13 +125,12 @@ const saveSession = (fhash) => {
const listOpenBuffers = () => { const listOpenBuffers = () => {
$('#buffers-modal').modal("toggle"); $('#buffers-modal').modal("toggle");
let ulElm = document.getElementById('buffers-selection'); let ulElm = document.getElementById('buffers-selection');
let keys = Object.keys(aceSessions); let keys = Object.keys(aceSessions);
clearChildNodes(ulElm); for (let i = 0; i < keys.length; i++) {
for (var i = 0; i < keys.length; i++) {
let session = aceSessions[keys[i]]; let session = aceSessions[keys[i]];
let liElm = document.createElement("li"); let liElm = document.createElement("li");
let fname = aceSessions[keys[i]]["fname"]; 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"); previewSel.classList.remove("bg-info");
let fhash = elm.target.getAttribute("fhash"); let fhash = eve.target.getAttribute("fhash");
let ftype = aceSessions[fhash]["ftype"]; let ftype = aceSessions[fhash]["ftype"];
let session = aceSessions[fhash]["session"]; let session = aceSessions[fhash]["session"];
previewSel = elm.target; previewSel = eve.target;
previewEditor.setSession(session); previewEditor.setSession(session);
@ -165,19 +166,21 @@ const listOpenBuffers = () => {
previewSel.classList.add("bg-info"); previewSel.classList.add("bg-info");
}) })
liElm.addEventListener("dblclick", (elm) => { liElm.addEventListener("dblclick", (eve) => {
let fhash = elm.target.getAttribute("fhash"); let fhash = eve.target.getAttribute("fhash");
let ftype = aceSessions[fhash]["ftype"]; let ftype = aceSessions[fhash]["ftype"];
let session = aceSessions[fhash]["session"]; let session = aceSessions[fhash]["session"];
previewSel = null;
clearChildNodes(previewSel.parentElement);
previewSel = null;
setSession(ftype, fhash, session); setSession(ftype, fhash, session);
$('#buffers-modal').modal("toggle"); $('#buffers-modal').modal("toggle");
editor.focus();
}) })
ulElm.appendChild(liElm); ulElm.appendChild(liElm);
} }
} }