Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring GitSavvy settings and project-wise settings #908

Merged
merged 4 commits into from Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Default.sublime-commands
Expand Up @@ -4,7 +4,12 @@
"command": "edit_settings",
"args": {
"base_file": "${packages}/GitSavvy/GitSavvy.sublime-settings",
"default": "// Settings in here override those in \"GitSavvy/GitSavvy.sublime-settings\",\n\n{\n\t$0\n}\n"}
"default": "// Settings in here override those in \"GitSavvy/GitSavvy.sublime-settings\",\n\n{\n\t$0\n}\n"
}
},
{
"caption": "Preferences: GitSavvy Project Settings",
"command": "gs_edit_project_settings"
},
{
"caption": "Preferences: GitSavvy Key Bindings",
Expand Down
60 changes: 35 additions & 25 deletions GitSavvy.sublime-project
@@ -1,27 +1,37 @@
{
"folders": [
{
"path": ".",
"folder_exclude_patterns": [
".git",
"__pycache__"
]
}
],
"settings": {
"rulers": [100, 120],
"tab_size": 4,
"translate_tabs_to_spaces": true
},
"build_systems":
[
{
"name": "Reload GitSavvy",
"target": "gs_reload_modules_debug"
},
{
"name": "Test GitSavvy",
"target": "unit_testing_current_package"
}
]
"GitSavvy":
{
},
"build_systems":
[
{
"name": "Reload GitSavvy",
"target": "gs_reload_modules_debug"
},
{
"name": "Test GitSavvy",
"target": "unit_testing_current_package"
}
],
"folders":
[
{
"folder_exclude_patterns":
[
".git",
"__pycache__"
],
"path": "."
}
],
"settings":
{
"rulers":
[
100,
120
],
"tab_size": 4,
"translate_tabs_to_spaces": true
}
}
5 changes: 5 additions & 0 deletions GitSavvy.sublime-settings
Expand Up @@ -51,6 +51,11 @@
*/
"github_per_page_max" : 100,

/*
maximum number of items per page when requesting from gitlab
*/
"gitlab_per_page_max" : 100,

/*
Change this to "full" to display a full diff for the current commit
when writing a commit message.
Expand Down
8 changes: 2 additions & 6 deletions common/commands/debug.py
Expand Up @@ -2,13 +2,10 @@
Sublime commands related to development and debugging.
"""

import sys
import urllib

import sublime
from sublime_plugin import WindowCommand

from ..util import debug, reload
from ...core.settings import GitSavvySettings

REPORT_URL_TEMPLATE = "https://github.com/divmain/GitSavvy/issues/new?{q}"

Expand All @@ -23,8 +20,7 @@ def run(self):
reload.reload_plugin()

def is_visible(self):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
return savvy_settings.get("dev_mode")
return GitSavvySettings().get("dev_mode")


class GsStartLoggingCommand(WindowCommand):
Expand Down
5 changes: 3 additions & 2 deletions common/commands/view_manipulation.py
@@ -1,5 +1,6 @@
import sublime
from sublime_plugin import TextCommand
from ...core.settings import GitSavvySettings


class GsInsertTextAtCursorCommand(TextCommand):
Expand Down Expand Up @@ -64,7 +65,7 @@ class GsHandleVintageousCommand(TextCommand):
"""

def run(self, edit):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
savvy_settings = GitSavvySettings()
if savvy_settings.get("vintageous_friendly", False) is True:
self.view.settings().set("git_savvy.vintageous_friendly", True)
if savvy_settings.get("vintageous_enter_insert_mode", False) is True:
Expand All @@ -79,6 +80,6 @@ class GsHandleArrowKeysCommand(TextCommand):
"""

def run(self, edit):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
savvy_settings = GitSavvySettings()
if savvy_settings.get("arrow_keys_navigation", False) is True:
self.view.settings().set("git_savvy.arrow_keys_navigation", True)
25 changes: 25 additions & 0 deletions common/global_events.py
Expand Up @@ -61,3 +61,28 @@ class GsEditSettingsCommand(WindowCommand):
"""
def run(self, **kwargs):
self.window.run_command("edit_settings", kwargs)

Copy link
Member

@stoivo stoivo Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been in the later commit but ¯_(ツ)_/¯

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, maybe.


class GsEditProjectSettingsCommand(WindowCommand):
"""
For some reasons, the command palette doesn't trigger `on_post_window_command` for
dev version of Sublime Text. The command palette would call `gs_edit_settings` and
subsequently trigger `on_post_window_command`.
"""
def run(self):
project_file_name = self.window.project_file_name()
project_data = self.window.project_data()
if not project_file_name or project_data is None:
sublime.error_message("No project data found.")

if project_data is None:
project_data = {}
if "GitSavvy" not in project_data:
project_data["GitSavvy"] = {}

self.window.set_project_data(project_data)

sublime.set_timeout(lambda: self.window.run_command("edit_settings", {
"user_file": project_file_name,
"base_file": "${packages}/GitSavvy/GitSavvy.sublime-settings"
}), 100)
4 changes: 2 additions & 2 deletions common/ui.py
Expand Up @@ -6,6 +6,7 @@
from sublime_plugin import TextCommand

from . import util
from ..core.settings import GitSavvySettings


interfaces = {}
Expand Down Expand Up @@ -73,15 +74,14 @@ def __init__(self, repo_path=None, view=None):

def create_view(self, repo_path):
window = sublime.active_window()
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
self.view = window.new_file()

self.view.settings().set("git_savvy.repo_path", repo_path)
self.view.set_name(self.title())
self.view.settings().set("git_savvy.{}_view".format(self.interface_type), True)
self.view.settings().set("git_savvy.tabbable", True)
self.view.settings().set("git_savvy.interface", self.interface_type)
self.view.settings().set("git_savvy.help_hidden", savvy_settings.get("hide_help_menu"))
self.view.settings().set("git_savvy.help_hidden", GitSavvySettings().get("hide_help_menu"))
self.view.set_syntax_file(self.syntax_file)
self.view.set_scratch(True)
self.view.set_read_only(self.read_only)
Expand Down
6 changes: 3 additions & 3 deletions common/util/actions.py
@@ -1,18 +1,18 @@
import sublime
from ...core.settings import GitSavvySettings


def destructive(description):
def decorator(fn):

def wrapped_fn(*args, **kwargs):
settings = sublime.load_settings("GitSavvy.sublime-settings")
if settings.get("prompt_before_destructive_action"):
if GitSavvySettings().get("prompt_before_destructive_action"):
message = (
"You are about to {desc}. "
"This is a destructive action. \n\n"
"Are you SURE you want to do this? \n\n"
"(you can disable this prompt in "
"GitSavvy.sublime-settings)").format(desc=description)
"GitSavvy settings)").format(desc=description)
if not sublime.ok_cancel_dialog(message):
return

Expand Down
5 changes: 3 additions & 2 deletions common/util/debug.py
Expand Up @@ -2,9 +2,10 @@
import json
import pprint as _pprint

import sublime
from contextlib import contextmanager

from ...core.settings import GitSavvySettings

_log = []
enabled = False
ENCODING_NOT_UTF8 = "{} was sent as binaries and we dont know the encoding, not utf-8"
Expand Down Expand Up @@ -125,7 +126,7 @@ def pprint(*args, **kwargs):


def get_trace_tags():
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
savvy_settings = GitSavvySettings()
if savvy_settings.get("dev_mode"):
return savvy_settings.get("dev_trace", [])
else:
Expand Down
3 changes: 2 additions & 1 deletion common/util/view.py
@@ -1,6 +1,7 @@
import bisect

import sublime
from ...core.settings import GitSavvySettings


##############
Expand Down Expand Up @@ -171,5 +172,5 @@ def get_instance_after_pt(view, pt, pattern):
def disable_other_plugins(view):
# Disable key-bindings for Vitageous
# https://github.com/guillermooo/Vintageous/wiki/Disabling
if sublime.load_settings("GitSavvy.sublime-settings").get("vintageous_friendly", False) is False:
if GitSavvySettings().get("vintageous_friendly", False) is False:
view.settings().set("__vi_external_disable", False)
10 changes: 3 additions & 7 deletions core/commands/blame.py
Expand Up @@ -97,8 +97,7 @@ def do_action(self, commit_hash, **kwargs):
100)

def log(self, **kwargs):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
follow = savvy_settings.get("blame_follow_rename")
follow = self.savvy_settings.get("blame_follow_rename")
kwargs["follow"] = follow
return super().log(**kwargs)

Expand Down Expand Up @@ -169,14 +168,12 @@ def run(self, edit):
(0, cursor_layout[1] - yoffset), animate=False), 100)

def get_content(self, ignore_whitespace=False, detect_options=None, commit_hash=None):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")

if commit_hash:
# git blame does not follow file name changes like git log, therefor we
# need to look at the log first too see if the file has changed names since
# selected commit. I would not be surprised if this brakes in some special cases
# like rebased or multimerged commits
follow = savvy_settings.get("blame_follow_rename")
follow = self.savvy_settings.get("blame_follow_rename")
filename_at_commit = self.filename_at_commit(self.file_path, commit_hash, follow=follow)
else:
filename_at_commit = self.file_path
Expand Down Expand Up @@ -358,8 +355,7 @@ def show_commit(self):
self.view.window().run_command("gs_show_commit", {"commit_hash": commit_hash})

def blame_neighbor(self, position, selected=False):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
follow = savvy_settings.get("blame_follow_rename")
follow = self.savvy_settings.get("blame_follow_rename")

if position == "newer" and selected:
raise Exception("blame a commit after selected commit is confusing")
Expand Down