From 362267fa69e537e96ca8d5b5f4d148cea76c31c5 Mon Sep 17 00:00:00 2001
From: itdominator <1itdominator@gmail.com>
Date: Sat, 27 Jan 2024 20:22:16 -0600
Subject: [PATCH] Opening file on IPC call; css changes; renamed core widget
---
.../{core_widget.py => base_container.py} | 4 +--
src/core/controllers/base_controller.py | 11 ++++----
src/core/controllers/files_controller.py | 25 +++++++++++++++++--
src/core/mixins/signals/ipc_signals_mixin.py | 17 -------------
src/core/mixins/signals_mixins.py | 3 +--
src/core/widgets/base/webkit/ace_editor.py | 10 +++++---
src/libs/data_types/event.py | 1 -
.../usr/share/newton/context_path/index.html | 3 ++-
.../resources/css/newton/main.css | 8 +++---
.../resources/css/newton/overrides.css | 2 +-
.../resources/js/newton/events.js | 4 +--
.../resources/js/newton/ui-logic.js | 2 +-
12 files changed, 50 insertions(+), 40 deletions(-)
rename src/core/containers/{core_widget.py => base_container.py} (94%)
delete mode 100644 src/core/mixins/signals/ipc_signals_mixin.py
diff --git a/src/core/containers/core_widget.py b/src/core/containers/base_container.py
similarity index 94%
rename from src/core/containers/core_widget.py
rename to src/core/containers/base_container.py
index e04841e..5670529 100644
--- a/src/core/containers/core_widget.py
+++ b/src/core/containers/base_container.py
@@ -14,9 +14,9 @@ from .editors_container import EditorsContainer
-class CoreWidget(Gtk.Box):
+class BaseContainer(Gtk.Box):
def __init__(self):
- super(CoreWidget, self).__init__()
+ super(BaseContainer, self).__init__()
builder = settings_manager.get_builder()
self.ctx = self.get_style_context()
diff --git a/src/core/controllers/base_controller.py b/src/core/controllers/base_controller.py
index cfe4d38..da34f74 100644
--- a/src/core/controllers/base_controller.py
+++ b/src/core/controllers/base_controller.py
@@ -11,7 +11,10 @@ from gi.repository import GLib
# Application imports
from ..mixins.signals_mixins import SignalsMixins
-from ..containers.core_widget import CoreWidget
+
+from ..containers.base_container import BaseContainer
+# from ..containers.core_widget import CoreWidget
+
from .base_controller_data import BaseControllerData
from .bridge_controller import BridgeController
@@ -52,7 +55,6 @@ class BaseController(SignalsMixins, BaseControllerData):
def _subscribe_to_events(self):
event_system.subscribe("shutting_down", lambda: print("Shutting down..."))
- event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
event_system.subscribe("set_active_src_view", self.set_active_src_view)
event_system.subscribe("get_active_src_view", self.get_active_src_view)
@@ -65,10 +67,9 @@ class BaseController(SignalsMixins, BaseControllerData):
self.builder.expose_object("main_window", self.window)
settings_manager.set_builder(self.builder)
- self.core_widget = CoreWidget()
+ self.core_widget = BaseContainer()
settings_manager.register_signals_to_builder([self, self.core_widget])
def get_core_widget(self):
- return self.core_widget
-
+ return self.core_widget
\ No newline at end of file
diff --git a/src/core/controllers/files_controller.py b/src/core/controllers/files_controller.py
index 4e3c172..00a3243 100644
--- a/src/core/controllers/files_controller.py
+++ b/src/core/controllers/files_controller.py
@@ -27,9 +27,10 @@ class FilesController:
def _subscribe_to_events(self):
event_system.subscribe(f"set_pre_drop_dnd_{self.INDEX}", self.set_pre_drop_dnd)
+ event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
event_system.subscribe(f"handle_file_event_{self.INDEX}", self.handle_file_event)
- def set_pre_drop_dnd(self, gfiles):
+ def set_pre_drop_dnd(self, gfiles, line: int = 0):
for gfile in gfiles:
fname = gfile.get_basename()
fpath = gfile.get_path()
@@ -46,10 +47,30 @@ class FilesController:
ftype,
fname,
fpath,
- content
+ content,
+ line
)
)
+ def handle_file_from_ipc(self, path: str) -> None:
+ logger.debug(f"Path From IPC: {path}")
+ line = "0"
+ fpath = ""
+
+ try:
+ fpath, line = path.split(":")
+ except:
+ fpath = path
+
+ print(fpath)
+ gfile = Gio.File.new_for_path(fpath)
+
+ try:
+ logger.info(f"Line: {line}")
+ self.set_pre_drop_dnd([gfile], int(line))
+ except Exception as e:
+ logger.info(repr(e))
+
def handle_file_event(self, event):
match event.topic:
case "save":
diff --git a/src/core/mixins/signals/ipc_signals_mixin.py b/src/core/mixins/signals/ipc_signals_mixin.py
deleted file mode 100644
index acd4717..0000000
--- a/src/core/mixins/signals/ipc_signals_mixin.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Python imports
-
-# Lib imports
-
-# Application imports
-
-
-
-class IPCSignalsMixin:
- """ IPCSignalsMixin handle messages from another starting solarfm process. """
-
- def print_to_console(self, message=None):
- print(message)
-
- def handle_file_from_ipc(self, path: any) -> None:
- logger.debug(f"Path From IPC: {path}")
- event_system.emit("create_view", (path,))
diff --git a/src/core/mixins/signals_mixins.py b/src/core/mixins/signals_mixins.py
index 76515f6..52e970e 100644
--- a/src/core/mixins/signals_mixins.py
+++ b/src/core/mixins/signals_mixins.py
@@ -1,7 +1,6 @@
# Python imports
# Lib imports
-from .signals.ipc_signals_mixin import IPCSignalsMixin
from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
# Application imports
@@ -9,5 +8,5 @@ from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
-class SignalsMixins(KeyboardSignalsMixin, IPCSignalsMixin):
+class SignalsMixins(KeyboardSignalsMixin):
...
diff --git a/src/core/widgets/base/webkit/ace_editor.py b/src/core/widgets/base/webkit/ace_editor.py
index 77f2d7f..216d995 100644
--- a/src/core/widgets/base/webkit/ace_editor.py
+++ b/src/core/widgets/base/webkit/ace_editor.py
@@ -80,8 +80,8 @@ class AceEditor(WebKit2.WebView):
except Exception as e:
logger.info(e)
- def load_file(self, ftype: str, fname: str, fpath: str, content: str):
- command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}')"
+ def load_file(self, ftype: str, fname: str, fpath: str, content: str, line: int = 0):
+ command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}', '{line}')"
self.run_javascript(command, None, None)
def new_session(self):
@@ -119,6 +119,8 @@ class WebkitUISettings(WebKit2.Settings):
# Note: Highly insecure setup but most "app" like setup I could think of.
# Audit heavily any scripts/links ran/clicked under this setup!
def _set_default_settings(self):
+ # self.set_enable_xss_auditor(True)
+ # self.set_enable_hyperlink_auditing(True)
self.set_enable_xss_auditor(False)
self.set_enable_hyperlink_auditing(False)
self.set_allow_file_access_from_file_urls(True)
@@ -137,4 +139,6 @@ class WebkitUISettings(WebKit2.Settings):
self.set_enable_webaudio(True)
self.set_enable_accelerated_2d_canvas(True)
- self.set_user_agent(f"{app_name}")
\ No newline at end of file
+ self.set_user_agent(f"Mozilla/5.0 {app_name}")
+
+
diff --git a/src/libs/data_types/event.py b/src/libs/data_types/event.py
index 506123d..efd7ee9 100644
--- a/src/libs/data_types/event.py
+++ b/src/libs/data_types/event.py
@@ -2,7 +2,6 @@
from dataclasses import dataclass, field
# Lib imports
-import gi
# Application imports
diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html
index 26b553e..4505043 100644
--- a/user_config/usr/share/newton/context_path/index.html
+++ b/user_config/usr/share/newton/context_path/index.html
@@ -38,10 +38,11 @@
+
+
-
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 d39bc26..45f15c6 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,3 +1,5 @@
+/* IDs */
+
#editor {
background-color: #00000000;
margin: 0;
@@ -110,6 +112,6 @@
}
/* Other message text colors */
-.errorTxt { color: rgb(170, 18, 18); }
-.warningTxt { color: rgb(255, 168, 0); }
-.successTxt { color: rgb(136, 204, 39); }
\ No newline at end of file
+.error { color: rgb(170, 18, 18); }
+.warning { color: rgb(255, 168, 0); }
+.success { color: rgb(136, 204, 39); }
\ No newline at end of file
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 fa2bd78..093c813 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,4 @@ body {
ul, li {
list-style: none;
-}
+}
\ 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 7fbf25a..f0928d3 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
@@ -14,6 +14,6 @@ window.onerror = function(msg, url, line, col, error) {
sendMessage("error", "", data)
- // If you return true, then error alerts (like in older versions of Internet Explorer) will be suppressed.
- return suppressErrorAlert;
+ // 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
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 4ceeb3a..16fa91b 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
@@ -76,7 +76,7 @@ const removeSession = (fhash) => {
delete aceSessions[fhash];
}
-const loadFile = (ftype, fname, fpath, content) => {
+const loadFile = (ftype, fname, fpath, content, line = 0) => {
let fhash = Date.now().toString();
session = ace.createEditSession( atob(content) );
aceSessions[fhash] = {"ftype": ftype, "fname": fname, "fpath": fpath, "session": session};