Fixing close bufer logic; imporoved error handling

This commit is contained in:
itdominator 2024-02-16 22:37:18 -06:00
parent 2a2fe27667
commit 9e3a7eab0b
6 changed files with 35 additions and 15 deletions

View File

@ -48,8 +48,6 @@ class BridgeController:
event_system.emit("post_file_to_ipc", file)
case "save":
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":
event_system.emit(f"handle_file_event_{event.originator}", (event,))
case "load_file":

View File

@ -62,7 +62,6 @@ class FilesController:
except:
fpath = path
print(fpath)
gfile = Gio.File.new_for_path(fpath)
try:
@ -80,8 +79,6 @@ class FilesController:
if ftype and fname and fpath:
event_system.emit(f"update_tab_{event.originator}", (event.fhash, fname,))
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":
self.load_buffer(event.fhash)
# event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",))

View File

@ -15,7 +15,7 @@
<body>
<div id="alerts-container" class="container-fluid">
<div id="alerts-container" class="container">
<div class="row page-alert-zone-container">
<div id="page-alert-zone" class="col">
</div>

View File

@ -4,6 +4,7 @@ window.onload = (eve) => {
loadEditor();
loadPreviewEditor();
loadInitialSession();
loadStartingFiles();
}
window.onerror = function(msg, url, line, col, error) {

View File

@ -33,6 +33,10 @@ const loadInitialSession = () => {
newSession(null, editor.getSession());
}
const loadStartingFiles = () => {
sendMessage("load_starting_files");
}
const newSession = (eve = null, session = null) => {
let ftype = "buffer";
let fhash = Date.now().toString();
@ -69,12 +73,27 @@ const updateSession = (fhash, ftype, fname, fpath) => {
aceSessions[fhash]["fpath"] = fpath;
}
const closeSession = (fhash) => {
let ftype = aceSessions["ftype"];
let fpath = aceSessions["fpath"];
const closeSession = () => {
let keys = Object.keys(aceSessions);
if (keys.length === 1) {
const msg = "Can't close last open buffer...";
displayMessage(msg, "warning", 3);
return;
}
delete aceSessions[fhash];
sendMessage("close", ftype, fhash, fpath, "");
let index = keys.indexOf(currentSession);
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) => {
@ -138,7 +157,7 @@ const listOpenBuffers = () => {
previewEditor.setSession(session);
if (ftype !== "buffer") {
previewEditor.session.setMode("ace/mode/" + ftype);
previewEditor.session.setMode(`ace/mode/${ftype}`);
}
previewSel.classList.add("bg-info");
@ -208,4 +227,3 @@ const toggleLineHighlight = () => {
highlightLine = !highlightLine;
editor.setHighlightActiveLine(highlightLine);
}

View File

@ -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 = {
"topic": topic,
"ftype": ftype,