Skip to content

Commit

Permalink
Introduced new configuration spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByZach committed Feb 10, 2019
1 parent 952d1c0 commit 2e01c84
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
12 changes: 3 additions & 9 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
{
"caption": "Color Helper: Show Palettes",
"command": "color_helper",
"args": {
"mode": "palette"
}
"args": { "mode": "palette" }
},
{
"caption": "Color Helper: Show Color Info",
"command": "color_helper",
"args": {
"mode": "info"
}
"args": { "mode": "info" }
},
{
"caption": "Color Helper: Show Color Picker",
"command": "color_helper",
"args": {
"mode": "color_picker"
}
"args": { "mode": "color_picker" }
}
]
16 changes: 14 additions & 2 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@
[
{
"caption": "Settings",
"command": "edit_settings",
"command": "z_edit_settings",
"args":
{
"base_file": "${packages}/ColorHelper/color_helper.sublime-settings",
"default": "{\n$0\n}\n"
"user_file": "${packages}/User/ColorHelper/color_helper.sublime-settings",
"default": "{\n\t$0\n}\n"
}
},
{ "caption": "-" },
{
"caption": "Commands",
"command": "z_edit_settings",
"args":
{
"file": "${packages}/ColorHelper/Default.sublime-commands",
"is_parent_setting": "1",
"default": "[\n\t$0\n]\n"
}
},
{ "caption": "-" },
Expand Down
44 changes: 44 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sublime
import sublime_plugin
import os


class ZEditSettings(sublime_plugin.WindowCommand):
def run(self, **kwargs):
is_parent_setting = False

if 'is_parent_setting' in kwargs:
is_parent_setting = kwargs.get('is_parent_setting')
del kwargs['is_parent_setting']

if is_parent_setting:
expanded_target_directory = sublime.expand_variables(os.path.dirname(kwargs.get('file')), self.window.extract_variables())
if not os.path.exists(expanded_target_directory):
os.makedirs(expanded_target_directory)

if 'contents' in kwargs:
kwargs['contents'] = kwargs.get('contents')

self.window.run_command('open_file', kwargs)

else:
if 'user_file' in kwargs:
expanded_target_directory = sublime.expand_variables(os.path.dirname(kwargs.get('user_file')), self.window.extract_variables())
if not os.path.exists(expanded_target_directory):
os.makedirs(expanded_target_directory)

if os.path.isfile(sublime.expand_variables(kwargs.get('base_file'), self.window.extract_variables())):
self.window.run_command('edit_settings', kwargs)
else:
if 'user_file' in kwargs:
kwargs['file'] = kwargs.get('user_file')
del kwargs['user_file']
else:
# source_path = kwargs.get('base_file')
# kwargs['file'] = source_path.replace(sublime.packages_path(), os.path.join(sublime.packages_path(), 'User'))
kwargs['file'] = os.path.join(sublime.packages_path(), 'User', os.path.basename(kwargs.get('base_file')))
del kwargs['base_file']
kwargs['contents'] = kwargs.get('default')
del kwargs['default']

self.window.run_command('open_file', kwargs)

0 comments on commit 2e01c84

Please sign in to comment.