forked from Zettelkasten-Method/sublime-notelink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sublime-notelink.py
57 lines (48 loc) · 2.01 KB
/
sublime-notelink.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sublime
import sublime_plugin
import os
import re
import subprocess
class FollowNoteLinkCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings = sublime.load_settings('sublime-notelink.sublime-settings')
directory = settings.get('note_directory')
directory = os.path.expanduser(directory)
extension = settings.get('note_extension')
window = self.view.window()
oldLocation = self.view.sel()[0]
self.view.run_command("bracketeer_select")
location = self.view.sel()[0]
selected_text = self.view.substr(location)
self.view.sel().clear()
self.view.sel().add(oldLocation)
the_file = directory+"/"+selected_text+extension
if os.path.exists(the_file):
#open the already-created page.
new_view = window.open_file(the_file)
elif selected_text:
#create the file then open it.
open(the_file, "a")
new_view = window.open_file(the_file)
class GetNoteLinkCommand(sublime_plugin.TextCommand):
def on_done(self, selection):
if selection == -1:
self.view.run_command(
"insert_note_link", {"args":
{'text': '[['}})
return
self.view.run_command(
"insert_note_link", {"args":
{'text': '[['+self.modified_files[selection]+']]'}})
def run(self, edit):
settings = sublime.load_settings('sublime-notelink.sublime-settings')
directory = settings.get('note_directory')
directory = os.path.expanduser(directory)
extension = settings.get('note_extension')
self.outputText = '[['
self.files = os.listdir(directory)
self.modified_files = [item.replace(extension,"") for item in self.files]
self.view.window().show_quick_panel(self.modified_files, self.on_done)
class InsertNoteLinkCommand(sublime_plugin.TextCommand):
def run(self, edit, args):
self.view.insert(edit, self.view.sel()[0].begin(), args['text'])