Opening file on IPC call; css changes; renamed core widget

This commit is contained in:
itdominator 2024-01-27 20:22:16 -06:00
parent 4e06bc3334
commit 362267fa69
12 changed files with 50 additions and 40 deletions

View File

@ -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()

View File

@ -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

View File

@ -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":

View File

@ -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,))

View File

@ -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):
...

View File

@ -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}")
self.set_user_agent(f"Mozilla/5.0 {app_name}")

View File

@ -2,7 +2,6 @@
from dataclasses import dataclass, field
# Lib imports
import gi
# Application imports

View File

@ -38,10 +38,11 @@
<script src="resources/js/libs/ace_editor/ace-linters.js"></script>
<!-- For Application... -->
<script src="resources/js/newton/globals.js"></script>
<!-- <script src="resources/js/newton/ajax.js"></script> -->
<!-- <script src="resources/js/newton/post-ajax.js"></script> -->
<script src="resources/js/newton/globals.js"></script>
<script src="resources/js/newton/utils.js"></script>
<script src="resources/js/newton/keybinding-newton.js"></script>
<script src="resources/js/newton/ui-logic.js"></script>

View File

@ -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); }
.error { color: rgb(170, 18, 18); }
.warning { color: rgb(255, 168, 0); }
.success { color: rgb(136, 204, 39); }

View File

@ -11,4 +11,4 @@ body {
ul, li {
list-style: none;
}
}

View File

@ -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;
};

View File

@ -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};