def run(self): branch = self.opts.branch revision = self.opts.revision reset = self.opts.reset checkout = self.opts.checkout track = self.opts.track model = self.opts.model results = [] status = 0 if track and '/' in revision: remote = revision.split('/', 1)[0] status, out = model.git.fetch(remote, with_status=True, with_stderr=True) self.emit(SIGNAL('command'), status, out) results.append(('fetch', status, out)) if status == 0: status, out = model.create_branch(branch, revision, force=reset, track=track) self.emit(SIGNAL('command'), status, out) results.append(('branch', status, out)) if status == 0 and checkout: status, out = model.git.checkout(branch, with_status=True, with_stderr=True) self.emit(SIGNAL('command'), status, out) results.append(('checkout', status, out)) cola.model().update_status() self.emit(SIGNAL('done'), results)
def tell_parent_model(self,*rest): """Notifies the main app's model about changed parameters""" params= ('global_cola_fontdiff', 'global_cola_fontdiff_size', 'global_cola_savewindowsettings', 'global_cola_tabwidth') for param in params: cola.model().set_param(param, self.model.param(param))
def diff_expression(): """Diff using an arbitrary expression.""" expr = choose_from_combo('Enter Diff Expression', cola.model().all_branches() + cola.model().tags) if not expr: return cola.notifier().broadcast(signals.diff_expr_mode, expr)
def review_branch(): """Diff against an arbitrary revision, branch, tag, etc.""" branch = choose_from_combo('Select Branch, Tag, or Commit-ish', cola.model().all_branches() + cola.model().tags) if not branch: return cola.notifier().broadcast(signals.review_branch_mode, branch)
def contextMenuEvent(self, event): """Create the context menu for the diff display.""" menu = QtGui.QMenu(self) s = cola.selection() if self.model.stageable(): if s.modified and s.modified[0] in cola.model().submodules: action = menu.addAction(qtutils.icon('add.svg'), cmds.Stage.name(), cmds.run(cmds.Stage, s.modified)) action.setShortcut(cmds.Stage.SHORTCUT) menu.addAction(qtutils.git_icon(), N_('Launch git-cola'), cmds.run(cmds.OpenRepo, os.path.abspath(s.modified[0]))) elif s.modified: action = menu.addAction(qtutils.icon('add.svg'), N_('Stage Section'), self.stage_section) action.setShortcut(Qt.Key_H) menu.addAction(self.action_stage_selection) menu.addSeparator() menu.addAction(qtutils.icon('undo.svg'), N_('Revert Section...'), self.revert_section) menu.addAction(self.action_revert_selection) if self.model.unstageable(): if s.staged and s.staged[0] in cola.model().submodules: action = menu.addAction(qtutils.icon('remove.svg'), cmds.Unstage.name(), cmds.do(cmds.Unstage, s.staged)) action.setShortcut(cmds.Unstage.SHORTCUT) menu.addAction(qtutils.git_icon(), N_('Launch git-cola'), cmds.do(cmds.OpenRepo, os.path.abspath(s.staged[0]))) elif s.staged: action = menu.addAction(qtutils.icon('remove.svg'), N_('Unstage Section'), self.unstage_section) action.setShortcut(Qt.Key_H) menu.addAction(self.action_unstage_selection) if self.model.stageable() or self.model.unstageable(): menu.addSeparator() menu.addAction(self.launch_editor) menu.addAction(self.launch_difftool) menu.addSeparator() action = menu.addAction(qtutils.icon('edit-copy.svg'), N_('Copy'), self.copy) action.setShortcut(QtGui.QKeySequence.Copy) action = menu.addAction(qtutils.icon('edit-select-all.svg'), N_('Select All'), self.selectAll) action.setShortcut(QtGui.QKeySequence.SelectAll) menu.exec_(self.mapToGlobal(event.pos()))
def contextMenuEvent(self, event): """Create the context menu for the diff display.""" menu = QtGui.QMenu(self) staged, modified, unmerged, untracked = cola.selection() if self.mode == self.model.mode_worktree: if modified and modified[0] in cola.model().submodules: menu.addAction(qtutils.icon('add.svg'), self.tr('Stage'), SLOT(signals.stage, modified)) menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(modified[0]))) elif modified: menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Section'), self.stage_section) menu.addAction(self.action_stage_selection) menu.addSeparator() menu.addAction(qtutils.icon('undo.svg'), self.tr('Revert Section...'), self.revert_section) menu.addAction(self.action_revert_selection) elif self.mode == self.model.mode_index: if staged and staged[0] in cola.model().submodules: menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage'), SLOT(signals.unstage, staged)) menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(staged[0]))) else: menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage Section'), self.unstage_section) menu.addAction(self.action_unstage_selection) elif self.mode == self.model.mode_branch: menu.addAction(qtutils.apply_icon(), self.tr('Apply Diff to Work Tree'), self.stage_section) menu.addAction(self.action_apply_selection) elif self.mode == self.model.mode_grep: menu.addAction(qtutils.icon('open.svg'), self.tr('Launch Editor'), lambda: guicmds.goto_grep(self.selected_line())) menu.addSeparator() menu.addAction(qtutils.icon('edit-copy.svg'), 'Copy', self.copy) menu.addAction(qtutils.icon('edit-select-all.svg'), 'Select All', self.selectAll) menu.exec_(self.mapToGlobal(event.pos()))
def contextMenuEvent(self, event): """Create the context menu for the diff display.""" menu = QtGui.QMenu(self) s = cola.selection() if self.model.stageable(): if s.modified and s.modified[0] in cola.model().submodules: action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage'), SLOT(signals.stage, s.modified)) action.setShortcut(defs.stage_shortcut) menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(s.modified[0]))) elif s.modified: action = menu.addAction(qtutils.icon('add.svg'), self.tr('Stage Section'), self.stage_section) action.setShortcut(Qt.Key_H) menu.addAction(self.action_stage_selection) menu.addSeparator() menu.addAction(qtutils.icon('undo.svg'), self.tr('Revert Section...'), self.revert_section) menu.addAction(self.action_revert_selection) if self.model.unstageable(): if s.staged and s.staged[0] in cola.model().submodules: action = menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage'), SLOT(signals.unstage, s.staged)) action.setShortcut(defs.stage_shortcut) menu.addAction(qtutils.git_icon(), self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(s.staged[0]))) elif s.staged: action = menu.addAction(qtutils.icon('remove.svg'), self.tr('Unstage Section'), self.unstage_section) action.setShortcut(Qt.Key_H) menu.addAction(self.action_unstage_selection) menu.addSeparator() action = menu.addAction(qtutils.icon('edit-copy.svg'), 'Copy', self.copy) action.setShortcut(QtGui.QKeySequence.Copy) action = menu.addAction(qtutils.icon('edit-select-all.svg'), 'Select All', self.selectAll) action.setShortcut(QtGui.QKeySequence.SelectAll) menu.exec_(self.mapToGlobal(event.pos()))
def tree_context_menu_setup(self): """Set up the status menu for the repo status tree.""" staged, modified, unmerged, untracked = self.selection() menu = QtGui.QMenu(self) enable_staging = self.model.enable_staging() if not enable_staging: menu.addAction(self.tr("Unstage Selected"), SLOT(signals.unstage, self.staged())) if staged and staged[0] in cola.model().submodules: menu.addAction(self.tr("Launch git-cola"), SLOT(signals.open_repo, os.path.abspath(staged[0]))) return menu elif staged: menu.addSeparator() menu.addAction(self.tr("Launch Editor"), SLOT(signals.edit, self.staged())) menu.addAction(self.tr("Launch Diff Tool"), SLOT(signals.difftool, True, self.staged())) menu.addSeparator() menu.addAction(self.tr("Remove Unstaged Edits"), lambda: self._remove_unstaged_edits(use_staged=True)) return menu if unmerged: if not utils.is_broken(): menu.addAction(self.tr("Launch Merge Tool"), SLOT(signals.mergetool, self.unmerged())) menu.addAction(self.tr("Launch Editor"), SLOT(signals.edit, self.unmerged())) menu.addSeparator() menu.addAction(self.tr("Stage Selected"), SLOT(signals.stage, self.unmerged())) return menu modified_submodule = modified and modified[0] in cola.model().submodules if enable_staging: menu.addAction(self.tr("Stage Selected"), SLOT(signals.stage, self.unstaged())) menu.addSeparator() if modified_submodule: menu.addAction(self.tr("Launch git-cola"), SLOT(signals.open_repo, os.path.abspath(modified[0]))) elif self.unstaged(): menu.addAction(self.tr("Launch Editor"), SLOT(signals.edit, self.unstaged())) if modified and enable_staging and not modified_submodule: menu.addAction(self.tr("Launch Diff Tool"), SLOT(signals.difftool, False, self.modified())) menu.addSeparator() menu.addAction(self.tr("Remove Unstaged Edits"), self._remove_unstaged_edits) menu.addAction(self.tr("Remove Uncommited Edits"), self._remove_uncommitted_edits) if untracked: menu.addSeparator() menu.addAction(self.tr("Delete File(s)"), SLOT(signals.delete, self.untracked())) menu.addSeparator() menu.addAction(self.tr("Add to .gitignore"), SLOT(signals.ignore, map(lambda x: "/" + x, self.untracked()))) return menu
def diff_font(): """Return the diff font string.""" qfont = QtGui.QFont() font = cola.model().cola_config('fontdiff') if font and qfont.fromString(font): return qfont family = 'Monospace' if cola.utils.is_darwin(): family = 'Monaco' qfont.setFamily(family) font = unicode(qfont.toString()) # TODO this might not be the best place for the default cola.model().set_diff_font(font) return qfont
def save_settings(self): """Save updated config variables back to git.""" params_to_save = [] params = self.model.config_params() for param in params: value = self.model.param(param) backup = self._backup_model.param(param) if value != backup: params_to_save.append(param) for param in params_to_save: self.model.save_config_param(param) # Update the main model with any changed parameters cola.model().copy_params(self.model, params_to_save) self.view.done(QtGui.QDialog.Accepted)
def diff_context_menu_setup(self): """Set up the context menu for the diff display.""" menu = QtGui.QMenu(self) staged, modified, unmerged, untracked = cola.selection() if self.mode == self.model.mode_worktree: if modified and modified[0] in cola.model().submodules: menu.addAction(self.tr('Stage'), SLOT(signals.stage, modified)) menu.addAction(self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(modified[0]))) elif modified: menu.addAction(self.tr('Stage &Hunk For Commit'), self.stage_hunk) menu.addAction(self.tr('Stage &Selected Lines'), self.stage_hunk_selection) menu.addSeparator() menu.addAction(self.tr('Undo Hunk'), self.undo_hunk) menu.addAction(self.tr('Undo Selected Lines'), self.undo_selection) elif self.mode == self.model.mode_index: if staged and staged[0] in cola.model().submodules: menu.addAction(self.tr('Unstage'), SLOT(signals.unstage, staged)) menu.addAction(self.tr('Launch git-cola'), SLOT(signals.open_repo, os.path.abspath(staged[0]))) else: menu.addAction(self.tr('Unstage &Hunk From Commit'), self.unstage_hunk) menu.addAction(self.tr('Unstage &Selected Lines'), self.unstage_hunk_selection) elif self.mode == self.model.mode_branch: menu.addAction(self.tr('Apply Diff to Work Tree'), self.stage_hunk) menu.addAction(self.tr('Apply Diff Selection to Work Tree'), self.stage_hunk_selection) elif self.mode == self.model.mode_grep: menu.addAction(self.tr('Go Here'), lambda: guicmds.goto_grep(self.selected_line())) menu.addSeparator() menu.addAction(self.tr('Copy'), self.copy_display) return menu
def load_commitmsg(parent): """Load a commit message from a file.""" filename = qtutils.open_dialog(parent, 'Load Commit Message...', cola.model().getcwd()) if filename: cola.notifier().broadcast(signals.load_commit_message, filename)
def diff_branch(): """Launches a diff against a branch.""" branch = choose_from_combo('Select Branch, Tag, or Commit-ish', ['HEAD^'] + cola.model().all_branches() + cola.model().tags) if not branch: return zfiles_str = git.instance().diff(branch, name_only=True, no_color=True, z=True).rstrip('\0') files = zfiles_str.split('\0') filename = choose_from_list('Select File', files) if not filename: return cola.notifier().broadcast(signals.branch_mode, branch, filename)
def __init__(self, parent): standard.TreeView.__init__(self, parent) self.setSortingEnabled(False) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) # Observe model updates model = cola.model() model.add_observer(model.message_updated, self.update_actions) # The non-Qt cola application model self.connect(self, SIGNAL('expanded(QModelIndex)'), self.size_columns) self.connect(self, SIGNAL('collapsed(QModelIndex)'), self.size_columns) # Sync selection before the key press event changes the model index self.connect(self, SIGNAL('indexAboutToChange()'), self.sync_selection) self.action_history =\ self._create_action( N_('View History...'), N_('View history for selected path(s).'), self.view_history, 'Shift+Ctrl+H') self.action_stage =\ self._create_action(N_('Stage Selected'), N_('Stage selected path(s) for commit.'), self.stage_selected, cmds.Stage.SHORTCUT) self.action_unstage =\ self._create_action( N_('Unstage Selected'), N_('Remove selected path(s) from the staging area.'), self.unstage_selected, 'Ctrl+U') self.action_untrack =\ self._create_action(N_('Untrack Selected'), N_('Stop tracking path(s)'), self.untrack_selected) self.action_difftool =\ self._create_action(cmds.LaunchDifftool.name(), N_('Launch git-difftool on the current path.'), run(cmds.LaunchDifftool), cmds.LaunchDifftool.SHORTCUT) self.action_difftool_predecessor =\ self._create_action(N_('Diff Against Predecessor...'), N_('Launch git-difftool against previous versions.'), self.difftool_predecessor, 'Shift+Ctrl+D') self.action_revert =\ self._create_action(N_('Revert Uncommitted Changes...'), N_('Revert changes to selected path(s).'), self.revert, 'Ctrl+Z') self.action_editor =\ self._create_action(cmds.LaunchEditor.name(), N_('Edit selected path(s).'), run(cmds.LaunchEditor), cmds.LaunchDifftool.SHORTCUT)
def open_repo(): """Spawn a new cola session.""" dirname = qtutils.opendir_dialog('Open Git Repository...', cola.model().getcwd()) if not dirname: return cola.notifier().broadcast(signals.open_repo, dirname)
def open_repo(): """Spawn a new cola session.""" dirname = qtutils.opendir_dialog(N_('Open Git Repository...'), cola.model().getcwd()) if not dirname: return cmds.do(cmds.OpenRepo, dirname)
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.add_item("Staged", "plus.png", hide=True) self.add_item("Modified", "modified.png", hide=True) self.add_item("Unmerged", "unmerged.png", hide=True) self.add_item("Untracked", "untracked.png", hide=True) # Used to restore the selection self.old_scroll = None self.expanded_items = set() self.connect(self, SIGNAL("about_to_update"), self._about_to_update) self.connect(self, SIGNAL("updated"), self._updated) self.model = cola.model() self.model.add_message_observer(self.model.message_about_to_update, self.about_to_update) self.model.add_message_observer(self.model.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("itemClicked(QTreeWidgetItem*,int)"), self.clicked)
def checkout_branch(): """Launch the 'Checkout Branch' dialog.""" branch = choose_from_combo(N_('Checkout Branch'), cola.model().local_branches) if not branch: return cmds.do(cmds.CheckoutBranch, branch)
def local_merge(): """Provides a dialog for merging branches""" model = cola.model() view = MergeView(model, qtutils.active_window()) view.show() view.raise_() return view
def branch_delete(): """Launch the 'Delete Branch' dialog.""" branch = choose_from_combo('Delete Branch', cola.model().local_branches) if not branch: return cola.notifier().broadcast(signals.delete_branch, branch)
def sync_selection(self): """Push selection into the selection model.""" staged = [] modified = [] unmerged = [] untracked = [] paths = self.selected_paths() model = cola.model() model_staged = set(model.staged) model_modified = set(model.modified) model_unmerged = set(model.unmerged) model_untracked = set(model.untracked) for path in paths: if path in model_unmerged: unmerged.append(path) elif path in model_untracked: untracked.append(path) elif path in model_staged: staged.append(path) elif path in model_modified: modified.append(path) # Push the new selection into the model. cola.selection_model().set_selection(staged, modified, unmerged, untracked) return paths
def local_merge(): """Provides a dialog for merging branches""" model = cola.model().clone() parent = QtGui.QApplication.instance().activeWindow() view = MergeView(parent) ctl = MergeController(model, view) view.show()
def selected_modified_paths(self, selection=None): """Return selected modified paths.""" if not selection: selection = self.selected_paths() model = cola.model() modified = cola.utils.add_parents(set(model.modified)) return [p for p in selection if p in modified]
def status(self): """Return the status for the entry's path.""" model = cola.model() unmerged = utils.add_parents(set(model.unmerged)) modified = utils.add_parents(set(model.modified)) staged = utils.add_parents(set(model.staged)) untracked = utils.add_parents(set(model.untracked)) upstream_changed = utils.add_parents(set(model.upstream_changed)) if self.path in unmerged: return (resources.icon('sigil-unmerged.png'), qtutils.tr('Unmerged')) if self.path in modified and self.path in staged: return (resources.icon('sigil-partial.png'), qtutils.tr('Partially Staged')) if self.path in modified: return (resources.icon('sigil-modified.png'), qtutils.tr('Modified')) if self.path in staged: return (resources.icon('sigil-staged.png'), qtutils.tr('Staged')) if self.path in upstream_changed: return (resources.icon('sigil-upstream.png'), qtutils.tr('Changed Upstream')) if self.path in untracked: return (None, '?') return (None, '')
def __init__(self, parent): self.matched_text = None QtGui.QStandardItemModel.__init__(self, parent) self.cmodel = cola.model() self.update_thread = UpdateGitLogCompletionModelThread(self) self.connect(self.update_thread, SIGNAL('items_gathered'), self.apply_matches)
def branch_delete(): """Launch the 'Delete Branch' dialog.""" branch = choose_from_combo(N_('Delete Branch'), cola.model().local_branches) if not branch: return cmds.do(cmds.DeleteBranch, branch)
def checkout_branch(): """Launch the 'Checkout Branch' dialog.""" branch = choose_from_combo('Checkout Branch', cola.model().local_branches) if not branch: return cola.notifier().broadcast(signals.checkout_branch, branch)
def create_new_branch(revision=''): """Launches a dialog for creating a new branch""" model = serializer.clone(cola.model()) parent = QtGui.QApplication.instance().activeWindow() view = createbranch.CreateBranchView(parent) ctl = CreateBranchController(model, view) model.set_revision(revision) view.show()
def __init__(self, view=None): QtCore.QObject.__init__(self, view) self.model = cola.model() self.view = view self.updated = set() self.connect(view, SIGNAL("history(QStringList)"), self.view_history) self.connect(view, SIGNAL("expanded(QModelIndex)"), self.query_model) self.connect(view, SIGNAL("difftool_predecessor"), self.difftool_predecessor)
def select_commits(title, revs, summaries, multiselect=True): """Use the SelectCommitsView to select commits from a list.""" model = cola.model() app = QtGui.QApplication.instance() parent = app.activeWindow() view = SelectCommitsView(parent, app.tr(title), multiselect=multiselect) ctl = SelectCommitsController(model, view, revs, summaries) return ctl.select_commits()
def data(self, key): """ Return git data for a path. Supported keys are 'date', 'message', and 'author' """ if not self._data: log_line = cola.model().git.log('-1', '--', self.path, M=True, all=False, no_color=True, pretty='format:%ar%x01%s%x01%an') if log_line: log_line = core.decode(log_line) date, message, author = log_line.split(chr(0x01), 2) self._data['date'] = date self._data['message'] = message self._data['author'] = author else: self._data['date'] = self.date() self._data['message'] = '-' self._data['author'] = self._cfg.get('user.name', 'unknown') return self._data[key]
def selected_staged_paths(self, selection=None): """Return selected staged paths.""" if not selection: selection = self.selected_paths() staged = utils.add_parents(set(cola.model().staged)) return [p for p in selection if p in staged]
def local_merge(): """Provides a dialog for merging branches""" model = cola.model() view = MergeView(model, qtutils.active_window()) view.show() view.raise_() return view def abort_merge(): """Prompts before aborting a merge in progress """ title = qtutils.tr('Abort Merge...') txt = ('Aborting the current merge will cause ' '*ALL* uncommitted changes to be lost.\n' 'Recovering uncommitted changes is not possible.') info_txt = 'Aborting the current merge?' ok_txt = 'Abort Merge' if qtutils.confirm(title, txt, info_txt, ok_txt, default=False, icon=qtutils.icon('undo.svg')): gitcmds.abort_merge() if __name__ == '__main__': from cola import app app = app.ColaApplication([]) view = local_merge() cola.model().update_status() app.exec_()
def _initialize(self): """Iterate over the cola model and create GitRepoItems.""" for path in cola.model().everything(): self.add_file(path)
def _get_paths(self): """Return paths of interest; e.g. paths with a status.""" model = cola.model() paths = set(model.staged + model.unstaged) return cola.utils.add_parents(paths)
def __init__(self, name): Command.__init__(self) self.name = name self.model = cola.model()
def load_commitmsg(): """Load a commit message from a file.""" filename = qtutils.open_dialog(N_('Load Commit Message'), cola.model().getcwd()) if filename: cmds.do(cmds.LoadCommitMessage, filename)
def __init__(self, parent): CompletionModel.__init__(self, parent) self.cola_model = model = cola.model() msg = model.message_updated model.add_observer(msg, self.emit_updated)
def __init__(self): observable.Observable.__init__(self) self.model = cola.model() # Relay the "updated" message msg = self.model.message_updated self.model.add_observer(msg, self.notify_updated)
def __init__(self, action_name): Command.__init__(self) self.action_name = action_name self.model = cola.model()
def main(context): """Parses the command-line arguments and starts git-cola """ setup_environment() opts, args, context = parse_args(context) repo = process_args(opts, args) # Allow Ctrl-C to exit signal.signal(signal.SIGINT, signal.SIG_DFL) # Initialize the app app = ColaApplication(sys.argv) # Ensure that we're working in a valid git repository. # If not, try to find one. When found, chdir there. model = cola.model() valid = model.set_worktree(repo) and not opts.prompt while not valid: startup_dlg = startup.StartupDialog(app.activeWindow()) gitdir = startup_dlg.find_git_repo() if not gitdir: sys.exit(-1) valid = model.set_worktree(gitdir) # Finally, go to the root of the git repo os.chdir(model.git.worktree()) # Show the GUI if context == 'archive': from cola.widgets.archive import GitArchiveDialog model.update_status() view = GitArchiveDialog(model.currentbranch) elif context == 'branch': from cola.widgets.createbranch import create_new_branch view = create_new_branch() elif context in ('git-dag', 'dag'): from cola.dag import git_dag view = git_dag(model, opts=opts, args=args) elif context in ('classic', 'browse'): from cola.classic import cola_classic view = cola_classic(update=False) elif context == 'config': from cola.prefs import preferences view = preferences() elif context == 'diff': from cola.difftool import diff_expression while args and args[0] == '--': args.pop(0) expr = subprocess.list2cmdline(map(core.decode, args)) view = diff_expression(None, expr, create_widget=True) elif context == 'fetch': # TODO: the calls to update_status() can be done asynchronously # by hooking into the message_updated notification. from cola.widgets import remote model.update_status() view = remote.fetch() elif context == 'grep': from cola.widgets import grep view = grep.run_grep(parent=None) elif context == 'merge': from cola.merge import view model.update_status() view = view.MergeView(model, parent=None) elif context == 'pull': from cola.widgets import remote model.update_status() view = remote.pull() elif context == 'push': from cola.widgets import remote model.update_status() view = remote.push() elif context == 'remote': from cola.widgets import editremotes view = editremotes.edit() elif context == 'search': from cola.widgets.search import search view = search() elif context == 'stash': from cola.stash import stash model.update_status() view = stash() elif context == 'tag': from cola.widgets.createtag import create_tag view = create_tag() else: view = MainView(model, qtutils.active_window()) # Make sure that we start out on top view.show() view.raise_() # Scan for the first time task = _start_update_thread(model) # Start the inotify thread inotify.start() msg_timer = QtCore.QTimer() msg_timer.setSingleShot(True) msg_timer.connect(msg_timer, SIGNAL('timeout()'), _send_msg) msg_timer.start(0) # Start the event loop result = app.exec_() # All done, cleanup inotify.stop() QtCore.QThreadPool.globalInstance().waitForDone() pattern = utils.tmp_file_pattern() for filename in glob.glob(pattern): os.unlink(filename) sys.exit(result) return view, task
def __init__(self, parent): QtGui.QTreeWidget.__init__(self, parent) self.setCursor(Qt.PointingHandCursor) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.setItemDelegateForColumn(0, ItemDelegate(self)) 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('Staged', hide=True) self.add_item('Unmerged', hide=True) self.add_item('Modified', hide=True) self.add_item('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, 'Stage/Unstage', self._process_selection, cmds.Stage.SHORTCUT) self.launch_difftool = qtutils.add_action( self, self.tr(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, self.tr(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, self.tr(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, self.tr(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, '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 load_commitmsg(): """Load a commit message from a file.""" filename = qtutils.open_dialog('Load Commit Message...', cola.model().getcwd()) if filename: cola.notifier().broadcast(signals.load_commit_message, filename)
def has_stashable_changes(self): model = cola.model() return bool(model.modified + model.staged)
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())