diff options
Diffstat (limited to 'note_tools/today.py')
-rw-r--r-- | note_tools/today.py | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/note_tools/today.py b/note_tools/today.py index 20f2e53..9afad5d 100644 --- a/note_tools/today.py +++ b/note_tools/today.py | |||
@@ -3,32 +3,20 @@ import os | |||
3 | import sublime | 3 | import sublime |
4 | import sublime_plugin | 4 | import sublime_plugin |
5 | from pathlib import Path | 5 | from pathlib import Path |
6 | from typing import List, Optional | 6 | from typing import Optional |
7 | 7 | ||
8 | class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | 8 | class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): |
9 | def run(self): | 9 | def run(self): |
10 | # Get the current date formatted as YYYYMMDD and YYYY-MM-DD | 10 | project_data = self.window.project_data() |
11 | self.date = self.get_date() | ||
12 | notes_path = self.get_notes_path(self.window.project_data()) | ||
13 | 11 | ||
14 | if notes_path: | 12 | def open_file(success: bool, message: str, file_path: Optional[str]): |
15 | year, month = self.get_date_parts() | 13 | if success: |
16 | directory = os.path.join(notes_path, year, month) | 14 | new_view = self.window.open_file(file_path) |
17 | print("directory: ", directory) | 15 | self.set_cursor_position(new_view) |
18 | os.makedirs(directory, exist_ok=True) | ||
19 | file_path = os.path.join(directory, self.file_name()) | ||
20 | print('path: ', file_path) | ||
21 | |||
22 | # Check if file already exists | ||
23 | if os.path.exists(file_path): | ||
24 | sublime.message_dialog(f"The file '{self.file_name()}' already exists.") | ||
25 | else: | 16 | else: |
26 | self.write_file_heading(file_path) | 17 | sublime.message_dialog(message) |
27 | new_view = self.window.open_file(file_path) | ||
28 | self.set_cursor_position(new_view) | ||
29 | 18 | ||
30 | else: | 19 | self.create_note(project_data=project_data, callback=open_file) |
31 | sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") | ||
32 | 20 | ||
33 | def set_cursor_position(self, view): | 21 | def set_cursor_position(self, view): |
34 | # Set the cursor position two lines beneath the underline | 22 | # Set the cursor position two lines beneath the underline |
@@ -42,8 +30,3 @@ class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | |||
42 | sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100) | 30 | sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100) |
43 | else: | 31 | else: |
44 | on_load() | 32 | on_load() |
45 | |||
46 | def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]: | ||
47 | if ignore_extensions is None: | ||
48 | ignore_extensions = [] | ||
49 | return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions] | ||