Skip to content

Commit

Permalink
Refactor: Use an enum for quick panel placeholders
Browse files Browse the repository at this point in the history
Improve readability and maintainability by using an enum for the quick panel placeholders, making it easier to manage and expand the list of placeholders in the future.
  • Loading branch information
RedAtman committed Aug 3, 2024
1 parent a104a88 commit 901167f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ._config import CONFIG
from .lib.core import GlobalStorage, sync_once
from .lib.gui import close_view, on_note_changed, open_view, show_message, show_quick_panel
from .lib.gui import QuickPanelPlaceholder, close_view, on_note_changed, open_view, show_message, show_quick_panel
from .lib.models import Note
from .lib.operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager

Expand Down Expand Up @@ -146,7 +146,7 @@ def callback(self, updated_notes: List[Note]):
)
first_sync = sync_times == 0
if first_sync:
show_quick_panel(first_sync)
show_quick_panel(QuickPanelPlaceholder.FIRST_SYNC)
global_storage.optimistic_update(CONFIG.SIMPLENOTE_SYNC_TIMES_KEY, sync_times + 1)
global_storage.optimistic_update(CONFIG.SIMPLENOTE_STARTED_KEY, False)

Expand Down
15 changes: 10 additions & 5 deletions lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"close_view",
"clear_orphaned_filepaths",
"on_note_changed",
"QuickPanelPlaceholder",
"show_quick_panel",
]

Expand Down Expand Up @@ -137,7 +138,15 @@ def on_select(list__modificationDate: List[float], selected_index: int):
view = open_view(filepath)


def show_quick_panel(first_sync: bool = False):
from enum import Enum


class QuickPanelPlaceholder(str, Enum):
DEFAULT = "Select Note press key 'enter' to open"
FIRST_SYNC = "Sync complete. Press [super+shift+s] [super+shift+l] to display the note list again."


def show_quick_panel(placeholder: str = QuickPanelPlaceholder.DEFAULT):
if Note.tree.count <= 0:
show_message(
"No notes found. Please wait for the synchronization to complete, or press [super+shift+s, super+shift+c] to create a note."
Expand All @@ -157,10 +166,6 @@ def show_quick_panel(first_sync: bool = False):
# TODO: Maybe doesn't need to run every time
clear_orphaned_filepaths(list__filename)

placeholder = "Select Note press key 'enter' to open"
if first_sync:
placeholder = "Sync complete. Press [super+shift+s] [super+shift+l] to display the note list again."

def show_panel():
sublime.active_window().show_quick_panel(
list__title,
Expand Down

0 comments on commit 901167f

Please sign in to comment.