Skip to content

Commit

Permalink
Enhancement: support project-wise settings
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Mar 31, 2018
1 parent 5fc7a07 commit 1ce57a7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
7 changes: 6 additions & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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"
}
]
"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":
{
"GitSavvy":
{
},
"rulers":
[
100,
120
],
"tab_size": 4,
"translate_tabs_to_spaces": true
}
}
10 changes: 6 additions & 4 deletions common/global_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ 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.")
sublime.error_message("No project data found.")

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

self.window.set_project_data(project_data)

self.window.run_command("edit_settings", {
sublime.set_timeout(lambda: self.window.run_command("edit_settings", {
"user_file": project_file_name,
"base_file": "${packages}/GitSavvy/GitSavvy.sublime-settings"
})
}), 100)
5 changes: 5 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def __init__(self, parent=None):
self.global_settings = sublime.load_settings("GitSavvy.sublime-settings")

def get(self, key, default=None):
project_data = sublime.active_window().project_data()
if project_data and "settings" in project_data and "GitSavvy" in project_data["settings"]:
project_savvy_settings = project_data["settings"]["GitSavvy"]
if key in project_savvy_settings:
return project_savvy_settings.get(key)
return self.global_settings.get(key, default)

def set(self, key, value):
Expand Down
15 changes: 14 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,20 @@ For all syntax specific view we have a settings file. These are nothing extra fr

### Editing Settings

To open the GitSavvy settings, simply run the `Preferences: GitSavvy Settings` command from the command palette. The default settings are documented with helpful inline comments.
To open the GitSavvy settings, simply run the `Preferences: GitSavvy Settings` command from the command palette. The default settings are documented with helpful inline comments. GitSavvy also supports project specific settings, run the
`Preference: GitSavvy Project Settings` command and add the key `"GitSavvy"` as follows

```
{
"settings":
{
"GitSavvy":
{
// GitSavvy settings go here
}
}
}
```

[Preferences Editor](https://packagecontrol.io/packages/Preferences%20Editor) is really good package for editing you settings.

Expand Down

0 comments on commit 1ce57a7

Please sign in to comment.