From 35a461ff68e6a853270f87f0ef2ddf6c7f128d26 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Wed, 14 Feb 2024 23:39:45 -0600 Subject: [PATCH] Vimifying efforts --- src/core/controllers/base_controller.py | 6 +- src/core/controllers/files_controller.py | 4 +- src/core/widgets/base/webkit/editor.py | 4 +- .../usr/share/newton/context_path/index.html | 43 ++++++- .../resources/css/newton/main.css | 27 +++++ .../resources/css/newton/overrides.css | 10 ++ .../resources/js/newton/events.js | 68 ++++++++++- .../resources/js/newton/globals.js | 3 + .../resources/js/newton/keybinding-newton.js | 7 ++ .../resources/js/newton/ui-logic.js | 109 +++++++++++++++++- 10 files changed, 265 insertions(+), 16 deletions(-) diff --git a/src/core/controllers/base_controller.py b/src/core/controllers/base_controller.py index da34f74..84e55ee 100644 --- a/src/core/controllers/base_controller.py +++ b/src/core/controllers/base_controller.py @@ -31,6 +31,7 @@ class BaseController(SignalsMixins, BaseControllerData): if len(messages) > 0: settings_manager.set_is_starting_with_file(True) + self.setup_controller_data() self._setup_styling() @@ -38,6 +39,7 @@ class BaseController(SignalsMixins, BaseControllerData): self._subscribe_to_events() self._load_controllers() + if args.no_plugins == "false": self.plugins.launch_plugins() @@ -50,8 +52,8 @@ class BaseController(SignalsMixins, BaseControllerData): def _setup_signals(self): self.window.connect("focus-out-event", self.unset_keys_and_data) - self.window.connect("key-press-event", self.on_global_key_press_controller) - self.window.connect("key-release-event", self.on_global_key_release_controller) + # self.window.connect("key-press-event", self.on_global_key_press_controller) + # self.window.connect("key-release-event", self.on_global_key_release_controller) def _subscribe_to_events(self): event_system.subscribe("shutting_down", lambda: print("Shutting down...")) diff --git a/src/core/controllers/files_controller.py b/src/core/controllers/files_controller.py index 00a3243..3870995 100644 --- a/src/core/controllers/files_controller.py +++ b/src/core/controllers/files_controller.py @@ -84,10 +84,10 @@ class FilesController: 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",)) + # event_system.emit(f"add_tab_{event.originator}", (event.fhash, "buffer",)) 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,)) + # event_system.emit(f"add_tab_with_name_{event.originator}", (event.fhash, content,)) case _: return diff --git a/src/core/widgets/base/webkit/editor.py b/src/core/widgets/base/webkit/editor.py index 1c83c73..736dd4f 100644 --- a/src/core/widgets/base/webkit/editor.py +++ b/src/core/widgets/base/webkit/editor.py @@ -7,7 +7,7 @@ from gi.repository import Gtk # Application imports from ....controllers.files_controller import FilesController -from ...controls.tab_bar import TabBar +# from ...controls.tab_bar import TabBar from .fixed_box import FixedBox @@ -44,5 +44,5 @@ class Editor(Gtk.Box): FilesController(self.INDEX) def _load_widgets(self): - self.add( TabBar(self.INDEX) ) + # self.add( TabBar(self.INDEX) ) self.add( FixedBox(self.INDEX) ) \ No newline at end of file diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index 4505043..c557fb7 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -14,16 +14,49 @@ -
-
-
-

+
+    
+
+
+ +

+
+    
+    
+
+
+
     
-    
+        
 
     
     
diff --git a/user_config/usr/share/newton/context_path/resources/css/newton/main.css b/user_config/usr/share/newton/context_path/resources/css/newton/main.css
index 45f15c6..7cdd1e8 100644
--- a/user_config/usr/share/newton/context_path/resources/css/newton/main.css
+++ b/user_config/usr/share/newton/context_path/resources/css/newton/main.css
@@ -1,5 +1,10 @@
 /* IDs */
 
+#editor,
+#preview-editor {
+    background-color: #00000000;
+}
+
 #editor {
     background-color: #00000000;
     margin: 0;
