From f94fc6165ee09b970f6596f0d937c22555971f31 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Thu, 20 Feb 2025 18:12:10 -0500 Subject: Move create note logic into command base. --- note_tools/tomorrow.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'note_tools/tomorrow.py') diff --git a/note_tools/tomorrow.py b/note_tools/tomorrow.py index 2198a3b..21b1fd5 100644 --- a/note_tools/tomorrow.py +++ b/note_tools/tomorrow.py @@ -3,25 +3,15 @@ import os from datetime import timedelta import sublime import sublime_plugin +from typing import Optional class NewNoteForTomorrowCommand(NoteBaseCommand, sublime_plugin.WindowCommand): def run(self): - self.date = self.get_date() + timedelta(days=1) + self.date += timedelta(days=1) + project_data = self.window.project_data() - notes_path = self.get_notes_path(self.window.project_data()) - - if notes_path: - year, month = self.get_date_parts() - directory = os.path.join(notes_path, year, month) - os.makedirs(directory, exist_ok=True) - file_path = os.path.join(directory, self.file_name()) - - # Check if file already exists - if os.path.exists(file_path): - sublime.message_dialog(f"The file '{self.file_name()}' already exists.") - else: - self.write_file_heading(file_path) - - else: - sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.") + def callback(success: bool, message: Optional[str], file_path: Optional[str]): + if not success: + sublime.message_dialog(message) + self.create_note(project_data=project_data, callback=callback) -- cgit v1.1