From cc2719d963d7ba8037e00a4298b25960d128b826 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 19:16:27 +0800 Subject: [PATCH 1/9] refactor: refactor note handling This commit introduces a significant refactoring of note handling logic. The changes streamline the process of updating, deleting, and closing notes, improving overall performance and reliability. Furthermore, orphaned file paths are now properly managed, reducing potential inconsistencies in the file system. These modifications lead to a more robust and efficient handling of notes within the Sublime Text plugin, ensuring a smoother user experience. --- gui.py | 48 ++++++++++++++++++++++++++++++++++++++- simplenote.py | 53 +++---------------------------------------- simplenotecommands.py | 3 +-- 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/gui.py b/gui.py index be99fa9..836c546 100644 --- a/gui.py +++ b/gui.py @@ -1,10 +1,12 @@ +from functools import partial import logging import os -from typing import Optional +from typing import List, Optional import sublime from ._config import CONFIG +from .models import Note logger = logging.getLogger() @@ -17,6 +19,8 @@ "get_view_window", "open_view", "close_view", + "clear_orphaned_filepaths", + "on_note_changed", ] settings_content = """ @@ -138,3 +142,45 @@ def close_view(view: sublime.View): window = get_view_window(view) window.focus_view(view) window.run_command("close_file") + + +def clear_orphaned_filepaths(list__filename: List[str] = []): + if not list__filename: + list__filename = [note.filename for note in Note.mapper_id_note.values()] + for filename in os.listdir(CONFIG.SIMPLENOTE_NOTES_DIR): + if filename not in list__filename: + os.remove(os.path.join(CONFIG.SIMPLENOTE_NOTES_DIR, filename)) + + +def on_note_changed(note: Note): + old_window = sublime.active_window() + old_view = old_window.find_open_file(note._filepath) + # if note is not open in the current window + if not isinstance(old_view, sublime.View): + note.flush() + return + + if note._filepath == note.filepath: + note.flush() + note.open() + return + + note._close(note._filepath) + note.flush() + close_view(old_view) + note.open() + new_view = open_view(note.filepath, old_view) + + # TODO: maybe not needed, or needed to be tested + old_active_view = old_window.active_view() + assert isinstance(old_active_view, sublime.View), "old_active_view is not a sublime.View" + if isinstance(old_active_view, sublime.View): + # old_window.focus_view(old_active_view) + if old_view.id() == old_active_view.id(): + old_note_window = [window for window in sublime.windows() if window.id() == old_window.id()] + if old_note_window: + old_note_window[0].focus_view(new_view) + else: + old_window.focus_view(old_active_view) + + sublime.set_timeout(partial(new_view.run_command, "revert"), 0) diff --git a/simplenote.py b/simplenote.py index 001c320..0dad3cb 100644 --- a/simplenote.py +++ b/simplenote.py @@ -1,25 +1,20 @@ from datetime import datetime -from functools import partial import logging -import os import pickle from typing import Any, Dict, List -# https://www.sublimetext.com/docs/api_reference.html -import sublime - from ._config import CONFIG -from .gui import close_view, open_view from .models import Note from .utils.patterns.singleton.base import Singleton +# https://www.sublimetext.com/docs/api_reference.html + + __all__: List[str] = [ "Local", "load_notes", - "clear_orphaned_filepaths", "sort_notes", - "on_note_changed", ] @@ -92,14 +87,6 @@ def load_notes(): logger.debug((f"Created new objects cache file: {CONFIG.SIMPLENOTE_NOTE_CACHE_FILE_PATH}")) -def clear_orphaned_filepaths(list__filename: List[str] = []): - if not list__filename: - list__filename = [note.filename for note in Note.mapper_id_note.values()] - for filename in os.listdir(CONFIG.SIMPLENOTE_NOTES_DIR): - if filename not in list__filename: - os.remove(os.path.join(CONFIG.SIMPLENOTE_NOTES_DIR, filename)) - - def sort_notes(a_note: Note, b_note: Note): if "pinned" in a_note.d.systemTags: return 1 @@ -109,37 +96,3 @@ def sort_notes(a_note: Note, b_note: Note): date_a = datetime.fromtimestamp(float(a_note.d.modificationDate)) date_b = datetime.fromtimestamp(float(b_note.d.modificationDate)) return (date_a > date_b) - (date_a < date_b) - - -def on_note_changed(note: Note): - old_window = sublime.active_window() - old_view = old_window.find_open_file(note._filepath) - # if note is not open in the current window - if not isinstance(old_view, sublime.View): - note.flush() - return - - if note._filepath == note.filepath: - note.flush() - note.open() - return - - note._close(note._filepath) - note.flush() - close_view(old_view) - note.open() - new_view = open_view(note.filepath, old_view) - - # TODO: maybe not needed, or needed to be tested - old_active_view = old_window.active_view() - assert isinstance(old_active_view, sublime.View), "old_active_view is not a sublime.View" - if isinstance(old_active_view, sublime.View): - # old_window.focus_view(old_active_view) - if old_view.id() == old_active_view.id(): - old_note_window = [window for window in sublime.windows() if window.id() == old_window.id()] - if old_note_window: - old_note_window[0].focus_view(new_view) - else: - old_window.focus_view(old_active_view) - - sublime.set_timeout(partial(new_view.run_command, "revert"), 0) diff --git a/simplenotecommands.py b/simplenotecommands.py index 7a2cda7..12515cb 100644 --- a/simplenotecommands.py +++ b/simplenotecommands.py @@ -7,10 +7,9 @@ import sublime_plugin from ._config import CONFIG -from .gui import close_view, open_view, show_message +from .gui import clear_orphaned_filepaths, close_view, on_note_changed, open_view, show_message from .models import Note from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager -from .simplenote import clear_orphaned_filepaths, on_note_changed __all__ = [ From b88125a0840b06125992cc18b51b9d001bc7d41d Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 19:53:10 +0800 Subject: [PATCH 2/9] refactor: Introduce library structure and core functionality Refactors the project by organizing code into a library structure, enhancing code organization and maintainability. This change introduces a `lib` directory containing modules for API interactions, GUI elements, model classes, operations, and core functionality. Additionally, it includes a core function `start()` to handle application initialization and syncing. This allows for a cleaner and more modular codebase, facilitating future development and potentially improving performance. --- api.py => lib/api.py | 6 ++-- lib/core.py | 47 ++++++++++++++++++++++++++ gui.py => lib/gui.py | 2 +- models.py => lib/models.py | 6 ++-- operations.py => lib/operations.py | 2 +- simplenote.py => lib/simplenote.py | 4 +-- main.py | 54 +++++------------------------- simplenotecommands.py | 7 ++-- 8 files changed, 68 insertions(+), 60 deletions(-) rename api.py => lib/api.py (98%) create mode 100644 lib/core.py rename gui.py => lib/gui.py (99%) rename models.py => lib/models.py (98%) rename operations.py => lib/operations.py (99%) rename simplenote.py => lib/simplenote.py (96%) diff --git a/api.py b/lib/api.py similarity index 98% rename from api.py rename to lib/api.py index b662008..6f10892 100644 --- a/api.py +++ b/lib/api.py @@ -11,9 +11,9 @@ from urllib.parse import urlencode from uuid import uuid4 -from ._config import CONFIG -from .utils.patterns.singleton.base import Singleton -from .utils.request import Response, request +from .._config import CONFIG +from ..utils.patterns.singleton.base import Singleton +from ..utils.request import Response, request logger = logging.getLogger() diff --git a/lib/core.py b/lib/core.py new file mode 100644 index 0000000..9d24ca6 --- /dev/null +++ b/lib/core.py @@ -0,0 +1,47 @@ +import logging + +import sublime + +from .._config import CONFIG +from .gui import edit_settings, remove_status, show_message +from .operations import OperationManager + + +logger = logging.getLogger() +SIMPLENOTE_STARTED = False + + +def sync(): + manager = OperationManager() + if not manager.running: + sublime.run_command("simplenote_sync") + else: + logger.debug("Sync omitted") + + settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH) + sync_every = settings.get("sync_every", 0) + logger.debug(("Simplenote sync_every", sync_every)) + if not isinstance(sync_every, int): + show_message("`sync_every` must be an integer. Please check settings file.") + return + + if sync_every > 0: + sublime.set_timeout(sync, sync_every * 1000) + + +def start(): + global SIMPLENOTE_STARTED + logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) + settings = sublime.load_settings("Simplenote.sublime-settings") + username = settings.get("username") + password = settings.get("password") + + if username and password: + sync() + SIMPLENOTE_STARTED = True + else: + edit_settings() + show_message("Simplenote: Please configure username/password, Please check settings file.") + sublime.set_timeout(remove_status, 2000) + SIMPLENOTE_STARTED = False + return SIMPLENOTE_STARTED diff --git a/gui.py b/lib/gui.py similarity index 99% rename from gui.py rename to lib/gui.py index 836c546..4547067 100644 --- a/gui.py +++ b/lib/gui.py @@ -5,7 +5,7 @@ import sublime -from ._config import CONFIG +from .._config import CONFIG from .models import Note diff --git a/models.py b/lib/models.py similarity index 98% rename from models.py rename to lib/models.py index f6d77d8..d6dfd98 100644 --- a/models.py +++ b/lib/models.py @@ -10,10 +10,10 @@ import sublime -from ._config import CONFIG +from .._config import CONFIG from .api import Simplenote -from .utils.decorator import class_property -from .utils.tree.redblacktree import rbtree as RedBlackTree +from ..utils.decorator import class_property +from ..utils.tree.redblacktree import rbtree as RedBlackTree # from typing_extensions import Unpack diff --git a/operations.py b/lib/operations.py similarity index 99% rename from operations.py rename to lib/operations.py index 2e16be0..91b78f4 100644 --- a/operations.py +++ b/lib/operations.py @@ -7,7 +7,7 @@ from .gui import _show_message, edit_settings, remove_status from .models import Note -from .utils.patterns.singleton.base import Singleton +from ..utils.patterns.singleton.base import Singleton __all__ = [ diff --git a/simplenote.py b/lib/simplenote.py similarity index 96% rename from simplenote.py rename to lib/simplenote.py index 0dad3cb..b3074bd 100644 --- a/simplenote.py +++ b/lib/simplenote.py @@ -3,9 +3,9 @@ import pickle from typing import Any, Dict, List -from ._config import CONFIG +from .._config import CONFIG from .models import Note -from .utils.patterns.singleton.base import Singleton +from ..utils.patterns.singleton.base import Singleton # https://www.sublimetext.com/docs/api_reference.html diff --git a/main.py b/main.py index b1a7103..dc3f65f 100644 --- a/main.py +++ b/main.py @@ -3,61 +3,23 @@ import sublime from ._config import CONFIG -from .gui import edit_settings, remove_status, show_message -from .models import Note -from .operations import OperationManager +from .lib.core import start +from .lib.models import Note logger = logging.getLogger() SIMPLENOTE_RELOAD_CALLS = -1 -SIMPLENOTE_STARTED = False - - -def sync(): - manager = OperationManager() - if not manager.running: - sublime.run_command("simplenote_sync") - else: - logger.debug("Sync omitted") - - settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH) - sync_every = settings.get("sync_every", 0) - logger.debug(("Simplenote sync_every", sync_every)) - if not isinstance(sync_every, int): - show_message("`sync_every` must be an integer. Please check settings file.") - return - - if sync_every > 0: - sublime.set_timeout(sync, sync_every * 1000) - - -def start(): - global SIMPLENOTE_STARTED - logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) - settings = sublime.load_settings("Simplenote.sublime-settings") - username = settings.get("username") - password = settings.get("password") - - if username and password: - sync() - SIMPLENOTE_STARTED = True - else: - edit_settings() - show_message("Simplenote: Please configure username/password, Please check settings file.") - sublime.set_timeout(remove_status, 2000) - SIMPLENOTE_STARTED = False - return SIMPLENOTE_STARTED def reload_if_needed(): - global SIMPLENOTE_RELOAD_CALLS + # global SIMPLENOTE_RELOAD_CALLS - # Sublime calls this twice for some reason :( - SIMPLENOTE_RELOAD_CALLS += 1 - if SIMPLENOTE_RELOAD_CALLS % 2 != 0: - logger.debug("Simplenote Reload call %s" % SIMPLENOTE_RELOAD_CALLS) - return + # # Sublime calls this twice for some reason :( + # SIMPLENOTE_RELOAD_CALLS += 1 + # if SIMPLENOTE_RELOAD_CALLS % 2 != 0: + # logger.debug("Simplenote Reload call %s" % SIMPLENOTE_RELOAD_CALLS) + # return logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) settings = sublime.load_settings("Simplenote.sublime-settings") diff --git a/simplenotecommands.py b/simplenotecommands.py index 12515cb..820a3a2 100644 --- a/simplenotecommands.py +++ b/simplenotecommands.py @@ -7,9 +7,9 @@ import sublime_plugin from ._config import CONFIG -from .gui import clear_orphaned_filepaths, close_view, on_note_changed, open_view, show_message -from .models import Note -from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager +from .lib.gui import clear_orphaned_filepaths, close_view, on_note_changed, open_view, show_message +from .lib.models import Note +from .lib.operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager __all__ = [ @@ -24,7 +24,6 @@ logger = logging.getLogger() -SIMPLENOTE_RELOAD_CALLS = -1 SIMPLENOTE_STARTED = False From f3d9743ad676464fbae8c8ccd927fc64468dfde8 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 19:53:38 +0800 Subject: [PATCH 3/9] misc: Exclude package-metadata.json from version control The `package-metadata.json` file is now excluded from version control, as it contains information specific to the local development environment and is not relevant to the project's core code. This prevents unnecessary clutter in the repository and ensures that the version control history focuses on code changes. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c23a47f..e88a541 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +package-metadata.json sublime_api.py # *.sublime-settings *.sublime-settings.example @@ -28,7 +29,7 @@ build/ develop-eggs/ dist/ eggs/ -lib/ +# lib/ lib64/ parts/ sdist/ From be266972d21251ca9846d7fd537b8b397a888358 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 19:53:51 +0800 Subject: [PATCH 4/9] misc: Exclude additional files from package Add `.gitignore` and `pyproject.toml` to the `export-ignore` list in `.gitattributes` to ensure these files are not included in the package. This prevents accidental inclusion of project configuration files and helps maintain a clean package. --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitattributes b/.gitattributes index d3ea577..e512308 100644 --- a/.gitattributes +++ b/.gitattributes @@ -36,3 +36,7 @@ test/* export-ignore # Exclude github files from the package .github/ export-ignore +.gitignore export-ignore + +# Exclude project files from the package +pyproject.toml export-ignore From 2b866899f187389fb0d4c225b2b7012d6c592e31 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 20:46:40 +0800 Subject: [PATCH 5/9] chore: Remove unnecessary warning logs Removed redundant `logger.warning` statements that were printing the path to the Simplenote settings file. This helps to reduce unnecessary noise in the console output, making it cleaner and easier to diagnose real issues. --- lib/core.py | 1 - lib/models.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/core.py b/lib/core.py index 9d24ca6..026e918 100644 --- a/lib/core.py +++ b/lib/core.py @@ -31,7 +31,6 @@ def sync(): def start(): global SIMPLENOTE_STARTED - logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) settings = sublime.load_settings("Simplenote.sublime-settings") username = settings.get("username") password = settings.get("password") diff --git a/lib/models.py b/lib/models.py index d6dfd98..f88be87 100644 --- a/lib/models.py +++ b/lib/models.py @@ -11,9 +11,9 @@ import sublime from .._config import CONFIG -from .api import Simplenote from ..utils.decorator import class_property from ..utils.tree.redblacktree import rbtree as RedBlackTree +from .api import Simplenote # from typing_extensions import Unpack @@ -141,7 +141,6 @@ def __init__(self, id: str = "", v: int = 0, d: Dict[str, Any] = {}, **kwargs): @class_property def API(cls) -> Simplenote: - logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH) username = settings.get("username") password = settings.get("password") From 1dcb3389199820b8f5dd3ae46675b52fa07f85ea Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 20:47:20 +0800 Subject: [PATCH 6/9] fix(core): Initialize core module This commit initializes the `core` module, which is responsible for managing the overall application logic. This lays the foundation for future features and improvements by providing a central point of control for the application's behavior. --- simplenotecommands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/simplenotecommands.py b/simplenotecommands.py index 820a3a2..bd19f36 100644 --- a/simplenotecommands.py +++ b/simplenotecommands.py @@ -7,6 +7,7 @@ import sublime_plugin from ._config import CONFIG +from .lib.core import start from .lib.gui import clear_orphaned_filepaths, close_view, on_note_changed, open_view, show_message from .lib.models import Note from .lib.operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager From 6fbdeff55914f75d01f94ff310121fe6331753d6 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 20:51:03 +0800 Subject: [PATCH 7/9] fix: Add settings template Adds a new template for configuring Simplenote's settings. This allows users to customize how the plugin interacts with their Simplenote account. --- _config.py | 81 +++++++++++++++++++++++++++++++++++++++++++++--------- lib/gui.py | 73 ++++-------------------------------------------- 2 files changed, 73 insertions(+), 81 deletions(-) diff --git a/_config.py b/_config.py index 343a418..c589586 100644 --- a/_config.py +++ b/_config.py @@ -24,6 +24,55 @@ ] +_SETTINGS_TEMPLATE = """ +// Simplenote Settings - User +// First time use, To configure your Simplenote account username and password in the settings file. +// After that, save the settings file, Then wait for the sync. +{ + // -------------------------------- + // Credentials: + // -------------------------------- + "username": "" + ,"password": "" + // -------------------------------- + // Sync settings: + // -------------------------------- + // Sync when sublime text starts: + ,"autostart": true + // Sync automatically (in seconds) + ,"sync_every": 30 + // Number of notes synchronized each time + ,"sync_note_number": 1000 + // Conflict resolution (If a file was edited on another client and also here, on sync..) + // Server Wins (Same as selecting 'Overwrite') + ,"on_conflict_use_server": false + // Local is left unchanged (Same as selecting 'Cancel') + ,"on_conflict_leave_alone": false + // -------------------------------- + // Autosave (beta) + // -------------------------------- + // Activate autosave and tell how much (in seconds) to wait + // after you stop typing to send the save + ,"autosave_debounce_time": 1 + // -------------------------------- + // File extension support + // -------------------------------- + // Which file extension should the temporal files use? + // This allows you to interact with other plugins such as + // PlainTasks defining an extension for certain note title + ,"title_extension_map": [{ + "title_regex": "[ST]" + ,"extension": "todo" + }, + { + "title_regex": "# " + ,"extension": "md" + ,"systemTags": ["markdown"] + }] +} +""" + + class _BaseConfig: # All subclasses of BaseConfig will be added to this mapping. mapping: typing.Dict[str, type] = {} @@ -39,7 +88,7 @@ def __init_subclass__(cls, **kwargs): sys.path.insert(0, BASE_DIR) # LOG_DIR: str = os.path.join(BASE_DIR, "logs") # os.makedirs(LOG_DIR, exist_ok=True) - LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO") + LOG_LEVEL: str = os.getenv("LOG_LEVEL", "WARNING") SIMPLENOTE_PROJECT_NAME: str = "Simplenote" SIMPLENOTE_PROJECT_VERSION: str = "0.0.1" @@ -64,12 +113,18 @@ def __init_subclass__(cls, **kwargs): SUBLIME_USER_DIR = os.path.join(packages_path(), "User") SIMPLENOTE_SETTINGS_FILE_PATH = SIMPLENOTE_SETTINGS_FILE - # SIMPLENOTE_SETTINGS_FILE_PATH = os.path.join(SUBLIME_USER_DIR, SIMPLENOTE_SETTINGS_FILE) - # if not os.path.exists(SIMPLENOTE_SETTINGS_FILE_PATH): - # import shutil - - # default_settings = os.path.join(os.path.dirname(__file__), SIMPLENOTE_SETTINGS_FILE) - # shutil.copy(default_settings, SIMPLENOTE_SETTINGS_FILE_PATH) + SIMPLENOTE_SETTINGS_USER_FILE_PATH = os.path.join(SUBLIME_USER_DIR, SIMPLENOTE_SETTINGS_FILE) + SETTINGS_TEMPLATE: str = _SETTINGS_TEMPLATE + if not os.path.exists(SIMPLENOTE_SETTINGS_USER_FILE_PATH): + try: + with open(SIMPLENOTE_SETTINGS_USER_FILE_PATH, "r") as f: + import json + + _ = json.loads(f.read()) + except Exception as e: + print(e) + with open(SIMPLENOTE_SETTINGS_USER_FILE_PATH, "w+") as f: + f.write(SETTINGS_TEMPLATE) SIMPLENOTE_CACHE_DIR = os.path.join(cache_path(), SIMPLENOTE_PROJECT_NAME) os.makedirs(SIMPLENOTE_CACHE_DIR, exist_ok=True) @@ -104,12 +159,12 @@ class Production(_BaseConfig): CONFIG: typing.Type[_BaseConfig] = _BaseConfig.mapping.get(env, Development) # Set environment variables -for attr in dir(CONFIG): - if attr.startswith("_"): - continue - if attr.startswith(("SIMPLENOTE", "LOG_LEVEL")): - os.environ[attr] = str(getattr(CONFIG, attr)) - # print("set %s: %s" % (attr, getattr(CONFIG, attr))) +# for attr in dir(CONFIG): +# if attr.startswith("_"): +# continue +# if attr.startswith(("SIMPLENOTE", "LOG_LEVEL")): +# os.environ[attr] = str(getattr(CONFIG, attr)) +# print("set %s: %s" % (attr, getattr(CONFIG, attr))) if __name__ == "Simplenote._config": diff --git a/lib/gui.py b/lib/gui.py index 4547067..c33e1ef 100644 --- a/lib/gui.py +++ b/lib/gui.py @@ -23,75 +23,9 @@ "on_note_changed", ] -settings_content = """ -{ - // -------------------------------- - // Credentials: - // -------------------------------- - "username": "" - ,"password": "" - // -------------------------------- - // Sync settings: - // -------------------------------- - // Sync when sublime text starts: - ,"autostart": true - // Sync automatically (in seconds) - ,"sync_every": 30 - // Number of notes synchronized each time - ,"sync_note_number": 1000 - // Conflict resolution (If a file was edited on another client and also here, on sync..) - // Server Wins (Same as selecting 'Overwrite') - ,"on_conflict_use_server": false - // Local is left unchanged (Same as selecting 'Cancel') - ,"on_conflict_leave_alone": false - // -------------------------------- - // Autosave (beta) - // -------------------------------- - // Activate autosave and tell how much (in seconds) to wait - // after you stop typing to send the save - ,"autosave_debounce_time": 1 - // -------------------------------- - // File extension support - // -------------------------------- - // Which file extension should the temporal files use? - // This allows you to interact with other plugins such as - // PlainTasks defining an extension for certain note title - ,"title_extension_map": [{ - "title_regex": "\\[ST\\]" - ,"extension": "todo" - }, - { - "title_regex": "\\# " - ,"extension": "md" - ,"systemTags": ["markdown"] - }] -} -""" - def edit_settings(): - installed_package_settings_file = os.path.join( - CONFIG.SIMPLENOTE_INSTALLED_PACKAGE_DIR, CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH - ) - package_settings_file = os.path.join(CONFIG.SIMPLENOTE_PACKAGE_DIR, CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH) - logger.warning((os.path.exists(installed_package_settings_file), installed_package_settings_file)) - logger.warning((os.path.exists(package_settings_file), package_settings_file)) - if os.path.exists(installed_package_settings_file): - settings_file = installed_package_settings_file - elif os.path.exists(package_settings_file): - settings_file = package_settings_file - else: - settings_file = CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH - - # logger.warning(("CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)) - - # settings_file = os.path.join( - # sublime.installed_packages_path(), "Simplenote.sublime-package", CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH - # ) - # settings_file = ( - # """/Users/nut/Library/Application Support/Sublime Text/Packages/Simplenote/Simplenote.sublime-settings""" - # ) - # settings_file = os.path.join(os.path.dirname(__file__), settings_file) + settings_file = CONFIG.SIMPLENOTE_SETTINGS_USER_FILE_PATH logger.warning((type(settings_file), settings_file)) # with open(settings_file) as f: # settings = f.read() @@ -99,7 +33,10 @@ def edit_settings(): # sublime.run_command("open_file", {"file": settings_file}) sublime.run_command( "edit_settings", - {"base_file": settings_file, "default": "// Simplenote Settings - User\n{\n\t$0\n}\n" + settings_content}, + { + "base_file": settings_file, + # "default": "// Simplenote Settings - User\n{\n\t$0\n}\n", + }, ) From 8715ec292ad016f7c652ed505cd4aac8eb480075 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 21:05:21 +0800 Subject: [PATCH 8/9] Refactor: Rename simplenotecommands.py to commands.py This commit renames the `simplenotecommands.py` file to `commands.py` for better organization and clarity. This change reflects the broader scope of the commands module, encompassing more than just Simplenote functionality. --- simplenotecommands.py => commands.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename simplenotecommands.py => commands.py (100%) diff --git a/simplenotecommands.py b/commands.py similarity index 100% rename from simplenotecommands.py rename to commands.py From 91fb1635f9c538337c97f852da4573f514f858c7 Mon Sep 17 00:00:00 2001 From: redatman Date: Thu, 1 Aug 2024 21:08:43 +0800 Subject: [PATCH 9/9] misc: isort import --- lib/operations.py | 2 +- lib/simplenote.py | 2 +- tests/test_api.py | 2 +- tests/test_model.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/operations.py b/lib/operations.py index 91b78f4..ade5370 100644 --- a/lib/operations.py +++ b/lib/operations.py @@ -5,9 +5,9 @@ import sublime +from ..utils.patterns.singleton.base import Singleton from .gui import _show_message, edit_settings, remove_status from .models import Note -from ..utils.patterns.singleton.base import Singleton __all__ = [ diff --git a/lib/simplenote.py b/lib/simplenote.py index b3074bd..de07367 100644 --- a/lib/simplenote.py +++ b/lib/simplenote.py @@ -4,8 +4,8 @@ from typing import Any, Dict, List from .._config import CONFIG -from .models import Note from ..utils.patterns.singleton.base import Singleton +from .models import Note # https://www.sublimetext.com/docs/api_reference.html diff --git a/tests/test_api.py b/tests/test_api.py index 12b7c5c..877c2ac 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,7 +4,7 @@ from unittest import TestCase, main from _config import CONFIG -from api import Simplenote +from lib.api import Simplenote logger = logging.getLogger() diff --git a/tests/test_model.py b/tests/test_model.py index 52ae226..0b6063d 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -3,7 +3,7 @@ from typing import Any from unittest import TestCase, main -from models import Note, _Note +from lib.models import Note, _Note import_module("utils.logger.init")