controllers: added a merge controller
[ugit.git] / ugit / views / __init__.py
blobd784695d7b87460c2de3ad122de3ed2a99f0f403
1 import os
2 import time
3 from PyQt4 import QtCore
4 from PyQt4.QtGui import QDialog
5 from PyQt4.QtGui import QMainWindow
6 from PyQt4.QtGui import QCheckBox
7 from PyQt4.QtGui import QSplitter
9 from ugit import qtutils
10 from ugit.syntax import DiffSyntaxHighlighter
11 from ugit.syntax import LogSyntaxHighlighter
13 from main import Ui_main
14 from push import Ui_push
15 from branch import Ui_branch
16 from commit import Ui_commit
17 from logger import Ui_logger
18 from search import Ui_search
19 from options import Ui_options
20 from createbranch import Ui_createbranch
21 from merge import Ui_merge
23 class View(Ui_main, QMainWindow):
24 '''The main ugit interface.'''
25 def __init__(self, parent=None):
26 QMainWindow.__init__(self, parent)
27 Ui_main.__init__(self)
28 self.setupUi(self)
29 self.staged.setAlternatingRowColors(True)
30 self.unstaged.setAlternatingRowColors(True)
31 self.set_display = self.display_text.setText
32 self.set_info = self.displayLabel.setText
33 self.action_undo = self.commitmsg.undo
34 self.action_redo = self.commitmsg.redo
35 self.action_paste = self.commitmsg.paste
36 self.action_select_all = self.commitmsg.selectAll
38 # Handle automatically setting the horizontal/vertical orientation
39 self.splitter.resizeEvent = self.splitter_resize_event
41 # Qt does not support noun/verbs
42 self.commit_button.setText(qtutils.tr('Commit@@verb'))
43 self.commit_menu.setTitle(qtutils.tr('Commit@@verb'))
44 # Default to creating a new commit(i.e. not an amend commit)
45 self.new_commit_radio.setChecked(True)
46 self.toolbar_show_log = self.toolbar.addAction(
47 qtutils.get_qicon('git.png'),
48 'Show/Hide Log Window')
49 self.toolbar_show_log.setEnabled(True)
51 # Setup the default dock layout
52 self.tabifyDockWidget(self.diff_dock, self.editor_dock)
54 dock_area = QtCore.Qt.TopDockWidgetArea
55 self.addDockWidget(dock_area, self.status_dock)
57 toolbar_area = QtCore.Qt.BottomToolBarArea
58 self.addToolBar(toolbar_area, self.toolbar)
60 # Diff/patch syntax highlighter
61 DiffSyntaxHighlighter(self.display_text.document())
63 def splitter_resize_event(self, event):
64 width = self.splitter.width()
65 height = self.splitter.height()
66 if width > height:
67 self.splitter.setOrientation(QtCore.Qt.Horizontal)
68 else:
69 self.splitter.setOrientation(QtCore.Qt.Vertical)
70 QSplitter.resizeEvent(self.splitter, event)
72 def action_cut(self):
73 self.action_copy()
74 self.action_delete()
75 def action_copy(self):
76 cursor = self.commitmsg.textCursor()
77 selection = cursor.selection().toPlainText()
78 qtutils.set_clipboard(selection)
79 def action_delete(self):
80 self.commitmsg.textCursor().removeSelectedText()
81 def reset_display(self):
82 self.set_display('')
83 self.set_info('')
84 def copy_display(self):
85 cursor = self.display_text.textCursor()
86 selection = cursor.selection().toPlainText()
87 qtutils.set_clipboard(selection)
88 def diff_selection(self):
89 cursor = self.display_text.textCursor()
90 offset = cursor.position()
91 selection = cursor.selection().toPlainText()
92 num_selected_lines = selection.count('\n')
93 return offset, selection
95 class LogView(Ui_logger, QDialog):
96 '''A simple dialog to display command logs.'''
97 def __init__(self, parent=None, output=None):
98 QDialog.__init__(self, parent)
99 Ui_logger.__init__(self)
100 self.setupUi(self)
101 self.setWindowTitle(self.tr('Git Command Log'))
102 # Syntax highlight the log window
103 LogSyntaxHighlighter(self.output_text.document())
104 if output: self.set_output(output)
105 def clear(self):
106 self.output_text.clear()
107 def set_output(self, output):
108 self.output_text.setText(output)
109 def log(self, output):
110 if not output: return
111 cursor = self.output_text.textCursor()
112 cursor.movePosition(cursor.End)
113 text = self.output_text
114 cursor.insertText(time.asctime() + '\n')
115 for line in unicode(output).splitlines():
116 cursor.insertText(line + '\n')
117 cursor.insertText('\n')
118 cursor.movePosition(cursor.End)
119 text.setTextCursor(cursor)
121 class BranchView(Ui_branch, QDialog):
122 '''A dialog for choosing branches.'''
123 def __init__(self, parent=None, branches=None):
124 QDialog.__init__(self, parent)
125 Ui_branch.__init__(self)
126 self.setupUi(self)
127 self.reset()
128 if branches: self.add(branches)
129 def reset(self):
130 self.branches = []
131 self.branch_combo.clear()
132 def add(self, branches):
133 for branch in branches:
134 self.branches.append(branch)
135 self.branch_combo.addItem(branch)
136 def get_selected(self):
137 self.show()
138 if self.exec_() == QDialog.Accepted:
139 return self.branches[self.branch_combo.currentIndex()]
140 else:
141 return None
143 class CommitView(Ui_commit, QDialog):
144 def __init__(self, parent=None, title=None):
145 QDialog.__init__(self, parent)
146 Ui_commit.__init__(self)
147 self.setupUi(self)
148 if title: self.setWindowTitle(title)
149 # Make the list widget slighty larger
150 self.splitter.setSizes([ 50, 200 ])
151 DiffSyntaxHighlighter(self.commit_text.document(),
152 whitespace=False)
154 class CreateBranchView(Ui_createbranch, QDialog):
155 def __init__(self, parent=None):
156 QDialog.__init__(self, parent)
157 Ui_createbranch.__init__(self)
158 self.setupUi(self)
160 class PushView(Ui_push, QDialog):
161 def __init__(self, parent=None):
162 QDialog.__init__(self, parent)
163 Ui_push.__init__(self)
164 self.setupUi(self)
166 class OptionsView(Ui_options, QDialog):
167 def __init__(self, parent=None):
168 QDialog.__init__(self, parent)
169 Ui_options.__init__(self)
170 self.setupUi(self)
172 class SearchView(Ui_search, QDialog):
173 def __init__(self, parent=None):
174 QDialog.__init__(self, parent)
175 Ui_search.__init__(self)
176 self.setupUi(self)
177 self.input.setFocus()
178 DiffSyntaxHighlighter(self.commit_text.document(),
179 whitespace=False)
181 class MergeView(Ui_merge, QDialog):
182 def __init__(self, parent=None):
183 QDialog.__init__(self, parent)
184 Ui_search.__init__(self)
185 self.setupUi(self)
186 self.revision.setFocus()