diff options
| author | Zach Berwaldt <zberwaldt@tutamail.com> | 2025-02-19 14:00:19 -0500 |
|---|---|---|
| committer | Zach Berwaldt <zberwaldt@tutamail.com> | 2025-02-19 14:00:19 -0500 |
| commit | 116c309b2efc394123f2cc67625effc3b2426a22 (patch) | |
| tree | 47a16f86555878a5bb9ae03385d625d3f4a96dca | |
| parent | dcfa79b9c86c31e9df261a903564c308fec6695a (diff) | |
| parent | 4da3c645173454d1fe73fea09710cb3db95f19a9 (diff) | |
Merge branch 'develop'
| -rw-r--r-- | Default (Linux).sublime-keymap | 4 | ||||
| -rw-r--r-- | Default (Windows).sublime-keymap | 4 | ||||
| -rw-r--r-- | main.py | 4 | ||||
| -rw-r--r-- | note_tools/commands.py | 49 |
4 files changed, 1 insertions, 60 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 @@ | |||
| 1 | [ | 1 | [ |
| 2 | { | 2 | { |
| 3 | "keys": ["alt+n", "o"], | ||
| 4 | "command": "organize_notes" | ||
| 5 | }, | ||
| 6 | { | ||
| 7 | "keys": ["alt+n", "n"], | 3 | "keys": ["alt+n", "n"], |
| 8 | "command": "new_note" | 4 | "command": "new_note" |
| 9 | } | 5 | } |
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 @@ | |||
| 1 | [ | 1 | [ |
| 2 | { | 2 | { |
| 3 | "keys": ["alt+n", "o"], | ||
| 4 | "command": "organize_notes" | ||
| 5 | }, | ||
| 6 | { | ||
| 7 | "keys": ["alt+n", "n"], | 3 | "keys": ["alt+n", "n"], |
| 8 | "command": "new_note" | 4 | "command": "new_note" |
| 9 | } | 5 | } |
| @@ -4,10 +4,8 @@ from .note_tools.commands import ( | |||
| 4 | ) | 4 | ) |
| 5 | 5 | ||
| 6 | __all__= [ | 6 | __all__= [ |
| 7 | "NewNoteCommand", | 7 | "NewNoteCommand" |
| 8 | "OrganizeNotesCommand" | ||
| 9 | ] | 8 | ] |
| 10 | 9 | ||
| 11 | def plugin_loaded(): | 10 | def plugin_loaded(): |
| 12 | print("Note tools have been loaded.") | 11 | print("Note tools have been loaded.") |
| 13 | \ No newline at end of file | ||
diff --git a/note_tools/commands.py b/note_tools/commands.py index 755bd5d..5d150a1 100644 --- a/note_tools/commands.py +++ b/note_tools/commands.py | |||
| @@ -2,56 +2,9 @@ import sublime | |||
| 2 | import sublime_plugin | 2 | import sublime_plugin |
| 3 | import datetime | 3 | import datetime |
| 4 | import os | 4 | import os |
| 5 | import sys | ||
| 6 | from pathlib import Path | 5 | from pathlib import Path |
| 7 | from typing import List, Optional, Tuple | 6 | from typing import List, Optional, Tuple |
| 8 | 7 | ||
| 9 | |||
| 10 | class OrganizeNotesCommand(sublime_plugin.WindowCommand): | ||
| 11 | def run(self): | ||
| 12 | |||
| 13 | now = datetime.datetime.now() | ||
| 14 | |||
| 15 | project_data = self.window.project_data() | ||
| 16 | |||
| 17 | notes_path = None | ||
| 18 | |||
| 19 | active_sheet = self.window.active_sheet() | ||
| 20 | |||
| 21 | # Close the active note right away | ||
| 22 | active_sheet.close() | ||
| 23 | |||
| 24 | if project_data and "folders" in project_data: | ||
| 25 | for folder in project_data['folders']: | ||
| 26 | folder_path = folder['path'] | ||
| 27 | print(folder_path) | ||
| 28 | if os.path.basename(folder_path).lower() == "notes": | ||
| 29 | notes_path = folder_path | ||
| 30 | break | ||
| 31 | |||
| 32 | if notes_path is not None: | ||
| 33 | notes = self.list_files(notes_path, ['.sublime-project', '.sublime-workspace']) | ||
| 34 | for note in notes: | ||
| 35 | year, month = self.parse_file_date(note.name) | ||
| 36 | dirs = os.path.join(notes_path, year, month) | ||
| 37 | os.makedirs(dirs, exist_ok=True) | ||
| 38 | new_note = os.path.join(notes_path, year, month, note.name) | ||
| 39 | os.rename(note.resolve(), new_note) | ||
| 40 | new_view = self.window.open_file(new_note) | ||
| 41 | else: | ||
| 42 | sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") | ||
| 43 | |||
| 44 | def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]: | ||
| 45 | if ignore_extensions is None: | ||
| 46 | ignore_extensions = [] | ||
| 47 | return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions] | ||
| 48 | |||
| 49 | def parse_file_date (self, file_name: str) -> Tuple[str, str]: | ||
| 50 | year = file_name[:4] | ||
| 51 | month = file_name[4:6] | ||
| 52 | return year, month | ||
| 53 | |||
| 54 | |||
| 55 | class NewNoteCommand(sublime_plugin.WindowCommand): | 8 | class NewNoteCommand(sublime_plugin.WindowCommand): |
| 56 | def run(self): | 9 | def run(self): |
| 57 | # Get the current date formatted as YYYYMMDD and YYYY-MM-DD | 10 | # Get the current date formatted as YYYYMMDD and YYYY-MM-DD |
| @@ -74,7 +27,6 @@ class NewNoteCommand(sublime_plugin.WindowCommand): | |||
| 74 | break | 27 | break |
| 75 | 28 | ||
| 76 | if notes_path: | 29 | if notes_path: |
| 77 | file_path = os.path.join(notes_path, file_name) | ||
| 78 | 30 | ||
| 79 | # Check if file already exists | 31 | # Check if file already exists |
| 80 | if os.path.exists(file_path): | 32 | if os.path.exists(file_path): |
| @@ -83,7 +35,6 @@ class NewNoteCommand(sublime_plugin.WindowCommand): | |||
| 83 | # Create the new file and write the date string with a line underneath | 35 | # Create the new file and write the date string with a line underneath |
| 84 | with open(file_path, 'w') as file: | 36 | with open(file_path, 'w') as file: |
| 85 | file.write(f"{date_str_display}\n{underline}\n\n\n") | 37 | file.write(f"{date_str_display}\n{underline}\n\n\n") |
| 86 | |||
| 87 | # Open the file and set the cursor position | 38 | # Open the file and set the cursor position |
| 88 | new_view = self.window.open_file(file_path) | 39 | new_view = self.window.open_file(file_path) |
| 89 | self.set_cursor_position(new_view) | 40 | self.set_cursor_position(new_view) |
