From 0fea88ad9689d0816f5ba8e261e8b08ae4e2bf11 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Mon, 20 Jan 2025 10:14:13 -0500 Subject: add .idea to ignore file. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7cad780..00efcab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.cache *.sublime-project *.sublime-workspace +.idea \ No newline at end of file -- cgit v1.1 From 83e091e7c5eefec6bd6c9001cbc35a6fb75895f7 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Thu, 13 Feb 2025 20:59:08 -0500 Subject: update organize notes command to close and reopen the active note. --- note_tools/commands.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/note_tools/commands.py b/note_tools/commands.py index 3c26915..755bd5d 100644 --- a/note_tools/commands.py +++ b/note_tools/commands.py @@ -2,6 +2,7 @@ import sublime import sublime_plugin import datetime import os +import sys from pathlib import Path from typing import List, Optional, Tuple @@ -15,6 +16,11 @@ class OrganizeNotesCommand(sublime_plugin.WindowCommand): notes_path = None + active_sheet = self.window.active_sheet() + + # Close the active note right away + active_sheet.close() + if project_data and "folders" in project_data: for folder in project_data['folders']: folder_path = folder['path'] @@ -30,7 +36,8 @@ class OrganizeNotesCommand(sublime_plugin.WindowCommand): dirs = os.path.join(notes_path, year, month) os.makedirs(dirs, exist_ok=True) new_note = os.path.join(notes_path, year, month, note.name) - os.rename(note.resolve(), new_note) + os.rename(note.resolve(), new_note) + new_view = self.window.open_file(new_note) else: sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") -- cgit v1.1 From 4da3c645173454d1fe73fea09710cb3db95f19a9 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Wed, 19 Feb 2025 13:55:16 -0500 Subject: Simplify the API for the plugin. Notes are automatically sorted on creation. --- Default (Linux).sublime-keymap | 4 --- Default (Windows).sublime-keymap | 4 --- main.py | 4 +-- note_tools/commands.py | 60 ++++++++-------------------------------- 4 files changed, 13 insertions(+), 59 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index 52ebbf1..58f6d3c 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -1,9 +1,5 @@ [ { - "keys": ["alt+n", "o"], - "command": "organize_notes" - }, - { "keys": ["alt+n", "n"], "command": "new_note" } diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index 52ebbf1..58f6d3c 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -1,9 +1,5 @@ [ { - "keys": ["alt+n", "o"], - "command": "organize_notes" - }, - { "keys": ["alt+n", "n"], "command": "new_note" } diff --git a/main.py b/main.py index d388de5..7095cf2 100644 --- a/main.py +++ b/main.py @@ -4,10 +4,8 @@ from .note_tools.commands import ( ) __all__= [ - "NewNoteCommand", - "OrganizeNotesCommand" + "NewNoteCommand" ] def plugin_loaded(): print("Note tools have been loaded.") - \ No newline at end of file diff --git a/note_tools/commands.py b/note_tools/commands.py index 755bd5d..610d9be 100644 --- a/note_tools/commands.py +++ b/note_tools/commands.py @@ -6,52 +6,6 @@ import sys from pathlib import Path from typing import List, Optional, Tuple - -class OrganizeNotesCommand(sublime_plugin.WindowCommand): - def run(self): - - now = datetime.datetime.now() - - project_data = self.window.project_data() - - notes_path = None - - active_sheet = self.window.active_sheet() - - # Close the active note right away - active_sheet.close() - - if project_data and "folders" in project_data: - for folder in project_data['folders']: - folder_path = folder['path'] - print(folder_path) - if os.path.basename(folder_path).lower() == "notes": - notes_path = folder_path - break - - if notes_path is not None: - notes = self.list_files(notes_path, ['.sublime-project', '.sublime-workspace']) - for note in notes: - year, month = self.parse_file_date(note.name) - dirs = os.path.join(notes_path, year, month) - os.makedirs(dirs, exist_ok=True) - new_note = os.path.join(notes_path, year, month, note.name) - os.rename(note.resolve(), new_note) - new_view = self.window.open_file(new_note) - else: - sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") - - def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]: - if ignore_extensions is None: - ignore_extensions = [] - return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions] - - def parse_file_date (self, file_name: str) -> Tuple[str, str]: - year = file_name[:4] - month = file_name[4:6] - return year, month - - class NewNoteCommand(sublime_plugin.WindowCommand): def run(self): # Get the current date formatted as YYYYMMDD and YYYY-MM-DD @@ -74,7 +28,8 @@ class NewNoteCommand(sublime_plugin.WindowCommand): break if notes_path: - file_path = os.path.join(notes_path, file_name) + year, month, day = date_str_display.split('-') + file_path = os.path.join(notes_path, year, month, file_name) # Check if file already exists if os.path.exists(file_path): @@ -83,7 +38,6 @@ class NewNoteCommand(sublime_plugin.WindowCommand): # Create the new file and write the date string with a line underneath with open(file_path, 'w') as file: file.write(f"{date_str_display}\n{underline}\n\n\n") - # Open the file and set the cursor position new_view = self.window.open_file(file_path) self.set_cursor_position(new_view) @@ -103,3 +57,13 @@ class NewNoteCommand(sublime_plugin.WindowCommand): sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100) else: on_load() + + def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]: + if ignore_extensions is None: + ignore_extensions = [] + return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions] + + def parse_file_date (self, file_name: str) -> Tuple[str, str]: + year = file_name[:4] + month = file_name[4:6] + return year, month -- cgit v1.1