Fixed opening file and DnD issues

This commit is contained in:
itdominator 2023-09-10 00:24:47 -05:00
parent 352534dd17
commit 3706ca50ed
9 changed files with 58 additions and 21 deletions

View File

@ -18,6 +18,14 @@ from .mixins.signals_mixins import SignalsMixins
class Controller(SignalsMixins, ControllerData):
def __init__(self, args, unknownargs):
messages = []
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
messages.append(f"FILE|{arg}")
if len(messages) > 0:
settings.set_is_starting_with_file(True)
self.setup_controller_data()
self._setup_styling()
@ -27,10 +35,8 @@ class Controller(SignalsMixins, ControllerData):
if args.no_plugins == "false":
self.plugins.launch_plugins()
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
message = f"FILE|{arg}"
event_system.emit("post_file_to_ipc", message)
for message in messages:
event_system.emit("post_file_to_ipc", message)
def _setup_styling(self):

View File

@ -9,9 +9,9 @@ from ..sourceview_container import SourceViewContainer
class EditorEventsMixin:
def create_view(self, widget = None, eve = None, gfile = None):
container = SourceViewContainer(self.close_tab)
container = SourceViewContainer(self.close_tab)
page_num = self.append_page(container, container.get_tab_widget())
page_num = self.append_page(container, container.get_tab_widget())
self.set_tab_detachable(container, True)
ctx = self.get_style_context()
@ -113,4 +113,4 @@ class EditorEventsMixin:
source_view.scale_down_text()
def toggle_highlight_line(self, source_view):
source_view.toggle_highlight_line()
source_view.toggle_highlight_line()

View File

@ -108,7 +108,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
self.set_action_widget(end_box, 1)
def _load_widgets(self):
if self.NAME == "notebook_1":
if self.NAME == "notebook_1" and not settings.is_starting_with_file():
self.create_view()
def _dbl_click_create_view(self, notebook, eve):
@ -140,11 +140,11 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
self.open_file(gfile)
def _keyboard_create_tab(self, _gfile=None):
def _keyboard_create_tab(self, _gfile = None):
if not self.is_editor_focused: # TODO: Find way to converge this
return
self.create_view(gfile=_gfile)
self.create_view(gfile = _gfile)
def _keyboard_close_tab(self):

View File

@ -166,7 +166,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
except Exception as e:
gfile = Gio.File.new_for_path(uri)
event_system.emit('create_view', (None, None, gfile,))
event_system.emit('create_view', (gfile,))
def _create_file_watcher(self, gfile = None):
@ -222,4 +222,4 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
(self._current_filename != "" and not save_as):
self.open_file(gfile)
else:
event_system.emit("create_view", (None, None, gfile,))
event_system.emit("create_view", (gfile,))

View File

@ -59,7 +59,6 @@ class Window(Gtk.ApplicationWindow):
if settings.is_debug():
self.set_interactive_debugging(True)
self._controller = Controller(args, unknownargs)
if not self._controller:
raise ControllerStartException("Controller exited and doesn't exist...")

View File

@ -85,15 +85,16 @@ class Settings(StartCheckMixin):
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
self._main_window = None
self._main_window_w = 800
self._main_window_h = 600
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
self._main_window = None
self._main_window_w = 800
self._main_window_h = 600
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
self._trace_debug = False
self._debug = False
self._dirty_start = False
self._trace_debug = False
self._debug = False
self._dirty_start = False
self._passed_in_file = False
self.load_settings()
@ -154,6 +155,7 @@ class Settings(StartCheckMixin):
def is_trace_debug(self) -> str: return self._trace_debug
def is_debug(self) -> str: return self._debug
def is_starting_with_file(self) -> bool: return self._passed_in_file
def get_ch_log_lvl(self) -> str: return self._settings["debugging"]["ch_log_lvl"]
def get_fh_log_lvl(self) -> str: return self._settings["debugging"]["fh_log_lvl"]
@ -164,6 +166,9 @@ class Settings(StartCheckMixin):
def set_debug(self, debug):
self._debug = debug
def set_is_starting_with_file(self, is_passed_in_file: False):
self._passed_in_file = is_passed_in_file
def load_settings(self):
with open(self._CONFIG_FILE) as f:

23
src/utils/singleton.py Normal file
View File

@ -0,0 +1,23 @@
# Python imports
# Lib imports
# Application imports
class SingletonError(Exception):
pass
class Singleton:
ccount = 0
def __new__(cls, *args, **kwargs):
obj = super(Singleton, cls).__new__(cls)
cls.ccount += 1
if cls.ccount == 2:
raise SingletonError(f"Exceeded {cls.__name__} instantiation limit...")
return obj

View File

@ -0,0 +1 @@
{}

View File

@ -56,6 +56,9 @@ notebook > header > tabs > tab:checked {
}
.sourceview > * {
background-color: rgba(0, 0, 0, 0.0);
}