@@ -28,8 +33,30 @@
 }
 
 
+#preview-editor {
+    height: -webkit-fill-available;
+    width: -webkit-fill-available;
+    max-height: calc(100% - 200px);
+}
+
+#buffers-selection {
+    max-height: 565px;
+    min-height: 565px;
+    overflow-y: auto;
+}
+
 
 /* CLASSES */
+
+.max-height-800 {
+    max-height: 800px;
+}
+
+
+.margin-bottom-neg-200 {
+    margin-bottom: -200px;
+}
+
 .ace_status-indicator {
     color: gray;
     position: absolute;
diff --git a/user_config/usr/share/newton/context_path/resources/css/newton/overrides.css b/user_config/usr/share/newton/context_path/resources/css/newton/overrides.css
index 093c813..3e9122e 100644
--- a/user_config/usr/share/newton/context_path/resources/css/newton/overrides.css
+++ b/user_config/usr/share/newton/context_path/resources/css/newton/overrides.css
@@ -11,4 +11,14 @@ body {
 
 ul, li {
     list-style: none;
+}
+
+.modal-header,
+.modal-footer {
+    background-color: rgba(0, 0, 0, 0.64);
+}
+
+.modal-content {
+    background-color: rgba(50, 56, 62, 0.74);
+    border-color: rgba(249, 148, 6, 0.74);
 }
\ No newline at end of file
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 f0928d3..379c637 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
@@ -1,8 +1,9 @@
 window.onload = (eve) => {
-    loadEditor();
-    loadInitialSessionTab();
-
     console.log("Window Loaded...");
+
+    loadEditor();
+    loadPreviewEditor();
+    loadInitialSession();
 }
 
 window.onerror = function(msg, url, line, col, error) {
@@ -16,4 +17,63 @@ window.onerror = function(msg, url, line, col, error) {
 
     // If you return true, then error alerts (like in older versions of Internet Explorer) will be suppressed.
     return suppressErrorAlert;
-};
\ No newline at end of file
+};
+
+
+document.addEventListener("keyup", (eve) => {
+    switch (eve.key) {
+        case "ArrowUp":
+            break;
+        case "ArrowDown":
+            break;
+        case "ArrowLeft":
+            break;
+        case "ArrowRight":
+            break;
+        case "Enter":
+            if ( isNotNullOrUndefined(previewSel) ) {
+                let event = new MouseEvent('dblclick', {
+                    'view': window,
+                    'bubbles': true,
+                    'cancelable': true
+                  });
+
+                previewSel.dispatchEvent(event);
+            }
+        case "Control":
+            isControlDown = false;
+        case "b":
+            if (isControlDown) {
+                $('#buffers-modal').modal("toggle");
+            }
+            break;
+        default:
+            break
+    }
+});
+
+
+document.addEventListener("keydown", (eve) => {
+    switch (eve.key) {
+        case "ArrowUp":
+            if ( isNotNullOrUndefined(previewSel) ) {
+                eve.preventDefault();
+                selectPriorPreview();
+            }
+            break;
+        case "ArrowDown":
+            if ( isNotNullOrUndefined(previewSel) ) {
+                eve.preventDefault();
+                selectNextPreview();
+            }
+            break;
+        case "ArrowLeft":
+            break;
+        case "ArrowRight":
+            break;
+        case "Control":
+            isControlDown = true;
+        default:
+            break
+    }
+});
diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/globals.js b/user_config/usr/share/newton/context_path/resources/js/newton/globals.js
index 2b277d4..6a4c785 100644
--- a/user_config/usr/share/newton/context_path/resources/js/newton/globals.js
+++ b/user_config/usr/share/newton/context_path/resources/js/newton/globals.js
@@ -3,5 +3,8 @@ const messenger  = (window.webkit) ? window.webkit.messageHandlers : (message) =
 };
 
 let editor         = null;
+let previewEditor  = null;
 let aceSessions    = {};
 let currentSession = null;
+let previewSel     = null;
+let isControlDown  = false;
\ No newline at end of file
diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js
index 13797d8..f8c5272 100644
--- a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js
+++ b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js
@@ -17,6 +17,13 @@ const editorCommands = [
                 editor.showKeyboardShortcuts();
             })
         }
