From 6752cf47dfbb83635a1ba160e01fe710319eb02c Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 12 Nov 2023 16:02:04 -0600 Subject: [PATCH] Resolving info widget updating events --- plugins/lsp_client/plugin.py | 2 +- plugins/markdown_preview/plugin.py | 2 +- src/core/controller_data.py | 7 ++++++- src/core/widgets/base/general_info_widget.py | 14 ++++++++++++-- src/core/widgets/base/notebook/editor_events.py | 2 +- .../base/sourceview/source_view_controller.py | 4 ++-- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/plugins/lsp_client/plugin.py b/plugins/lsp_client/plugin.py index 29c87ff..11f2954 100644 --- a/plugins/lsp_client/plugin.py +++ b/plugins/lsp_client/plugin.py @@ -96,7 +96,7 @@ class Plugin(PluginBase): self.delay_completion(source_view, context, callback) def _do_completion(self, source_view, context, callback): - filepath = source_view.get_current_filepath() + filepath = source_view.get_current_file() if not filepath: return diff --git a/plugins/markdown_preview/plugin.py b/plugins/markdown_preview/plugin.py index 24df4a9..b363acb 100644 --- a/plugins/markdown_preview/plugin.py +++ b/plugins/markdown_preview/plugin.py @@ -103,7 +103,7 @@ class Plugin(MarkdownTemplateMixin, PluginBase): text = buffer.get_text(start_iter, end_iter, include_hidden_chars = False) html = markdown.markdown(text) - path = self._active_src_view.get_current_filepath().get_parent().get_path() + path = self._active_src_view.get_current_file().get_parent().get_path() data = self.wrap_html_to_body(html) self._markdown_view.load_html(content = data, base_uri = f"file://{path}/") diff --git a/src/core/controller_data.py b/src/core/controller_data.py index 519e767..def6d80 100644 --- a/src/core/controller_data.py +++ b/src/core/controller_data.py @@ -34,10 +34,15 @@ class ControllerData: ctx = old_notebook.get_style_context() ctx.remove_class("notebook-selected-focus") - notebook = source_view.get_parent().get_parent() ctx = notebook.get_style_context() ctx.add_class("notebook-selected-focus") + + file = source_view.get_current_file() + if file: + source_view.set_bottom_labels(file) + else: + event_system.emit("set_bottom_labels") self.active_src_view = source_view diff --git a/src/core/widgets/base/general_info_widget.py b/src/core/widgets/base/general_info_widget.py index 9e8dc51..f34ff9b 100644 --- a/src/core/widgets/base/general_info_widget.py +++ b/src/core/widgets/base/general_info_widget.py @@ -65,11 +65,13 @@ class GeneralInfoWidget: def set_bottom_labels(self, path = None, line_char = None, file_type = None, encoding_type = None): self._set_path_label(path) - self._set_line_char_label() + self._set_line_char_label(line_char) self._set_file_type_label(file_type) - self._set_encoding_label() + self._set_encoding_label(encoding_type) def _set_path_label(self, gfile = ""): + gfile = "" if not gfile else gfile + if isinstance(gfile, str): self.bottom_path_label.set_text( gfile ) self.bottom_path_label.set_tooltip_text( gfile ) @@ -78,10 +80,18 @@ class GeneralInfoWidget: self.bottom_path_label.set_tooltip_text( gfile.get_path() ) def _set_line_char_label(self, line_char = "1:1"): + line_char = "1:1" if not line_char else line_char + self.bottom_line_char_label.set_text(line_char) def _set_file_type_label(self, file_type = "buffer"): + file_type = "buffer" if not file_type else file_type + self.bottom_file_type_label.set_text(file_type) def _set_encoding_label(self, encoding_type = "utf-8"): + encoding_type = "utf-8" if not encoding_type else encoding_type + self.bottom_encoding_label.set_text(encoding_type) + + diff --git a/src/core/widgets/base/notebook/editor_events.py b/src/core/widgets/base/notebook/editor_events.py index bec494c..73993f5 100644 --- a/src/core/widgets/base/notebook/editor_events.py +++ b/src/core/widgets/base/notebook/editor_events.py @@ -42,7 +42,7 @@ class EditorEventsMixin: file_type = source_view.get_filetype() if not file_type == "buffer": - uri = source_view.get_current_filepath().get_uri() + uri = source_view.get_current_file().get_uri() event_system.emit("textDocument/didClose", (file_type, uri,)) page_num = notebook.page_num(container) diff --git a/src/core/widgets/base/sourceview/source_view_controller.py b/src/core/widgets/base/sourceview/source_view_controller.py index 447a9b9..a173524 100644 --- a/src/core/widgets/base/sourceview/source_view_controller.py +++ b/src/core/widgets/base/sourceview/source_view_controller.py @@ -13,7 +13,7 @@ from .source_view_events import SourceViewEvents class SourceViewControllerMixin(KeyInputController, SourceViewEvents): - def get_current_filepath(self): + def get_current_file(self): return self._current_file def get_filetype(self): @@ -30,7 +30,7 @@ class SourceViewControllerMixin(KeyInputController, SourceViewEvents): iter = buffer.get_iter_at_mark( buffer.get_insert() ) line = iter.get_line() offset = iter.get_line_offset() - uri = self.get_current_filepath().get_uri() + uri = self.get_current_file().get_uri() event_system.emit("textDocument/definition", (self.get_filetype(), uri, line, offset,))