def __init__(self, hint, parent=None): QtGui.QLineEdit.__init__(self, parent) HintedTextWidgetMixin.__init__(self, hint) self.setFont(diff_font()) self.connect(self, SIGNAL('cursorPositionChanged(int,int)'), lambda x, y: self.emit_position())
def __init__(self, hint='', parent=None): QtGui.QLineEdit.__init__(self, parent) HintedTextWidgetMixin.__init__(self, hint) self.setFont(diff_font()) self.connect(self, SIGNAL('cursorPositionChanged(int,int)'), lambda x, y: self.emit_position())
def __init__(self, parent): 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 update_from_config(self): FormWidget.update_from_config(self) block = self.fixed_font.blockSignals(True) font = diff_font() self.fixed_font.setCurrentFont(font) self.fixed_font.blockSignals(block) block = self.font_size.blockSignals(True) font_size = font.pointSize() self.font_size.setValue(font_size) self.font_size.blockSignals(block)
def __init__(self, title, label, parent): QtGui.QProgressDialog.__init__(self, parent) self.setFont(qtutils.diff_font()) self.setRange(0, 0) self.setCancelButton(None) if parent is not None: self.setWindowModality(Qt.WindowModal) self.progress_thread = ProgressAnimationThread(label, self) self.connect(self.progress_thread, SIGNAL('update_progress'), self.update_progress) self.set_details(title, label)
def text_dialog(text, title): """Show a wall of text in a dialog""" parent = qtutils.active_window() label = QtGui.QLabel(parent) label.setFont(qtutils.diff_font()) label.setText(text) label.setTextInteractionFlags(Qt.NoTextInteraction) widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(title) layout = qtutils.hbox(defs.margin, defs.spacing, label) widget.setLayout(layout) qtutils.add_action(widget, N_("Close"), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def __init__(self, model, hint='', parent=None): text.HintedLineEdit.__init__(self, hint=hint, parent=parent) self.setFont(qtutils.diff_font()) completion_model = model(self) completer = Completer(completion_model, self) completer.setWidget(self) self._completer = completer self._delegate = HighlightDelegate(self) self.connect(self, SIGNAL('textChanged(QString)'), self._text_changed) completer.popup().setItemDelegate(self._delegate) self.connect(self._completer, SIGNAL('activated(QString)'), self._complete) self.connect(self, SIGNAL('destroyed(QObject*)'), self.dispose)
def text_dialog(text, title): """Show a wall of text in a dialog""" parent = qtutils.active_window() label = QtGui.QLabel(parent) label.setFont(qtutils.diff_font()) label.setText(text) label.setTextInteractionFlags(Qt.NoTextInteraction) widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(title) layout = qtutils.hbox(defs.margin, defs.spacing, label) widget.setLayout(layout) qtutils.add_action(widget, N_('Close'), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def __init__(self, model, parent=None): QtGui.QLineEdit.__init__(self, parent) self.setFont(qtutils.diff_font()) # used to hide the completion popup after a drag-select self._drag = 0 self._keys_to_ignore = set( [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape]) completion_model = model(self) completer = Completer(completion_model, self) completer.setWidget(self) self._completer = completer self._delegate = HighlightDelegate(self) self.connect(self, SIGNAL('textChanged(QString)'), self._text_changed) completer.popup().setItemDelegate(self._delegate) self.connect(self._completer, SIGNAL('activated(QString)'), self._complete)
def __init__(self, model, parent=None): QtGui.QLineEdit.__init__(self, parent) self.setFont(qtutils.diff_font()) # used to hide the completion popup after a drag-select self._drag = 0 self._keys_to_ignore = set([Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape]) completion_model = model(self) completer = Completer(completion_model, self) completer.setWidget(self) self._completer = completer self._delegate = HighlightDelegate(self) self.connect(self, SIGNAL('textChanged(QString)'), self._text_changed) completer.popup().setItemDelegate(self._delegate) self.connect(self._completer, SIGNAL('activated(QString)'), self._complete)
def setup_mono_font(widget): widget.setFont(qtutils.diff_font()) widget.set_tabwidth(prefs.tabwidth())
def __init__(self, hint='', parent=None): LineEdit.__init__(self, parent=parent, get_value=get_value_hinted) self.hint = HintWidget(self, hint) self.setFont(qtutils.diff_font()) self.connect(self, SIGNAL('textChanged(QString)'), lambda text: self.hint.refresh())
def __init__(self, parent=None): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Search')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.edit_action = qtutils.add_action( self, N_('Edit'), self.edit, hotkeys.EDIT) self.refresh_action = qtutils.add_action( self, N_('Refresh'), self.search, *hotkeys.REFRESH_HOTKEYS) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) self.input_txt = HintedLineEdit(N_('command-line arguments'), self) self.input_txt.hint.enable(True) self.regexp_combo = combo = QtGui.QComboBox() combo.setToolTip(N_('Choose the "git grep" regular expression mode')) items = [N_('Basic Regexp'), N_('Extended Regexp'), N_('Fixed String')] combo.addItems(items) combo.setCurrentIndex(0) combo.setEditable(False) combo.setItemData(0, N_('Search using a POSIX basic regular expression'), Qt.ToolTipRole) combo.setItemData(1, N_('Search using a POSIX extended regular expression'), Qt.ToolTipRole) combo.setItemData(2, N_('Search for a fixed string'), Qt.ToolTipRole) combo.setItemData(0, '--basic-regexp', Qt.UserRole) combo.setItemData(1, '--extended-regexp', Qt.UserRole) combo.setItemData(2, '--fixed-strings', Qt.UserRole) self.result_txt = GrepTextView(N_('grep result...'), self) self.result_txt.hint.enable(True) self.edit_button = qtutils.edit_button() qtutils.button_action(self.edit_button, self.edit_action) self.refresh_button = qtutils.refresh_button() qtutils.button_action(self.refresh_button, self.refresh_action) text = N_('Shell arguments') tooltip = N_('Parse arguments using a shell.\n' 'Queries with spaces will require "double quotes".') self.shell_checkbox = qtutils.checkbox(text=text, tooltip=tooltip, checked=False) self.close_button = qtutils.close_button() self.refresh_group = Group(self.refresh_action, self.refresh_button) self.refresh_group.setEnabled(False) self.edit_group = Group(self.edit_action, self.edit_button) self.edit_group.setEnabled(False) self.input_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.input_label, self.input_txt, self.regexp_combo) self.bottom_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.edit_button, self.refresh_button, self.shell_checkbox, qtutils.STRETCH, self.close_button) self.mainlayout = qtutils.vbox(defs.margin, defs.no_spacing, self.input_layout, self.result_txt, self.bottom_layout) self.setLayout(self.mainlayout) self.worker_thread = GrepThread(self) self.connect(self.worker_thread, SIGNAL('result(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)'), self.process_result, Qt.QueuedConnection) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.regexp_combo, SIGNAL('currentIndexChanged(int)'), lambda x: self.search()) self.connect(self.result_txt, SIGNAL('leave()'), lambda: self.input_txt.setFocus()) qtutils.add_action(self.input_txt, 'Focus Results', self.focus_results, hotkeys.DOWN, *hotkeys.ACCEPT) qtutils.add_action(self, 'Focus Input', self.focus_input, hotkeys.FOCUS) qtutils.connect_toggle(self.shell_checkbox, lambda x: self.search()) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not self.restore_state(): width, height = qtutils.default_size(parent, 666, 420) self.resize(width, height)
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 = qtutils.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 = qtutils.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.setMinimumHeight(defs.tool_button_height) 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 = qtutils.create_toolbutton( text=N_('Commit@@verb'), tooltip=commit_button_tooltip, icon=qtutils.save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = qtutils.create_toolbutton( icon=qtutils.options_icon(), tooltip=N_('Actions...')) self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) qtutils.hide_button_menu_indicator(self.actions_button) 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) # Bypass hooks self.bypass_commit_hooks_action = self.actions_menu.addAction( N_('Bypass Commit Hooks')) self.bypass_commit_hooks_action.setCheckable(True) self.bypass_commit_hooks_action.setChecked(False) # Sign commits cfg = gitcfg.current() self.sign_action = self.actions_menu.addAction( N_('Create Signed Commit')) self.sign_action.setCheckable(True) self.sign_action.setChecked(cfg.get('cola.signcommits', False)) # 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.autowrap_action = self.actions_menu.addAction( N_('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(prefs.linebreak()) # Commit message self.actions_menu.addSeparator() self.load_commitmsg_menu = self.actions_menu.addMenu( N_('Load Previous Commit Message')) self.connect(self.load_commitmsg_menu, SIGNAL('aboutToShow()'), self.build_commitmsg_menu) self.fixup_commit_menu = self.actions_menu.addMenu( N_('Fixup Previous Commit')) self.connect(self.fixup_commit_menu, SIGNAL('aboutToShow()'), self.build_fixup_menu) self.toplayout = qtutils.hbox(defs.no_margin, defs.spacing, self.actions_button, self.summary, self.commit_button) self.toplayout.setContentsMargins(defs.margin, defs.no_margin, defs.no_margin, defs.no_margin) self.mainlayout = qtutils.vbox(defs.no_margin, defs.spacing, self.toplayout, self.description) self.setLayout(self.mainlayout) qtutils.connect_button(self.commit_button, self.commit) # Broadcast the amend mode qtutils.connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) qtutils.connect_action_bool(self.check_spelling_action, self.toggle_check_spelling) # Handle the one-off autowrapping qtutils.connect_action_bool(self.autowrap_action, self.set_linebreak) qtutils.add_action(self.summary, N_('Move Down'), self.focus_description, Qt.Key_Return, Qt.Key_Enter) qtutils.add_action(self.summary, N_('Move Down'), self.summary_cursor_down, Qt.Key_Down) 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_summary_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('leave()'), self.focus_summary) self.setFont(qtutils.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(prefs.tabwidth()) self.set_textwidth(prefs.textwidth()) self.set_linebreak(prefs.linebreak()) # Loading message commit_msg = '' commit_msg_path = commit_message_path() if commit_msg_path: commit_msg = core.read(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, action, parent): """Customizes the dialog based on the remote action """ standard.Dialog.__init__(self, parent=parent) self.model = model self.action = action self.tasks = [] self.filtered_remote_branches = [] self.selected_remotes = [] self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowModality(Qt.WindowModal) self.setWindowTitle(N_(action)) self.progress = QtGui.QProgressDialog(self) self.progress.setFont(qtutils.diff_font()) self.progress.setRange(0, 0) self.progress.setCancelButton(None) self.progress.setWindowTitle(action) self.progress.setWindowModality(Qt.WindowModal) self.progress.setLabelText(N_('Updating') + '.. ') self.progress_thread = ProgressAnimationThread(N_('Updating'), self) self.local_label = QtGui.QLabel() self.local_label.setText(N_('Local Branch')) self.local_branch = QtGui.QLineEdit() self.local_branches = QtGui.QListWidget() self.local_branches.addItems(self.model.local_branches) self.remote_label = QtGui.QLabel() self.remote_label.setText(N_('Remote')) self.remote_name = QtGui.QLineEdit() self.remotes = QtGui.QListWidget() if action == PUSH: self.remotes.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) self.remotes.addItems(self.model.remotes) self.remote_branch_label = QtGui.QLabel() self.remote_branch_label.setText(N_('Remote Branch')) self.remote_branch = QtGui.QLineEdit() self.remote_branches = QtGui.QListWidget() self.remote_branches.addItems(self.model.remote_branches) self.ffwd_only_checkbox = QtGui.QCheckBox() self.ffwd_only_checkbox.setText(N_('Fast Forward Only ')) self.ffwd_only_checkbox.setChecked(True) self.tags_checkbox = QtGui.QCheckBox() self.tags_checkbox.setText(N_('Include tags ')) self.rebase_checkbox = QtGui.QCheckBox() self.rebase_checkbox.setText(N_('Rebase ')) self.action_button = QtGui.QPushButton() self.action_button.setText(N_(action)) self.action_button.setIcon(qtutils.ok_icon()) self.close_button = QtGui.QPushButton() self.close_button.setText(N_('Close')) self.close_button.setIcon(qtutils.close_icon()) self.local_branch_layout = QtGui.QHBoxLayout() self.local_branch_layout.addWidget(self.local_label) self.local_branch_layout.addWidget(self.local_branch) self.remote_branch_layout = QtGui.QHBoxLayout() self.remote_branch_layout.addWidget(self.remote_label) self.remote_branch_layout.addWidget(self.remote_name) self.remote_branches_layout = QtGui.QHBoxLayout() self.remote_branches_layout.addWidget(self.remote_branch_label) self.remote_branches_layout.addWidget(self.remote_branch) self.options_layout = QtGui.QHBoxLayout() self.options_layout.setSpacing(defs.button_spacing) self.options_layout.addStretch() self.options_layout.addWidget(self.ffwd_only_checkbox) self.options_layout.addWidget(self.tags_checkbox) self.options_layout.addWidget(self.rebase_checkbox) self.options_layout.addWidget(self.action_button) self.options_layout.addWidget(self.close_button) self.main_layout = QtGui.QVBoxLayout() self.main_layout.setMargin(defs.margin) self.main_layout.setSpacing(defs.spacing) self.main_layout.addLayout(self.remote_branch_layout) self.main_layout.addWidget(self.remotes) if action == PUSH: self.main_layout.addLayout(self.local_branch_layout) self.main_layout.addWidget(self.local_branches) self.main_layout.addLayout(self.remote_branches_layout) self.main_layout.addWidget(self.remote_branches) else: # fetch and pull self.main_layout.addLayout(self.remote_branches_layout) self.main_layout.addWidget(self.remote_branches) self.main_layout.addLayout(self.local_branch_layout) self.main_layout.addWidget(self.local_branches) self.main_layout.addLayout(self.options_layout) self.setLayout(self.main_layout) remotes = self.model.remotes if 'origin' in remotes: idx = remotes.index('origin') if self.select_remote(idx): self.remote_name.setText('origin') else: if self.select_first_remote(): self.remote_name.setText(remotes[0]) # Trim the remote list to just the default remote self.update_remotes() self.set_field_defaults() # Setup signals and slots self.connect(self.remotes, SIGNAL('itemSelectionChanged()'), self.update_remotes) self.connect(self.local_branches, SIGNAL('itemSelectionChanged()'), self.update_local_branches) self.connect(self.remote_branches, SIGNAL('itemSelectionChanged()'), self.update_remote_branches) connect_button(self.action_button, self.action_callback) connect_button(self.close_button, self.close) qtutils.add_action(self, N_('Close'), self.close, QtGui.QKeySequence.Close, 'Esc') self.connect(self, SIGNAL('action_completed'), self.action_completed) self.connect(self.progress_thread, SIGNAL('str'), self.update_progress) if action == PULL: self.tags_checkbox.hide() self.ffwd_only_checkbox.hide() self.local_label.hide() self.local_branch.hide() self.local_branches.hide() self.remote_branch.setFocus() else: self.rebase_checkbox.hide() if not qtutils.apply_state(self): self.resize(666, 420) self.remote_name.setFocus()
def __init__(self, model, action, parent): """Customizes the dialog based on the remote action """ standard.Dialog.__init__(self, parent=parent) self.model = model self.action = action self.tasks = [] self.filtered_remote_branches = [] self.selected_remotes = [] self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowModality(Qt.WindowModal) self.setWindowTitle(N_(action)) self.progress = QtGui.QProgressDialog(self) self.progress.setFont(qtutils.diff_font()) self.progress.setRange(0, 0) self.progress.setCancelButton(None) self.progress.setWindowTitle(action) self.progress.setWindowModality(Qt.WindowModal) self.progress.setLabelText(N_('Updating') + '.. ') self.progress_thread = ProgressAnimationThread(N_('Updating'), self) self.local_label = QtGui.QLabel() self.local_label.setText(N_('Local Branch')) self.local_branch = QtGui.QLineEdit() self.local_branches = QtGui.QListWidget() self.local_branches.addItems(self.model.local_branches) self.remote_label = QtGui.QLabel() self.remote_label.setText(N_('Remote')) self.remote_name = QtGui.QLineEdit() self.remotes = QtGui.QListWidget() if action == PUSH: self.remotes.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.remotes.addItems(self.model.remotes) self.remote_branch_label = QtGui.QLabel() self.remote_branch_label.setText(N_('Remote Branch')) self.remote_branch = QtGui.QLineEdit() self.remote_branches = QtGui.QListWidget() self.remote_branches.addItems(self.model.remote_branches) self.ffwd_only_checkbox = QtGui.QCheckBox() self.ffwd_only_checkbox.setText(N_('Fast Forward Only ')) self.ffwd_only_checkbox.setChecked(True) self.tags_checkbox = QtGui.QCheckBox() self.tags_checkbox.setText(N_('Include tags ')) self.rebase_checkbox = QtGui.QCheckBox() self.rebase_checkbox.setText(N_('Rebase ')) self.action_button = QtGui.QPushButton() self.action_button.setText(N_(action)) self.action_button.setIcon(qtutils.ok_icon()) self.close_button = QtGui.QPushButton() self.close_button.setText(N_('Close')) self.close_button.setIcon(qtutils.close_icon()) self.local_branch_layout = QtGui.QHBoxLayout() self.local_branch_layout.addWidget(self.local_label) self.local_branch_layout.addWidget(self.local_branch) self.remote_branch_layout = QtGui.QHBoxLayout() self.remote_branch_layout.addWidget(self.remote_label) self.remote_branch_layout.addWidget(self.remote_name) self.remote_branches_layout = QtGui.QHBoxLayout() self.remote_branches_layout.addWidget(self.remote_branch_label) self.remote_branches_layout.addWidget(self.remote_branch) self.options_layout = QtGui.QHBoxLayout() self.options_layout.setSpacing(defs.button_spacing) self.options_layout.addStretch() self.options_layout.addWidget(self.ffwd_only_checkbox) self.options_layout.addWidget(self.tags_checkbox) self.options_layout.addWidget(self.rebase_checkbox) self.options_layout.addWidget(self.action_button) self.options_layout.addWidget(self.close_button) self.main_layout = QtGui.QVBoxLayout() self.main_layout.setMargin(defs.margin) self.main_layout.setSpacing(defs.spacing) self.main_layout.addLayout(self.remote_branch_layout) self.main_layout.addWidget(self.remotes) if action == PUSH: self.main_layout.addLayout(self.local_branch_layout) self.main_layout.addWidget(self.local_branches) self.main_layout.addLayout(self.remote_branches_layout) self.main_layout.addWidget(self.remote_branches) else: # fetch and pull self.main_layout.addLayout(self.remote_branches_layout) self.main_layout.addWidget(self.remote_branches) self.main_layout.addLayout(self.local_branch_layout) self.main_layout.addWidget(self.local_branches) self.main_layout.addLayout(self.options_layout) self.setLayout(self.main_layout) remotes = self.model.remotes if 'origin' in remotes: idx = remotes.index('origin') if self.select_remote(idx): self.remote_name.setText('origin') else: if self.select_first_remote(): self.remote_name.setText(remotes[0]) # Trim the remote list to just the default remote self.update_remotes() self.set_field_defaults() # Setup signals and slots self.connect(self.remotes, SIGNAL('itemSelectionChanged()'), self.update_remotes) self.connect(self.local_branches, SIGNAL('itemSelectionChanged()'), self.update_local_branches) self.connect(self.remote_branches, SIGNAL('itemSelectionChanged()'), self.update_remote_branches) connect_button(self.action_button, self.action_callback) connect_button(self.close_button, self.close) qtutils.add_action(self, N_('Close'), self.close, QtGui.QKeySequence.Close, 'Esc') self.connect(self, SIGNAL('action_completed'), self.action_completed) self.connect(self.progress_thread, SIGNAL('str'), self.update_progress) if action == PULL: self.tags_checkbox.hide() self.ffwd_only_checkbox.hide() self.local_label.hide() self.local_branch.hide() self.local_branches.hide() self.remote_branch.setFocus() else: self.rebase_checkbox.hide() if not qtutils.apply_state(self): self.resize(666, 420) self.remote_name.setFocus()
def __init__(self, parent=None): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Search')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.edit_action = qtutils.add_action(self, N_('Edit'), self.edit, hotkeys.EDIT) self.refresh_action = qtutils.add_action(self, N_('Refresh'), self.search, *hotkeys.REFRESH_HOTKEYS) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) self.input_txt = HintedLineEdit(N_('command-line arguments'), self) self.input_txt.hint.enable(True) self.regexp_combo = combo = QtGui.QComboBox() combo.setToolTip(N_('Choose the "git grep" regular expression mode')) items = [N_('Basic Regexp'), N_('Extended Regexp'), N_('Fixed String')] combo.addItems(items) combo.setCurrentIndex(0) combo.setEditable(False) combo.setItemData(0, N_('Search using a POSIX basic regular expression'), Qt.ToolTipRole) combo.setItemData( 1, N_('Search using a POSIX extended regular expression'), Qt.ToolTipRole) combo.setItemData(2, N_('Search for a fixed string'), Qt.ToolTipRole) combo.setItemData(0, '--basic-regexp', Qt.UserRole) combo.setItemData(1, '--extended-regexp', Qt.UserRole) combo.setItemData(2, '--fixed-strings', Qt.UserRole) self.result_txt = GrepTextView(N_('grep result...'), self) self.result_txt.hint.enable(True) self.edit_button = qtutils.edit_button() qtutils.button_action(self.edit_button, self.edit_action) self.refresh_button = qtutils.refresh_button() qtutils.button_action(self.refresh_button, self.refresh_action) text = N_('Shell arguments') tooltip = N_('Parse arguments using a shell.\n' 'Queries with spaces will require "double quotes".') self.shell_checkbox = qtutils.checkbox(text=text, tooltip=tooltip, checked=False) self.close_button = qtutils.close_button() self.refresh_group = Group(self.refresh_action, self.refresh_button) self.refresh_group.setEnabled(False) self.edit_group = Group(self.edit_action, self.edit_button) self.edit_group.setEnabled(False) self.input_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.input_label, self.input_txt, self.regexp_combo) self.bottom_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.edit_button, self.refresh_button, self.shell_checkbox, qtutils.STRETCH, self.close_button) self.mainlayout = qtutils.vbox(defs.margin, defs.no_spacing, self.input_layout, self.result_txt, self.bottom_layout) self.setLayout(self.mainlayout) self.worker_thread = GrepThread(self) self.connect( self.worker_thread, SIGNAL('result(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)'), self.process_result, Qt.QueuedConnection) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.regexp_combo, SIGNAL('currentIndexChanged(int)'), lambda x: self.search()) self.connect(self.result_txt, SIGNAL('leave()'), lambda: self.input_txt.setFocus()) qtutils.add_action(self.input_txt, 'Focus Results', self.focus_results, hotkeys.DOWN, *hotkeys.ACCEPT) qtutils.add_action(self, 'Focus Input', self.focus_input, hotkeys.FOCUS) qtutils.connect_toggle(self.shell_checkbox, lambda x: self.search()) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not self.restore_state(): width, height = qtutils.default_size(parent, 666, 420) self.resize(width, height)
def __init__(self, parent=None): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Search')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) self.input_txt = HintedLineEdit(N_('command-line arguments'), self) self.input_txt.enable_hint(True) self.regexp_combo = combo = QtGui.QComboBox() combo.setToolTip(N_('Choose the "git grep" regular expression mode')) items = [N_('Basic Regexp'), N_('Extended Regexp'), N_('Fixed String')] combo.addItems(items) combo.setCurrentIndex(0) combo.setEditable(False) combo.setItemData(0, N_('Search using a POSIX basic regular expression'), Qt.ToolTipRole) combo.setItemData(1, N_('Search using a POSIX extended regular expression'), Qt.ToolTipRole) combo.setItemData(2, N_('Search for a fixed string'), Qt.ToolTipRole) combo.setItemData(0, '--basic-regexp', Qt.UserRole) combo.setItemData(1, '--extended-regexp', Qt.UserRole) combo.setItemData(2, '--fixed-strings', Qt.UserRole) self.result_txt = GrepTextView(N_('grep result...'), self) self.result_txt.enable_hint(True) self.edit_button = QtGui.QPushButton(N_('Edit')) self.edit_button.setIcon(qtutils.open_file_icon()) self.edit_button.setEnabled(False) self.edit_button.setShortcut(cmds.Edit.SHORTCUT) self.refresh_button = QtGui.QPushButton(N_('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setShortcut(QtGui.QKeySequence.Refresh) self.shell_checkbox = QtGui.QCheckBox(N_('Shell arguments')) self.shell_checkbox.setToolTip( N_('Parse arguments using a shell.\n' 'Queries with spaces will require "double quotes".')) self.shell_checkbox.setChecked(False) self.close_button = QtGui.QPushButton(N_('Close')) self.input_layout = QtGui.QHBoxLayout() self.input_layout.setMargin(0) self.input_layout.setSpacing(defs.button_spacing) self.bottom_layout = QtGui.QHBoxLayout() self.bottom_layout.setMargin(0) self.bottom_layout.setSpacing(defs.button_spacing) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.input_layout.addWidget(self.input_label) self.input_layout.addWidget(self.input_txt) self.input_layout.addWidget(self.regexp_combo) self.bottom_layout.addWidget(self.edit_button) self.bottom_layout.addWidget(self.refresh_button) self.bottom_layout.addWidget(self.shell_checkbox) self.bottom_layout.addStretch() self.bottom_layout.addWidget(self.close_button) self.mainlayout.addLayout(self.input_layout) self.mainlayout.addWidget(self.result_txt) self.mainlayout.addLayout(self.bottom_layout) self.setLayout(self.mainlayout) self.grep_thread = GrepThread(self) self.connect(self.grep_thread, SIGNAL('result'), self.process_result) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.regexp_combo, SIGNAL('currentIndexChanged(int)'), lambda x: self.search()) self.connect(self.result_txt, SIGNAL('leave()'), lambda: self.input_txt.setFocus()) qtutils.add_action(self.input_txt, 'FocusResults', lambda: self.result_txt.setFocus(), Qt.Key_Down, Qt.Key_Enter, Qt.Key_Return) qtutils.add_action(self, 'FocusSearch', lambda: self.input_txt.setFocus(), 'Ctrl+l') qtutils.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_toggle(self.shell_checkbox, lambda x: self.search()) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not self.restore_state(): self.resize(666, 420)
def __init__(self, parent=None): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Search')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) self.input_txt = HintedLineEdit(N_('command-line arguments'), self) self.input_txt.enable_hint(True) self.regexp_combo = combo = QtGui.QComboBox() combo.setToolTip(N_('Choose the "git grep" regular expression mode')) items = [N_('Basic Regexp'), N_('Extended Regexp'), N_('Fixed String')] combo.addItems(items) combo.setCurrentIndex(0) combo.setEditable(False) combo.setItemData(0, N_('Search using a POSIX basic regular expression'), Qt.ToolTipRole) combo.setItemData(1, N_('Search using a POSIX extended regular expression'), Qt.ToolTipRole) combo.setItemData(2, N_('Search for a fixed string'), Qt.ToolTipRole) combo.setItemData(0, '--basic-regexp', Qt.UserRole) combo.setItemData(1, '--extended-regexp', Qt.UserRole) combo.setItemData(2, '--fixed-strings', Qt.UserRole) self.result_txt = GrepTextView(N_('grep result...'), self) self.result_txt.enable_hint(True) self.edit_button = QtGui.QPushButton(N_('Edit')) self.edit_button.setIcon(qtutils.open_file_icon()) self.edit_button.setEnabled(False) self.edit_button.setShortcut(cmds.Edit.SHORTCUT) self.refresh_button = QtGui.QPushButton(N_('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setShortcut(QtGui.QKeySequence.Refresh) self.shell_checkbox = QtGui.QCheckBox(N_('Shell arguments')) self.shell_checkbox.setToolTip( N_('Parse arguments using a shell.\n' 'Queries with spaces will require "double quotes".')) self.shell_checkbox.setChecked(False) self.close_button = QtGui.QPushButton(N_('Close')) self.input_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.input_label, self.input_txt, self.regexp_combo) self.bottom_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.edit_button, self.refresh_button, self.shell_checkbox, qtutils.STRETCH, self.close_button) self.mainlayout = qtutils.vbox(defs.margin, defs.no_spacing, self.input_layout, self.result_txt, self.bottom_layout) self.setLayout(self.mainlayout) self.worker_thread = GrepThread(self) self.connect(self.worker_thread, SIGNAL('result'), self.process_result) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.regexp_combo, SIGNAL('currentIndexChanged(int)'), lambda x: self.search()) self.connect(self.result_txt, SIGNAL('leave()'), lambda: self.input_txt.setFocus()) qtutils.add_action(self.input_txt, 'Focus Results', self.focus_results, Qt.Key_Down, Qt.Key_Enter, Qt.Key_Return) qtutils.add_action(self, 'Focus Input', self.focus_input, 'Ctrl+L') qtutils.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_toggle(self.shell_checkbox, lambda x: self.search()) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not self.restore_state(): width, height = qtutils.default_size(parent, 666, 420) self.resize(width, height)
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 = qtutils.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 = qtutils.add_action(self, N_('Commit@@verb'), self.commit, cmds.Commit.SHORTCUT) self.commit_action.setToolTip(N_('Commit staged changes')) self.clear_action = qtutils.add_action(self, N_('Clear...'), self.clear) # Widgets self.summary = CommitSummaryLineEdit() self.summary.setMinimumHeight(defs.tool_button_height) self.summary.extra_actions.append(self.clear_action) self.summary.extra_actions.append(None) 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.clear_action) self.description.extra_actions.append(None) 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 = qtutils.create_toolbutton( text=N_('Commit@@verb'), tooltip=commit_button_tooltip, icon=qtutils.save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = qtutils.create_toolbutton( icon=qtutils.options_icon(), tooltip=N_('Actions...')) self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) qtutils.hide_button_menu_indicator(self.actions_button) 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) # Bypass hooks self.bypass_commit_hooks_action = self.actions_menu.addAction( N_('Bypass Commit Hooks')) self.bypass_commit_hooks_action.setCheckable(True) self.bypass_commit_hooks_action.setChecked(False) # Sign commits cfg = gitcfg.current() self.sign_action = self.actions_menu.addAction( N_('Create Signed Commit')) self.sign_action.setCheckable(True) self.sign_action.setChecked(cfg.get('cola.signcommits', False)) # 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.autowrap_action = self.actions_menu.addAction( N_('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(prefs.linebreak()) # Commit message self.actions_menu.addSeparator() self.load_commitmsg_menu = self.actions_menu.addMenu( N_('Load Previous Commit Message')) self.connect(self.load_commitmsg_menu, SIGNAL('aboutToShow()'), self.build_commitmsg_menu) self.fixup_commit_menu = self.actions_menu.addMenu( N_('Fixup Previous Commit')) self.connect(self.fixup_commit_menu, SIGNAL('aboutToShow()'), self.build_fixup_menu) self.toplayout = qtutils.hbox(defs.no_margin, defs.spacing, self.actions_button, self.summary, self.commit_button) self.toplayout.setContentsMargins(defs.margin, defs.no_margin, defs.no_margin, defs.no_margin) self.mainlayout = qtutils.vbox(defs.no_margin, defs.spacing, self.toplayout, self.description) self.setLayout(self.mainlayout) qtutils.connect_button(self.commit_button, self.commit) # Broadcast the amend mode qtutils.connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) qtutils.connect_action_bool(self.check_spelling_action, self.toggle_check_spelling) # Handle the one-off autowrapping qtutils.connect_action_bool(self.autowrap_action, self.set_linebreak) qtutils.add_action(self.summary, N_('Move Down'), self.focus_description, Qt.Key_Return, Qt.Key_Enter) qtutils.add_action(self.summary, N_('Move Down'), self.summary_cursor_down, Qt.Key_Down) 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_summary_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('leave()'), self.focus_summary) self.setFont(qtutils.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(prefs.tabwidth()) self.set_textwidth(prefs.textwidth()) self.set_linebreak(prefs.linebreak()) # Loading message commit_msg = '' commit_msg_path = commit_message_path() if commit_msg_path: commit_msg = core.read(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)