3 from PyQt4
.QtGui
import QDialog
4 from PyQt4
.QtGui
import QFont
7 from ugit
import qtutils
8 from ugit
.model
import Model
9 from ugit
.views
import BranchView
10 from ugit
.views
import CommitView
11 from ugit
.views
import OptionsView
12 from ugit
.views
import LogView
13 from ugit
.qobserver
import QObserver
15 def set_diff_font(model
, widget
):
16 if model
.has_param('global_ugit_fontdiff'):
17 font
= model
.get_param('global_ugit_fontdiff')
23 def choose_branch(title
, parent
, branches
):
24 dlg
= BranchView(parent
,branches
)
25 dlg
.setWindowTitle(dlg
.tr(title
))
26 return dlg
.get_selected()
28 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 #+ The Commit Browser GUI Controller
30 def select_commits(model
, parent
, title
, revs
, summaries
):
31 '''Use the CommitView to select commits from a list.'''
33 model
.set_revisions(revs
)
34 model
.set_summaries(summaries
)
35 view
= CommitView(parent
, title
)
36 ctl
= SelectCommitsController(model
, view
)
37 return ctl
.select_commits()
39 class SelectCommitsController(QObserver
):
40 def __init__(self
, model
, view
):
41 QObserver
.__init
__(self
, model
, view
)
42 set_diff_font(model
, self
.view
.commit_text
)
43 self
.connect(view
.commit_list
, 'itemSelectionChanged()',
44 self
.commit_sha1_selected
)
46 def select_commits(self
):
47 summaries
= self
.model
.get_summaries()
49 msg
= self
.tr('No commits exist in this branch.')
50 qtutils
.show_output(msg
)
52 qtutils
.set_items(self
.view
.commit_list
, summaries
)
54 if self
.view
.exec_() != QDialog
.Accepted
:
56 revs
= self
.model
.get_revisions()
57 list_widget
= self
.view
.commit_list
58 return qtutils
.get_selection_list(list_widget
, revs
)
60 def commit_sha1_selected(self
):
61 row
, selected
= qtutils
.get_selected_row(self
.view
.commit_list
)
63 self
.view
.commit_text
.setText('')
64 self
.view
.revision
.setText('')
67 # Get the sha1 and put it in the revision line
68 sha1
= self
.model
.get_revision_sha1(row
)
69 self
.view
.revision
.setText(sha1
)
70 self
.view
.revision
.selectAll()
72 # Lookup the sha1's commit
73 commit_diff
= self
.model
.get_commit_diff(sha1
)
74 self
.view
.commit_text
.setText(commit_diff
)
76 # Copy the sha1 into the clipboard
77 qtutils
.set_clipboard(sha1
)
80 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
81 #+ The Options GUI Controller
82 def update_options(model
, parent
):
83 view
= OptionsView(parent
)
84 ctl
= OptionsController(model
,view
)
86 return view
.exec_() == QDialog
.Accepted
88 class OptionsController(QObserver
):
90 This controller assumes that the view's widgets are named
91 the same as the model parameters.'''
93 def __init__(self
,model
,view
):
95 # used for telling about interactive font changes
96 self
.original_model
= model
99 QObserver
.__init
__(self
,model
,view
)
100 self
.add_observables(
103 'local_merge_summary',
104 'local_merge_diffstat',
105 'local_merge_verbosity',
106 'local_gui_diffcontext',
109 'global_merge_summary',
110 'global_merge_diffstat',
111 'global_merge_verbosity',
112 'global_gui_diffcontext',
113 'global_ugit_fontdiff_size',
114 'global_ugit_fontdiff',
115 'global_ugit_fontui_size',
116 'global_ugit_fontui',
117 'global_ugit_historybrowser',
118 'global_ugit_savewindowsettings',
119 'global_ugit_saveatexit',
121 self
.add_actions(global_ugit_fontdiff_size
= self
.update_size
)
122 self
.add_actions(global_ugit_fontui_size
= self
.update_size
)
123 self
.add_actions(global_ugit_fontdiff
= self
.tell_parent_model
)
124 self
.add_actions(global_ugit_fontui
= self
.tell_parent_model
)
125 self
.add_callbacks(save_button
= self
.save_settings
)
126 self
.connect(self
.view
, 'rejected()', self
.restore_settings
)
129 self
.backup_model
= self
.model
.clone()
131 def refresh_view(self
):
132 font
= self
.model
.get_param('global_ugit_fontui')
134 size
= int(font
.split(',')[1])
135 self
.view
.global_ugit_fontui_size
.setValue(size
)
136 self
.model
.set_global_ugit_fontui_size(size
)
138 fontui
.fromString(font
)
139 self
.view
.global_ugit_fontui
.setCurrentFont(fontui
)
141 font
= self
.model
.get_global_ugit_fontdiff()
143 size
= int(font
.split(',')[1])
144 self
.view
.global_ugit_fontdiff_size
.setValue(size
)
145 self
.model
.set_global_ugit_fontdiff_size(size
)
147 fontdiff
.fromString(font
)
148 self
.view
.global_ugit_fontdiff
.setCurrentFont(fontdiff
)
150 self
.view
.local_groupbox
.setTitle(
151 unicode(self
.tr('%s Repository'))
152 % self
.model
.get_project())
153 QObserver
.refresh_view(self
)
156 def save_settings(self
):
158 params
= self
.model
.get_config_params()
160 value
= self
.model
.get_param(param
)
161 backup
= self
.backup_model
.get_param(param
)
163 params_to_save
.append(param
)
164 for param
in params_to_save
:
165 self
.model
.save_config_param(param
)
167 self
.original_model
.copy_params(self
.model
, params_to_save
)
168 self
.view
.done(QDialog
.Accepted
)
170 # cancel button -> undo changes
171 def restore_settings(self
):
172 params
= self
.backup_model
.get_config_params()
173 self
.model
.copy_params(self
.backup_model
, params
)
174 self
.tell_parent_model()
176 def tell_parent_model(self
,*rest
):
178 'global_ugit_fontdiff',
179 'global_ugit_fontui',
180 'global_ugit_fontdiff_size',
181 'global_ugit_fontui_size',
182 'global_ugit_savewindowsettings',
183 'global_ugit_saveatexit',
186 self
.original_model
.set_param(
187 param
, self
.model
.get_param(param
))
189 def update_size(self
, *rest
):
190 combo
= self
.view
.global_ugit_fontui
191 param
= str(combo
.objectName())
192 default
= str(combo
.currentFont().toString())
193 self
.model
.apply_font_size(param
, default
)
195 combo
= self
.view
.global_ugit_fontdiff
196 param
= str(combo
.objectName())
197 default
= str(combo
.currentFont().toString())
198 self
.model
.apply_font_size(param
, default
)
200 self
.tell_parent_model()
202 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203 #+ The Log GUI Controller
205 model
= Model( search_text
= '' )
207 ctl
= LogController(model
,view
)
210 class LogController(QObserver
):
211 def __init__(self
, model
, view
):
212 QObserver
.__init
__(self
, model
, view
)
214 self
.add_observables('search_text')
215 self
.add_actions(search_text
= self
.insta_search
)
217 clear_button
= self
.clear
,
218 next_button
= self
.next
,
219 prev_button
= self
.prev
,
221 self
.connect(self
.view
.output_text
,
222 'cursorPositionChanged()',
223 self
.cursor_position_changed
)
224 self
.search_offset
= 0
226 def insta_search(self
,*rest
):
227 self
.search_offset
= 0
228 txt
= self
.model
.get_search_text().lower()
232 cursor
= self
.view
.output_text
.textCursor()
233 cursor
.clearSelection()
234 self
.view
.output_text
.setTextCursor(cursor
)
237 self
.view
.output_text
.clear()
238 self
.search_offset
= 0
241 text
= self
.model
.get_search_text().lower().strip()
243 output
= str(self
.view
.output_text
.toPlainText())
244 if self
.search_offset
+ len(text
) > len(output
):
245 answer
= qtutils
.question(
247 unicode(self
.tr("%s not found")) % text
,
249 "Could not find '%s'.\n"
250 "Search from the beginning?"
255 self
.search_offset
= 0
259 find_in
= output
[self
.search_offset
:].lower()
261 index
= find_in
.index(text
)
263 self
.search_offset
= 0
264 answer
= qtutils
.question(
266 unicode(self
.tr("%s not found")) % text
,
268 "Could not find '%s'.\n"
269 "Search from the beginning?"
275 cursor
= self
.view
.output_text
.textCursor()
276 offset
= self
.search_offset
+ index
277 new_offset
= offset
+ len(text
)
279 cursor
.setPosition(offset
)
280 cursor
.setPosition(new_offset
, cursor
.KeepAnchor
)
282 self
.view
.output_text
.setTextCursor(cursor
)
283 self
.search_offset
= new_offset
286 text
= self
.model
.get_search_text().lower().strip()
288 output
= str(self
.view
.output_text
.toPlainText())
289 if self
.search_offset
== 0:
290 self
.search_offset
= len(output
)
292 find_in
= output
[:self
.search_offset
].lower()
294 offset
= find_in
.rindex(text
)
296 self
.search_offset
= 0
299 unicode(self
.tr("%s not found")) % text
,
300 unicode(self
.tr("Could not find '%s'.\n"
301 "Search from the end?"
305 cursor
= self
.view
.output_text
.textCursor()
306 new_offset
= offset
+ len(text
)
308 cursor
.setPosition(offset
)
309 cursor
.setPosition(new_offset
, cursor
.KeepAnchor
)
311 self
.view
.output_text
.setTextCursor(cursor
)
312 self
.search_offset
= offset
314 def cursor_position_changed(self
):
315 cursor
= self
.view
.output_text
.textCursor()
316 self
.search_offset
= cursor
.selectionStart()