diff --git a/src/biscuit/binder.py b/src/biscuit/binder.py index 6deacbaa..bcb87dc1 100644 --- a/src/biscuit/binder.py +++ b/src/biscuit/binder.py @@ -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) diff --git a/src/biscuit/commands.py b/src/biscuit/commands.py index 2b168ed4..c003a6d7 100644 --- a/src/biscuit/commands.py +++ b/src/biscuit/commands.py @@ -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: @@ -127,6 +127,9 @@ 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() @@ -134,6 +137,17 @@ 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": @@ -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: @@ -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() diff --git a/src/biscuit/layout/editors/editorsbar.py b/src/biscuit/layout/editors/editorsbar.py index 0ec0021a..bba9a1c6 100644 --- a/src/biscuit/layout/editors/editorsbar.py +++ b/src/biscuit/layout/editors/editorsbar.py @@ -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() diff --git a/src/biscuit/layout/editors/manager.py b/src/biscuit/layout/editors/manager.py index ab284651..9a40a207 100644 --- a/src/biscuit/layout/editors/manager.py +++ b/src/biscuit/layout/editors/manager.py @@ -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) @@ -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. @@ -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: diff --git a/src/biscuit/layout/menubar/menubar.py b/src/biscuit/layout/menubar/menubar.py index 1d3c2787..77100a2d 100644 --- a/src/biscuit/layout/menubar/menubar.py +++ b/src/biscuit/layout/menubar/menubar.py @@ -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( @@ -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) diff --git a/src/biscuit/layout/secondary_sidebar.py b/src/biscuit/layout/secondary_sidebar.py index bef19124..f81aff81 100644 --- a/src/biscuit/layout/secondary_sidebar.py +++ b/src/biscuit/layout/secondary_sidebar.py @@ -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) @@ -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.""" @@ -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 diff --git a/src/biscuit/layout/sidebar.py b/src/biscuit/layout/sidebar.py index dcea74e3..278b1b9b 100644 --- a/src/biscuit/layout/sidebar.py +++ b/src/biscuit/layout/sidebar.py @@ -28,6 +28,7 @@ def __init__( self.views = [] self.active_view = None + self.visible = False self.activitybar = activitybar self.activitybar.attach_sidebar(self) @@ -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.""" @@ -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 diff --git a/src/biscuit/settings/bindings.py b/src/biscuit/settings/bindings.py index 847aed12..19927853 100644 --- a/src/biscuit/settings/bindings.py +++ b/src/biscuit/settings/bindings.py @@ -19,11 +19,33 @@ def __init__(self, master: Settings) -> None: self.save = "" self.save_as = "" self.close_file = "" + self.goto_line = "" self.quit = "" - self.commandpalette = "" - self.filesearch = "" - self.symbolpalette = "" - self.panel = "" self.undo = "" self.redo = "" - self.restore_closed_tab = "" + self.restore_closed_tab = "" + self.close_all_tabs = "" + self.change_tab = "" + self.change_tab_back = "" + self.split_tab = "" + + self.command_palette = "" + self.file_search = "" + self.symbol_outline = "" + + self.panel = "" + self.sidebar = "" + self.secondary_sidebar = "" + self.directory_tree = "" + self.extensions = "" + self.global_search = "" + self.debugger = "" + self.git = "" + self.assistant = "" + self.logs = "" + + self.open_settings = "" + self.restore_recent_session = "" + self.open_recent_folders = "" + self.open_recent_files = "" + self.open_recent_session = ""