1 from __future__
import division
, absolute_import
, unicode_literals
6 from .. import observable
8 from ..cmd
import Command
11 BACKGROUND_EDITOR
= 'cola.backgroundeditor'
12 BLAME_VIEWER
= 'cola.blameviewer'
13 BOLD_HEADERS
= 'cola.boldheaders'
14 CHECKCONFLICTS
= 'cola.checkconflicts'
15 COMMENT_CHAR
= 'core.commentchar'
16 DIFFCONTEXT
= 'gui.diffcontext'
17 DIFFTOOL
= 'diff.tool'
18 DISPLAY_UNTRACKED
= 'gui.displayuntracked'
20 FONTDIFF
= 'cola.fontdiff'
21 HISTORY_BROWSER
= 'gui.historybrowser'
22 LINEBREAK
= 'cola.linebreak'
23 MAXRECENT
= 'cola.maxrecent'
24 MERGE_DIFFSTAT
= 'merge.diffstat'
25 MERGE_KEEPBACKUP
= 'merge.keepbackup'
26 MERGE_SUMMARY
= 'merge.summary'
27 MERGE_VERBOSITY
= 'merge.verbosity'
28 MERGETOOL
= 'merge.tool'
29 EXPANDTAB
= 'cola.expandtab'
30 SAVEWINDOWSETTINGS
= 'cola.savewindowsettings'
31 SORT_BOOKMARKS
= 'cola.sortbookmarks'
32 TABWIDTH
= 'cola.tabwidth'
33 TEXTWIDTH
= 'cola.textwidth'
34 USER_EMAIL
= 'user.email'
35 USER_NAME
= 'user.name'
36 SAFE_MODE
= 'cola.safemode'
37 SHOW_PATH
= 'cola.showpath'
38 SPELL_CHECK
= 'cola.spellcheck'
41 class Defaults(object):
42 """Read-only class for holding defaults that get overridden"""
43 # These should match Git's defaults for git-defined values.
44 blame_viewer
= 'git gui blame'
46 check_conflicts
= True
48 display_untracked
= True
53 history_browser
= 'gitk'
58 merge_keep_backup
= True
61 save_window_settings
= True
70 def blame_viewer(context
):
71 default
= Defaults
.blame_viewer
72 return context
.cfg
.get(BLAME_VIEWER
, default
=default
)
75 def bold_headers(context
):
76 return context
.cfg
.get(BOLD_HEADERS
, default
=Defaults
.bold_headers
)
79 def check_conflicts(context
):
80 return context
.cfg
.get(CHECKCONFLICTS
, default
=Defaults
.check_conflicts
)
83 def display_untracked(context
):
84 return context
.cfg
.get(DISPLAY_UNTRACKED
,
85 default
=Defaults
.display_untracked
)
89 app
= context
.cfg
.get(EDITOR
, default
=Defaults
.editor
)
90 return _remap_editor(app
)
93 def background_editor(context
):
94 app
= context
.cfg
.get(BACKGROUND_EDITOR
, default
=editor(context
))
95 return _remap_editor(app
)
98 def _remap_editor(app
):
99 return {'vim': 'gvim -f'}.get(app
, app
)
102 def comment_char(context
):
103 return context
.cfg
.get(COMMENT_CHAR
, default
=Defaults
.comment_char
)
106 def default_history_browser():
108 # On Windows, a sensible default is "python git-cola dag"
109 # which is different than `gitk` below, but is preferred
110 # because we don't have to guess paths.
111 git_cola
= sys
.argv
[0].replace('\\', '/')
112 python
= sys
.executable
.replace('\\', '/')
113 cwd
= core
.getcwd().replace('\\', '/')
114 argv
= [python
, git_cola
, 'dag', '--repo', cwd
]
115 argv
= core
.prep_for_subprocess(argv
)
116 default
= core
.list2cmdline(argv
)
118 # The `gitk` script can be launched as-is on unix
119 default
= Defaults
.history_browser
123 def history_browser(context
):
124 default
= default_history_browser()
125 return context
.cfg
.get(HISTORY_BROWSER
, default
=default
)
128 def linebreak(context
):
129 return context
.cfg
.get(LINEBREAK
, default
=Defaults
.linebreak
)
132 def maxrecent(context
):
133 value
= Defaults
.maxrecent
135 value
= context
.cfg
.get(MAXRECENT
, default
=value
)
139 def spellcheck(context
):
140 return context
.cfg
.get(SPELL_CHECK
, default
=Defaults
.spellcheck
)
143 def expandtab(context
):
144 return context
.cfg
.get(EXPANDTAB
, default
=Defaults
.expandtab
)
147 def sort_bookmarks(context
):
148 return context
.cfg
.get(SORT_BOOKMARKS
, default
=Defaults
.sort_bookmarks
)
151 def tabwidth(context
):
152 return context
.cfg
.get(TABWIDTH
, default
=Defaults
.tabwidth
)
155 def textwidth(context
):
156 return context
.cfg
.get(TEXTWIDTH
, default
=Defaults
.textwidth
)
159 class PreferencesModel(observable
.Observable
):
160 message_config_updated
= 'config_updated'
162 def __init__(self
, context
):
163 observable
.Observable
.__init
__(self
)
164 self
.context
= context
165 self
.config
= context
.cfg
167 def set_config(self
, source
, config
, value
):
169 self
.config
.set_repo(config
, value
)
171 self
.config
.set_user(config
, value
)
172 message
= self
.message_config_updated
173 self
.notify_observers(message
, source
, config
, value
)
175 def get_config(self
, source
, config
):
177 value
= self
.config
.get_repo(config
)
179 value
= self
.config
.get(config
)
183 class SetConfig(Command
):
184 """Store a gitconfig value"""
188 def __init__(self
, model
, source
, config
, value
):
192 self
.old_value
= None
196 self
.old_value
= self
.model
.get_config(self
.source
, self
.config
)
197 self
.model
.set_config(self
.source
, self
.config
, self
.value
)
200 if self
.old_value
is None:
202 self
.model
.set_config(self
.source
, self
.config
, self
.old_value
)