def create_branch(self): """Creates a branch; called by the "Create Branch" button""" self.getopts() revision = self.opts.revision branch = self.opts.branch no_update = self.no_update_radio.isChecked() ffwd_only = self.ffwd_only_radio.isChecked() existing_branches = gitcmds.branch_list() check_branch = False if not branch or not revision: qtutils.critical(N_('Missing Data'), N_('Please provide both a branch ' 'name and revision expression.')) return if branch in existing_branches: if no_update: msg = N_('Branch "%s" already exists.') % branch qtutils.critical(N_('Branch Exists'), msg) return # Whether we should prompt the user for lost commits commits = gitcmds.rev_list_range(revision, branch) check_branch = bool(commits) if check_branch: msg = (N_('Resetting "%(branch)s" to "%(revision)s" ' 'will lose commits.') % dict(branch=branch, revision=revision)) if ffwd_only: qtutils.critical(N_('Branch Exists'), msg) return lines = [msg] for idx, commit in enumerate(commits): subject = commit[1][0:min(len(commit[1]),16)] if len(subject) < len(commit[1]): subject += '...' lines.append('\t' + commit[0][:8] +'\t' + subject) if idx >= 5: skip = len(commits) - 5 lines.append('\t(%s)' % (N_('%d skipped') % skip)) break line = N_('Recovering lost commits may not be easy.') lines.append(line) if not qtutils.confirm(N_('Reset Branch?'), '\n'.join(lines), (N_('Reset "%(branch)s" to "%(revision)s"?') % dict(branch=branch, revision=revision)), N_('Reset Branch'), default=False, icon=icons.undo()): return self.setEnabled(False) self.progress.setEnabled(True) QtGui.QApplication.setOverrideCursor(Qt.WaitCursor) # Show a nice progress bar self.progress.setLabelText(N_('Updating...')) self.progress.show() self.thread.start()
def abort_merge(): """Prompts before aborting a merge in progress """ title = N_('Abort Merge...') txt = N_('Aborting the current merge will cause ' '*ALL* uncommitted changes to be lost.\n' 'Recovering uncommitted changes is not possible.') info_txt = N_('Aborting the current merge?') ok_txt = N_('Abort Merge') if qtutils.confirm(title, txt, info_txt, ok_txt, default=False, icon=icons.undo()): gitcmds.abort_merge()
def revert_selection(self): """Destructively revert selected lines or hunk from a worktree file.""" if self.has_selection(): title = N_('Revert Selected Lines?') ok_text = N_('Revert Selected Lines') else: title = N_('Revert Diff Hunk?') ok_text = N_('Revert Diff Hunk') if not qtutils.confirm(title, N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), ok_text, default=True, icon=icons.undo()): return self.process_diff_selection(reverse=True, apply_to_worktree=True)
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, titlebar): DiffTextEdit.__init__(self, parent) self.model = model = main.model() # "Diff Options" tool menu self.diff_ignore_space_at_eol_action = add_action( self, N_('Ignore changes in whitespace at EOL'), self._update_diff_opts) self.diff_ignore_space_at_eol_action.setCheckable(True) self.diff_ignore_space_change_action = add_action( self, N_('Ignore changes in amount of whitespace'), self._update_diff_opts) self.diff_ignore_space_change_action.setCheckable(True) self.diff_ignore_all_space_action = add_action( self, N_('Ignore all whitespace'), self._update_diff_opts) self.diff_ignore_all_space_action.setCheckable(True) self.diff_function_context_action = add_action( self, N_('Show whole surrounding functions of changes'), self._update_diff_opts) self.diff_function_context_action.setCheckable(True) self.diffopts_button = create_action_button( tooltip=N_('Diff Options'), icon=icons.configure()) self.diffopts_menu = create_menu(N_('Diff Options'), self.diffopts_button) self.diffopts_menu.addAction(self.diff_ignore_space_at_eol_action) self.diffopts_menu.addAction(self.diff_ignore_space_change_action) self.diffopts_menu.addAction(self.diff_ignore_all_space_action) self.diffopts_menu.addAction(self.diff_function_context_action) self.diffopts_button.setMenu(self.diffopts_menu) qtutils.hide_button_menu_indicator(self.diffopts_button) titlebar.add_corner_widget(self.diffopts_button) self.action_apply_selection = qtutils.add_action( self, 'Apply', self.apply_selection, hotkeys.STAGE_DIFF) self.action_revert_selection = qtutils.add_action( self, 'Revert', self.revert_selection, hotkeys.REVERT) self.action_revert_selection.setIcon(icons.undo()) self.launch_editor = actions.launch_editor(self, 'Return', 'Enter') self.launch_difftool = actions.launch_difftool(self) self.stage_or_unstage = actions.stage_or_unstage(self) # Emit up/down signals so that they can be routed by the main widget self.move_down = actions.move_down(self) self.move_up = actions.move_up(self) model.add_observer(model.message_diff_text_changed, self._emit_text) self.selection_model = selection_model = selection.selection_model() selection_model.add_observer(selection_model.message_selection_changed, self._update) self.connect(self, SIGNAL('update()'), self._update_callback, Qt.QueuedConnection) self.connect(self, SIGNAL('set_text(PyQt_PyObject)'), self.setPlainText)
def __init__(self, parent, titlebar): DiffTextEdit.__init__(self, parent) self.model = model = main.model() # "Diff Options" tool menu self.diff_ignore_space_at_eol_action = add_action( self, N_('Ignore changes in whitespace at EOL'), self._update_diff_opts) self.diff_ignore_space_at_eol_action.setCheckable(True) self.diff_ignore_space_change_action = add_action( self, N_('Ignore changes in amount of whitespace'), self._update_diff_opts) self.diff_ignore_space_change_action.setCheckable(True) self.diff_ignore_all_space_action = add_action( self, N_('Ignore all whitespace'), self._update_diff_opts) self.diff_ignore_all_space_action.setCheckable(True) self.diff_function_context_action = add_action( self, N_('Show whole surrounding functions of changes'), self._update_diff_opts) self.diff_function_context_action.setCheckable(True) self.diffopts_button = create_action_button(tooltip=N_('Diff Options'), icon=icons.configure()) self.diffopts_menu = create_menu(N_('Diff Options'), self.diffopts_button) self.diffopts_menu.addAction(self.diff_ignore_space_at_eol_action) self.diffopts_menu.addAction(self.diff_ignore_space_change_action) self.diffopts_menu.addAction(self.diff_ignore_all_space_action) self.diffopts_menu.addAction(self.diff_function_context_action) self.diffopts_button.setMenu(self.diffopts_menu) qtutils.hide_button_menu_indicator(self.diffopts_button) titlebar.add_corner_widget(self.diffopts_button) self.action_apply_selection = qtutils.add_action( self, 'Apply', self.apply_selection, hotkeys.STAGE_DIFF) self.action_revert_selection = qtutils.add_action( self, 'Revert', self.revert_selection, hotkeys.REVERT) self.action_revert_selection.setIcon(icons.undo()) self.launch_editor = actions.launch_editor(self, 'Return', 'Enter') self.launch_difftool = actions.launch_difftool(self) self.stage_or_unstage = actions.stage_or_unstage(self) # Emit up/down signals so that they can be routed by the main widget self.move_down = actions.move_down(self) self.move_up = actions.move_up(self) model.add_observer(model.message_diff_text_changed, self._emit_text) self.selection_model = selection_model = selection.selection_model() selection_model.add_observer(selection_model.message_selection_changed, self._update) self.connect(self, SIGNAL('update()'), self._update_callback, Qt.QueuedConnection) self.connect(self, SIGNAL('set_text(PyQt_PyObject)'), self.setPlainText)