Skip to content

Commit

Permalink
feat: Floating opened editors list & minor UI tweaks #395
Browse files Browse the repository at this point in the history
from tomlin7/open_editors
  • Loading branch information
tomlin7 authored Oct 7, 2024
2 parents 7f53242 + 0ca0777 commit 8853022
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 78 deletions.
1 change: 1 addition & 0 deletions src/biscuit/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .io import IO
from .menu import Checkable, Command, Dropdown, Menu
from .notifications import Notification, Notifications
from .open_editors import OpenEditors
from .palette import Palette
from .sysinfo import SysInfo
from .textutils import *
2 changes: 2 additions & 0 deletions src/biscuit/common/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def _process_in(self) -> None:
self.p.stdin.write(chunk)
except queue.Empty:
continue
except OSError:
continue

try:
self.p.stdin.flush()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
import tkinter as tk

from biscuit.common.icons import Icons
from biscuit.common.ui import Closable
from biscuit.common.ui import Closable, Frame
from biscuit.common.ui.native import Label, Toplevel

from ..sidebar_item import SideBarViewItem


class OpenEditors(SideBarViewItem):
"""View that displays the open editors in the editor tabs.
class OpenEditors(Toplevel):
"""Toplevel view that displays the open editors in the editor tabs.
The OpenEditors view displays the open editors in the editor tabs.
- The user can switch between open editors, close the editors."""

def __init__(self, master, startpath=None, itembar=True, *args, **kwargs) -> None:
self.title = "Open Editors"
self.__actions__ = (
(Icons.NEW_FILE, lambda: self.base.palette.show("newfile:")),
)
super().__init__(master, itembar=itembar, *args, **kwargs)
self.path = startpath
def __init__(self, master, *args, **kwargs) -> None:
super().__init__(master, *args, **kwargs)
self.config(bg=self.base.theme.border)
self.overrideredirect(True)
self.nodes = {}
self.withdraw()

def refresh(self):
if not self.nodes:
self.itembar.hide_content()
else:
self.itembar.show_content()
self.container = Frame(self)
self.container.pack(fill=tk.BOTH, expand=True, padx=1, pady=1)

Label(
self.container,
text="Opened Editors",
font=self.base.settings.uifont,
padx=10,
pady=5,
**self.base.theme.utils.label,
).pack(fill=tk.X, expand=True, anchor=tk.W)

self.bind("<FocusOut>", lambda _: self.hide())

def show(self, e: tk.Event) -> None:
btn = e.widget
x, y = (
btn.winfo_rootx() - self.winfo_width() + btn.winfo_width(),
btn.winfo_rooty() + btn.winfo_height(),
)
self.geometry(f"+{x}+{y}")
self.deiconify()
self.update()
self.focus_force()

def hide(self) -> None:
self.withdraw()

def add_item(self, editor):
temp = Closable(
self.content,
self.container,
text=editor.filename or editor.path,
callback=lambda p=editor.path: self.openfile(p),
closefn=lambda p=editor.path: self.closefile(p),
padx=10,
)
try:
temp.text_label.config(anchor=tk.W)
except AttributeError:
pass

temp.pack(fill=tk.X, expand=True)

self.nodes[editor.path] = temp
self.refresh()
self.update()

def remove_item(self, editor):
if not self.nodes:
Expand All @@ -53,7 +68,7 @@ def remove_item(self, editor):
e = self.nodes.pop(editor.path)
e.pack_forget()
e.destroy()
self.refresh()
self.update()

def set_active(self, editor):
# TODO: set highlight, clear highlight on others
Expand All @@ -63,7 +78,6 @@ def clear(self):
for node in self.nodes.values():
node.destroy()
self.nodes = {}
self.refresh()

def openfile(self, path) -> None:
self.base.editorsmanager.editorsbar.switch_tabs(path)
Expand Down
8 changes: 5 additions & 3 deletions src/biscuit/common/ui/closables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
callback=lambda *_: None,
closefn=lambda *_: None,
iconside=tk.LEFT,
padx=5,
padx=1,
pady=1,
fg=None,
bg=None,
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
fg=self.fg,
font=("codicon", 14),
)
self.icon_label.pack(side=iconside, fill=tk.BOTH)
self.icon_label.pack(side=iconside, fill=tk.BOTH, padx=(10, 0))

if text:
self.text_label = tk.Label(
Expand All @@ -72,7 +72,9 @@ def __init__(
fg=self.fg,
font=self.base.settings.uifont,
)
self.text_label.pack(side=iconside, fill=tk.BOTH, expand=True)
self.text_label.pack(
side=iconside, fill=tk.BOTH, expand=True, padx=10 if not icon else 0
)

self.close_btn = IconButton(self, Icons.CLOSE, self.closefn)
self.close_btn.config(bg=self.bg, fg=self.fg)
Expand Down
1 change: 1 addition & 0 deletions src/biscuit/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def setup_floating_widgets(self) -> None:
self.findreplace = FindReplace(self)
self.notifications = Notifications(self)

self.open_editors = OpenEditors(self)
self.autocomplete = AutoComplete(self)
self.peek = Peek(self)
self.rename = Rename(self)
Expand Down
1 change: 1 addition & 0 deletions src/biscuit/layout/editors/editorsbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, master: EditorsManager, *args, **kwargs) -> None:
self.buttons: list[IconButton] = []
self.default_buttons = (
(Icons.ELLIPSIS, self.menu.show),
(Icons.CHEVRON_DOWN, self.base.open_editors.show),
(Icons.ADD, self.base.commands.open_empty_editor),
)

Expand Down
10 changes: 5 additions & 5 deletions src/biscuit/layout/editors/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def add_editor(self, editor: Union[Editor, BaseEditor]) -> Editor | BaseEditor:
if editor.content:
editor.content.create_buttons(self.editorsbar.action_container)
self.editorsbar.add_tab(editor)
self.base.explorer.open_editors.add_item(editor)
self.base.open_editors.add_item(editor)
self.refresh()
return editor

Expand All @@ -119,7 +119,7 @@ def delete_all_editors(self) -> None:

self.editorsbar.clear_all_tabs()
self.active_editors.clear()
self.base.explorer.open_editors.clear()
self.base.open_editors.clear()
self.refresh()

def reopen_active_editor(self, *_) -> None:
Expand Down Expand Up @@ -211,7 +211,7 @@ def close_editor(self, editor: Editor) -> None:
self.closed_editors[editor.path] = editor
else:
editor.destroy()
self.base.explorer.open_editors.remove_item(editor)
self.base.open_editors.remove_item(editor)

def close_editor_by_path(self, path: str) -> None:
"""Closes the editor with the given path.
Expand Down Expand Up @@ -252,7 +252,7 @@ def delete_editor(self, editor: Editor) -> None:
self.closed_editors.pop(editor.path)

