From 5c975d6f5d3e32b636143e7243c74143ac2b34dd Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 30 Mar 2024 05:28:44 +0530 Subject: [PATCH 1/4] feat: Checkable menu items --- .../core/components/floating/menu/__init__.py | 10 ++++++++++ .../core/components/floating/menu/checkable.py | 18 ++++++++++++++++++ .../core/components/utils/iconlabelbutton.py | 13 ++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 biscuit/core/components/floating/menu/checkable.py diff --git a/biscuit/core/components/floating/menu/__init__.py b/biscuit/core/components/floating/menu/__init__.py index 18ae642a..b54f2b3a 100644 --- a/biscuit/core/components/floating/menu/__init__.py +++ b/biscuit/core/components/floating/menu/__init__.py @@ -8,6 +8,7 @@ from biscuit.core.components.utils import Frame, Toplevel +from .checkable import CheckableMenuItem from .menuitem import MenuItem from .separator import Separator @@ -61,6 +62,15 @@ def add_item(self, text, command=lambda *_:...): self.menu_items.append(new_item) self.row += 1 + return new_item + + def add_checkable(self, text, command=lambda *_:...): + new_item = CheckableMenuItem(self.container, text, command) + new_item.grid(row=self.row, sticky=tk.EW, pady=0) + self.menu_items.append(new_item) + + self.row += 1 + return new_item def add_command(self, *args, **kwargs): self.add_item(*args, **kwargs) diff --git a/biscuit/core/components/floating/menu/checkable.py b/biscuit/core/components/floating/menu/checkable.py new file mode 100644 index 00000000..fb9880ac --- /dev/null +++ b/biscuit/core/components/floating/menu/checkable.py @@ -0,0 +1,18 @@ +import tkinter as tk + +from biscuit.core.components.utils import IconLabelButton + + +class CheckableMenuItem(IconLabelButton): + def __init__(self, master, text, command=lambda *_:..., *args, **kwargs) -> None: + super().__init__(master, text, 'check', command, expandicon=False, iconsize=10, toggle=False, *args, **kwargs) + + self.command = command + self.bg, self.fg, self.hbg, self.hfg = self.base.theme.menu.item.values() + self.on_leave() + + def on_click(self, *_) -> None: + self.master.hide() + self.toggle_icon() + return super().on_click(*_) + diff --git a/biscuit/core/components/utils/iconlabelbutton.py b/biscuit/core/components/utils/iconlabelbutton.py index a08b9e3b..9c2bc844 100644 --- a/biscuit/core/components/utils/iconlabelbutton.py +++ b/biscuit/core/components/utils/iconlabelbutton.py @@ -5,7 +5,7 @@ class IconLabelButton(Frame): - def __init__(self, master, text=None, icon=None, function=lambda *_: None, iconside=tk.LEFT, padx=5, pady=1, expandicon=True, highlighted=False, *args, **kwargs) -> None: + def __init__(self, master, text=None, icon=None, function=lambda *_: None, iconside=tk.LEFT, padx=5, pady=1, expandicon=True, highlighted=False, iconsize=14, toggle=True, *args, **kwargs) -> None: super().__init__(master, padx=padx, pady=pady, *args, **kwargs) self.function = function @@ -13,10 +13,13 @@ def __init__(self, master, text=None, icon=None, function=lambda *_: None, icons self.config(bg=self.bg) self.text = text self.icon = icon + self.codicon = get_codicon(self.icon) + + self.toggle = True if icon: - self.icon_label = tk.Label(self, text=get_codicon(self.icon), anchor=tk.E, - bg=self.bg, fg=self.fg, font=("codicon", 14)) + self.icon_label = tk.Label(self, text=self.codicon if self.toggle else " ", anchor=tk.E, + bg=self.bg, fg=self.fg, font=("codicon", iconsize)) self.icon_label.pack(side=iconside, fill=tk.BOTH, expand=expandicon) if text: @@ -53,6 +56,10 @@ def on_leave(self, *_) -> None: def on_click(self, *_) -> None: self.function() + + def toggle_icon(self) -> None: + self.icon_label.config(text=self.codicon if not self.toggle else " ") + self.toggle = not self.toggle def change_text(self, text) -> None: self.text_label.config(text=text) From d98237ff7a00e4c64ae761fedb3ffb066c9b7398 Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 30 Mar 2024 05:29:43 +0530 Subject: [PATCH 2/4] feat: Implemented checkable menu items for all context menus --- .../views/sidebar/explorer/__init__.py | 2 +- .../views/sidebar/sourcecontrol/__init__.py | 18 +++++++----- .../views/sidebar/sourcecontrol/git.py | 28 +++++++++++++++---- .../sidebar/sourcecontrol/placeholder.py | 2 +- biscuit/core/layout/menubar/__init__.py | 2 +- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/biscuit/core/components/views/sidebar/explorer/__init__.py b/biscuit/core/components/views/sidebar/explorer/__init__.py index 3c55c589..4605244a 100644 --- a/biscuit/core/components/views/sidebar/explorer/__init__.py +++ b/biscuit/core/components/views/sidebar/explorer/__init__.py @@ -17,7 +17,7 @@ def __init__(self, master, *args, **kwargs) -> None: self.name = 'Explorer' self.menu = ExplorerMenu(self, 'files') - self.menu.add_item("Open Editors", self.toggle_active_editors) + self.menu.add_checkable("Open Editors", self.toggle_active_editors) self.menu.add_separator(10) self.menu.add_item("Search", self.base.events.show_file_search_palette) self.add_button('ellipsis', self.menu.show) diff --git a/biscuit/core/components/views/sidebar/sourcecontrol/__init__.py b/biscuit/core/components/views/sidebar/sourcecontrol/__init__.py index 202ad483..37be8d0b 100644 --- a/biscuit/core/components/views/sidebar/sourcecontrol/__init__.py +++ b/biscuit/core/components/views/sidebar/sourcecontrol/__init__.py @@ -7,21 +7,25 @@ class SourceControl(SidebarView): def __init__(self, master, *args, **kwargs) -> None: - self.__buttons__ = [('list-tree',), ('check',), ('refresh',)] + self.__buttons__ = [('list-tree',), ('check',), ('refresh', self.refresh)] super().__init__(master, *args, **kwargs) self.__icon__ = 'source-control' self.name = 'Source Control' + self.tree = Git(self) + self.add_widget(self.tree) + self.bind('', self.reload_tree) + self.menu = SourceControlMenu(self, 'files') - self.menu.add_item("Show Staged") + self.menu.add_checkable("Show Staged", self.tree.toggle_staged) self.menu.add_separator(10) - self.menu.add_item("Show Changes") + self.menu.add_checkable("Show Changes", self.tree.toggle_changes) self.add_button('ellipsis', self.menu.show) - - self.tree = Git(self) - self.add_widget(self.tree) - def refresh(self) -> None: + def reload_tree(self, *_) -> None: + self.tree.open_repo() + + def refresh(self, *_) -> None: if self.base.git_found: self.tree.enable_tree() self.tree.open_repo() diff --git a/biscuit/core/components/views/sidebar/sourcecontrol/git.py b/biscuit/core/components/views/sidebar/sourcecontrol/git.py index a7b982d8..2b47d095 100644 --- a/biscuit/core/components/views/sidebar/sourcecontrol/git.py +++ b/biscuit/core/components/views/sidebar/sourcecontrol/git.py @@ -1,6 +1,7 @@ import tkinter as tk from biscuit.core.components.utils import Button, Entry, Frame, IconButton +from biscuit.core.components.utils.iconlabelbutton import IconLabelButton from .changes import Changes from .placeholder import ChangesTreePlaceholder @@ -16,12 +17,14 @@ def __init__(self, master, *args, **kwargs) -> None: self.commit_message = Entry(self.commitbox, hint="Message", **self.base.theme.utils.entry) self.commit_message.pack(fill=tk.X, pady=(0, 5)) - self.commit_button = Button(self.commitbox, text='Commit', command=self.commit) + self.commit_button = IconLabelButton(self.commitbox, text='Commit', icon='git-commit', function=self.commit, highlighted=True) self.commit_button.pack(fill=tk.BOTH, side=tk.LEFT, expand=True) - tk.Label(self.commitbox, text="|", **self.base.theme.utils.colorlabel).pack(side=tk.LEFT, fill=tk.Y) - self.more = IconButton(self.commitbox, icon='chevron-down') - self.more.config(**self.base.theme.utils.button) - self.more.pack(fill=tk.Y) + + # Commit menu + # tk.Label(self.commitbox, text="|", **self.base.theme.utils.colorlabel).pack(side=tk.LEFT, fill=tk.Y) + # self.more = IconButton(self.commitbox, icon='chevron-down') + # self.more.config(**self.base.theme.utils.button) + # self.more.pack(fill=tk.BOTH) self.staged_changes_tree = StagedChanges(self, *args, **kwargs) self.changes_tree = Changes(self, *args, **kwargs) @@ -46,6 +49,9 @@ def open_repo(self) -> None: self.changes_tree.clear_tree() # self.set_title(f"{os.path.basename(self.base.active_directory)}({self.base.git.active_branch})") + if not self.base.git.repo: + return + self.add_staged_changes(self.base.git.repo.get_staged_deleted_files(), 0) self.add_staged_changes(self.base.git.repo.get_staged_added_files(), 1) self.add_staged_changes(self.base.git.repo.get_staged_modified_files(), 2) @@ -54,6 +60,18 @@ def open_repo(self) -> None: self.add_changes(self.base.git.repo.get_added_files(), 1) self.add_changes(self.base.git.repo.get_modified_files(), 2) self.add_changes(self.base.git.repo.get_untracked_files(), 3) + + def toggle_staged(self, *_) -> None: + if not self.base.git_found: + return + + self.staged_changes_tree.pack_forget() if self.staged_changes_tree.winfo_ismapped() else self.staged_changes_tree.pack(fill=tk.BOTH, before=self.changes_tree) + + def toggle_changes(self, *_) -> None: + if not self.base.git_found: + return + + self.changes_tree.pack_forget() if self.changes_tree.winfo_ismapped() else self.changes_tree.pack(fill=tk.BOTH, after=self.staged_changes_tree) def enable_tree(self) -> None: self.placeholder.pack_forget() diff --git a/biscuit/core/components/views/sidebar/sourcecontrol/placeholder.py b/biscuit/core/components/views/sidebar/sourcecontrol/placeholder.py index 1e30b2b4..415bad05 100644 --- a/biscuit/core/components/views/sidebar/sourcecontrol/placeholder.py +++ b/biscuit/core/components/views/sidebar/sourcecontrol/placeholder.py @@ -18,7 +18,7 @@ def __init__(self, master, *args, **kwargs) -> None: clone_btn = IconLabelButton(self, text="Clone Repository", icon="clone", function=self.clone_repo, pady=2, highlighted=True) clone_btn.grid(row=2, pady=5, sticky=tk.EW) - def open_folder(self, _) -> None: + def open_folder(self, *_) -> None: self.base.events.open_directory() def clone_repo(self, *_) -> None: diff --git a/biscuit/core/layout/menubar/__init__.py b/biscuit/core/layout/menubar/__init__.py index 340fceb0..7cac404d 100644 --- a/biscuit/core/layout/menubar/__init__.py +++ b/biscuit/core/layout/menubar/__init__.py @@ -142,7 +142,7 @@ def add_edit_menu(self) -> None: self.edit_menu.add_item("Find in Files", events.show_file_search_palette) self.edit_menu.add_item("Change Language Mode", events.change_language_mode) self.edit_menu.add_separator() - self.edit_menu.add_item("Word Wrap", events.toggle_wordwrap) + self.edit_menu.add_checkable("Word Wrap", events.toggle_wordwrap) def add_selection_menu(self) -> None: events = self.events From 1139da898df222551c04bdd00ec7e62c9fc33530 Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 30 Mar 2024 05:32:18 +0530 Subject: [PATCH 3/4] chore: Bump version to v2.66.2 --- biscuit/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/biscuit/__init__.py b/biscuit/__init__.py index 66a1fb12..80aa6881 100644 --- a/biscuit/__init__.py +++ b/biscuit/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.66.0" +__version__ = "2.66.2" __version_info__ = tuple([int(num) for num in __version__.split(".")]) # For tests to run successfully diff --git a/pyproject.toml b/pyproject.toml index 37fe93b8..7acccba9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "biscuit" -version = "2.66.0" +version = "2.66.2" description = "The uncompromising code editor" authors = ["Billy "] license = "MIT" From 3dd390f83e37a56b0c120421bd72b649316b2f4a Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 30 Mar 2024 05:33:05 +0530 Subject: [PATCH 4/4] Commit changes