Skip to content

Commit 8116713

Browse files
Tool bar improvements
1 parent 1ad35a8 commit 8116713

File tree

2 files changed

+123
-72
lines changed

2 files changed

+123
-72
lines changed

CodeReview/GUI/DiffViewer/DiffViewerMainWindow.py

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def __init__(self, parent=None):
5959
self._init_ui()
6060
self._create_actions()
6161
self._create_toolbar()
62+
63+
icon_loader = IconLoader()
64+
self.setWindowIcon(icon_loader['code-review@svg'])
6265

6366
##############################################
6467

@@ -102,41 +105,81 @@ def _create_actions(self):
102105
QtWidgets.QAction(icon_loader['view-refresh'],
103106
'Refresh',
104107
self,
105-
toolTip='refresh',
108+
toolTip='Refresh',
106109
shortcut='Ctrl+R',
107110
triggered=lambda: self._refresh,
108111
)
109112

110113
self._complete_action = \
111-
QtWidgets.QAction('Complete',
114+
QtWidgets.QAction(icon_loader['complete-mode@svg'],
115+
'Complete',
112116
self,
113117
toolTip='Complete view',
114118
shortcut='Ctrl+A',
115119
checkable=True,
116120
triggered=self._set_document_models,
117121
)
118-
122+
119123
self._highlight_action = \
120-
QtWidgets.QAction('Highlight',
124+
QtWidgets.QAction(icon_loader['highlight@svg'],
125+
'Highlight',
121126
self,
122127
toolTip='Highlight text',
123128
shortcut='Ctrl+H',
124129
checkable=True,
125-
triggered=self._on_highlight_action,
130+
triggered=self._refresh,
126131
)
127132

128133
##############################################
129134

130135
def _create_toolbar(self):
131136

137+
self._algorithm_combobox = QtWidgets.QComboBox(self)
138+
for algorithm in ('Patience',):
139+
self._algorithm_combobox.addItem(algorithm, algorithm)
140+
self._algorithm_combobox.currentIndexChanged.connect(self._refresh)
141+
142+
self._lines_of_context_combobox = QtWidgets.QComboBox(self)
143+
for number_of_lines_of_context in (3, 6, 12):
144+
self._lines_of_context_combobox.addItem(str(number_of_lines_of_context),
145+
number_of_lines_of_context)
146+
self._lines_of_context_combobox.currentIndexChanged.connect(self._refresh)
147+
148+
self._font_size_combobox = QtWidgets.QComboBox(self)
149+
min_font_size, max_font_size = 4, 20
150+
application_font_size = QtWidgets.QApplication.font().pointSize()
151+
min_font_size = min(min_font_size, application_font_size)
152+
max_font_size = max(max_font_size, application_font_size)
153+
for font_size in range(min_font_size, max_font_size +1):
154+
self._font_size_combobox.addItem(str(font_size), font_size)
155+
self._font_size_combobox.setCurrentIndex(application_font_size - min_font_size)
156+
self._font_size_combobox.currentIndexChanged.connect(self._on_font_size_change)
157+
self._on_font_size_change(refresh=False)
158+
159+
items = [
160+
self._algorithm_combobox,
161+
QtWidgets.QLabel(' '), # Fixme
162+
QtWidgets.QLabel('Context:'),
163+
self._lines_of_context_combobox,
164+
QtWidgets.QLabel(' '), # Fixme
165+
QtWidgets.QLabel('Font Size:'),
166+
self._font_size_combobox,
167+
self._complete_action,
168+
self._highlight_action,
169+
self._refresh_action,
170+
]
171+
if self._application._main_window is not None:
172+
items.extend((
173+
self._previous_file_action,
174+
self._next_file_action,
175+
))
176+
132177
self._tool_bar = self.addToolBar('Diff Viewer')
133-
for action in (self._previous_file_action,
134-
self._next_file_action,
135-
self._complete_action,
136-
self._highlight_action,
137-
self._refresh_action,
138-
):
139-
self._tool_bar.addAction(action)
178+
for item in items:
179+
if isinstance(item, QtWidgets.QAction):
180+
self._tool_bar.addAction(item)
181+
else:
182+
self._tool_bar.addWidget(item)
140183

141184
##############################################
142185

@@ -210,7 +253,7 @@ def _get_lexer(path, text):
210253

211254
##############################################
212255

213-
def diff_documents(self, paths, texts, workdir='', show=False, highlight=False):
256+
def diff_documents(self, paths, texts, workdir='', show=False):
214257

215258
self._paths = list(paths)
216259
self._texts = list(texts)
@@ -225,9 +268,13 @@ def diff_documents(self, paths, texts, workdir='', show=False, highlight=False):
225268
lexers = [self._get_lexer(path, text) for path, text in zip(self._paths, self._texts)]
226269
raw_text_documents = [RawTextDocument(text) for text in self._texts]
227270

271+
highlight = self._highlight_action.isChecked()
272+
number_of_lines_of_context = self._lines_of_context_combobox.currentData()
273+
228274
self._highlighted_documents = []
229275
if not show:
230-
file_diff = TwoWayFileDiffFactory().process(* raw_text_documents)
276+
file_diff = TwoWayFileDiffFactory().process(* raw_text_documents,
277+
number_of_lines_of_context=number_of_lines_of_context)
231278
document_models = TextDocumentDiffModelFactory().process(file_diff)
232279
for raw_text_document, document_model, lexer in zip(raw_text_documents, document_models, lexers):
233280
if lexer is not None and highlight:
@@ -262,16 +309,17 @@ def _set_document_models(self):
262309

263310
##############################################
264311

265-
def _refresh(self):
312+
def _on_font_size_change(self, index=None, refresh=True):
266313

267-
self.diff_documents(self._paths, self._texts, self._workdir)
314+
self._diff_view.set_font(self._font_size_combobox.currentData())
315+
if refresh:
316+
self._refresh() # Fixme: block position are not updated
268317

269318
##############################################
270319

271-
def _on_highlight_action(self):
320+
def _refresh(self):
272321

273-
highlight = self._highlight_action.isChecked()
274-
self.diff_documents(self._paths, self._texts, self._workdir, highlight=highlight)
322+
self.diff_documents(self._paths, self._texts, self._workdir)
275323

276324
##############################################
277325

0 commit comments

Comments
 (0)