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,))
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
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()
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}, {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue