Skip to content

Commit

Permalink
feat: More key bindings added #449
Browse files Browse the repository at this point in the history
from tomlin7/keybinds
  • Loading branch information
tomlin7 authored Nov 2, 2024
2 parents 7d16318 + af8eb62 commit 89f94d0
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 17 deletions.
31 changes: 28 additions & 3 deletions src/biscuit/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,39 @@ def bind_all(self) -> None:
self.bind(
self.bindings.restore_closed_tab, self.events.restore_last_closed_editor
)
self.bind(self.bindings.close_all_tabs, self.events.close_all_editors)
self.bind(self.bindings.change_tab, self.events.change_tab_forward)
self.bind(self.bindings.change_tab_back, self.events.change_tab_back)
self.bind(self.bindings.split_tab, self.events.split_editor)

def late_bind_all(self) -> None:
"""Bindings that require full initialization"""

self.bind(self.bindings.commandpalette, self.events.show_command_palette)
self.bind(self.bindings.filesearch, self.events.search_files)
self.bind(self.bindings.symbolpalette, self.events.show_symbol_palette)
self.bind(self.bindings.command_palette, self.events.show_command_palette)
self.bind(self.bindings.file_search, self.events.search_files)
self.bind(self.bindings.symbol_outline, self.events.show_symbol_palette)
self.bind(self.bindings.goto_line, self.events.goto_line_column)

self.bind(self.bindings.panel, self.base.contentpane.toggle_panel)
self.bind(self.bindings.sidebar, self.events.toggle_sidebar)
self.bind(self.bindings.secondary_sidebar, self.events.toggle_secondary_sidebar)
self.bind(self.bindings.directory_tree, self.events.show_directory_tree)
self.bind(self.bindings.extensions, self.events.show_extensions)
self.bind(self.bindings.global_search, self.events.show_search)
self.bind(self.bindings.debugger, self.events.show_debugger)
self.bind(self.bindings.git, self.events.show_source_control)
self.bind(self.bindings.assistant, self.events.show_assistant)
self.bind(self.bindings.logs, self.events.show_logs)

self.bind(self.bindings.open_settings, self.events.open_settings)
self.bind(
self.bindings.restore_recent_session, self.events.restore_recent_session
)
self.bind(self.bindings.open_recent_folders, self.events.show_recent_folders)
self.bind(self.bindings.open_recent_files, self.events.show_recent_files)
self.bind(
self.bindings.open_recent_session, self.events.restore_last_closed_editor
)

def bind(self, this, to_this) -> None:
self.base.bind(this, to_this)
36 changes: 33 additions & 3 deletions src/biscuit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def open_directory(self, *_) -> None:
self.base.open_directory(path)
self.base.history.register_folder_history(path)

def open_recent_file(self, *_):
def show_recent_files(self, *_):
self.base.palette.show("recentf:")

def open_recent_dir(self, *_):
def show_recent_folders(self, *_):
self.base.palette.show("recentd:")

def restore_recent_session(self, *_) -> None:
Expand Down Expand Up @@ -127,13 +127,27 @@ def open_settings(self, *_) -> None:
def close_editor(self, *_) -> None:
self.base.close_active_editor()

def close_all_editors(self, *_) -> None:
self.base.editorsmanager.delete_all_editors()

def close_folder(self, *_) -> None:
self.base.close_active_directory()

def quit_biscuit(self, *_) -> None:
self.base.on_close_app()
# self.base.destroy()

def split_editor(self, *_) -> None:
self.base.editorsmanager.split_editor()

def change_tab_forward(self, *_) -> None:
self.base.editorsbar.change_tab_forward()
return "break"

def change_tab_back(self, *_) -> None:
self.base.editorsbar.change_tab_back()
return "break"

def maximize_biscuit(self, *_) -> None:
match platform.system():
case "Windows" | "Darwin":
Expand Down Expand Up @@ -319,7 +333,14 @@ def debugger_stop(self, *_):
if self.base.debugger_manager.latest:
self.base.debugger_manager.latest.stop()

def show_explorer(self, *_) -> None:
def toggle_sidebar(self, *_) -> None:
self.base.sidebar.toggle()

def toggle_secondary_sidebar(self, *_) -> None:
self.base.secondary_sidebar.toggle()

def show_directory_tree(self, *_) -> None:
# TODO: some renaming needed
self.base.sidebar.show_explorer()

def show_outline(self, *_) -> None:
Expand All @@ -337,6 +358,15 @@ def show_debugger(self, *_) -> None:
def show_extensions(self, *_) -> None:
self.base.secondary_sidebar.show_extensions()

def show_assistant(self, *_) -> None:
self.base.secondary_sidebar.show_ai()

def show_outline(self, *_) -> None:
self.base.secondary_sidebar.show_outline()

def show_github(self, *_) -> None:
self.base.secondary_sidebar.show_github()

def show_terminal(self, *_) -> None:
self.base.panel.show_terminal()

Expand Down
12 changes: 12 additions & 0 deletions src/biscuit/layout/editors/editorsbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def __init__(self, master: EditorsManager, *args, **kwargs) -> None:
self.breadcrumbs = BreadCrumbs(self.secondary_container)
self.breadcrumbs.show()

def change_tab_forward(self) -> None:
if self.active_tab:
i = self.active_tabs.index(self.active_tab)
next_index = (i + 1) % len(self.active_tabs)
self.active_tabs[next_index].select()

def change_tab_back(self) -> None:
if self.active_tab:
i = self.active_tabs.index(self.active_tab)
prev_index = (i - 1) % len(self.active_tabs)
self.active_tabs[prev_index].select()

def hide_breadcrumbs(self) -> None:
self.secondary_container.pack_forget()

Expand Down
27 changes: 27 additions & 0 deletions src/biscuit/layout/editors/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ def delete_all_editors(self) -> None:
self.base.open_editors.clear()
self.refresh()

def close_all_editors(self) -> None:
for tab in self.editorsbar.active_tabs:
if e := tab.editor:
self.editorsbar.save_unsaved_changes(e)
self.close_editor(e)
self.refresh()

def reopen_active_editor(self, *_) -> None:
if self.active_editor and self.active_editor.exists:
self.delete_editor(self.active_editor)
Expand Down Expand Up @@ -279,6 +286,16 @@ def set_active_editor(self, editor: Editor) -> Editor:
self.refresh()
return editor

def set_active_editor_by_index(self, index: int) -> Editor:
"""Set an existing editor to currently shown one by index.
Args:
index (int): The index of the editor to set as active."""

if index < len(self.editorsbar.active_tabs):
self.editorsbar.set_active_tab(self.editorsbar.active_tabs[index])
return self.editorsbar.active_tabs[index].editor

