Added code minimap; added DnD of text; initial multi mark insert inferastructure

This commit is contained in:
itdominator 2023-10-07 14:51:12 -05:00
parent 5512655f3d
commit c86c339138
12 changed files with 148 additions and 37 deletions

View File

@ -8,6 +8,7 @@ from utils.ipc_server import IPCServer
from core.window import Window
class AppLaunchException(Exception):
...

View File

@ -6,10 +6,10 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .widgets.save_file_dialog import SaveFileDialog
from .widgets.base.banner_controls import BannerControls
from .editors_container import EditorsContainer
from .widgets.base.general_info_widget import GeneralInfoWidget
from .widgets.save_file_dialog import SaveFileDialog
@ -37,4 +37,4 @@ class CoreWidget(Gtk.Box):
SaveFileDialog()
self.add(BannerControls())
GeneralInfoWidget()
self.add(EditorsContainer())
self.add(EditorsContainer())

View File

@ -6,25 +6,27 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .widgets.miniview_widget import MiniViewWidget
from .widgets.base.notebook.editor_notebook import EditorNotebook
class EditorsContainer(Gtk.Paned):
class EditorsPaned(Gtk.Paned):
def __init__(self):
super(EditorsContainer, self).__init__()
super(EditorsPaned, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show()
self.show_all()
def _setup_styling(self):
self.set_wide_handle(True)
self.set_vexpand(True)
self.set_hexpand(True)
def _setup_signals(self):
...
@ -35,3 +37,32 @@ class EditorsContainer(Gtk.Paned):
def _load_widgets(self):
self.add1(EditorNotebook())
self.add2(EditorNotebook())
class EditorsContainer(Gtk.Box):
def __init__(self):
super(EditorsContainer, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_vexpand(True)
self.set_hexpand(True)
def _setup_signals(self):
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
self.add(EditorsPaned())
self.add(MiniViewWidget())

View File

@ -41,6 +41,8 @@ class EditorControllerMixin:
self.keyboard_move_tab_left(page_num)
if action == "keyboard_move_tab_right":
self.keyboard_move_tab_right(page_num)
if action == "keyboard_insert_mark":
self.keyboard_insert_mark(source_view)
if action == "keyboard_move_tab_to_1":
self.keyboard_move_tab_to_1(page_num)
if action == "keyboard_move_tab_to_2":

View File

@ -65,6 +65,10 @@ class EditorEventsMixin:
page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1
self.set_current_page(page_num)
# NOTE: This feels bad man...
def keyboard_insert_mark(self, source_view):
source_view.keyboard_insert_mark()
def keyboard_move_tab_to_1(self, page_num):
notebook = self.builder.get_object("notebook_1")
if self.NAME == "notebook_1":

View File

@ -55,11 +55,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
def _setup_signals(self):
self.connect("switch-page", self._switch_page_update)
# self.connect("button-press-event", self._dbl_click_create_view)
...
def _subscribe_to_events(self):
# event_system.subscribe("set_buffer_language", self.action_controller, *("set_buffer_language",))
event_system.subscribe("create_view", self._create_view)
event_system.subscribe("set_buffer_style", self.action_controller)
event_system.subscribe("set_buffer_language", self.action_controller)
@ -72,6 +69,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab)
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
event_system.subscribe("keyboard_move_tab_right", self._keyboard_move_tab_right)
event_system.subscribe("keyboard_insert_mark", self._keyboard_insert_mark)
event_system.subscribe("keyboard_move_tab_to_1", self._keyboard_move_tab_to_1)
event_system.subscribe("keyboard_move_tab_to_2", self._keyboard_move_tab_to_2)
event_system.subscribe("keyboard_scale_up_text", self._keyboard_scale_up_text)
@ -118,6 +116,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
def _switch_page_update(self, notebook, page, page_num):
source_view = page.get_source_view()
gfile = source_view.get_current_file()
if not gfile:
event_system.emit("set_path_label", ("",))
event_system.emit("set_file_type_label", (source_view._current_filetype,))
@ -126,6 +125,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
source_view.update_cursor_position()
source_view.set_bottom_labels(gfile)
event_system.emit(f"set_source_view", (source_view,))
def _create_view(self, gfile = None, line: int = 0):
if not self.is_editor_focused: # TODO: Find way to converge this
return
@ -168,6 +169,9 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
def _keyboard_move_tab_right(self):
self.action_controller("keyboard_move_tab_right")
def _keyboard_insert_mark(self):
self.action_controller("keyboard_insert_mark")
def _keyboard_move_tab_to_1(self):
self.action_controller("keyboard_move_tab_to_1")

View File

@ -59,7 +59,7 @@ class PythonCompletionProvider(GObject.Object, GtkSource.CompletionProvider):
return False
ch = iter.get_char()
if not (ch in ('_', '.') or ch.isalnum()):
if not (ch in ('_', '.', ' ') or ch.isalnum()):
return False
return True

View File

@ -7,6 +7,7 @@ gi.require_version('GtkSource', '4')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import Gio
from gi.repository import GtkSource
@ -40,6 +41,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
self._ignore_internal_change = False
self._buffer = self.get_buffer()
self._completion = self.get_completion()
self._insert_marks = []
self._setup_styling()
self._setup_signals()
@ -72,6 +74,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
self.connect("focus", self._on_widget_focus)
self._buffer.connect("mark-set", self._on_cursor_move)
self._buffer.connect('changed', self._is_modified)
self._buffer.connect('insert-text', self._insert_text)
def _subscribe_to_events(self):
...
@ -106,6 +109,15 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
self._is_changed = True
self.update_cursor_position()
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
with text_buffer.freeze_notify():
for mark in self._insert_marks:
itr = text_buffer.get_iter_at_mark(mark)
print(itr)
# GLib.idle_add(text_buffer.insert, *(itr, text_str, -1))
text_buffer.insert(itr, text_str, -1)
def _on_widget_focus(self, widget, eve = None):
target = self.get_parent().get_parent().NAME
path = self._current_file if self._current_file else ""
@ -121,20 +133,19 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
if mark != buf.get_insert(): return
self.update_cursor_position()
# NOTE: Not sure but this might not be efficient if the map reloads the same view.
event_system.emit(f"set_source_view", (self,))
def _set_up_dnd(self):
WIDGET_TARGET_TYPE = 70
URI_TARGET_TYPE = 80
widget_target = Gtk.TargetEntry.new('dummy', Gtk.TargetFlags(0), WIDGET_TARGET_TYPE)
PLAIN_TEXT_TARGET_TYPE = 70
URI_TARGET_TYPE = 80
text_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(0), PLAIN_TEXT_TARGET_TYPE)
uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
targets = [ widget_target, uri_target ]
targets = [ text_target, uri_target ]
self.drag_dest_set_target_list(targets)
def _on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
if info == 70:
print(drag_context)
print(data)
print(info)
# detach_tab(child)
return
if info == 80:

