Skip to content

Commit

Permalink
Moving code from git_gutter_handler to view_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
natecavanaugh committed Jan 7, 2015
1 parent c8dcd38 commit ef85276
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
4 changes: 3 additions & 1 deletion GitGutter.sublime-settings
Expand Up @@ -4,7 +4,9 @@

// The commit, branch, tag, or remote to compare against
// Can be set on a per-project basis by adding a project
// setting of "git_gutter_compare_against"
// setting of "git_gutter_compare_against".
// This setting only changes the default (HEAD), but can
// still be overwritten temporarily using one of the commands
"compare_against": "",

// Live mode evaluates changes every time file is modified,
Expand Down
10 changes: 5 additions & 5 deletions git_gutter.py
Expand Up @@ -42,10 +42,10 @@ def run(self, force_refresh=False):
else:
branch = ""

self.update_status(len(inserted),
len(modified),
len(deleted),
ViewCollection.get_compare(), branch)
self.update_status(len(inserted),
len(modified),
len(deleted),
ViewCollection.get_compare(self.view), branch)
else:
self.update_status(0, 0, 0, "", "")

Expand Down Expand Up @@ -108,7 +108,7 @@ def icon_path(self, icon_name):
extn = '.png'

return "/".join([path, 'icons', icon_name + extn])

def bind_icons(self, event, lines):
regions = self.lines_to_regions(lines)
event_scope = event
Expand Down
3 changes: 2 additions & 1 deletion git_gutter_compare.py
Expand Up @@ -77,6 +77,7 @@ def run(self):

class GitGutterShowCompare(sublime_plugin.WindowCommand):
def run(self):
comparing = ViewCollection.get_compare()
self.view = self.window.active_view()
comparing = ViewCollection.get_compare(self.view)
sublime.message_dialog("GitGutter is comparing against: " + comparing)

15 changes: 2 additions & 13 deletions git_gutter_handler.py
Expand Up @@ -82,7 +82,7 @@ def update_git_file(self):
'--git-dir=' + self.git_dir,
'--work-tree=' + self.git_tree,
'show',
ViewCollection.get_compare() + ':' + self.git_path,
ViewCollection.get_compare(self.view) + ':' + self.git_path,
]
try:
contents = self.run_command(args)
Expand Down Expand Up @@ -257,17 +257,6 @@ def load_settings(self):
if git_binary:
self.git_binary_path = git_binary

view_settings = sublime.active_window().active_view().settings()

# Set the branch to compare against
self.compare_against = view_settings.get('git_gutter_compare_against')

if not self.compare_against:
self.compare_against = self.settings.get('compare_against')

if self.compare_against:
ViewCollection.set_compare(self.compare_against)

# Ignore White Space Setting
self.ignore_whitespace = self.settings.get('ignore_whitespace')
if self.ignore_whitespace == 'all':
Expand All @@ -290,4 +279,4 @@ def load_settings(self):
# Show information in status bar
self.show_status = self.user_settings.get('show_status') or self.settings.get('show_status')
if self.show_status != 'all' and self.show_status != 'none':
self.show_status = 'default'
self.show_status = 'default'
14 changes: 9 additions & 5 deletions view_collection.py
@@ -1,3 +1,4 @@
import sublime
import tempfile
import time

Expand Down Expand Up @@ -100,11 +101,9 @@ def set_compare(commit):
ViewCollection.compare_against = commit

@staticmethod
def get_compare():
if ViewCollection.compare_against:
return ViewCollection.compare_against
else:
return "HEAD"
def get_compare(view):
compare = ViewCollection.compare_against
return view.settings().get('git_gutter_compare_against', compare)

@staticmethod
def current_branch(view):
Expand All @@ -115,3 +114,8 @@ def current_branch(view):
def show_status(view):
key = ViewCollection.get_key(view)
return ViewCollection.views[key].show_status


def plugin_loaded():
settings = sublime.load_settings('GitGutter.sublime-settings')
ViewCollection.compare_against = settings.get('compare_against', 'HEAD')

0 comments on commit ef85276

Please sign in to comment.