Tab inferastructure setup

This commit is contained in:
itdominator 2024-01-19 23:52:18 -06:00
parent 45f813a1b0
commit 2dcfdabe37
5 changed files with 131 additions and 35 deletions

View File

@ -9,6 +9,8 @@ from gi.repository import Gtk
from ..widgets.separator_widget import Separator
from ..widgets.miniview_widget import MiniViewWidget
from ..widgets.base.notebook.editor_notebook import EditorNotebook
from ..widgets.controls.tab_bar import TabBar
from .fixed_box import FixedBox
@ -35,8 +37,30 @@ class EditorsPaned(Gtk.Paned):
event_system.subscribe("update_paned_handle", self._update_paned_handle)
def _load_widgets(self):
self.add1(FixedBox())
self.add2(FixedBox())
left_view = Gtk.Box()
right_view = Gtk.Box()
left_view.add( TabBar() )
left_view.add( FixedBox() )
right_view.add( TabBar() )
right_view.add( FixedBox() )
left_view.set_orientation( Gtk.Orientation.VERTICAL )
right_view.set_orientation( Gtk.Orientation.VERTICAL )
left_view.show()
right_view.show()
self.add1(left_view)
self.add2(right_view)
# self.add1(FixedBox())
# self.add2(FixedBox())
# self.add1(EditorNotebook())
# self.add2(EditorNotebook())
@ -77,6 +101,8 @@ class EditorsContainer(Gtk.Box):
def _load_widgets(self):
miniview = MiniViewWidget()
miniview.hide()
self.add(Separator("separator_left"))
self.add(EditorsPaned())
self.add(Separator("separator_right"))

View File

@ -29,7 +29,7 @@ class FixedBox(Gtk.Fixed):
def _setup_styling(self):
self.size_allocate( self.get_parent().get_allocated_size().allocation )
...
def _setup_signals(self):
self.connect("realize", self._on_realize)

View File

@ -0,0 +1,96 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..tab_header_widget import TabHeaderWidget
class TabBar(Gtk.Notebook):
def __init__(self):
super(TabBar, self).__init__()
self.set_group_name("editor_widget")
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
...
def _setup_signals(self):
self.connect("switch-page", self._switch_page_update)
# self.connect("key-press-event", self._key_press_event)
# self.connect("key-release-event", self._key_release_event)
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
start_box = Gtk.Box()
end_box = Gtk.Box()
add_tab = Gtk.Button(label = "+")
add_tab.connect("released", self.add_tab_click)
end_box.add(add_tab)
start_box.show_all()
end_box.show_all()
self.set_action_widget(start_box, 0)
self.set_action_widget(end_box, 1)
self.add_tab_click(None)
def _switch_page_update(self, notebook, page, page_num):
...
def add_tab_click(self, widget):
container = Gtk.Box()
page_num = self.append_page(container, TabHeaderWidget(container, self._close_tab))
self.set_tab_detachable(container, True)
self.set_tab_reorderable(container, True)
self.show_all()
self.set_current_page(page_num)
# Note: Need to get parent instead given we pass the close_tab method
# from a potentially former notebook.
def _close_tab(self, widget, container):
notebook = container.get_parent()
page_num = notebook.page_num(container)
notebook.remove_page(page_num)
# def close_tab(self, button, container, source_view, eve = None):
# notebook = container.get_parent()
# if notebook.NAME == "notebook_1" and notebook.get_n_pages() == 1:
# return
# file_type = source_view.get_filetype()
# if not file_type == "buffer":
# uri = source_view.get_current_file().get_uri()
# event_system.emit("textDocument/didClose", (file_type, uri,))
# page_num = notebook.page_num(container)
# source_view._cancel_current_file_watchers()
# notebook.remove_page(page_num)
# if notebook.NAME == "notebook_2" and notebook.get_n_pages() == 0:
# notebook.hide()
# event_system.emit("focused_target_changed", ("notebook_1",))

View File

@ -12,28 +12,17 @@ from gi.repository import Gtk
class TabHeaderWidget(Gtk.Box):
""" docstring for TabHeaderWidget """
ccount = 0
def __new__(cls, *args, **kwargs):
obj = super(TabHeaderWidget, cls).__new__(cls)
cls.ccount += 1
return obj
def __init__(self, scroll_view, source_view, close_tab):
def __init__(self, content, close_tab):
super(TabHeaderWidget, self).__init__()
self.INDEX = self.ccount
self.NAME = f"tab_{self.INDEX}"
self._scroll_view = scroll_view
self._source_view = source_view
self._close_tab = close_tab # NOTE: Close method in tab_mixin
self.content = content
self.close_tab = close_tab
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.set_tab_label()
self.show_all()
@ -48,11 +37,11 @@ class TabHeaderWidget(Gtk.Box):
...
def _load_widgets(self):
label = Gtk.Label()
label = Gtk.Label(label = "buffer")
close = Gtk.Button()
icon = Gtk.Image(stock = Gtk.STOCK_CLOSE)
# NOTE: Setup with settings and from file
# TODO: Setup with settings and from file
label.set_xalign(0.0)
label.set_margin_left(25)
label.set_margin_right(25)
@ -61,16 +50,7 @@ class TabHeaderWidget(Gtk.Box):
close.set_always_show_image(True)
close.set_hexpand(False)
close.set_image( Gtk.Image.new_from_icon_name("gtk-close", 4) )
close.connect("released", self._close_tab, *(self._scroll_view, self._source_view,))
close.connect("released", self.close_tab, *(self.content,))
self.add(label)
self.add(close)
def set_tab_label(self, label = "untitled"):
self.get_children()[0].set_label(label)
def set_status(self, changed = False):
label = self.get_children()[0]
ctx = label.get_style_context()
ctx.add_class("buffer_changed") if changed else ctx.remove_class("buffer_changed")

View File

@ -28,12 +28,6 @@
/* CLASSES */
.editor-container {
position: relative;
width: 100vw;
height: 100vh;
}
.ace_status-indicator {
color: gray;
position: absolute;