View File

@ -50,6 +50,14 @@ class SourceViewEventsMixin:
event_system.emit("set_line_char_label", (f"{row}:{col}",))
def keyboard_insert_mark(self):
iter = self._buffer.get_iter_at_mark( self._buffer.get_insert() )
mark = Gtk.TextMark.new(name = None, left_gravity = False)
self._buffer.add_mark(mark, iter)
self._insert_marks.append(mark)
mark.set_visible(True)
def got_to_line(self, line: int = 0):
index = line - 1
buffer = self.get_buffer()

View File

@ -0,0 +1,38 @@
# Python imports
# Lib imports
import gi
gi.require_version('GtkSource', '4')
from gi.repository.GtkSource import Map
# Application imports
class MiniViewWidget(Map):
def __init__(self):
super(MiniViewWidget, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_hexpand(False)
def _setup_signals(self):
event_system.subscribe(f"set_source_view", self.set_source_view)
def _subscribe_to_events(self):
...
def _load_widgets(self):
...
def set_source_view(self, source_view):
self.set_view(source_view)

View File

@ -1,23 +1,24 @@
{
"keybindings": {
"help" : "F1",
"open_terminal" : "F4",
"tggl_top_main_menubar" : "Alt_L",
"tear_down" : "<Control>q",
"toggle_highlight_line" : "<Control>h",
"open_files" : "<Control>o",
"keyboard_create_tab" : "<Control>t",
"keyboard_close_tab" : "<Control>w",
"keyboard_save_file" : "<Control>s",
"keyboard_save_file_as" : "<Shift><Control>s",
"keyboard_up" : "Up",
"keyboard_down" : "Down",
"keyboard_left" : "Left",
"keyboard_riht" : "Right",
"keyboard_move_tab_to_1" : "<Shift><Control>Down",
"keyboard_move_tab_to_2" : "<Shift><Control>Up",
"keyboard_move_tab_right" : "<Alt>Right",
"keyboard_move_tab_left" : "<Alt>Left",
"help" : "F1",
"open_terminal" : "F4",
"tggl_top_main_menubar" : "Alt_L",
"tear_down" : "<Control>q",
"toggle_highlight_line" : "<Control>h",
"open_files" : "<Control>o",
"keyboard_create_tab" : "<Control>t",
"keyboard_close_tab" : "<Control>w",
"keyboard_save_file" : "<Control>s",
"keyboard_insert_mark" : "<Control>m",
"keyboard_save_file_as" : "<Shift><Control>s",
"keyboard_up" : "Up",
"keyboard_down" : "Down",
"keyboard_left" : "Left",
"keyboard_riht" : "Right",
"keyboard_move_tab_to_1" : "<Shift><Control>Down",
"keyboard_move_tab_to_2" : "<Shift><Control>Up",
"keyboard_move_tab_right" : "<Alt>Right",
"keyboard_move_tab_left" : "<Alt>Left",
"keyboard_next_tab" : "<Alt>Up",
"keyboard_prev_tab" : "<Alt>Down",
"keyboard_scale_up_text" : "<Control>equal",

View File

@ -1,5 +1,16 @@
/* Set fm to have transparent window */
* {
background: rgba(39, 43, 52, 0.24);
color: rgba(255, 255, 255, 1);
}
}
* selection {
background-color: rgba(0, 115, 115, 0.34);
/* Bergundy */
/* background-color: rgba(116, 0, 0, 0.64); */
color: rgba(255, 255, 255, 0.5);
}
.error_txt { color: rgb(170, 18, 18); }
.warning_txt { color: rgb(255, 168, 0); }
.success_txt { color: rgb(136, 204, 39); }