1 from __future__
import division
, absolute_import
, unicode_literals
6 from .. import observable
10 BACKGROUND_EDITOR
= 'cola.backgroundeditor'
11 BLAME_VIEWER
= 'cola.blameviewer'
12 BOLD_HEADERS
= 'cola.boldheaders'
13 CHECKCONFLICTS
= 'cola.checkconflicts'
14 COMMENT_CHAR
= 'core.commentchar'
15 DIFFCONTEXT
= 'gui.diffcontext'
16 DIFFTOOL
= 'diff.tool'
17 DISPLAY_UNTRACKED
= 'gui.displayuntracked'
19 FONTDIFF
= 'cola.fontdiff'
20 HISTORY_BROWSER
= 'gui.historybrowser'
21 LINEBREAK
= 'cola.linebreak'
22 MAXRECENT
= 'cola.maxrecent'
23 MERGE_DIFFSTAT
= 'merge.diffstat'
24 MERGE_KEEPBACKUP
= 'merge.keepbackup'
25 MERGE_SUMMARY
= 'merge.summary'
26 MERGE_VERBOSITY
= 'merge.verbosity'
27 MERGETOOL
= 'merge.tool'
28 EXPANDTAB
= 'cola.expandtab'
29 SAVEWINDOWSETTINGS
= 'cola.savewindowsettings'
30 SORT_BOOKMARKS
= 'cola.sortbookmarks'
31 TABWIDTH
= 'cola.tabwidth'
32 TEXTWIDTH
= 'cola.textwidth'
33 USER_EMAIL
= 'user.email'
34 USER_NAME
= 'user.name'
35 SAFE_MODE
= 'cola.safemode'
36 SHOW_PATH
= 'cola.showpath'
37 SPELL_CHECK
= 'cola.spellcheck'
40 class Defaults(object):
41 """Read-only class for holding defaults that get overridden"""
42 # These should match Git's defaults for git-defined values.
43 blame_viewer
= 'git gui blame'
45 check_conflicts
= True
47 display_untracked
= True
52 history_browser
= 'gitk'
57 merge_keep_backup
= True
60 save_window_settings
= True
69 def blame_viewer(context
):
70 default
= Defaults
.blame_viewer
71 return context
.cfg
.get(BLAME_VIEWER
, default
=default
)
74 def bold_headers(context
):
75 return context
.cfg
.get(BOLD_HEADERS
, default
=Defaults
.bold_headers
)
78 def check_conflicts(context
):
79 return context
.cfg
.get(CHECKCONFLICTS
, default
=Defaults
.check_conflicts
)
82 def display_untracked(context
):
83 return context
.cfg
.get(DISPLAY_UNTRACKED
,
84 default
=Defaults
.display_untracked
)
88 app
= context
.cfg
.get(EDITOR
, default
=Defaults
.editor
)
89 return _remap_editor(app
)
92 def background_editor(context
):
93 app
= context
.cfg
.get(BACKGROUND_EDITOR
, default
=editor(context
))
94 return _remap_editor(app
)
97 def _remap_editor(app
):
98 return {'vim': 'gvim -f'}.get(app
, app
)
101 def comment_char(context
):
102 return context
.cfg
.get(COMMENT_CHAR
, default
=Defaults
.comment_char
)
105 def default_history_browser():
107 # On Windows, a sensible default is "python git-cola dag"
108 # which is different than `gitk` below, but is preferred
109 # because we don't have to guess paths.
110 git_cola
= sys
.argv
[0].replace('\\', '/')
111 python
= sys
.executable
.replace('\\', '/')
112 cwd
= core
.getcwd().replace('\\', '/')
113 argv
= [python
, git_cola
, 'dag', '--repo', cwd
]
114 argv
= core
.prep_for_subprocess(argv
)
115 default
= core
.list2cmdline(argv
)
117 # The `gitk` script can be launched as-is on unix
118 default
= Defaults
.history_browser
122 def history_browser(context
):
123 default
= default_history_browser()
124 return context
.cfg
.get(HISTORY_BROWSER
, default
=default
)
127 def linebreak(context
):
128 return context
.cfg
.get(LINEBREAK
, default
=Defaults
.linebreak
)
131 def maxrecent(context
):
132 value
= Defaults
.maxrecent
134 value
= context
.cfg
.get(MAXRECENT
, default
=value
)
138 def spellcheck(context
):
139 return context
.cfg
.get(SPELL_CHECK
, default
=Defaults
.spellcheck
)
142 def expandtab(context
):
143 return context
.cfg
.get(EXPANDTAB
, default
=Defaults
.expandtab
)
146 def sort_bookmarks(context
):
147 return context
.cfg
.get(SORT_BOOKMARKS
, default
=Defaults
.sort_bookmarks
)
150 def tabwidth(context
):
151 return context
.cfg
.get(TABWIDTH
, default
=Defaults
.tabwidth
)
154 def textwidth(context
):
155 return context
.cfg
.get(TEXTWIDTH
, default
=Defaults
.textwidth
)
158 class PreferencesModel(observable
.Observable
):
159 message_config_updated
= 'config_updated'
161 def __init__(self
, context
):
162 observable
.Observable
.__init
__(self
)
163 self
.context
= context
164 self
.config
= context
.cfg
166 def set_config(self
, source
, config
, value
):
168 self
.config
.set_repo(config
, value
)
170 self
.config
.set_user(config
, value
)
171 message
= self
.message_config_updated
172 self
.notify_observers(message
, source
, config
, value
)
174 def get_config(self
, source
, config
):
176 value
= self
.config
.get_repo(config
)
178 value
= self
.config
.get(config
)
182 class SetConfig(object):
184 def __init__(self
, model
, source
, config
, value
):
188 self
.old_value
= None
191 def is_undoable(self
):
195 self
.old_value
= self
.model
.get_config(self
.source
, self
.config
)
196 self
.model
.set_config(self
.source
, self
.config
, self
.value
)
199 if self
.old_value
is None:
201 self
.model
.set_config(self
.source
, self
.config
, self
.old_value
)