def __init__(self, parent): from cola.prefs import diff_font, tabwidth QtGui.QTextEdit.__init__(self, parent) self._tabwidth = 8 self.setMinimumSize(QtCore.QSize(1, 1)) self.setLineWrapMode(QtGui.QTextEdit.NoWrap) self.setAcceptRichText(False) self.setFont(diff_font()) self.set_tabwidth(tabwidth()) self.setCursorWidth(2)
def __init__(self, model, parent): QtGui.QWidget.__init__(self, parent) self.model = model self.notifying = False self.spellcheck_initialized = False self._linebreak = None self._textwidth = None self._tabwidth = None # Actions self.signoff_action = add_action(self, cmds.SignOff.name(), cmds.run(cmds.SignOff), cmds.SignOff.SHORTCUT) self.signoff_action.setToolTip(N_('Sign off on this commit')) self.commit_action = add_action(self, N_('Commit@@verb'), self.commit, cmds.Commit.SHORTCUT) self.commit_action.setToolTip(N_('Commit staged changes')) # Widgets self.summary = CommitSummaryLineEdit() self.summary.extra_actions.append(self.signoff_action) self.summary.extra_actions.append(self.commit_action) self.description = CommitMessageTextEdit() self.description.extra_actions.append(self.signoff_action) self.description.extra_actions.append(self.commit_action) commit_button_tooltip = N_('Commit staged changes\n' 'Shortcut: Ctrl+Enter') self.commit_button = create_toolbutton(text=N_('Commit@@verb'), tooltip=commit_button_tooltip, icon=save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = create_toolbutton(icon=options_icon(), tooltip=N_('Actions...')) self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.actions_menu.addAction(self.signoff_action) self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() # Amend checkbox self.amend_action = self.actions_menu.addAction( N_('Amend Last Commit')) self.amend_action.setCheckable(True) self.amend_action.setShortcut(cmds.AmendMode.SHORTCUT) self.amend_action.setShortcutContext(Qt.ApplicationShortcut) # Spell checker self.check_spelling_action = self.actions_menu.addAction( N_('Check Spelling')) self.check_spelling_action.setCheckable(True) self.check_spelling_action.setChecked(False) # Line wrapping self.actions_menu.addSeparator() self.autowrap_action = self.actions_menu.addAction( N_('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(linebreak()) self.prev_commits_menu = self.actions_menu.addMenu( N_('Load Previous Commit Message')) self.connect(self.prev_commits_menu, SIGNAL('aboutToShow()'), self.build_prev_commits_menu) self.toplayout = QtGui.QHBoxLayout() self.toplayout.setMargin(0) self.toplayout.setSpacing(defs.spacing) self.toplayout.addWidget(self.actions_button) self.toplayout.addWidget(self.summary) self.toplayout.addWidget(self.commit_button) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.mainlayout.addLayout(self.toplayout) self.mainlayout.addWidget(self.description) self.setLayout(self.mainlayout) connect_button(self.commit_button, self.commit) notifier = cola.notifier() notifier.connect(notifier.AMEND, self.amend_action.setChecked) # Broadcast the amend mode connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) connect_action_bool(self.check_spelling_action, self.toggle_check_spelling) # Handle the one-off autowrapping connect_action_bool(self.autowrap_action, self.set_linebreak) add_action(self.summary, N_('Move Down'), self.focus_description, Qt.Key_Down, Qt.Key_Return, Qt.Key_Enter) self.model.add_observer(self.model.message_commit_message_changed, self.set_commit_message) self.connect(self.summary, SIGNAL('cursorPosition(int,int)'), self.emit_position) self.connect(self.description, SIGNAL('cursorPosition(int,int)'), # description starts at line 2 lambda row, col: self.emit_position(row + 2, col)) # Keep model informed of changes self.connect(self.summary, SIGNAL('textChanged(QString)'), self.commit_message_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('leave()'), self.focus_summary) self.setFont(diff_font()) self.summary.enable_hint(True) self.description.enable_hint(True) self.commit_button.setEnabled(False) self.commit_action.setEnabled(False) self.setFocusProxy(self.summary) self.set_tabwidth(tabwidth()) self.set_textwidth(textwidth()) self.set_linebreak(linebreak()) # Loading message commit_msg = "" commit_msg_path = commit_message_path() if commit_msg_path: commit_msg = utils.slurp(commit_msg_path) self.set_commit_message(commit_msg) # Allow tab to jump from the summary to the description self.setTabOrder(self.summary, self.description)
def __init__(self, model, parent): QtGui.QWidget.__init__(self, parent) self.model = model self.notifying = False self._linebreak = None self._textwidth = None self._tabwidth = None # Actions self.signoff_action = add_action(self, cmds.SignOff.NAME, cmds.run(cmds.SignOff), cmds.SignOff.SHORTCUT) self.signoff_action.setToolTip("Sign off on this commit") self.commit_action = add_action(self, "Commit@@verb", self.commit, "Ctrl+Return") self.commit_action.setToolTip(tr("Commit staged changes")) # Widgets self.summary = CommitSummaryLineEdit() self.summary.extra_actions.append(self.signoff_action) self.summary.extra_actions.append(self.commit_action) self.description = CommitMessageTextEdit() self.description.extra_actions.append(self.signoff_action) self.description.extra_actions.append(self.commit_action) commit_button_tooltip = "Commit staged changes\nShortcut: Ctrl+Enter" self.commit_button = create_toolbutton(text="Commit@@verb", tooltip=commit_button_tooltip, icon=save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = create_toolbutton(icon=options_icon(), tooltip="Actions...") self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.actions_menu.addAction(self.signoff_action) self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() # Amend checkbox self.amend_action = self.actions_menu.addAction(tr("Amend Last Commit")) self.amend_action.setCheckable(True) # Line wrapping self.actions_menu.addSeparator() self.autowrap_action = self.actions_menu.addAction(tr("Auto-Wrap Lines")) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(linebreak()) self.prev_commits_menu = self.actions_menu.addMenu(tr("Load Previous Commit Message")) self.connect(self.prev_commits_menu, SIGNAL("aboutToShow()"), self.build_prev_commits_menu) self.toplayout = QtGui.QHBoxLayout() self.toplayout.setMargin(0) self.toplayout.setSpacing(defs.spacing) self.toplayout.addWidget(self.actions_button) self.toplayout.addWidget(self.summary) self.toplayout.addWidget(self.commit_button) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.mainlayout.addLayout(self.toplayout) self.mainlayout.addWidget(self.description) self.setLayout(self.mainlayout) connect_button(self.commit_button, self.commit) notifier = cola.notifier() notifier.connect(notifier.AMEND, self.amend_action.setChecked) # Broadcast the amend mode connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) # Handle the one-off autowrapping connect_action_bool(self.autowrap_action, self.set_linebreak) self.model.add_observer(self.model.message_commit_message_changed, self.set_commit_message) self.connect(self.summary, SIGNAL("returnPressed()"), self.focus_description) self.connect(self.summary, SIGNAL("downPressed()"), self.focus_description) self.connect(self.summary, SIGNAL("cursorPosition(int,int)"), self.emit_position) self.connect( self.description, SIGNAL("cursorPosition(int,int)"), # description starts at line 2 lambda row, col: self.emit_position(row + 2, col), ) # Keep model informed of changes self.connect(self.summary, SIGNAL("textChanged(QString)"), self.commit_message_changed) self.connect(self.description, SIGNAL("textChanged()"), self.commit_message_changed) self.connect(self.description, SIGNAL("shiftTab()"), self.focus_summary) self.setFont(diff_font()) self.summary.enable_hint(True) self.description.enable_hint(True) self.commit_button.setEnabled(False) self.commit_action.setEnabled(False) self.setFocusProxy(self.summary) self.set_tabwidth(tabwidth()) self.set_textwidth(textwidth()) self.set_linebreak(linebreak()) # Allow tab to jump from the summary to the description self.setTabOrder(self.summary, self.description)
def __init__(self, model, parent): QtGui.QWidget.__init__(self, parent) self.model = model self.notifying = False self._linebreak = None self._textwidth = None self._tabwidth = None # Actions self.signoff_action = add_action(self, cmds.SignOff.NAME, cmds.run(cmds.SignOff), cmds.SignOff.SHORTCUT) self.signoff_action.setToolTip('Sign off on this commit') self.commit_action = add_action(self, 'Commit@@verb', self.commit, 'Ctrl+Return') self.commit_action.setToolTip(tr('Commit staged changes')) # Widgets self.summary = CommitSummaryLineEdit() self.summary.extra_actions.append(self.signoff_action) self.summary.extra_actions.append(self.commit_action) self.description = CommitMessageTextEdit() self.description.extra_actions.append(self.signoff_action) self.description.extra_actions.append(self.commit_action) commit_button_tooltip = 'Commit staged changes\nShortcut: Ctrl+Enter' self.commit_button = create_toolbutton(text='Commit@@verb', tooltip=commit_button_tooltip, icon=save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = create_toolbutton(icon=options_icon(), tooltip='Actions...') self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.actions_menu.addAction(self.signoff_action) self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() # Amend checkbox self.amend_action = self.actions_menu.addAction( tr('Amend Last Commit')) self.amend_action.setCheckable(True) # Line wrapping self.actions_menu.addSeparator() self.autowrap_action = self.actions_menu.addAction( tr('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(linebreak()) self.prev_commits_menu = self.actions_menu.addMenu( tr('Load Previous Commit Message')) self.connect(self.prev_commits_menu, SIGNAL('aboutToShow()'), self.build_prev_commits_menu) self.toplayout = QtGui.QHBoxLayout() self.toplayout.setMargin(0) self.toplayout.setSpacing(defs.spacing) self.toplayout.addWidget(self.actions_button) self.toplayout.addWidget(self.summary) self.toplayout.addWidget(self.commit_button) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.mainlayout.addLayout(self.toplayout) self.mainlayout.addWidget(self.description) self.setLayout(self.mainlayout) connect_button(self.commit_button, self.commit) notifier = cola.notifier() notifier.connect(notifier.AMEND, self.amend_action.setChecked) # Broadcast the amend mode connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) # Handle the one-off autowrapping connect_action_bool(self.autowrap_action, self.set_linebreak) self.model.add_observer(self.model.message_commit_message_changed, self.set_commit_message) self.connect(self.summary, SIGNAL('returnPressed()'), self.focus_description) self.connect(self.summary, SIGNAL('downPressed()'), self.focus_description) self.connect(self.summary, SIGNAL('cursorPosition(int,int)'), self.emit_position) self.connect( self.description, SIGNAL('cursorPosition(int,int)'), # description starts at line 2 lambda row, col: self.emit_position(row + 2, col)) # Keep model informed of changes self.connect(self.summary, SIGNAL('textChanged(QString)'), self.commit_message_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('shiftTab()'), self.focus_summary) self.setFont(diff_font()) self.summary.enable_hint(True) self.description.enable_hint(True) self.commit_button.setEnabled(False) self.commit_action.setEnabled(False) self.setFocusProxy(self.summary) self.set_tabwidth(tabwidth()) self.set_textwidth(textwidth()) self.set_linebreak(linebreak()) # Allow tab to jump from the summary to the description self.setTabOrder(self.summary, self.description)