1 from __future__
import division
, absolute_import
, unicode_literals
7 from .. import observable
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 MERGE_DIFFSTAT
= 'merge.diffstat'
23 MERGE_KEEPBACKUP
= 'merge.keepbackup'
24 MERGE_SUMMARY
= 'merge.summary'
25 MERGE_VERBOSITY
= 'merge.verbosity'
26 MERGETOOL
= 'merge.tool'
27 SAVEWINDOWSETTINGS
= 'cola.savewindowsettings'
28 SORT_BOOKMARKS
= 'cola.sortbookmarks'
29 TABWIDTH
= 'cola.tabwidth'
30 TEXTWIDTH
= 'cola.textwidth'
31 USER_EMAIL
= 'user.email'
32 USER_NAME
= 'user.name'
33 SPELL_CHECK
= 'cola.spellcheck'
36 def default_blame_viewer():
37 return 'git gui blame'
41 default
= default_blame_viewer()
42 return gitcfg
.current().get(BLAME_VIEWER
, default
)
46 return gitcfg
.current().get(BOLD_HEADERS
, False)
49 def check_conflicts():
50 return gitcfg
.current().get(CHECKCONFLICTS
, True)
53 def display_untracked():
54 return gitcfg
.current().get(DISPLAY_UNTRACKED
, True)
58 app
= gitcfg
.current().get(EDITOR
, 'gvim')
59 return {'vim': 'gvim -f'}.get(app
, app
)
63 return gitcfg
.current().get(COMMENT_CHAR
, '#')
66 def default_history_browser():
68 # On Windows, a sensible default is "python git-cola dag"
69 # which is different than `gitk` below, but is preferred
70 # because we don't have to guess paths.
71 git_cola
= sys
.argv
[0].replace("\\", '/')
72 python
= sys
.executable
.replace("\\", '/')
73 argv
= [python
, git_cola
, 'dag']
74 argv
= core
.prep_for_subprocess(argv
)
75 default
= core
.list2cmdline(argv
)
77 # The `gitk` script can be launched as-is on unix
82 def history_browser():
83 default
= default_history_browser()
84 return gitcfg
.current().get(HISTORY_BROWSER
, default
)
88 return gitcfg
.current().get(LINEBREAK
, True)
91 return gitcfg
.current().get(SPELL_CHECK
, False)
94 return gitcfg
.current().get(SORT_BOOKMARKS
, True)
98 return gitcfg
.current().get(TABWIDTH
, 8)
102 return gitcfg
.current().get(TEXTWIDTH
, 72)
105 class PreferencesModel(observable
.Observable
):
106 message_config_updated
= 'config_updated'
109 observable
.Observable
.__init
__(self
)
110 self
.config
= gitcfg
.current()
112 def set_config(self
, source
, config
, value
):
114 self
.config
.set_repo(config
, value
)
116 self
.config
.set_user(config
, value
)
117 message
= self
.message_config_updated
118 self
.notify_observers(message
, source
, config
, value
)
120 def get_config(self
, source
, config
):
122 return self
.config
.get_repo(config
)
124 return self
.config
.get(config
)
127 class SetConfig(object):
129 def __init__(self
, model
, source
, config
, value
):
133 self
.old_value
= None
136 def is_undoable(self
):
140 self
.old_value
= self
.model
.get_config(self
.source
, self
.config
)
141 self
.model
.set_config(self
.source
, self
.config
, self
.value
)
144 if self
.old_value
is None:
146 self
.model
.set_config(self
.source
, self
.config
, self
.old_value
)