editor.destroy()
self.base.explorer.open_editors.remove_item(editor)
self.base.open_editors.remove_item(editor)
self.refresh()

def set_active_editor(self, editor: Editor) -> Editor:
Expand All @@ -264,7 +264,7 @@ def set_active_editor(self, editor: Editor) -> Editor:
for tab in self.editorsbar.active_tabs:
if tab.editor == editor:
self.editorsbar.set_active_tab(tab)
self.base.explorer.open_editors.set_active(editor)
self.base.open_editors.set_active(editor)

return editor

Expand Down
6 changes: 4 additions & 2 deletions src/biscuit/views/ai/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def __init__(self, master, *args, **kwargs) -> None:
self.chat = None
self.api_key = ""

self.title.grid_forget()

self.api_providers = {
"Gemini 1.5 Flash": Gemini1p5Flash,
}
Expand All @@ -60,8 +62,8 @@ def __init__(self, master, *args, **kwargs) -> None:
callback=self.set_current_provider,
)
self.top.grid_columnconfigure(self.column, weight=1)
self.dropdown.grid(row=0, column=self.column, sticky=tk.NSEW, padx=(0, 10))
self.column += 1

self.dropdown.grid(row=0, column=0, sticky=tk.NSEW, padx=(0, 10))

self.menu = AIMenu(self)
self.menu.add_command("New Chat", self.new_chat)
Expand Down
8 changes: 4 additions & 4 deletions src/biscuit/views/debug/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ def __init__(self, master, *args, **kwargs) -> None:
self.running = False
self.manager = self.base.debugger_manager

self.top.pack_forget()

self.dropdown = Dropdown(
self.top,
self,
icon=Icons.PLAY,
callback=self.set_config,
iconfg="#87d282",
iconhfg="#87d282",
empty_message=EMPTY_MESSAGE,
)
self.dropdown.icon_label.bind("<Button-1>", self.run_config)
self.top.grid_columnconfigure(self.column, weight=1)
self.dropdown.grid(row=0, column=self.column, sticky=tk.NSEW, padx=(0, 10))
self.column += 1
self.dropdown.pack(fill=tk.X, padx=10, pady=10)

self.configs = {}
self.selected_config = ""
Expand Down
23 changes: 5 additions & 18 deletions src/biscuit/views/explorer/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ..sidebar_view import SideBarView
from .directorytree import DirectoryTree
from .menu import ExplorerMenu
from .open_editors import OpenEditors


class Explorer(SideBarView):
Expand All @@ -24,17 +23,12 @@ def __init__(self, master, *args, **kwargs) -> None:
self.__icon__ = Icons.HOME
self.name = "Explorer"

self.menu = ExplorerMenu(self, "files")
self.menu.add_checkable(
"Open Editors", self.toggle_active_editors, checked=True
)
self.menu.add_separator(10)
self.menu.add_command("Search", self.base.commands.search_files)
self.add_action(Icons.ELLIPSIS, self.menu.show)
# self.menu = ExplorerMenu(self, "files")
# self.menu.add_command("Search", self.base.commands.search_files)
# self.add_action(Icons.ELLIPSIS, self.menu.show)

self.top.pack_forget()

self.active_editors_visible = True
self.open_editors = OpenEditors(self)
self.open_editors.pack(fill=tk.X)
self.directory = DirectoryTree(self, observe_changes=True)
self.add_item(self.directory)

Expand Down Expand Up @@ -76,13 +70,6 @@ def __init__(self, master, *args, **kwargs) -> None:
)
self.base.palette.register_actionset(lambda: self.rename_actionset)

def toggle_active_editors(self):
if self.active_editors_visible:
self.open_editors.pack_forget()
else:
self.open_editors.pack(fill=tk.X, before=self.directory)
self.active_editors_visible = not self.active_editors_visible

def get_actionset(self, term: str) -> ActionSet:
self.filesearch_actionset.update(self.filesearch(term))
return self.filesearch_actionset
Expand Down
26 changes: 7 additions & 19 deletions src/biscuit/views/explorer/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,27 @@ def __init__(self, master, *args, **kwargs) -> None:

WrappingLabel(
self,
text="You have not yet opened a folder.",
text="No folder opened",
font=self.base.settings.uifont,
anchor=tk.W,
**self.base.theme.views.sidebar.item.content
).grid(row=0, sticky=tk.EW)

open_btn = IconLabelButton(
open_btn = Button(
self,
text="Open Folder",
icon=Icons.FOLDER,
callback=self.open_folder,
command=self.open_folder,
pady=2,
highlighted=True,
)
open_btn.grid(row=1, pady=5, sticky=tk.EW)

WrappingLabel(
self,
text="You can clone a repository locally.",
font=self.base.settings.uifont,
anchor=tk.W,
**self.base.theme.views.sidebar.item.content
).grid(row=2, sticky=tk.EW)

clone_btn = IconLabelButton(
clone_btn = Button(
self,
text="Clone Repository",
icon=Icons.REPO_CLONE,
callback=self.clone_repo,
text="Clone Repo",
command=self.clone_repo,
pady=2,
highlighted=True,
)
clone_btn.grid(row=3, pady=5, sticky=tk.EW)
clone_btn.grid(row=3, sticky=tk.EW)

def open_folder(self, *_) -> None:
self.base.commands.open_directory()
Expand Down
2 changes: 2 additions & 0 deletions src/biscuit/views/outline/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self, master, *args, **kwargs) -> None:
self.__icon__ = Icons.SYMBOL_CLASS
self.name = "Outline"

self.top.pack_forget()

self.tree = OutlineTree(self)
self.add_item(self.tree)

Expand Down
2 changes: 2 additions & 0 deletions src/biscuit/views/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, master, *args, **kwargs) -> None:
self.name = "Search"
self.searchterm = tk.StringVar(self)

self.top.pack_forget()

self.results = Results(self, **self.base.theme.views.sidebar.item)

self.container = Frame(self, **self.base.theme.views.sidebar)
Expand Down
2 changes: 1 addition & 1 deletion src/biscuit/views/sidebar_item_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, master, title: str, buttons=(), *args, **kwargs) -> None:
self,
anchor=tk.W,
textvariable=self.title,
font=self.base.settings.uifont_bold,
font=self.base.settings.uifont,
**self.base.theme.views.sidebar.itembar.title
)
self.label_title.grid(row=0, column=1, sticky=tk.EW)
Expand Down
5 changes: 3 additions & 2 deletions src/biscuit/views/sidebar_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ def __init__(
self.top.pack(fill=tk.X, padx=(15, 10), pady=7)
self.top.grid_columnconfigure(0, weight=1)

tk.Label(
self.title = tk.Label(
self.top,
text=name.upper() if name else self.__class__.__name__.upper(),
anchor=tk.W,
font=self.base.settings.uifont,
**self.base.theme.views.sidebar.title
).grid(row=0, column=0, sticky=tk.EW)
)
self.title.grid(row=0, column=0, sticky=tk.EW)

self.column = 1
if not self.__actions__:
Expand Down

0 comments on commit 8853022

Please sign in to comment.