def set_active_editor_by_path(self, path: str) -> Editor:
"""Set an existing editor to currently shown one by path.
Expand All @@ -294,6 +311,16 @@ def set_active_editor_by_path(self, path: str) -> Editor:
self.editorsbar.set_active_tab(tab)
return tab.editor

def split_editor(self) -> None:
# TODO: Implement split editor
...

def change_tab_forward(self) -> None:
self.editorsbar.change_tab_forward()

def change_tab_back(self) -> None:
self.editorsbar.change_tab_back()

@property
def active_editor(self) -> Editor:
if not self.editorsbar.active_tab:
Expand Down
6 changes: 3 additions & 3 deletions src/biscuit/layout/menubar/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def add_file_menu(self) -> None:
self.file_menu.add_separator()
self.file_menu.add_command("Open File", events.open_file)
self.file_menu.add_command("Open Folder", events.open_directory)
self.file_menu.add_command("Open Recent File...", events.open_recent_file)
self.file_menu.add_command("Open Recent Folder...", events.open_recent_dir)
self.file_menu.add_command("Open Recent File...", events.show_recent_files)
self.file_menu.add_command("Open Recent Folder...", events.show_recent_folders)
self.file_menu.add_separator()
self.file_menu.add_command("Open workspace...", events.open_workspace)
self.file_menu.add_command(
Expand Down Expand Up @@ -196,7 +196,7 @@ def add_view_menu(self) -> None:
self.view_menu = self.add_menu("View")
# TODO: Add the rest of the view menu items
self.view_menu.add_command("Command Palette...", events.show_command_palette)
self.view_menu.add_command("Explorer", events.show_explorer)
self.view_menu.add_command("Explorer", events.show_directory_tree)
self.view_menu.add_command("Outline", events.show_outline)
self.view_menu.add_command("Search", events.show_search)
self.view_menu.add_command("Source Control", events.show_source_control)
Expand Down
12 changes: 10 additions & 2 deletions src/biscuit/layout/secondary_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(
self.columnconfigure(1, weight=1)

self.views = []

self.active_view = None
self.visible = False

self.secondary_activitybar = activitybar
self.secondary_activitybar.attach_sidebar(self)
Expand All @@ -45,7 +45,13 @@ def __init__(
def toggle(self) -> None:
"""Toggle the sidebar."""

self.show_explorer()
if self.visible:
self.hide()
else:
if not self.active_view:
self.show_source_control()
else:
self.pack()

def add_views(self, views: list[SideBarView]) -> None:
"""Adds multiple views to the sidebar at once."""
Expand Down Expand Up @@ -150,6 +156,8 @@ def show_extensions(self, *_) -> Extensions:

def pack(self):
super().pack(side=tk.LEFT, fill=tk.Y, after=self.base.contentpane, padx=(1, 0))
self.visible = True

def hide(self):
super().pack_forget()
self.visible = False
11 changes: 10 additions & 1 deletion src/biscuit/layout/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(

self.views = []
self.active_view = None
self.visible = False

self.activitybar = activitybar
self.activitybar.attach_sidebar(self)
Expand All @@ -42,7 +43,13 @@ def __init__(
def toggle(self) -> None:
"""Toggle the sidebar."""

self.show_explorer()
if self.visible:
self.hide()
else:
if not self.active_view:
self.show_explorer()
else:
self.pack()

def add_views(self, views: list[SideBarView]) -> None:
"""Adds multiple views to the sidebar at once."""
Expand Down Expand Up @@ -124,6 +131,8 @@ def show_debug(self, *_) -> Debug:

def pack(self):
super().pack(side=tk.LEFT, fill=tk.Y, before=self.base.contentpane, padx=(0, 1))
self.visible = True

def hide(self):
super().pack_forget()
self.visible = False
32 changes: 27 additions & 5 deletions src/biscuit/settings/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,33 @@ def __init__(self, master: Settings) -> None:
self.save = "<Control-s>"
self.save_as = "<Control-S>"
self.close_file = "<Control-w>"
self.goto_line = "<Control-g>"
self.quit = "<Control-q>"
self.commandpalette = "<Control-P>"
self.filesearch = "<Control-p>"
self.symbolpalette = "<Control-J>"
self.panel = "<Control-grave>"
self.undo = "<Control-z>"
self.redo = "<Control-y>"
self.restore_closed_tab = "<Control-Shift-T>"
self.restore_closed_tab = "<Control-T>"
self.close_all_tabs = "<Control-W>"
self.change_tab = "<Control-Tab>"
self.change_tab_back = "<Control-Shift-Tab>"
self.split_tab = "<Control-\\>"

self.command_palette = "<Control-P>"
self.file_search = "<Control-p>"
self.symbol_outline = "<Control-j>"

self.panel = "<Control-grave>"
self.sidebar = "<Control-b>"
self.secondary_sidebar = "<Control-B>"
self.directory_tree = "<Control-E>"
self.extensions = "<Control-X>"
self.global_search = "<Control-F>"
self.debugger = "<Control-D>"
self.git = "<Control-G>"
self.assistant = "<Control-A>"
self.logs = "<Control-U>"

self.open_settings = "<Control-comma>"
self.restore_recent_session = "<Control-Alt-r>"
self.open_recent_folders = "<Control-r>"
self.open_recent_files = "<Control-R>"
self.open_recent_session = "<Control-Alt-r>"

0 comments on commit 89f94d0

Please sign in to comment.