Skip to content

Commit

Permalink
Merge pull request #263 from billyeatcookies/check-menus (nightly)
Browse files Browse the repository at this point in the history
feat: Checkable menu items
  • Loading branch information
tomlin7 authored Mar 30, 2024
2 parents 083b8df + 3dd390f commit f6df8da
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 20 deletions.
2 changes: 1 addition & 1 deletion biscuit/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions biscuit/core/components/floating/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from biscuit.core.components.utils import Frame, Toplevel

from .checkable import CheckableMenuItem
from .menuitem import MenuItem
from .separator import Separator

Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions biscuit/core/components/floating/menu/checkable.py
Original file line number Diff line number Diff line change
@@ -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(*_)

13 changes: 10 additions & 3 deletions biscuit/core/components/utils/iconlabelbutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@


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

self.bg, self.fg, self.hbg, self.hfg = self.base.theme.utils.iconlabelbutton.values() if not highlighted else self.base.theme.utils.button.values()
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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/views/sidebar/explorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions biscuit/core/components/views/sidebar/sourcecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<Visibility>', 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()
Expand Down
28 changes: 23 additions & 5 deletions biscuit/core/components/views/sidebar/sourcecontrol/git.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/layout/menubar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biscuit"
version = "2.66.0"
version = "2.66.2"
description = "The uncompromising code editor"
authors = ["Billy <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit f6df8da

Please sign in to comment.