generated from itdominator/Python-With-Gtk-Template
Fixed switching buffers; setup open file key binding
This commit is contained in:
parent
35a461ff68
commit
f17e92d148
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
filename = chooser.get_filename()
|
||||||
event_system.emit("keyboard_open_file", (_gfile,))
|
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()
|
chooser.destroy()
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
}, {
|
}, {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue