def _create_unmerged_context_menu(self, menu, s): menu.addAction(self.launch_difftool_action) action = menu.addAction(icons.add(), 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() open_default = cmds.run(cmds.OpenDefaultApp, self.unmerged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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) menu.addAction(self.view_blame_action) return menu
def _create_unmerged_context_menu(self, menu, s): menu.addAction(self.launch_difftool_action) action = menu.addAction(icons.add(), 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() open_default = cmds.run(cmds.OpenDefaultApp, self.unmerged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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_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(icons.remove(), 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() open_default = cmds.run(cmds.OpenDefaultApp, self.staged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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) menu.addAction(self.view_blame_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(icons.add(), N_('Stage Selected'), cmds.run(cmds.Stage, self.unstaged())) action.setShortcut(hotkeys.STAGE_SELECTION) # Do all of the selected items exist? all_exist = all(i not 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() open_default = cmds.run(cmds.OpenDefaultApp, self.unstaged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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(icons.edit(), N_('Add to .gitignore'), cmds.run(cmds.Ignore, [('/' + x) for x in 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) menu.addAction(self.view_blame_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(icons.add(), 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() open_default = cmds.run(cmds.OpenDefaultApp, self.unstaged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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( icons.edit(), 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) menu.addAction(self.view_blame_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(icons.remove(), 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() open_default = cmds.run(cmds.OpenDefaultApp, self.staged()) action = menu.addAction(icons.default_app(), cmds.OpenDefaultApp.name(), open_default) action.setShortcut(hotkeys.PRIMARY_ACTION) action = menu.addAction(icons.folder(), 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) menu.addAction(self.view_blame_action) return menu
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) ok = icons.ok() compare = icons.compare() question = icons.question() self.add_toplevel_item(N_('Staged'), ok, hide=True) self.add_toplevel_item(N_('Unmerged'), compare, hide=True) self.add_toplevel_item(N_('Modified'), compare, hide=True) self.add_toplevel_item(N_('Untracked'), question, 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) self.revert_unstaged_edits_action.setIcon(icons.undo()) self.launch_difftool_action = qtutils.add_action( self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), hotkeys.DIFF) self.launch_difftool_action.setIcon(icons.diff()) self.launch_editor_action = qtutils.add_action( self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), hotkeys.EDIT, *hotkeys.ACCEPT) self.launch_editor_action.setIcon(icons.edit()) 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(icons.default_app()) 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(icons.folder()) 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(icons.copy()) self.copy_relpath_action = qtutils.add_action( self, N_('Copy Relative Path to Clipboard'), self.copy_relpath, hotkeys.CUT) self.copy_relpath_action.setIcon(icons.copy()) 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(icons.discard()) 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(icons.discard()) 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): 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.setAutoScroll(False) ok = icons.ok() compare = icons.compare() question = icons.question() self.add_toplevel_item(N_('Staged'), ok, hide=True) self.add_toplevel_item(N_('Unmerged'), compare, hide=True) self.add_toplevel_item(N_('Modified'), compare, hide=True) self.add_toplevel_item(N_('Untracked'), question, hide=True) # Used to restore the selection self.old_vscroll = None self.old_hscroll = 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) self.revert_unstaged_edits_action.setIcon(icons.undo()) self.launch_difftool_action = qtutils.add_action( self, cmds.LaunchDifftool.name(), cmds.run(cmds.LaunchDifftool), hotkeys.DIFF) self.launch_difftool_action.setIcon(icons.diff()) self.launch_editor_action = qtutils.add_action( self, cmds.LaunchEditor.name(), cmds.run(cmds.LaunchEditor), hotkeys.EDIT, *hotkeys.ACCEPT) self.launch_editor_action.setIcon(icons.edit()) 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(icons.default_app()) 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(icons.folder()) 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(icons.copy()) self.copy_relpath_action = qtutils.add_action( self, N_('Copy Relative Path to Clipboard'), self.copy_relpath, hotkeys.CUT) self.copy_relpath_action.setIcon(icons.copy()) self.view_history_action = qtutils.add_action( self, N_('View History...'), self.view_history, hotkeys.HISTORY) self.view_blame_action = qtutils.add_action( self, N_('Blame...'), self.view_blame, hotkeys.BLAME) # 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(icons.discard()) 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(icons.discard()) 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.hint.enable(True) self.tree = filetree.FileTree(parent=self) self.edit_button = qtutils.edit_button() self.edit_button.setShortcut(hotkeys.EDIT) text = cmds.OpenDefaultApp.name() icon = icons.default_app() self.open_default_button = qtutils.create_button(text=text, icon=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 = qtutils.refresh_button() self.refresh_button.setShortcut(hotkeys.REFRESH) self.help_button = qtutils.create_button( text=N_('Help'), tooltip=N_('Show help\nShortcut: ?'), icon=icons.question()) self.close_button = qtutils.close_button() 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)