+    }, {
+        name: "listBuffers",
+        bindKey: {win: "ctrl-b", mac: "ctrl-b"},
+        exec: function(editor) {
+            listOpenBuffers();
+        },
+        readOnly: true
     }, {
         name: "saveSession",
         bindKey: {win: "ctrl-s", mac: "ctrl-s"},
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 16fa91b..3ac9885 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
@@ -1,3 +1,30 @@
+
+const loadPreviewEditor = () => {
+    ace.require("ace/ext/language_tools");
+
+    previewEditor = ace.edit("preview-editor");
+    // Note:  https://github.com/ajaxorg/ace/wiki/Configuring-Ace
+    previewEditor.setOptions({
+        printMarginColumn: 80,
+        enableBasicAutocompletion: true,
+        enableInlineAutocompletion: true,
+        enableSnippets: true,
+        enableLiveAutocompletion: true,
+        highlightActiveLine: true,
+        useSoftTabs: true,
+        tabSize: 4,
+        tooltipFollowsMouse: true,
+        useWrapMode: false,
+        scrollPastEnd: 0.5,
+        mergeUndoDeltas: false
+    });
+
+    // Note:  https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts
+    previewEditor.commands.addCommands(editorCommands);
+
+    previewEditor.setTheme("ace/theme/one_dark");
+}
+
 const loadEditor = () => {
     ace.require("ace/ext/language_tools");
 
@@ -24,7 +51,7 @@ const loadEditor = () => {
     editor.setTheme("ace/theme/one_dark");
 }
 
-const loadInitialSessionTab = () => {
+const loadInitialSession = () => {
     newSession(null, editor.getSession());
 }
 
@@ -93,3 +120,83 @@ const saveSession = (fhash) => {
 
     sendMessage("save", ftype, fhash, fpath, content);
 }
+
+
+
+
+const listOpenBuffers = () => {
+     $('#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++) {
+        let session = aceSessions[keys[i]];
+        let liElm   = document.createElement("li");
+        let fname   = aceSessions[keys[i]]["fname"];
+        let fhash   = keys[i];
+
+        liElm.innerText = ( fname === "" ) ? "buffer" : fname;
+        liElm.classList.add("list-group-item");
+        liElm.setAttribute("fhash", fhash);
+
+        if (fhash === currentSession) {
+            previewSel  = liElm;
+            liElm.classList.add("bg-success");
+            liElm.classList.add("bg-info");
+        }
+
+
+        liElm.addEventListener("click", (elm) => {
+            previewSel.classList.remove("bg-info");
+
+            let fhash   = elm.target.getAttribute("fhash");
+            let ftype   = aceSessions[fhash]["ftype"];
+            let session = aceSessions[fhash]["session"];
+            previewSel  = elm.target;
+
+            previewEditor.setSession(session);
+
+            if (ftype !== "buffer") {
+                previewEditor.session.setMode("ace/mode/" + ftype);
+            }
+
+            previewSel.classList.add("bg-info");
+        })
+
+        liElm.addEventListener("dblclick", (elm) => {
+            let fhash   = elm.target.getAttribute("fhash");
+            let ftype   = aceSessions[fhash]["ftype"];
+            let session = aceSessions[fhash]["session"];
+            previewSel  = null;
+
+            setSession(ftype, fhash, session);
+            $('#buffers-modal').modal("toggle");
+        })
+
+        ulElm.appendChild(liElm);
+    }
+
+}
+
+
+const selectPriorPreview = () => {
+    let selectedElm = previewSel.previousElementSibling;
+    if ( !isNotNullOrUndefined(selectedElm) ) {
+        let childrenElms = previewSel.parentElement.children;
+        selectedElm = childrenElms[childrenElms.length - 1];
+    }
+
+    selectedElm.click();
+}
+
+const selectNextPreview = () => {
+    let selectedElm = previewSel.nextElementSibling;
+    if ( !isNotNullOrUndefined(selectedElm) ) {
+        let childrenElms = previewSel.parentElement.children;
+        selectedElm = childrenElms[0];
+    }
+
+    selectedElm.click();
+}
\ No newline at end of file