From ab2274d6d1031f82bf8a0cfc12bf645a3ece7439 Mon Sep 17 00:00:00 2001 From: Billy Date: Sun, 12 May 2024 23:42:15 +0530 Subject: [PATCH] fix: Handling empty issues & prs, added placeholder for github view --- .../views/sidebar/github/__init__.py | 39 +++++++++++++------ .../components/views/sidebar/github/prs.py | 2 + biscuit/core/events.py | 1 + biscuit/core/settings/config/theme/theme.py | 1 + 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/biscuit/core/components/views/sidebar/github/__init__.py b/biscuit/core/components/views/sidebar/github/__init__.py index 1461ad8c..ab90358b 100644 --- a/biscuit/core/components/views/sidebar/github/__init__.py +++ b/biscuit/core/components/views/sidebar/github/__init__.py @@ -3,6 +3,7 @@ import tkinter as tk from biscuit.core.components.floating.palette import ActionSet +from biscuit.core.utils.label import WrappingLabel from ..sidebarview import SidebarView from .issues import Issues @@ -24,27 +25,31 @@ def __init__(self, master, *args, **kwargs) -> None: self.git = self.base.git self.issues = Issues(self) - self.add_item(self.issues) - self.prs = PRs(self) - self.add_item(self.prs) + + self.placeholder = WrappingLabel(self, text="Open a GitHub repository to see issues & pull requests.", font=self.base.settings.uifont, + **self.base.theme.utils.label) + self.placeholder.pack(fill=tk.X, side=tk.TOP) self.base.bind("<>", self.on_directory_change, add=True) def on_directory_change(self, e) -> None: """Event handler for directory change event.""" - - if not self.base.git_found: + + if not (self.base.active_directory and self.base.git_found): + self.show_placeholder("Open a GitHub repository to see issues & pull requests.") return repo = self.git.repo remote = repo.get_remote_origin() if not remote: - self.base.notifications.error("No remote found for repository.") + self.base.notifications.info("No remote found.") + self.show_placeholder("No remote found.") return if not "github.com" in remote.url: self.base.notifications.info("Remote is not a GitHub repository.") + self.show_placeholder("Remote is not a GitHub repository.") return try: @@ -54,8 +59,10 @@ def on_directory_change(self, e) -> None: except Exception as e: self.base.notifications.error(f"Failed to fetch remote info.") self.base.logger.error(f"Failed to fetch remote info: {e}") + self.show_placeholder("Failed to fetch remote info.") return + self.show_content() threading.Thread(target=self.fetch_issues_and_prs, daemon=True).start() def fetch_issues_and_prs(self) -> None: @@ -64,9 +71,17 @@ def fetch_issues_and_prs(self) -> None: self.issues.fetch() self.prs.fetch() - # 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 show_placeholder(self, text: str) -> None: + """Adds a placeholder label to the view.""" + + self.issues.pack_forget() + self.prs.pack_forget() + self.placeholder.config(text=text) + self.placeholder.pack(fill=tk.X, side=tk.TOP) + + def show_content(self) -> None: + """Shows the content of the view.""" + + self.placeholder.pack_forget() + self.issues.pack(fill=tk.BOTH, expand=True) + self.prs.pack(fill=tk.BOTH, expand=True) diff --git a/biscuit/core/components/views/sidebar/github/prs.py b/biscuit/core/components/views/sidebar/github/prs.py index 2de93832..5664e5d0 100644 --- a/biscuit/core/components/views/sidebar/github/prs.py +++ b/biscuit/core/components/views/sidebar/github/prs.py @@ -33,6 +33,8 @@ def __init__(self, master, itembar=True, *args, **kwargs) -> None: def set_url(self, owner: str, repo: str) -> None: """Sets the URL for the current repository.""" + self.owner = owner + self.repo = repo self.url = self.url_template.format(owner, repo) def on_click(self, *_) -> None: diff --git a/biscuit/core/events.py b/biscuit/core/events.py index f5cc8259..5ad9faff 100644 --- a/biscuit/core/events.py +++ b/biscuit/core/events.py @@ -124,6 +124,7 @@ def close_active_directory(self) -> None: self.set_title() self.git_found = False self.update_git() + self.event_generate("<>") def close_active_editor(self) -> None: self.editorsmanager.close_active_editor() diff --git a/biscuit/core/settings/config/theme/theme.py b/biscuit/core/settings/config/theme/theme.py index 0807df87..4d22842e 100644 --- a/biscuit/core/settings/config/theme/theme.py +++ b/biscuit/core/settings/config/theme/theme.py @@ -244,6 +244,7 @@ def __init__(self, *args, **kwargs) -> None: theme = self.master self.button = HighlightableThemeObject(self, theme.biscuit, "white", theme.biscuit_dark) + self.label = ThemeObject(self) self.linklabel = ThemeObject(self, theme.secondary_background, theme.biscuit, self.highlightbackground) self.colorlabel = ThemeObject(self, theme.biscuit, "white", theme.biscuit_dark) self.tree = FrameThemeObject(self)