generated from itdominator/Python-With-Gtk-Template
Base handling of java source dir paths
This commit is contained in:
parent
e3774ee5f3
commit
84b24d6767
|
@ -1,4 +1,5 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import urllib.parse as url_parse
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
import gi
|
import gi
|
||||||
|
@ -89,7 +90,10 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
|
||||||
result = message.result[0]
|
result = message.result[0]
|
||||||
line = result["range"]["start"]["line"]
|
line = result["range"]["start"]["line"]
|
||||||
uri = result["uri"].replace("file://", "")
|
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)
|
event_system.emit("handle_file_from_ipc", file)
|
||||||
|
|
||||||
if hasattr(message, "method"):
|
if hasattr(message, "method"):
|
||||||
|
@ -98,7 +102,25 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
|
||||||
|
|
||||||
source_view = None
|
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:
|
# Gotten logic from:
|
||||||
# https://stackoverflow.com/questions/7139645/find-the-cursor-position-on-a-gtksourceview-window
|
# https://stackoverflow.com/questions/7139645/find-the-cursor-position-on-a-gtksourceview-window
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import zipfile
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
import gi
|
import gi
|
||||||
|
@ -122,12 +123,22 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook):
|
||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(gfile, str):
|
if isinstance(gfile, str):
|
||||||
parts = gfile.split(":")
|
parts = gfile.replace("file://", "").split(":")
|
||||||
gfile = Gio.File.new_for_path(parts[0])
|
if len(parts) > 2:
|
||||||
try:
|
with zipfile.ZipFile(parts[0], 'r') as file:
|
||||||
line = int(parts[1]) if len(parts) > 1 else 0
|
file.extract(parts[1][1:], "/tmp/newton_extracts")
|
||||||
except Exception:
|
|
||||||
...
|
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)
|
self.create_view(None, None, gfile, line)
|
||||||
|
|
||||||
|
@ -142,4 +153,4 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook):
|
||||||
self.action_controller("scale_up_text")
|
self.action_controller("scale_up_text")
|
||||||
|
|
||||||
def _keyboard_scale_down_text(self):
|
def _keyboard_scale_down_text(self):
|
||||||
self.action_controller("scale_down_text")
|
self.action_controller("scale_down_text")
|
Loading…
Reference in New Issue