diff --git a/src/core/controllers/bridge_controller.py b/src/core/controllers/bridge_controller.py index a230e83..5e06603 100644 --- a/src/core/controllers/bridge_controller.py +++ b/src/core/controllers/bridge_controller.py @@ -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": diff --git a/src/core/controllers/files_controller.py b/src/core/controllers/files_controller.py index 7ea1ba1..0c75b28 100644 --- a/src/core/controllers/files_controller.py +++ b/src/core/controllers/files_controller.py @@ -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",)) diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index 495a773..03343e1 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -15,7 +15,7 @@ -
+
diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/events.js b/user_config/usr/share/newton/context_path/resources/js/newton/events.js index 5162210..3ed69fa 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/events.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/events.js @@ -4,6 +4,7 @@ window.onload = (eve) => { loadEditor(); loadPreviewEditor(); loadInitialSession(); + loadStartingFiles(); } window.onerror = function(msg, url, line, col, error) { diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js index 461d311..78f962e 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js @@ -23,7 +23,7 @@ const loadEditor = () => { editor.commands.addCommands(editorCommands); editor.setTheme("ace/theme/one_dark"); - + editor.addEventListener("click", (eve) => { setLabels(); }); @@ -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); } - diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/utils.js b/user_config/usr/share/newton/context_path/resources/js/newton/utils.js index c778273..e6d361b 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/utils.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/utils.js @@ -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,