diff --git a/src/core/widgets/base/notebook/editor_controller.py b/src/core/widgets/base/notebook/editor_controller.py index e2630d9..d3acba1 100644 --- a/src/core/widgets/base/notebook/editor_controller.py +++ b/src/core/widgets/base/notebook/editor_controller.py @@ -1,4 +1,5 @@ # Python imports +import urllib.parse as url_parse # Lib imports import gi @@ -89,7 +90,10 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin): result = message.result[0] line = result["range"]["start"]["line"] uri = result["uri"].replace("file://", "") - file = f"{uri}:{line}" + if "jdt:" in uri: + uri = self.parse_java_jdt_to_uri(uri) + + file = f"{uri}:{line}" event_system.emit("handle_file_from_ipc", file) if hasattr(message, "method"): @@ -98,7 +102,25 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin): source_view = None + def parse_java_jdt_to_uri(self, uri): + parse_str = url_parse.unquote(uri) + post_stub, \ + pre_stub = parse_str.split("?=") + post_stub = post_stub.replace("jdt://contents/", "") + replace_stub = post_stub[ + post_stub.index(".jar") + 4 : post_stub.index(".class") + ] + post_stub = post_stub.replace(replace_stub, replace_stub.replace(".", "/") ) \ + .replace(".jar", "-sources.jar:") + post_stub = post_stub.replace(".class", ".java") + + pre_stub = pre_stub[ + pre_stub.index("/\\/") + 2 : pre_stub.index(".jar") + ] + pre_stub = pre_stub[: pre_stub.rfind("/") + 1 ].replace("\\", "") + + return f"file://{pre_stub}{post_stub}" # Gotten logic from: # https://stackoverflow.com/questions/7139645/find-the-cursor-position-on-a-gtksourceview-window diff --git a/src/core/widgets/base/notebook/editor_notebook.py b/src/core/widgets/base/notebook/editor_notebook.py index 03f3927..2b8eb38 100644 --- a/src/core/widgets/base/notebook/editor_notebook.py +++ b/src/core/widgets/base/notebook/editor_notebook.py @@ -1,4 +1,5 @@ # Python imports +import zipfile # Lib imports import gi @@ -122,12 +123,22 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook): return if isinstance(gfile, str): - parts = gfile.split(":") - gfile = Gio.File.new_for_path(parts[0]) - try: - line = int(parts[1]) if len(parts) > 1 else 0 - except Exception: - ... + parts = gfile.replace("file://", "").split(":") + if len(parts) > 2: + with zipfile.ZipFile(parts[0], 'r') as file: + file.extract(parts[1][1:], "/tmp/newton_extracts") + + gfile = Gio.File.new_for_path( f"/tmp/newton_extracts/{ parts[1][1:] }" ) + try: + line = int(parts[2]) + except Exception: + ... + else: + gfile = Gio.File.new_for_path(parts[0]) + try: + line = int(parts[1]) if len(parts) > 1 else 0 + except Exception: + ... self.create_view(None, None, gfile, line) @@ -142,4 +153,4 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook): self.action_controller("scale_up_text") def _keyboard_scale_down_text(self): - self.action_controller("scale_down_text") + self.action_controller("scale_down_text") \ No newline at end of file