diff options
Diffstat (limited to 'note_tools/commands.py')
-rw-r--r-- | note_tools/commands.py | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/note_tools/commands.py b/note_tools/commands.py deleted file mode 100644 index 97778ba..0000000 --- a/note_tools/commands.py +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | from . import NoteBaseCommand | ||
2 | import sublime_plugin | ||
3 | import datetime | ||
4 | import os | ||
5 | from typing import List, Optional, Tuple | ||
6 | |||
7 | class NewNoteForTomorrowCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | ||
8 | def run(self): | ||
9 | self.date = self.get_date() + timedelta(days=1) | ||
10 | |||
11 | notes_path = self.get_notes_path(self.window.project_data()) | ||
12 | |||
13 | if notes_path: | ||
14 | year, month, day = self.get_date_parts() | ||
15 | directory = os.path.join(notes_path, year, month) | ||
16 | os.makedirs(directory, exist_ok=True) | ||
17 | file_path = os.path.join(directory, self.file_name()) | ||
18 | |||
19 | # Check if file already exists | ||
20 | if os.path.exists(file_path): | ||
21 | sublime.message_dialog(f"The file '{self.file_name()}' already exists.") | ||
22 | else: | ||
23 | self.write_file_heading(file_path) | ||
24 | |||
25 | else: | ||
26 | sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") | ||
27 | |||
28 | class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | ||
29 | def run(self): | ||
30 | # Get the current date formatted as YYYYMMDD and YYYY-MM-DD | ||
31 | self.date = self.get_date() | ||
32 | notes_path = self.get_notes_path(self.window.project_data()) | ||
33 | |||
34 | if notes_path: | ||
35 | year, month, day = self.get_date_parts() | ||
36 | directory = os.path.join(notes_path, year, month) | ||
37 | os.makedirs(directory, exist_ok=True) | ||
38 | file_path = os.path.join(directory, self.file_name()) | ||
39 | |||
40 | # Check if file already exists | ||
41 | if os.path.exists(file_path): | ||
42 | sublime.message_dialog(f"The file '{self.file_name()}' already exists.") | ||
43 | else: | ||
44 | self.write_file_heading(file_path) | ||
45 | new_view = self.window.open_file(file_path) | ||
46 | self.set_cursor_position(new_view) | ||
47 | |||
48 | else: | ||
49 | sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") | ||
50 | |||
51 | def set_cursor_position(self, view): | ||
52 | # Set the cursor position two lines beneath the underline | ||
53 | def on_load(): | ||
54 | view.run_command("move_to", {"to": "bof"}) | ||
55 | for _ in range(3): | ||
56 | view.run_command("move", {"by": "lines", "forward": True}) | ||
57 | |||
58 | # Add an event listener for when the file is loaded | ||
59 | if view.is_loading(): | ||
60 | sublime.set_timeout_async(lambda: self.set_cursor_position(view), 100) | ||
61 | else: | ||
62 | on_load() | ||
63 | |||
64 | def list_files(self, directory: str, ignore_extensions: Optional[List[str]] = None) -> List[Path]: | ||
65 | if ignore_extensions is None: | ||
66 | ignore_extensions = [] | ||
67 | return [file for file in Path(directory).glob("*") if file.is_file() and file.suffix not in ignore_extensions] | ||