generated from itdominator/Python-With-Gtk-Template
Fixing close bufer logic; imporoved error handling
This commit is contained in:
parent
2a2fe27667
commit
9e3a7eab0b
|
@ -48,8 +48,6 @@ class BridgeController:
|
||||||
event_system.emit("post_file_to_ipc", file)
|
event_system.emit("post_file_to_ipc", file)
|
||||||
case "save":
|
case "save":
|
||||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||||
case "close":
|
|
||||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
|
||||||
case "load_buffer":
|
case "load_buffer":
|
||||||
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":
|
||||||
|
|
|
@ -62,7 +62,6 @@ class FilesController:
|
||||||
except:
|
except:
|
||||||
fpath = path
|
fpath = path
|
||||||
|
|
||||||
print(fpath)
|
|
||||||
gfile = Gio.File.new_for_path(fpath)
|
gfile = Gio.File.new_for_path(fpath)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -80,8 +79,6 @@ class FilesController:
|
||||||
if ftype and fname and fpath:
|
if ftype and fname and fpath:
|
||||||
event_system.emit(f"update_tab_{event.originator}", (event.fhash, fname,))
|
event_system.emit(f"update_tab_{event.originator}", (event.fhash, fname,))
|
||||||
event_system.emit(f"updated_session_{event.originator}", (event.fhash, ftype, fname, fpath))
|
event_system.emit(f"updated_session_{event.originator}", (event.fhash, ftype, fname, fpath))
|
||||||
case "close":
|
|
||||||
event_system.emit(f"close_tab_{event.originator}", (event.fhash))
|
|
||||||
case "load_buffer":
|
case "load_buffer":
|
||||||
self.load_buffer(event.fhash)
|
self.load_buffer(event.fhash)
|
||||||
# event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",))
|
# event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",))
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div id="alerts-container" class="container-fluid">
|
<div id="alerts-container" class="container">
|
||||||
<div class="row page-alert-zone-container">
|
<div class="row page-alert-zone-container">
|
||||||
<div id="page-alert-zone" class="col">
|
<div id="page-alert-zone" class="col">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,6 +4,7 @@ window.onload = (eve) => {
|
||||||
loadEditor();
|
loadEditor();
|
||||||
loadPreviewEditor();
|
loadPreviewEditor();
|
||||||
loadInitialSession();
|
loadInitialSession();
|
||||||
|
loadStartingFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onerror = function(msg, url, line, col, error) {
|
window.onerror = function(msg, url, line, col, error) {
|
||||||
|
|
|
@ -33,6 +33,10 @@ const loadInitialSession = () => {
|
||||||
newSession(null, editor.getSession());
|
newSession(null, editor.getSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadStartingFiles = () => {
|
||||||
|
sendMessage("load_starting_files");
|
||||||
|
}
|
||||||
|
|
||||||
const newSession = (eve = null, session = null) => {
|
const newSession = (eve = null, session = null) => {
|
||||||
let ftype = "buffer";
|
let ftype = "buffer";
|
||||||
let fhash = Date.now().toString();
|
let fhash = Date.now().toString();
|
||||||
|
@ -69,12 +73,27 @@ const updateSession = (fhash, ftype, fname, fpath) => {
|
||||||
aceSessions[fhash]["fpath"] = fpath;
|
aceSessions[fhash]["fpath"] = fpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeSession = (fhash) => {
|
const closeSession = () => {
|
||||||
let ftype = aceSessions["ftype"];
|
let keys = Object.keys(aceSessions);
|
||||||
let fpath = aceSessions["fpath"];
|
if (keys.length === 1) {
|
||||||
|
const msg = "Can't close last open buffer...";
|
||||||
|
displayMessage(msg, "warning", 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
delete aceSessions[fhash];
|
let index = keys.indexOf(currentSession);
|
||||||
sendMessage("close", ftype, fhash, fpath, "");
|
let fhash = keys[index + 1];
|
||||||
|
if ( !isNotNullOrUndefined(fhash) ) {
|
||||||
|
fhash = keys[index - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let ftype = aceSessions[fhash]["ftype"];
|
||||||
|
let session = aceSessions[fhash]["session"];
|
||||||
|
|
||||||
|
delete aceSessions[currentSession]["session"];
|
||||||
|
delete aceSessions[currentSession];
|
||||||
|
|
||||||
|
setSession(ftype, fhash, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeSession = (fhash) => {
|
const removeSession = (fhash) => {
|
||||||
|
@ -138,7 +157,7 @@ const listOpenBuffers = () => {
|
||||||
previewEditor.setSession(session);
|
previewEditor.setSession(session);
|
||||||
|
|
||||||
if (ftype !== "buffer") {
|
if (ftype !== "buffer") {
|
||||||
previewEditor.session.setMode("ace/mode/" + ftype);
|
previewEditor.session.setMode(`ace/mode/${ftype}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
previewSel.classList.add("bg-info");
|
previewSel.classList.add("bg-info");
|
||||||
|
@ -208,4 +227,3 @@ const toggleLineHighlight = () => {
|
||||||
highlightLine = !highlightLine;
|
highlightLine = !highlightLine;
|
||||||
editor.setHighlightActiveLine(highlightLine);
|
editor.setHighlightActiveLine(highlightLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,13 @@ const displayMessage = (message, type, timeout, msgWindow = "page-alert-zone") =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMessage = (topic, ftype, fhash, fpath, content) => {
|
const sendMessage = (topic = null, ftype = "", fhash = "", fpath = "", content = "") => {
|
||||||
|
if ( !isNotNullOrUndefined(topic) ) {
|
||||||
|
const msg = "No 'topic' passed in 'sendMessage' method...";
|
||||||
|
displayMessage(msg, "danger");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const messageBody = {
|
const messageBody = {
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
"ftype": ftype,
|
"ftype": ftype,
|
||||||
|
|
Loading…
Reference in New Issue