Skip to content

Commit

Permalink
Merge 7fbfd65 into c2d42fb
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Aug 3, 2017
2 parents c2d42fb + 7fbfd65 commit f475234
Show file tree
Hide file tree
Showing 22 changed files with 754 additions and 438 deletions.
2 changes: 1 addition & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
},
{
"caption": "git: blame current file",
"command": "gs_blame"
"command": "gs_blame_current_file"
},
{
"caption": "GitSavvy: reload modules (debug)",
Expand Down
32 changes: 22 additions & 10 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"args": { "reset": true },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true }
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.inline_diff_view.in_cached_mode", "operator": "equal", "operand": false },
]
},
{
Expand All @@ -35,7 +36,8 @@
"args": { "reset": true },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true }
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.inline_diff_view.in_cached_mode", "operator": "equal", "operand": false },
]
},
{
Expand Down Expand Up @@ -724,6 +726,24 @@
{ "key": "setting.git_savvy.blame_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["w"],
"command": "gs_blame_toggle_setting",
"args": { "setting": "ignore_whitespace" },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.blame_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["m"],
"command": "gs_blame_toggle_setting",
"args": { "setting": "detect_move_or_copy_within" },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.blame_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["?"],
"command": "gs_interface_toggle_popup_help",
Expand Down Expand Up @@ -964,14 +984,6 @@
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["u"],
"command": "gs_branches_pull_selected",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["p"],
"command": "gs_branches_push_selected",
Expand Down
68 changes: 59 additions & 9 deletions common/theme_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
</dict>
"""

GLOBAL_STYLE_TEMPLATE = """
<dict>
<key>settings</key>
<dict>
{properties}
</dict>
</dict>
"""

PROPERTY_TEMPLATE = """
<key>{key}</key>
<string>{value}</string>
Expand All @@ -44,8 +53,33 @@ class ThemeGenerator():
def __init__(self, original_color_scheme):
color_scheme_xml = sublime.load_resource(original_color_scheme)
self.plist = ElementTree.XML(color_scheme_xml)
self.global_style = self.find_global_style()
self.styles = self.plist.find("./dict/array")

def find_global_style(self):
for style in self.plist.iterfind("./dict/array/dict"):
if "scope" not in [t.text for t in style.iterfind("./key")]:
return style
return None

def get_style_settings(self, style, key):
settings = style.find("./dict")
for i, entry in enumerate(settings):
if entry.text == key and settings[i+1].tag == "string":
return settings[i+1].text

def set_style_settings(self, style, key, value):
settings = style.find("./dict")
for i, entry in enumerate(settings):
if entry.text == key and settings[i+1].tag == "string":
settings[i+1].text = value

def get_global_settings(self, key):
return self.get_style_settings(self.global_style, key)

def set_global_settings(self, key, value):
self.set_style_settings(self.global_style, key, value)

def add_scoped_style(self, name, scope, **kwargs):
"""
Add scope-specific styles to the theme. A unique name should be provided
Expand All @@ -56,10 +90,26 @@ def add_scoped_style(self, name, scope, **kwargs):
new_style = STYLE_TEMPLATE.format(name=name, scope=scope, properties=properties)
self.styles.append(ElementTree.XML(new_style))

def set_global_style(self, **kwargs):
"""
Remvoe the global style (if found) and restruct it from the arguments.
"""
self.global_style = self.find_global_style()
if self.global_style:
self.styles.remove(self.global_style)
properties = "".join(PROPERTY_TEMPLATE.format(key=k, value=v) for k, v in kwargs.items())
new_style = GLOBAL_STYLE_TEMPLATE.format(properties=properties)
self.styles.insert(0, ElementTree.XML(new_style))
self.global_style = self.find_global_style()

def remove_all_styles(self):
styles = [s for s in self.styles]
for style in styles:
self.styles.remove(style)

def get_new_theme_path(self, name):
"""
Save the transformed theme to disk and return the path to that theme,
relative to the Sublime packages directory.
Return the path to the theme relative to the Sublime packages directory.
"""
if not os.path.exists(os.path.join(sublime.packages_path(), "User", "GitSavvy")):
os.makedirs(os.path.join(sublime.packages_path(), "User", "GitSavvy"))
Expand All @@ -68,20 +118,20 @@ def get_new_theme_path(self, name):
"GitSavvy",
"GitSavvy.{}.hidden-tmTheme".format(name))

full_path = os.path.join(sublime.packages_path(), path_in_packages)

with util.file.safe_open(full_path, "wb") as out_f:
out_f.write(STYLES_HEADER.encode("utf-8"))
out_f.write(ElementTree.tostring(self.plist, encoding="utf-8"))

return path_in_packages

def apply_new_theme(self, name, target_view):
"""
Apply the transformed theme to the specified target view.
Save the transformed theme to disk and apply the transformed theme to the specified target view.
"""
path_in_packages = self.get_new_theme_path(name)

full_path = os.path.join(sublime.packages_path(), path_in_packages)

with util.file.safe_open(full_path, "wb") as out_f:
out_f.write(STYLES_HEADER.encode("utf-8"))
out_f.write(ElementTree.tostring(self.plist, encoding="utf-8"))

# Sublime expects `/`-delimited paths, even in Windows.
theme_path = os.path.join("Packages", path_in_packages).replace("\\", "/")
target_view.settings().set("color_scheme", theme_path)
1 change: 1 addition & 0 deletions common/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
from . import debug
from . import diff_string
from . import reload
from . import color

super_key = "SUPER" if sys.platform == "darwin" else "CTRL"
9 changes: 9 additions & 0 deletions common/util/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def next_color(color_text):
"""
Given a color string "#xxxxxy", returns its next color "#xxxxx{y+1}".
"""
hex_value = int(color_text[1:], 16)
if hex_value == 16777215: # #ffffff
return "#fffffe"
else:
return "#{}".format(hex(hex_value+1)[2:])
5 changes: 1 addition & 4 deletions common/util/view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bisect
from contextlib import contextmanager

import sublime

Expand Down Expand Up @@ -68,10 +69,6 @@ def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True):

if view.settings().get("git_savvy.interface") is not None:
view.run_command("gs_interface_refresh")
if view.settings().get("git_savvy.branch_commit_history_view") is not None:
view.run_command("gs_branches_diff_commit_history_refresh")
if view.settings().get("git_savvy.blame_view") is not None:
view.run_command("gs_blame_initialize_view")

if refresh_status_bar:
view.run_command("gs_update_status_bar")
Expand Down
Loading

0 comments on commit f475234

Please sign in to comment.