summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Berwaldt <zberwaldt@tutamail.com>2025-02-19 13:55:16 -0500
committerZach Berwaldt <zberwaldt@tutamail.com>2025-02-19 13:55:16 -0500
commit4da3c645173454d1fe73fea09710cb3db95f19a9 (patch)
tree6ebdcf79200744d11d4e623b4af784517c2ee3da
parent83e091e7c5eefec6bd6c9001cbc35a6fb75895f7 (diff)
Simplify the API for the plugin. Notes are automatically sorted on creation.
-rw-r--r--Default (Linux).sublime-keymap4
-rw-r--r--Default (Windows).sublime-keymap4
-rw-r--r--main.py4
-rw-r--r--note_tools/commands.py60
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 @@
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 }
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 (
4) 4)
5 5
6__all__= [ 6__all__= [
7 "NewNoteCommand", 7 "NewNoteCommand"
8 "OrganizeNotesCommand"
9] 8]
10 9
11def plugin_loaded(): 10def 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..610d9be 100644
--- a/note_tools/commands.py
+++ b/note_tools/commands.py
@@ -6,52 +6,6 @@ import sys
6from pathlib import Path 6from pathlib import Path
7from typing import List, Optional, Tuple 7from typing import List, Optional, Tuple
8 8
9
10class 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
55class NewNoteCommand(sublime_plugin.WindowCommand): 9class NewNoteCommand(sublime_plugin.WindowCommand):
56 def run(self): 10 def run(self):
57 # Get the current date formatted as YYYYMMDD and YYYY-MM-DD 11 # Get the current date formatted as YYYYMMDD and YYYY-MM-DD
@@ -74,7 +28,8 @@ class NewNoteCommand(sublime_plugin.WindowCommand):
74 break 28 break
75 29
76 if notes_path: 30 if notes_path:
77 file_path = os.path.join(notes_path, file_name) 31 year, month, day = date_str_display.split('-')
32 file_path = os.path.join(notes_path, year, month, file_name)
78 33
79 # Check if file already exists 34 # Check if file already exists
80 if os.path.exists(file_path): 35 if os.path.exists(file_path):
@@ -83,7 +38,6 @@ class NewNoteCommand(sublime_plugin.WindowCommand):
83 # Create the new file and write the date string with a line underneath 38 # Create the new file and write the date string with a line underneath
84 with open(file_path, 'w') as file: 39 with open(file_path, 'w') as file:
85 file.write(f"{date_str_display}\n{underline}\n\n\n") 40 file.write(f"{date_str_display}\n{underline}\n\n\n")
86
87 # Open the file and set the cursor position 41 # Open the file and set the cursor position
88 new_view = self.window.open_file(file_path) 42 new_view = self.window.open_file(file_path)
89 self.set_cursor_position(new_view) 43 self.set_cursor_position(new_view)
@@ -103,3 +57,13 @@ class NewNoteCommand(sublime_plugin.WindowCommand):
103 sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100) 57 sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100)
104 else: 58 else:
105 on_load() 59 on_load()
60
61 def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]:
62 if ignore_extensions is None:
63 ignore_extensions = []
64 return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions]
65
66 def parse_file_date (self, file_name: str) -> Tuple[str, str]:
67 year = file_name[:4]
68 month = file_name[4:6]
69 return year, month