Skip to content

Commit

Permalink
add a command to change color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhao28 committed Jun 29, 2017
1 parent 70b4a2c commit 22ef751
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,9 @@
{
"same_level" : false
}
},
{
"caption": "MarkdownEditing: Change color scheme...",
"command": "mde_color_activate"
}
]
4 changes: 4 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"caption": "README",
"command": "open_file"
},
{
"caption": "Change color scheme...",
"command": "mde_color_activate"
},
{
"caption": "-"
},
Expand Down
100 changes: 100 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import sys
import sublime
import sublime_plugin
import re
try:
from MarkdownEditing.mdeutils import *
except ImportError:
from mdeutils import *

package_name = 'MarkdownEditing'

Expand Down Expand Up @@ -27,12 +34,99 @@ def enable_native_markdown_package():
save_ingored_packages(ignored_packages)


def choose_color_theme(window):
window = window or sublime.active_window()
view = window.new_file()
view.run_command('append', {'characters': '''# A sample Markdown document
This is a sample document so you can preview the color themes.
## I am a second-level header
Markdown supports _italics_, __bold__, and ___bold italics___ style.
There are also inline styles like `inline code in monospace font` and ~~strikethrough style~~. __There may be ~~strikethroughed text~~ or `code text` inside bold text.__ _And There may be ~~strikethroughed text~~ or `code text` inside italic text._
To reference something from a URL, [Named Links][links] and [Inline links](https://example.com/index.html) are of great help. Sometimes ![A picture][sample image] is worth a thousand words.
There are two types of lists, numbered and unnumbered.
1. Item 1
2. Item 2
3. Item 3
* Item A
- Sub list
+ Sub sub list
+ Sub sub list 2
- Sub list 2
* Item B
* Item C
## Fenced code
You can write fenced code inside three backticks.
```javascript
function fibo(n) {
fibo.mem = fibo.mem || []; // I am some comment
return fibo.mem[n] || fibo.mem[n] = n <= 1 ? 1 : fibo(n - 1) + fibo(n - 2);
}
```
## The following section is used to define named links
[links]: https://example.com/index.html
[sample image]: https://example.com/sample.png
'''})
view.set_syntax_file('Packages/MarkdownEditing/Markdown.tmLanguage')
default_mde_scheme = sublime.load_settings('Markdown.sublime-settings').get('color_scheme') or 'Packages/MarkdownEditing/MarkdownEditor.tmTheme'
print(default_mde_scheme)
view.settings().set('color_scheme', default_mde_scheme)
view.set_read_only(True)
view.set_scratch(True)

global_scheme = sublime.load_settings('Preferences.sublime-settings').get('color_scheme')
themes = ['Packages/MarkdownEditing/MarkdownEditor.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Focus.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Yellow.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Dark.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-ArcDark.tmTheme',
global_scheme]

themes_display = [re.search('[^/]+(?=\.tmTheme$)', s).group(0) + (' (Current)' if s == default_mde_scheme else '') + (' (Global)' if s == global_scheme else '') for s in themes]

def set_scheme(scheme):
view.settings().set('color_scheme', scheme)
sublime.load_settings('Markdown.sublime-settings').set('color_scheme', scheme)

def on_done(index):
if index == -1:
set_scheme(default_mde_scheme)
elif index == len(themes) - 1:
set_scheme(global_scheme)
else:
set_scheme(themes[index])
sublime.save_settings('Markdown.sublime-settings')
view.close()

def on_highlighted(index):
if index == len(themes) - 1:
set_scheme(global_scheme)
else:
set_scheme(themes[index])

window.show_quick_panel(themes_display, on_done, flags=sublime.KEEP_OPEN_ON_FOCUS_LOST, on_highlight=on_highlighted)


def plugin_loaded():
from package_control import events

if events.install(package_name):
# Native package causes some conflicts.
disable_native_markdown_package()
# Prmopts to select a color theme
choose_color_theme()


def plugin_unloaded():
Expand All @@ -46,3 +140,9 @@ def plugin_unloaded():
if sys.version_info < (3,):
plugin_loaded()
unload_handler = plugin_unloaded


class MdeColorActivateCommand(MDETextCommand):

def run(self, edit):
choose_color_theme(self.view.window())
10 changes: 9 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
"2.1.2": "messages/2.1.2.md",
"2.1.3": "messages/2.1.3.md",
"2.1.4": "messages/2.1.4.md",
"2.1.5": "messages/2.1.5.md"
"2.1.5": "messages/2.1.5.md",
"2.1.6": "messages/2.1.6.md",
"2.1.7": "messages/2.1.7.md",
"2.1.8": "messages/2.1.8.md",
"2.1.9": "messages/2.1.9.md",
"2.2.0": "messages/2.2.0.md",
"2.2.1": "messages/2.2.1.md",
"2.2.2": "messages/2.2.2.md",
"2.2.3": "messages/2.2.3.md"
}
1 change: 1 addition & 0 deletions messages/2.2.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ feedback you can use [GitHub issues][issues].
* You can now disable some of the key bindings through configuration. For example, if you want to disable the "shift+tab" => "fold current section" key binding, add `"mde.keymap_disable.fold_section": true` to your user config. For a full list of such key bindings, check the list below.
* Organize References command now sorts references by referencing order rather than alphebetic order.
* Code block highlight for clojure.
* You can use `MarkdownEditing: Change color scheme...` command in command palette to preview and change the color scheme you are using for markdown.

### Configurable Key Bindings

Expand Down

0 comments on commit 22ef751

Please sign in to comment.