diff --git a/Main.sublime-menu b/Main.sublime-menu new file mode 100644 index 0000000..702400b --- /dev/null +++ b/Main.sublime-menu @@ -0,0 +1,39 @@ +[ + { + "caption": "Preferences", + "mnemonic": "n", + "id": "preferences", + "children": + [ + { + "caption": "Package Settings", + "mnemonic": "P", + "id": "package-settings", + "children": + [ + { + "caption": "Scratchpad", + "children": + [ + { + "command": "open_file", + "args": { + "file": "${packages}/Scratchpad/Scratchpad.sublime-settings" + }, + "caption": "Settings – Default" + }, + { + "command": "open_file", + "args": { + "file": "${packages}/User/Scratchpad.sublime-settings" + }, + "caption": "Settings – User" + }, + { "caption": "-" } + ] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/README.md b/README.md index 0f3dc56..66be49b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,29 @@ You can also type "Scratch Pad" in command panel(ctrl+shift+p) to edit the scrat This will help you stay organized with all your notes, as it will allow you to easily search your file contents. The time-stamp is a very useful feature to organize your notes. +## Configuration + +You can customize the location of the scratchpad file through the plugin settings: + +1. Go to `Preferences → Package Settings → Scratchpad → Settings – User` +2. Add the following configuration: + +```json +{ + // Path to your scratchpad file + "scratchpad_path": "~/Documents/my_notes.txt" +} +``` + +### Supported Path Formats: +- **Absolute paths**: `/home/username/notes/scratchpad.txt` +- **Paths with tilde**: `~/Documents/scratchpad.txt` +- **Windows paths**: `C:\\Users\\username\\Documents\\scratchpad.txt` + +If no custom path is specified, the scratchpad file will be created in the Sublime Text configuration directory (default behavior). + +The plugin will automatically create the directory structure if it doesn't exist. + ## Installation You can install this plugin from package control. Once you have package control installed type diff --git a/Scratchpad.py b/Scratchpad.py index ee6e8d5..4163eea 100644 --- a/Scratchpad.py +++ b/Scratchpad.py @@ -1,7 +1,8 @@ from sublime_plugin import WindowCommand, TextCommand -from sublime import packages_path, run_command, ENCODED_POSITION +from sublime import packages_path, run_command, ENCODED_POSITION, load_settings, save_settings from time import strftime -from os.path import isfile +from os.path import isfile, expanduser, join, dirname +import os headerText = """ _____ _ _ _ @@ -15,30 +16,60 @@ """ +def get_scratchpad_file(): + """Get the scratchpad file path from settings or use default.""" + settings = load_settings('Scratchpad.sublime-settings') + + # Get custom path from settings + custom_path = settings.get('scratchpad_path') + + if custom_path: + # Expand user home directory if present + custom_path = expanduser(custom_path) + + # Ensure the directory exists + directory = dirname(custom_path) + if directory and not os.path.exists(directory): + try: + os.makedirs(directory) + except OSError: + # Fall back to default if directory creation fails + return packages_path()[:-8] + 'scratchpad.txt' + + return custom_path + else: + # Use default location (Sublime Text config folder) + return packages_path()[:-8] + 'scratchpad.txt' + class OpenScratchpadCommand(WindowCommand): - def run(self): - scratchpadFile = packages_path()[:-8]+'scratchpad.txt' - checkAndFillEmpty(scratchpadFile) - self.window.open_file(scratchpadFile) + def run(self): + scratchpadFile = get_scratchpad_file() + checkAndFillEmpty(scratchpadFile) + self.window.open_file(scratchpadFile) class ScratchpadCommand(WindowCommand): - def run(self): - scratchpadFile = packages_path()[:-8]+'scratchpad.txt' - global headerText - checkAndFillEmpty(scratchpadFile) - count = putTimeStamp(scratchpadFile) - self.window.open_file(scratchpadFile+':'+str(count+1), ENCODED_POSITION) + def run(self): + scratchpadFile = get_scratchpad_file() + global headerText + checkAndFillEmpty(scratchpadFile) + count = putTimeStamp(scratchpadFile) + self.window.open_file(scratchpadFile + ':' + str(count + 1), ENCODED_POSITION) def checkAndFillEmpty(scratchpadFile): - global headerText - if not isfile(scratchpadFile): - with open(scratchpadFile, "a") as scratchFile: - scratchFile.write(headerText) + global headerText + if not isfile(scratchpadFile): + # Ensure directory exists + directory = dirname(scratchpadFile) + if directory and not os.path.exists(directory): + os.makedirs(directory) + + with open(scratchpadFile, "a") as scratchFile: + scratchFile.write(headerText) def putTimeStamp(scratchpadFile): - timeStamp = "\n\n" + strftime("%c") + " : " + "\n" +"========================" + "\n" - with open(scratchpadFile, "a") as scratchFile: - scratchFile.write(timeStamp) - with open(scratchpadFile) as scratchFile: - count = sum(1 for line in scratchFile) - return count + timeStamp = "\n\n" + strftime("%c") + " : " + "\n" + "========================" + "\n" + with open(scratchpadFile, "a") as scratchFile: + scratchFile.write(timeStamp) + with open(scratchpadFile) as scratchFile: + count = sum(1 for line in scratchFile) + return count \ No newline at end of file diff --git a/Scratchpad.sublime-settings b/Scratchpad.sublime-settings new file mode 100644 index 0000000..1052a69 --- /dev/null +++ b/Scratchpad.sublime-settings @@ -0,0 +1,11 @@ +{ + // Path to the scratchpad file + // You can use absolute paths or paths with ~ for home directory + // If not specified, defaults to Sublime Text config folder + // Examples: + // "scratchpad_path": "~/Documents/scratchpad.txt" + // "scratchpad_path": "/home/username/notes/scratchpad.txt" + // "scratchpad_path": "C:\\Users\\username\\Documents\\scratchpad.txt" + + "scratchpad_path": null +} \ No newline at end of file