Skip to content

Commit

Permalink
Merge pull request #67 from RedAtman/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RedAtman authored Aug 3, 2024
2 parents b899178 + 02ee5d8 commit 14f814e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Sublime Text 3 & 4 plugin of Simplenote, Use Sublime Text as a Simplenote client
* Forked from [quick_simplenote](https://github.com/sickmartian/quick_simplenote)
* UPDATES:
* Sublime Text 3 & 4 compatibility: Adapt to latest version of Sublime Text's default Python interpreter(Python 3.8)
* Beautify the note list style:
* Introduce QuickPanelItem for improved note representation
* Enhance the quick panel to display notes with richer information, including:
- Note body snippet
- Version and update timestamp
- Tags (to be implemented in the future)
* Bug fixes

Planned features:
Expand Down
Binary file modified assets/images/note_create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/note_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/note_markdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 29 additions & 12 deletions lib/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from functools import partial
import logging
import os
Expand Down Expand Up @@ -162,13 +163,13 @@ def on_note_changed(note: Note):
sublime.set_timeout(partial(new_view.run_command, "revert"), 0)


def on_select(list__modificationDate: List[float], selected_index: int):
def on_select(list__item: List[float], selected_index: int, *args, **kwargs):
if selected_index == -1:
return
note_id = list__modificationDate[selected_index]
selected_note = Note.tree.find(note_id)
selected_item = list__item[selected_index]
selected_note = getattr(selected_item, "note", None)
if not isinstance(selected_note, Note):
show_message("Note not found: note id(%s), Please restart simplenote or sublime text." % note_id)
show_message("Note not found: note id(%s), Please restart simplenote or sublime text." % selected_index)
return
filepath = selected_note.open()
selected_note.flush()
Expand All @@ -191,24 +192,40 @@ class QuickPanelPlaceholder(str, Enum):
FIRST_SYNC = "Sync complete. Press [super+shift+s] [super+shift+l] to display the note list again."


class QuickPanelItem(sublime.QuickPanelItem):
def __init__(self, note: Note, trigger, details="", annotation="", kind=sublime.KIND_AMBIGUOUS):
super().__init__(trigger, details, annotation, kind)
self.note = note

def __repr__(self):
return "QuickPanelItem(%s)" % self.trigger


def show_quick_panel(first_sync: bool = False):
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."
)
return

list__modificationDate: List[float] = []
list__title: List[str] = []
list__filename: List[str] = []
list__item = []
for note in Note.tree.iter(reverse=True):
if not isinstance(note, Note):
raise Exception("note is not a Note: %s" % type(note))
if note.d.deleted:
continue
list__modificationDate.append(note.d.modificationDate)
list__title.append(note.title)
list__filename.append(note.filename)
item = QuickPanelItem(
note,
note.title,
[
note.body,
# f"tags: {note.d.tags}",
], # type: ignore
f"version:{note.v} | update:{datetime.fromtimestamp(note.d.modificationDate).strftime('%Y-%m-%d %H:%M:%S')}",
kind=(sublime.KIND_ID_SNIPPET, "", ""),
)
list__item.append(item)

placeholder = QuickPanelPlaceholder.DEFAULT
if first_sync:
Expand All @@ -218,9 +235,9 @@ def show_quick_panel(first_sync: bool = False):

def show_panel():
sublime.active_window().show_quick_panel(
list__title,
partial(on_select, list__modificationDate),
flags=sublime.MONOSPACE_FONT,
list__item,
partial(on_select, list__item),
flags=sublime.MONOSPACE_FONT | sublime.KEEP_OPEN_ON_FOCUS_LOST | sublime.WANT_EVENT,
# on_highlight=self.on_select,
placeholder=placeholder,
)
Expand Down
27 changes: 19 additions & 8 deletions lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,35 @@ def _title(self):
content = self._content
except Exception:
return CONFIG.SIMPLENOTE_DEFAULT_NOTE_TITLE
return self.get_title(content)
title, _ = self.get_title_body(content)
return title

@property
def title(self):
try:
content = self.d.content
except Exception:
return CONFIG.SIMPLENOTE_DEFAULT_NOTE_TITLE
return self.get_title(content)
title, _ = self.get_title_body(content)
return title

@property
def body(self) -> str:
_, body = self.get_title_body(self.d.content)
return body

@staticmethod
def get_title(content: str) -> str:
index = content.find("\n")
if index > -1:
title = content[:index]
def get_title_body(content: str) -> tuple[str, str]:
if not isinstance(content, str):
return CONFIG.SIMPLENOTE_DEFAULT_NOTE_TITLE, "empty body"
_content = content.split("\n", 1)
title, body = CONFIG.SIMPLENOTE_DEFAULT_NOTE_TITLE, "empty body"
if len(_content) == 1:
title = _content[0] or title
else:
title = content or CONFIG.SIMPLENOTE_DEFAULT_NOTE_TITLE
return title
title = _content[0] or title
body = _content[1] or body
return title, body

@property
def _filename(self) -> str:
Expand Down

0 comments on commit 14f814e

Please sign in to comment.