def _create_unstaged_context_menu(self, menu, s): modified_submodule = (s.modified and s.modified[0] in self.m.submodules) if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.unstaged(): action = menu.addAction(qtutils.options_icon(), cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor)) action.setShortcut(cmds.Edit.SHORTCUT) if s.modified and self.m.stageable(): action = menu.addAction(qtutils.git_icon(), cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool)) action.setShortcut(cmds.LaunchDifftool.SHORTCUT) if self.m.stageable(): menu.addSeparator() action = menu.addAction(qtutils.icon('add.svg'), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(qtutils.icon('undo.svg'), N_('Revert Unstaged Edits...'), self._revert_unstaged_edits) menu.addAction(qtutils.icon('undo.svg'), N_('Revert Uncommited Edits...'), lambda: self._revert_uncommitted_edits( self.modified())) if self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if s.untracked: menu.addSeparator() menu.addAction(qtutils.discard_icon(), N_('Delete File(s)...'), self._delete_files) menu.addSeparator() menu.addAction(qtutils.icon('edit-clear.svg'), N_('Add to .gitignore'), cmds.run(cmds.Ignore, map(lambda x: '/' + x, self.untracked()))) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_staged_context_menu(self, menu, s): if s.staged[0] in self.m.submodules: return self._create_staged_submodule_context_menu(menu, s) if self.m.unstageable(): action = menu.addAction(qtutils.icon('remove.svg'), N_('Unstage Selected'), cmds.run(cmds.Unstage, self.staged())) action.setShortcut(cmds.Unstage.SHORTCUT) menu.addAction(self.launch_editor) menu.addAction(self.launch_difftool) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.staged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addAction(qtutils.icon('undo.svg'), N_('Revert Uncommited Edits...'), lambda: self._revert_uncommitted_edits( self.staged())) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_unmerged_context_menu(self, menu, s): menu.addAction(self.launch_difftool_action) action = menu.addAction(qtutils.add_icon(), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(hotkeys.STAGE_SELECTION) menu.addSeparator() menu.addAction(self.launch_editor_action) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unmerged())) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(hotkeys.SECONDARY_ACTION) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) menu.addAction(self.view_history_action) return menu
def _create_unmerged_context_menu(self, menu, s): menu.addAction(qtutils.git_icon(), self.tr('Launch Merge Tool'), cmds.run(cmds.Mergetool, self.unmerged())) action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) menu.addSeparator() action = menu.addAction(qtutils.options_icon(), self.tr(cmds.LaunchEditor.NAME), cmds.run(cmds.LaunchEditor)) action.setShortcut(cmds.LaunchEditor.SHORTCUT) if not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), self.tr(cmds.OpenDefaultApp.NAME), cmds.run(cmds.OpenDefaultApp, self.unmerged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), self.tr(cmds.OpenParentDir.NAME), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_unmerged_context_menu(self, menu, s): menu.addAction(qtutils.git_icon(), self.tr('Launch Merge Tool'), cmds.run(cmds.Mergetool, self.unmerged())) action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) menu.addSeparator() action = menu.addAction(qtutils.options_icon(), self.tr(cmds.LaunchEditor.NAME), cmds.run(cmds.LaunchEditor)) action.setShortcut(cmds.LaunchEditor.SHORTCUT) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), self.tr(cmds.OpenDefaultApp.NAME), cmds.run(cmds.OpenDefaultApp, self.unmerged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), self.tr(cmds.OpenParentDir.NAME), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_unmerged_context_menu(self, menu, s): menu.addAction(self.launch_difftool_action) action = menu.addAction(qtutils.icon('add.svg'), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) menu.addSeparator() menu.addAction(self.launch_editor_action) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unmerged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) return menu
def _create_staged_context_menu(self, menu, s): if s.staged[0] in self.m.submodules: return self._create_staged_submodule_context_menu(menu, s) if self.m.unstageable(): action = menu.addAction( qtutils.remove_icon(), N_("Unstage Selected"), cmds.run(cmds.Unstage, self.staged()) ) action.setShortcut(cmds.Unstage.SHORTCUT) # Do all of the selected items exist? all_exist = all(not i in self.m.staged_deleted and core.exists(i) for i in self.staged()) if all_exist: menu.addAction(self.launch_editor_action) menu.addAction(self.launch_difftool_action) if all_exist and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.staged()) ) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) return menu
def _create_unstaged_context_menu(self, menu, s): modified_submodule = (s.modified and s.modified[0] in self.m.submodules) if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.m.stageable(): action = menu.addAction(qtutils.icon('add.svg'), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) # Do all of the selected items exist? unstaged_items = self.unstaged_items() all_exist = all([i.exists for i in unstaged_items]) if all_exist and self.unstaged(): menu.addAction(self.launch_editor_action) if all_exist and s.modified and self.m.stageable(): menu.addAction(self.launch_difftool_action) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addAction(qtutils.icon('undo.svg'), N_('Revert Uncommited Edits...'), lambda: self._revert_uncommitted_edits( self.modified())) if all_exist and self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if all_exist and s.untracked: menu.addSeparator() if self.move_to_trash_action is not None: menu.addAction(self.move_to_trash_action) menu.addAction(self.delete_untracked_files_action) menu.addSeparator() menu.addAction(qtutils.icon('edit-clear.svg'), N_('Add to .gitignore'), cmds.run(cmds.Ignore, map(lambda x: '/' + x, self.untracked()))) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_unstaged_context_menu(self, menu, s): modified_submodule = (s.modified and s.modified[0] in self.m.submodules) if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.m.stageable(): action = menu.addAction(qtutils.add_icon(), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(hotkeys.STAGE_SELECTION) # Do all of the selected items exist? all_exist = all(not i in self.m.unstaged_deleted and core.exists(i) for i in self.staged()) if all_exist and self.unstaged(): menu.addAction(self.launch_editor_action) if all_exist and s.modified and self.m.stageable(): menu.addAction(self.launch_difftool_action) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) if all_exist and self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged())) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(hotkeys.SECONDARY_ACTION) if all_exist and s.untracked: menu.addSeparator() if self.move_to_trash_action is not None: menu.addAction(self.move_to_trash_action) menu.addAction(self.delete_untracked_files_action) menu.addSeparator() menu.addAction(qtutils.theme_icon('edit-clear.svg'), N_('Add to .gitignore'), cmds.run(cmds.Ignore, map(lambda x: '/' + x, self.untracked()))) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) if not selection.selection_model().is_empty(): menu.addAction(self.view_history_action) return menu
def _create_unstaged_context_menu(self, menu, s): modified_submodule = (s.modified and s.modified[0] in self.m.submodules) if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.m.stageable(): action = menu.addAction(qtutils.icon('add.svg'), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) # Do all of the selected items exist? unstaged_items = self.unstaged_items() all_exist = all([i.exists for i in unstaged_items]) if all_exist and self.unstaged(): menu.addAction(self.launch_editor_action) if all_exist and s.modified and self.m.stageable(): menu.addAction(self.launch_difftool_action) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addAction(self.revert_uncommitted_edits_action) if all_exist and self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if all_exist and s.untracked: menu.addSeparator() if self.move_to_trash_action is not None: menu.addAction(self.move_to_trash_action) menu.addAction(self.delete_untracked_files_action) menu.addSeparator() menu.addAction( qtutils.icon('edit-clear.svg'), N_('Add to .gitignore'), cmds.run(cmds.Ignore, map(lambda x: '/' + x, self.untracked()))) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) return menu
def _create_unstaged_context_menu(self, menu, s): modified_submodule = s.modified and s.modified[0] in self.m.submodules if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.m.stageable(): action = menu.addAction( qtutils.icon("add.svg"), N_("Stage Selected"), cmds.run(cmds.Stage, self.unstaged()) ) action.setShortcut(cmds.Stage.SHORTCUT) # Do all of the selected items exist? unstaged_items = self.unstaged_items() all_exist = all([i.exists for i in unstaged_items]) if all_exist and self.unstaged(): menu.addAction(self.launch_editor) if all_exist and s.modified and self.m.stageable(): menu.addAction(self.launch_difftool) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addAction( qtutils.icon("undo.svg"), N_("Revert Uncommited Edits..."), lambda: self._revert_uncommitted_edits(self.modified()), ) if all_exist and self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged()) ) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if all_exist and s.untracked: menu.addSeparator() menu.addAction(qtutils.discard_icon(), N_("Delete File(s)..."), self._delete_files) menu.addSeparator() menu.addAction( qtutils.icon("edit-clear.svg"), N_("Add to .gitignore"), cmds.run(cmds.Ignore, map(lambda x: "/" + x, self.untracked())), ) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_unstaged_context_menu(self, menu, s): modified_submodule = s.modified and s.modified[0] in self.m.submodules if modified_submodule: return self._create_modified_submodule_context_menu(menu, s) if self.m.stageable(): action = menu.addAction(qtutils.add_icon(), N_("Stage Selected"), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(cmds.Stage.SHORTCUT) # Do all of the selected items exist? all_exist = all(not i in self.m.unstaged_deleted and core.exists(i) for i in self.staged()) if all_exist and self.unstaged(): menu.addAction(self.launch_editor_action) if all_exist and s.modified and self.m.stageable(): menu.addAction(self.launch_difftool_action) if s.modified and self.m.stageable(): if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) if all_exist and self.unstaged() and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.unstaged()) ) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if all_exist and s.untracked: menu.addSeparator() if self.move_to_trash_action is not None: menu.addAction(self.move_to_trash_action) menu.addAction(self.delete_untracked_files_action) menu.addSeparator() menu.addAction( qtutils.theme_icon("edit-clear.svg"), N_("Add to .gitignore"), cmds.run(cmds.Ignore, map(lambda x: "/" + x, self.untracked())), ) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) return menu
def _create_staged_context_menu(self, menu, s): if s.staged[0] in self.m.submodules: return self._create_staged_submodule_context_menu(menu, s) if self.m.unstageable(): action = menu.addAction( qtutils.icon("remove.svg"), N_("Unstage Selected"), cmds.run(cmds.Unstage, self.staged()) ) action.setShortcut(cmds.Unstage.SHORTCUT) # Do all of the selected items exist? staged_items = self.staged_items() all_exist = all([i.exists for i in staged_items]) if all_exist: menu.addAction(self.launch_editor) menu.addAction(self.launch_difftool) if all_exist and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.staged()) ) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addAction( qtutils.icon("undo.svg"), N_("Revert Uncommited Edits..."), lambda: self._revert_uncommitted_edits(self.staged()), ) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def _create_staged_context_menu(self, menu, s): if s.staged[0] in self.m.submodules: return self._create_staged_submodule_context_menu(menu, s) if self.m.unstageable(): action = menu.addAction(qtutils.remove_icon(), N_('Unstage Selected'), cmds.run(cmds.Unstage, self.staged())) action.setShortcut(hotkeys.STAGE_SELECTION) # Do all of the selected items exist? all_exist = all(not i in self.m.staged_deleted and core.exists(i) for i in self.staged()) if all_exist: menu.addAction(self.launch_editor_action) menu.addAction(self.launch_difftool_action) if all_exist and not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.staged())) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(hotkeys.SECONDARY_ACTION) if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) menu.addAction(self.view_history_action) return menu
def _create_staged_context_menu(self, menu, s): if s.staged[0] in self.m.submodules: return self._create_staged_submodule_context_menu(menu, s) if self.m.unstageable(): action = menu.addAction(qtutils.icon('remove.svg'), N_('Unstage Selected'), cmds.run(cmds.Unstage, self.staged())) action.setShortcut(cmds.Unstage.SHORTCUT) # Do all of the selected items exist? staged_items = self.staged_items() all_exist = all([i.exists for i in staged_items]) if all_exist: menu.addAction(self.launch_editor_action) menu.addAction(self.launch_difftool_action) if all_exist and not utils.is_win32(): menu.addSeparator() action = menu.addAction( qtutils.file_icon(), cmds.OpenDefaultApp.name(), cmds.run(cmds.OpenDefaultApp, self.staged())) action.setShortcut(cmds.OpenDefaultApp.SHORTCUT) action = menu.addAction(qtutils.open_file_icon(), cmds.OpenParentDir.name(), self._open_parent_dir) action.setShortcut(cmds.OpenParentDir.SHORTCUT) if self.m.undoable(): menu.addSeparator() menu.addAction(self.revert_unstaged_edits_action) menu.addSeparator() menu.addAction(self.copy_path_action) menu.addAction(self.copy_relpath_action) return menu
def __init__(self, parent): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) hint = 'command-line arguments' self.input_txt = GrepLineEdit(hint, self) self.input_txt.enable_hint(True) hint = 'grep result...' self.result_txt = GrepTextView(hint, self) self.result_txt.enable_hint(True) self.edit_button = QtGui.QPushButton(self.tr('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(self.tr('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setShortcut(QtGui.QKeySequence.Refresh) self.shell_checkbox = QtGui.QCheckBox(self.tr('Shell arguments')) self.shell_checkbox.setToolTip( 'Parse arguments using a shell.\n' 'Queries with spaces will require "double quotes".') self.shell_checkbox.setChecked(False) self.close_button = QtGui.QPushButton(self.tr('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.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)'), self.input_txt_changed) self.connect(self.input_txt, SIGNAL('returnPressed()'), lambda: self.result_txt.setFocus()) qtutils.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not qtutils.apply_state(self): self.resize(666, 420)
def __init__(self, parent): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.setIndentation(0) self.add_item(N_('Staged'), hide=True) self.add_item(N_('Unmerged'), hide=True) self.add_item(N_('Modified'), hide=True) self.add_item(N_('Untracked'), hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.old_current_item = None self.expanded_items = set() self.process_selection = qtutils.add_action(self, N_('Stage / Unstage'), self._process_selection, cmds.Stage.SHORTCUT) self.revert_unstaged_edits_action = qtutils.add_action( self, N_('Revert Unstaged Edits...'), cmds.run(cmds.RevertUnstagedEdits), cmds.RevertUnstagedEdits.SHORTCUT) self.revert_unstaged_edits_action.setIcon(qtutils.icon('undo.svg')) self.launch_difftool = qtutils.add_action( self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), cmds.LaunchDifftool.SHORTCUT) self.launch_difftool.setIcon(qtutils.icon('git.svg')) self.launch_editor = qtutils.add_action(self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), cmds.LaunchEditor.SHORTCUT, 'Return', 'Enter') self.launch_editor.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action( self, cmds.OpenDefaultApp.name(), self._open_using_default_app, cmds.OpenDefaultApp.SHORTCUT) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir = qtutils.add_action( self, cmds.OpenParentDir.name(), self._open_parent_dir, cmds.OpenParentDir.SHORTCUT) self.open_parent_dir.setIcon(qtutils.open_file_icon()) self.up = qtutils.add_action(self, N_('Move Up'), self.move_up, Qt.Key_K) self.down = qtutils.add_action(self, N_('Move Down'), self.move_down, Qt.Key_J) self.copy_path_action = qtutils.add_action( self, N_('Copy Path to Clipboard'), self.copy_path, QtGui.QKeySequence.Copy) self.copy_path_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.connect(self, SIGNAL('about_to_update'), self._about_to_update) self.connect(self, SIGNAL('updated'), self._updated) self.m = main.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL('itemSelectionChanged()'), self.show_selection) self.connect(self, SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'), self.double_clicked) self.connect(self, SIGNAL('itemCollapsed(QTreeWidgetItem*)'), lambda x: self.update_column_widths()) self.connect(self, SIGNAL('itemExpanded(QTreeWidgetItem*)'), lambda x: self.update_column_widths())
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, parent=None): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.setIndentation(0) self.setDragEnabled(True) self.add_item(N_('Staged'), hide=True) self.add_item(N_('Unmerged'), hide=True) self.add_item(N_('Modified'), hide=True) self.add_item(N_('Untracked'), hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.old_current_item = None self.expanded_items = set() self.process_selection_action = qtutils.add_action(self, cmds.StageOrUnstage.name(), cmds.run(cmds.StageOrUnstage), cmds.StageOrUnstage.SHORTCUT) self.revert_unstaged_edits_action = qtutils.add_action(self, cmds.RevertUnstagedEdits.name(), cmds.run(cmds.RevertUnstagedEdits), cmds.RevertUnstagedEdits.SHORTCUT) self.revert_unstaged_edits_action.setIcon(qtutils.icon('undo.svg')) self.revert_uncommitted_edits_action = qtutils.add_action(self, cmds.RevertUncommittedEdits.name(), cmds.run(cmds.RevertUncommittedEdits), cmds.RevertUncommittedEdits.SHORTCUT) self.revert_uncommitted_edits_action.setIcon(qtutils.icon('undo.svg')) self.launch_difftool_action = qtutils.add_action(self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), cmds.LaunchDifftool.SHORTCUT) self.launch_difftool_action.setIcon(qtutils.git_icon()) self.launch_editor_action = qtutils.add_action(self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), cmds.LaunchEditor.SHORTCUT, 'Return', 'Enter') self.launch_editor_action.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action(self, cmds.OpenDefaultApp.name(), self._open_using_default_app, cmds.OpenDefaultApp.SHORTCUT) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir_action = qtutils.add_action(self, cmds.OpenParentDir.name(), self._open_parent_dir, cmds.OpenParentDir.SHORTCUT) self.open_parent_dir_action.setIcon(qtutils.open_file_icon()) self.up_action = qtutils.add_action(self, N_('Move Up'), self.move_up, Qt.Key_K) self.down_action = qtutils.add_action(self, N_('Move Down'), self.move_down, Qt.Key_J) self.copy_path_action = qtutils.add_action(self, N_('Copy Path to Clipboard'), self.copy_path, QtGui.QKeySequence.Copy) self.copy_path_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.copy_relpath_action = qtutils.add_action(self, N_('Copy Relative Path to Clipboard'), self.copy_relpath, QtGui.QKeySequence.Cut) self.copy_relpath_action.setIcon(qtutils.theme_icon('edit-copy.svg')) if cmds.MoveToTrash.AVAILABLE: self.move_to_trash_action = qtutils.add_action(self, N_('Move file(s) to trash'), self._trash_untracked_files, cmds.MoveToTrash.SHORTCUT) self.move_to_trash_action.setIcon(qtutils.discard_icon()) delete_shortcut = cmds.Delete.SHORTCUT else: self.move_to_trash_action = None delete_shortcut = cmds.Delete.ALT_SHORTCUT self.delete_untracked_files_action = qtutils.add_action(self, N_('Delete File(s)...'), self._delete_untracked_files, delete_shortcut) self.delete_untracked_files_action.setIcon(qtutils.discard_icon()) self.connect(self, SIGNAL('about_to_update'), self._about_to_update) self.connect(self, SIGNAL('updated'), self._updated) self.m = main.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL('itemSelectionChanged()'), self.show_selection) self.connect(self, SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'), self.double_clicked) self.connect(self, SIGNAL('itemCollapsed(QTreeWidgetItem*)'), lambda x: self.update_column_widths()) self.connect(self, SIGNAL('itemExpanded(QTreeWidgetItem*)'), lambda x: self.update_column_widths())
def __init__(self, parent): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) hint = N_('command-line arguments') self.input_txt = HintedLineEdit(hint, self) self.input_txt.enable_hint(True) hint = N_('grep result...') self.result_txt = GrepTextView(hint, 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.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)'), self.input_txt_changed) 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.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_button(self.close_button, self.close) qtutils.add_close_action(self) if not qtutils.apply_state(self): self.resize(666, 420)
def __init__(self, parent): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.setIndentation(0) self.add_item(N_('Staged'), hide=True) self.add_item(N_('Unmerged'), hide=True) self.add_item(N_('Modified'), hide=True) self.add_item(N_('Untracked'), hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.expanded_items = set() self.process_selection = qtutils.add_action(self, N_('Stage / Unstage'), self._process_selection, cmds.Stage.SHORTCUT) self.launch_difftool = qtutils.add_action(self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), cmds.LaunchDifftool.SHORTCUT) self.launch_difftool.setIcon(qtutils.icon('git.svg')) self.launch_editor = qtutils.add_action(self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), cmds.LaunchEditor.SHORTCUT, 'Return', 'Enter') self.launch_editor.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action(self, cmds.OpenDefaultApp.name(), self._open_using_default_app, cmds.OpenDefaultApp.SHORTCUT) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir = qtutils.add_action(self, cmds.OpenParentDir.name(), self._open_parent_dir, cmds.OpenParentDir.SHORTCUT) self.open_parent_dir.setIcon(qtutils.open_file_icon()) self.up = qtutils.add_action(self, N_('Move Up'), self.move_up, Qt.Key_K) self.down = qtutils.add_action(self, N_('Move Down'), self.move_down, Qt.Key_J) self.copy_path_action = qtutils.add_action(self, N_('Copy Path to Clipboard'), self.copy_path, QtGui.QKeySequence.Copy) self.copy_path_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.connect(self, SIGNAL('about_to_update'), self._about_to_update) self.connect(self, SIGNAL('updated'), self._updated) self.m = cola.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL('itemSelectionChanged()'), self.show_selection) self.connect(self, SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'), self.double_clicked) self.connect(self, SIGNAL('itemCollapsed(QTreeWidgetItem*)'), lambda x: self.update_column_widths()) self.connect(self, SIGNAL('itemExpanded(QTreeWidgetItem*)'), lambda x: self.update_column_widths())
def __init__(self, parent=None): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.setIndentation(0) self.setDragEnabled(True) self.add_item(N_("Staged"), hide=True) self.add_item(N_("Unmerged"), hide=True) self.add_item(N_("Modified"), hide=True) self.add_item(N_("Untracked"), hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.old_current_item = None self.expanded_items = set() self.process_selection_action = qtutils.add_action( self, cmds.StageOrUnstage.name(), cmds.run(cmds.StageOrUnstage), cmds.StageOrUnstage.SHORTCUT ) self.revert_unstaged_edits_action = qtutils.add_action( self, cmds.RevertUnstagedEdits.name(), cmds.run(cmds.RevertUnstagedEdits), cmds.RevertUnstagedEdits.SHORTCUT ) self.revert_unstaged_edits_action.setIcon(qtutils.theme_icon("edit-undo.svg")) self.launch_difftool_action = qtutils.add_action( self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), cmds.LaunchDifftool.SHORTCUT ) self.launch_difftool_action.setIcon(qtutils.git_icon()) self.launch_editor_action = qtutils.add_action( self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), cmds.LaunchEditor.SHORTCUT, "Return", "Enter" ) self.launch_editor_action.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action( self, cmds.OpenDefaultApp.name(), self._open_using_default_app, cmds.OpenDefaultApp.SHORTCUT ) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir_action = qtutils.add_action( self, cmds.OpenParentDir.name(), self._open_parent_dir, cmds.OpenParentDir.SHORTCUT ) self.open_parent_dir_action.setIcon(qtutils.open_file_icon()) self.up_action = qtutils.add_action(self, N_("Move Up"), self.move_up, Qt.Key_K) self.down_action = qtutils.add_action(self, N_("Move Down"), self.move_down, Qt.Key_J) self.copy_path_action = qtutils.add_action( self, N_("Copy Path to Clipboard"), self.copy_path, QtGui.QKeySequence.Copy ) self.copy_path_action.setIcon(qtutils.theme_icon("edit-copy.svg")) self.copy_relpath_action = qtutils.add_action( self, N_("Copy Relative Path to Clipboard"), self.copy_relpath, QtGui.QKeySequence.Cut ) self.copy_relpath_action.setIcon(qtutils.theme_icon("edit-copy.svg")) # MoveToTrash and Delete use the same shortcut. # We will only bind one of them, depending on whether or not the # MoveToTrash command is avaialble. When available, the hotkey # is bound to MoveToTrash, otherwise it is bound to Delete. if cmds.MoveToTrash.AVAILABLE: self.move_to_trash_action = qtutils.add_action( self, N_("Move file(s) to trash"), self._trash_untracked_files, cmds.MoveToTrash.SHORTCUT ) self.move_to_trash_action.setIcon(qtutils.discard_icon()) delete_shortcut = [] else: self.move_to_trash_action = None delete_shortcut = [cmds.Delete.SHORTCUT] self.delete_untracked_files_action = qtutils.add_action( self, N_("Delete File(s)..."), self._delete_untracked_files, *delete_shortcut ) self.delete_untracked_files_action.setIcon(qtutils.discard_icon()) self.connect(self, SIGNAL("about_to_update()"), self._about_to_update, Qt.QueuedConnection) self.connect(self, SIGNAL("updated()"), self._updated, Qt.QueuedConnection) self.m = main.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL("itemSelectionChanged()"), self.show_selection) self.connect(self, SIGNAL("itemDoubleClicked(QTreeWidgetItem*,int)"), self.double_clicked) self.connect(self, SIGNAL("itemCollapsed(QTreeWidgetItem*)"), lambda x: self.update_column_widths()) self.connect(self, SIGNAL("itemExpanded(QTreeWidgetItem*)"), lambda x: self.update_column_widths())
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, cmds.Edit.SHORTCUT) self.edit_action.setEnabled(False) self.refresh_action = qtutils.add_action( self, N_('Refresh'), self.search, *cmds.Refresh.SHORTCUTS) self.refresh_action.setEnabled(False) 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 = QtGui.QPushButton(N_('Edit')) self.edit_button.setIcon(qtutils.open_file_icon()) self.edit_button.setEnabled(False) qtutils.button_action(self.edit_button, self.edit_action) self.refresh_button = QtGui.QPushButton(N_('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setEnabled(False) qtutils.button_action(self.refresh_button, self.refresh_action) 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(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, Qt.Key_Down, Qt.Key_Enter, Qt.Key_Return) qtutils.add_action(self, 'Focus Input', self.focus_input, 'Ctrl+L') 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): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.add_item('Staged', 'plus.png', hide=True) self.add_item('Unmerged', 'unmerged.png', hide=True) self.add_item('Modified', 'modified.png', hide=True) self.add_item('Untracked', 'untracked.png', hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.expanded_items = set() self.process_selection = qtutils.add_action(self, 'Process Selection', self._process_selection, defs.stage_shortcut) self.launch_difftool = qtutils.add_action(self, 'Launch Diff Tool', self._launch_difftool, defs.difftool_shortcut) self.launch_difftool.setIcon(qtutils.icon('git.svg')) self.launch_editor = qtutils.add_action(self, 'Launch Editor', self._launch_editor, defs.editor_shortcut) self.launch_editor.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action(self, self.txt_default_app, self._open_using_default_app, defs.default_app_shortcut) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir = qtutils.add_action(self, self.txt_parent_dir, self._open_parent_dir, defs.parent_dir_shortcut) self.open_parent_dir.setIcon(qtutils.open_file_icon()) self.up = qtutils.add_action(self, 'Move Up', self.move_up, Qt.Key_K) self.down = qtutils.add_action(self, 'Move Down', self.move_down, Qt.Key_J) self.copy_path_action = qtutils.add_action(self, 'Copy Path to Clipboard', self.copy_path, QtGui.QKeySequence.Copy) self.copy_path_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.connect(self, SIGNAL('about_to_update'), self._about_to_update) self.connect(self, SIGNAL('updated'), self._updated) self.m = cola.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL('itemSelectionChanged()'), self.show_selection) self.connect(self, SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'), self.double_clicked) self.connect(self, SIGNAL('itemCollapsed(QTreeWidgetItem*)'), lambda x: self.update_column_widths()) self.connect(self, SIGNAL('itemExpanded(QTreeWidgetItem*)'), lambda x: self.update_column_widths())
def create_context_menu(self): """Set up the status menu for the repo status tree.""" s = self.selection() menu = QtGui.QMenu(self) selection = self.selected_indexes() if selection: category, idx = selection[0] # A header item e.g. 'Staged', 'Modified', etc. if category == self.idx_header: if idx == self.idx_staged: menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage All'), SLOT(signals.unstage_all)) return menu elif idx == self.idx_unmerged: action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Merged'), SLOT(signals.stage_unmerged)) action.setShortcut(defs.stage_shortcut) return menu elif idx == self.idx_modified: action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Modified'), SLOT(signals.stage_modified)) action.setShortcut(defs.stage_shortcut) return menu elif idx == self.idx_untracked: action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Untracked'), SLOT(signals.stage_untracked)) action.setShortcut(defs.stage_shortcut) return menu if s.staged and self.m.unstageable(): action = menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage Selected'), SLOT(signals.unstage, self.staged())) action.setShortcut(defs.stage_shortcut) if s.staged and s.staged[0] in self.m.submodules: menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(s.staged[0]))) menu.addSeparator() menu.addAction(self.copy_path_action) return menu elif s.staged: menu.addSeparator() action = menu.addAction(qtutils.git_icon(), self.tr('Launch Diff Tool'), SLOT(signals.difftool, True, self.staged())) action.setShortcut(defs.difftool_shortcut) action = menu.addAction(qtutils.options_icon(), self.tr('Launch Editor'), SLOT(signals.edit, self.staged())) action.setShortcut(defs.editor_shortcut) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), self.tr(self.txt_default_app), SLOT(signals.open_default_app, self.staged())) action.setShortcut(defs.default_app_shortcut) action = menu.addAction(qtutils.open_file_icon(), self.tr(self.txt_parent_dir), self._open_parent_dir) action.setShortcut(defs.parent_dir_shortcut) if self.m.undoable(): menu.addSeparator() menu.addAction(qtutils.icon('undo.svg'), self.tr('Revert Unstaged Edits...'), lambda: self._revert_unstaged_edits(staged=True)) menu.addSeparator() menu.addAction(self.copy_path_action) return menu if s.unmerged: menu.addAction(qtutils.git_icon(), self.tr('Launch Merge Tool'), SLOT(signals.mergetool, self.unmerged())) action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Selected'), SLOT(signals.stage, self.unstaged())) action.setShortcut(defs.stage_shortcut) menu.addSeparator() action = menu.addAction(qtutils.options_icon(), self.tr('Launch Editor'), SLOT(signals.edit, self.unmerged())) action.setShortcut(defs.editor_shortcut) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), self.tr(self.txt_default_app), SLOT(signals.open_default_app, self.unmerged())) action.setShortcut(defs.default_app_shortcut) action = menu.addAction(qtutils.open_file_icon(), self.tr(self.txt_parent_dir), self._open_parent_dir) action.setShortcut(defs.parent_dir_shortcut) menu.addSeparator() menu.addAction(self.copy_path_action) return menu modified_submodule = (s.modified and s.modified[0] in self.m.submodules) if self.m.stageable(): action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Selected'), SLOT(signals.stage, self.unstaged())) action.setShortcut(defs.stage_shortcut) menu.addSeparator() if s.modified and self.m.stageable() and not modified_submodule: action = menu.addAction(qtutils.git_icon(), self.tr('Launch Diff Tool'), SLOT(signals.difftool, False, self.modified())) action.setShortcut(defs.difftool_shortcut) if modified_submodule: menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(s.modified[0]))) elif self.unstaged(): action = menu.addAction(qtutils.options_icon(), self.tr('Launch Editor'), SLOT(signals.edit, self.unstaged())) action.setShortcut(defs.editor_shortcut) if not utils.is_win32(): menu.addSeparator() action = menu.addAction(qtutils.file_icon(), self.tr(self.txt_default_app), SLOT(signals.open_default_app, self.unstaged())) action.setShortcut(defs.default_app_shortcut) action = menu.addAction(qtutils.open_file_icon(), self.tr(self.txt_parent_dir), self._open_parent_dir) action.setShortcut(defs.parent_dir_shortcut) menu.addSeparator() if s.modified and self.m.stageable() and not modified_submodule: if self.m.undoable(): menu.addAction(qtutils.icon('undo.svg'), self.tr('Revert Unstaged Edits...'), self._revert_unstaged_edits) menu.addAction(qtutils.icon('undo.svg'), self.tr('Revert Uncommited Edits...'), self._revert_uncommitted_edits) if s.untracked: menu.addSeparator() menu.addAction(qtutils.discard_icon(), self.tr('Delete File(s)...'), self._delete_files) menu.addSeparator() menu.addAction(qtutils.icon('edit-clear.svg'), self.tr('Add to .gitignore'), SLOT(signals.ignore, map(lambda x: '/' + x, self.untracked()))) menu.addSeparator() menu.addAction(self.copy_path_action) return menu
def __init__(self, parent=None): standard.Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Find Files')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel(os.path.basename(core.getcwd()) + '/') self.input_txt = completion.GitTrackedLineEdit(hint=N_('<path> ...')) self.input_txt.hint.enable(True) self.tree = filetree.FileTree(parent=self) self.edit_button = QtGui.QPushButton(N_('Edit')) self.edit_button.setIcon(qtutils.open_file_icon()) self.edit_button.setShortcut(hotkeys.EDIT) self.open_default_button = QtGui.QPushButton( cmds.OpenDefaultApp.name()) self.open_default_button.setIcon(qtutils.open_file_icon()) self.open_default_button.setShortcut(hotkeys.PRIMARY_ACTION) self.button_group = Group(self.edit_button, self.open_default_button) self.button_group.setEnabled(False) self.refresh_button = QtGui.QPushButton(N_('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setShortcut(hotkeys.REFRESH) self.help_button = qtutils.create_button( text=N_('Help'), tooltip=N_('Show help\nShortcut: ?'), icon=qtutils.help_icon()) 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.bottom_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.edit_button, self.open_default_button, self.refresh_button, self.help_button, qtutils.STRETCH, self.close_button) self.main_layout = qtutils.vbox(defs.margin, defs.no_spacing, self.input_layout, self.tree, self.bottom_layout) self.setLayout(self.main_layout) self.setFocusProxy(self.input_txt) self.worker_thread = FindFilesThread(self) self.connect(self.worker_thread, SIGNAL('result(PyQt_PyObject)'), self.process_result, Qt.QueuedConnection) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.input_txt, SIGNAL('activated()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('down()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('enter()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('return()'), self.focus_tree) self.connect(self.tree, SIGNAL('itemSelectionChanged()'), self.tree_item_selection_changed) self.connect(self.tree, SIGNAL('up()'), self.focus_input) self.connect(self.tree, SIGNAL('space()'), self.open_default) qtutils.add_action(self, 'Focus Input', self.focus_input, hotkeys.FOCUS, hotkeys.FINDER) self.show_help_action = qtutils.add_action(self, N_('Show Help'), show_help, hotkeys.QUESTION) qtutils.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.open_default_button, self.open_default) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_button(self.help_button, show_help) 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): QtGui.QTreeWidget.__init__(self, parent) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.headerItem().setHidden(True) self.setAllColumnsShowFocus(True) self.setSortingEnabled(False) self.setUniformRowHeights(True) self.setAnimated(True) self.setRootIsDecorated(False) self.setIndentation(0) self.setDragEnabled(True) self.add_item(N_('Staged'), hide=True) self.add_item(N_('Unmerged'), hide=True) self.add_item(N_('Modified'), hide=True) self.add_item(N_('Untracked'), hide=True) # Used to restore the selection self.old_scroll = None self.old_selection = None self.old_contents = None self.old_current_item = None self.expanded_items = set() self.process_selection_action = qtutils.add_action(self, cmds.StageOrUnstage.name(), cmds.run(cmds.StageOrUnstage), hotkeys.STAGE_SELECTION) self.revert_unstaged_edits_action = qtutils.add_action(self, cmds.RevertUnstagedEdits.name(), cmds.run(cmds.RevertUnstagedEdits), hotkeys.REVERT) icon = qtutils.theme_icon('edit-undo.svg') self.revert_unstaged_edits_action.setIcon(icon) self.launch_difftool_action = qtutils.add_action(self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), hotkeys.DIFF) self.launch_difftool_action.setIcon(qtutils.git_icon()) self.launch_editor_action = qtutils.add_action(self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), hotkeys.EDIT, *hotkeys.ACCEPT) self.launch_editor_action.setIcon(qtutils.options_icon()) if not utils.is_win32(): self.open_using_default_app = qtutils.add_action(self, cmds.OpenDefaultApp.name(), self._open_using_default_app, hotkeys.PRIMARY_ACTION) self.open_using_default_app.setIcon(qtutils.file_icon()) self.open_parent_dir_action = qtutils.add_action(self, cmds.OpenParentDir.name(), self._open_parent_dir, hotkeys.SECONDARY_ACTION) self.open_parent_dir_action.setIcon(qtutils.open_file_icon()) self.up_action = qtutils.add_action(self, N_('Move Up'), self.move_up, hotkeys.MOVE_UP, hotkeys.MOVE_UP_SECONDARY) self.down_action = qtutils.add_action(self, N_('Move Down'), self.move_down, hotkeys.MOVE_DOWN, hotkeys.MOVE_DOWN_SECONDARY) self.copy_path_action = qtutils.add_action(self, N_('Copy Path to Clipboard'), self.copy_path, hotkeys.COPY) self.copy_path_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.copy_relpath_action = qtutils.add_action(self, N_('Copy Relative Path to Clipboard'), self.copy_relpath, hotkeys.CUT) self.copy_relpath_action.setIcon(qtutils.theme_icon('edit-copy.svg')) self.view_history_action = qtutils.add_action(self, N_('View History...'), self.view_history, hotkeys.HISTORY) # MoveToTrash and Delete use the same shortcut. # We will only bind one of them, depending on whether or not the # MoveToTrash command is avaialble. When available, the hotkey # is bound to MoveToTrash, otherwise it is bound to Delete. if cmds.MoveToTrash.AVAILABLE: self.move_to_trash_action = qtutils.add_action(self, N_('Move file(s) to trash'), self._trash_untracked_files, hotkeys.TRASH) self.move_to_trash_action.setIcon(qtutils.discard_icon()) delete_shortcut = hotkeys.DELETE_FILE else: self.move_to_trash_action = None delete_shortcut = hotkeys.DELETE_FILE_SECONDARY self.delete_untracked_files_action = qtutils.add_action(self, N_('Delete File(s)...'), self._delete_untracked_files, delete_shortcut) self.delete_untracked_files_action.setIcon(qtutils.discard_icon()) self.connect(self, SIGNAL('about_to_update()'), self._about_to_update, Qt.QueuedConnection) self.connect(self, SIGNAL('updated()'), self._updated, Qt.QueuedConnection) self.m = main.model() self.m.add_observer(self.m.message_about_to_update, self.about_to_update) self.m.add_observer(self.m.message_updated, self.updated) self.connect(self, SIGNAL('itemSelectionChanged()'), self.show_selection) self.connect(self, SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'), self.double_clicked) self.connect(self, SIGNAL('itemCollapsed(QTreeWidgetItem*)'), lambda x: self.update_column_widths()) self.connect(self, SIGNAL('itemExpanded(QTreeWidgetItem*)'), lambda x: self.update_column_widths())
def __init__(self, parent=None): standard.Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Find Files')) if parent is not None: self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel(os.path.basename(core.getcwd()) + '/') self.input_txt = completion.GitTrackedLineEdit(hint=N_('<path> ...')) self.input_txt.enable_hint(True) self.tree = filetree.FileTree(parent=self) 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.open_default_button = QtGui.QPushButton(cmds.OpenDefaultApp.name()) self.open_default_button.setIcon(qtutils.open_file_icon()) self.open_default_button.setEnabled(False) self.open_default_button.setShortcut(cmds.OpenDefaultApp.SHORTCUT) self.refresh_button = QtGui.QPushButton(N_('Refresh')) self.refresh_button.setIcon(qtutils.reload_icon()) self.refresh_button.setShortcut(QtGui.QKeySequence.Refresh) self.help_button = qtutils.create_button( text=N_('Help'), tooltip=N_('Show help\nShortcut: ?'), icon=qtutils.help_icon()) 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.bottom_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.edit_button, self.open_default_button, self.refresh_button, self.help_button, qtutils.STRETCH, self.close_button) self.main_layout = qtutils.vbox(defs.margin, defs.no_spacing, self.input_layout, self.tree, self.bottom_layout) self.setLayout(self.main_layout) self.setFocusProxy(self.input_txt) self.worker_thread = FindFilesThread(self) self.connect(self.worker_thread, SIGNAL('result(PyQt_PyObject)'), self.process_result, Qt.QueuedConnection) self.connect(self.input_txt, SIGNAL('textChanged(QString)'), lambda s: self.search()) self.connect(self.input_txt, SIGNAL('activated()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('down()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('enter()'), self.focus_tree) self.connect(self.input_txt, SIGNAL('return()'), self.focus_tree) self.connect(self.tree, SIGNAL('itemSelectionChanged()'), self.tree_item_selection_changed) self.connect(self.tree, SIGNAL('up()'), self.focus_input) self.connect(self.tree, SIGNAL('space()'), self.open_default) qtutils.add_action(self, 'Focus Input', self.focus_input, 'Ctrl+L', 'Ctrl+T') self.show_help_action = qtutils.add_action(self, N_('Show Help'), show_help, Qt.Key_Question) qtutils.connect_button(self.edit_button, self.edit) qtutils.connect_button(self.open_default_button, self.open_default) qtutils.connect_button(self.refresh_button, self.search) qtutils.connect_button(self.help_button, show_help) 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)