From 9206b6de62fa4d4bc87eed98a42885460cc3de5d Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Mon, 9 Jan 2017 15:08:13 +1100 Subject: [PATCH] auto open up preview window #7 --- .sublime/MarkdownLivePreview.sublime-commands | 8 +++++++ .sublime/MarkdownLivePreview.sublime-settings | 1 + ...rkdownLivePreviewSyntax.hidden-tmLanguage} | 2 +- MLPApi.py | 2 +- MarkdownLivePreview.py | 21 ++++++++++++++++--- MarkdownLivePreview.tasks | 1 + 6 files changed, 30 insertions(+), 5 deletions(-) rename .sublime/{MarkdownLivePreview.hidden-tmLanguage => MarkdownLivePreviewSyntax.hidden-tmLanguage} (87%) diff --git a/.sublime/MarkdownLivePreview.sublime-commands b/.sublime/MarkdownLivePreview.sublime-commands index effb64e..f092fa7 100644 --- a/.sublime/MarkdownLivePreview.sublime-commands +++ b/.sublime/MarkdownLivePreview.sublime-commands @@ -6,5 +6,13 @@ { "caption": "MarkdownLivePreview: Clear Cache", "command": "markdown_live_preview_clear_cache" + }, + { + "caption": "Preferences: MarkdownLivePreview Settings", + "command": "edit_settings", + "args": { + "base_file": "${packages}/MarkdownLivePreview/.sublime/MarkdownLivePreview.sublime-settings", + "default": "// Your settings for MarkdownLivePreview. See the default file to see the different options. \n{\n\t$0\n}\n" + } } ] diff --git a/.sublime/MarkdownLivePreview.sublime-settings b/.sublime/MarkdownLivePreview.sublime-settings index d499f35..6ee0e56 100644 --- a/.sublime/MarkdownLivePreview.sublime-settings +++ b/.sublime/MarkdownLivePreview.sublime-settings @@ -1,3 +1,4 @@ { + "markdown_live_preview_on_open": false, "load_from_internet_when_starts": ["http://", "https://"] } diff --git a/.sublime/MarkdownLivePreview.hidden-tmLanguage b/.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage similarity index 87% rename from .sublime/MarkdownLivePreview.hidden-tmLanguage rename to .sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage index 8544295..af0511f 100644 --- a/.sublime/MarkdownLivePreview.hidden-tmLanguage +++ b/.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage @@ -3,7 +3,7 @@ name - MarkdownLivePreview + MarkdownLivePreviewSyntax patterns diff --git a/MLPApi.py b/MLPApi.py index fa84499..ea28b64 100644 --- a/MLPApi.py +++ b/MLPApi.py @@ -36,7 +36,7 @@ def create_preview(window, file_name): preview.set_name(get_preview_name(file_name)) preview.set_scratch(True) preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/' - 'MarkdownLivePreview.hidden-tmLanguage') + 'MarkdownLivePreviewSyntax.hidden-tmLanguage') return preview diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index 49f79ee..bbd2333 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -17,7 +17,8 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand): file_name = current_view.file_name() current_view.close() if file_name is None: - return sublime.error_message('Not supporting unsaved file for now') + return sublime.error_message('MarkdownLivePreview: Not supporting ' + 'unsaved file for now') sublime.run_command('new_window') self.window = sublime.active_window() @@ -43,8 +44,6 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand): class MarkdownLivePreviewListener(sublime_plugin.EventListener): def update(self, view): - if not is_markdown_view(view): # faster than getting the settings - return vsettings = view.settings() if not vsettings.get(PREVIEW_ENABLED): return @@ -59,16 +58,32 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): return view, preview def on_modified(self, view): + if not is_markdown_view(view): # faster than getting the settings + return self.update(view) def on_window_command(self, window, command, args): if command == 'close' and window.settings().get(PREVIEW_WINDOW): return 'close_window', {} + def on_activated_async(self, view): + vsettings = view.settings() + + if (is_markdown_view(view) + and get_settings().get('markdown_live_preview_on_open') + and not vsettings.get(PREVIEW_ENABLED) + and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + '.sublime/MarkdownLivePreviewSyntax' + '.hidden-tmLanguage'): + sublime.run_command('new_markdown_live_preview') + + def on_load_async(self, view): + """Check the settings to hide menu, minimap, etc""" try: md_view, preview = self.update(view) except TypeError: + # the function update has returned None return window = preview.window() psettings = preview.settings() diff --git a/MarkdownLivePreview.tasks b/MarkdownLivePreview.tasks index 00cee7e..7f0ceac 100644 --- a/MarkdownLivePreview.tasks +++ b/MarkdownLivePreview.tasks @@ -4,6 +4,7 @@ Fast: ☐ cache image in object when used, so that it's faster @needsTest ☐ add clear cache command ☐ update README for settings in view + ☐ add edit settings Medium: ☐ auto refresh preview if loading images