def select_commits(title, revs, summaries, multiselect=True): """Use the SelectCommitsDialog to select commits from a list.""" model = Model(revs, summaries) parent = qtutils.active_window() dialog = SelectCommitsDialog(model, parent, qtutils.tr(title), multiselect=multiselect) return dialog.select_commits()
def diff_revision(): """Diff an arbitrary revision against the worktree""" ref = choose_ref('Select Revision to Diff', 'Diff', default='HEAD^') if not ref: return difftool.diff_commits(qtutils.active_window(), ref, None)
def create_tag(name='', ref='', sign=False): """Entry point for external callers.""" view = new_create_tag(name=name, ref=ref, sign=sign, parent=qtutils.active_window()) view.show() view.raise_() return view
def review_branch(): """Diff against an arbitrary revision, branch, tag, etc.""" branch = choose_ref(N_('Select Branch to Review'), N_('Review')) if not branch: return merge_base = gitcmds.merge_base_parent(branch) difftool.diff_commits(qtutils.active_window(), merge_base, branch)
def select_commits(title, revs, summaries, multiselect=True): """Use the SelectCommitsView to select commits from a list.""" model = MainModel() parent = qtutils.active_window() view = SelectCommitsView(parent, qtutils.tr(title), multiselect=multiselect) ctl = SelectCommitsController(model, view, revs, summaries) return ctl.select_commits()
def show_shortcuts(): try: from PyQt4 import QtWebKit except ImportError: # redhat disabled QtWebKit in their qt build but don't punish the # users qtutils.critical(N_('This PyQt4 does not include QtWebKit.\n' 'The keyboard shortcuts feature is unavailable.')) return try: html = show_shortcuts.html except AttributeError: hotkeys_html = resources.doc(N_('hotkeys.html')) html = show_shortcuts.html = core.read(hotkeys_html) try: widget = show_shortcuts.widget except AttributeError: parent = qtutils.active_window() widget = show_shortcuts.widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(N_('Shortcuts')) web = QtWebKit.QWebView(parent) web.setHtml(html) layout = qtutils.hbox(defs.no_margin, defs.spacing, web) widget.setLayout(layout) widget.resize(800, min(parent.height(), 600)) qtutils.add_action(widget, N_('Close'), widget.accept, hotkeys.QUESTION, *hotkeys.ACCEPT) widget.show() return widget
def local_merge(): """Provides a dialog for merging branches""" model = main.model() view = MergeView(model, qtutils.active_window()) view.show() view.raise_() return view
def branch_compare(): """Launches a dialog for comparing a pair of branches""" model = BranchCompareModel() view = BranchCompareView(qtutils.active_window()) ctl = BranchCompareController(model, view) view.show() return ctl
def compare(filename=None): """Launches a dialog for comparing a pair of commits""" model = CompareModel() view = CompareView(qtutils.active_window()) ctl = CompareController(model, view, filename) view.show() return ctl
def show_shortcuts(): try: from PyQt4 import QtWebKit except ImportError: # redhat disabled QtWebKit in their qt build but don't punish the # users qtutils.critical( N_('This PyQt4 does not include QtWebKit.\n' 'The keyboard shortcuts feature is unavailable.')) return try: html = show_shortcuts.html except AttributeError: hotkeys_html = resources.doc(N_('hotkeys.html')) html = show_shortcuts.html = core.read(hotkeys_html) try: widget = show_shortcuts.widget except AttributeError: parent = qtutils.active_window() widget = show_shortcuts.widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(N_('Shortcuts')) web = QtWebKit.QWebView(parent) web.setHtml(html) layout = qtutils.hbox(defs.no_margin, defs.spacing, web) widget.setLayout(layout) widget.resize(800, min(parent.height(), 600)) qtutils.add_action(widget, N_('Close'), widget.accept, hotkeys.QUESTION, *hotkeys.ACCEPT) widget.show() return widget
def local_merge(): """Provides a dialog for merging branches""" model = MergeModel() view = MergeView(model, qtutils.active_window()) ctl = MergeController(model, view) view.show() view.raise_() return ctl
def grep(): """Prompt and use 'git grep' to find the content.""" from cola.widgets.grep import run_grep widget = run_grep(parent=qtutils.active_window()) widget.show() widget.raise_() return widget
def stash(): """Launches a stash dialog using the provided model + view """ model = StashModel() view = StashView(model, qtutils.active_window()) view.show() view.raise_() return view
def stash(): """Launches a stash dialog using the provided model + view """ model = StashModel() view = StashView(model, qtutils.active_window()) ctl = StashController(model, view) view.show() return ctl
def diff_expression(): """Diff using an arbitrary expression.""" tracked = gitcmds.tracked_branch() current = gitcmds.current_branch() if tracked and current: ref = tracked + '..' + current else: ref = 'origin/master..' difftool.diff_expression(qtutils.active_window(), ref)
def create_tag(revision=''): """Entry point for external callers.""" model = tag.TagModel() if revision: model.revision = [revision] view = createtag.CreateTag(qtutils.active_window()) ctl = CreateTagController(model, view) view.show() return ctl
def run_command(title, command): """Show a command widget""" view = GitCommandWidget(title, qtutils.active_window()) view.set_command(command) view.show() view.raise_() view.run() view.exec_() return (view.exitstatus, view.out, view.err)
def create_new_branch(revision=''): """Launches a dialog for creating a new branch""" model = main.MainModel() model.update_status() view = CreateBranchDialog(model, qtutils.active_window()) if revision: view.set_revision(revision) view.show() return view
def run_command(title, command): """Show a command widget""" view = GitCommandWidget(qtutils.active_window()) view.setWindowModality(QtCore.Qt.ApplicationModal) view.set_command(command) view.setWindowTitle(title) view.show() view.raise_() view.run() view.exec_() return (view.exitstatus, view.out, view.err)
def confirm_config_action(name, opts): dlg = ActionDialog(qtutils.active_window(), name, opts) dlg.show() if dlg.exec_() != QtGui.QDialog.Accepted: return False rev = unicode(dlg.revision()) if rev: opts['revision'] = rev args = unicode(dlg.args()) if args: opts['args'] = args return True
def git_dag(model, opts=None, args=None): """Return a pre-populated git DAG widget.""" dag = DAG(model.currentbranch, 1000) dag.set_options(opts, args) view = DAGView(model, dag, qtutils.active_window()) ctl = DAGController(dag, view) view.show() view.raise_() if dag.ref: view.thread.start(QtCore.QThread.LowPriority) return ctl
def confirm_config_action(name, opts): dlg = ActionDialog(qtutils.active_window(), name, opts) dlg.show() if dlg.exec_() != QtGui.QDialog.Accepted: return False rev = ustr(dlg.revision()) if rev: opts['revision'] = rev args = ustr(dlg.args()) if args: opts['args'] = args return True
def diff_expression(): """Diff using an arbitrary expression.""" tracked = gitcmds.tracked_branch() current = gitcmds.current_branch() if tracked and current: default = tracked + '..' + current else: default = 'origin/master..' ref = choose_ref('Enter Diff Expression', 'Diff', default=default) if not ref: return difftool.diff_expression(qtutils.active_window(), ref)
def select_file(ref): parent = qtutils.active_window() model = BrowseModel(ref) dlg = BrowseDialog(model, select_file=True, parent=parent) dlg_model = GitTreeModel(ref, dlg) dlg.setModel(dlg_model) dlg.setWindowTitle(N_('Select file from "%s"') % model.ref) dlg.resize(parent.width()*3//4, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return model.filename
def select_file(ref): parent = qtutils.active_window() model = BrowseModel(ref) dlg = BrowseDialog(model, select_file=True, parent=parent) dlg_model = GitTreeModel(ref, dlg) dlg.setModel(dlg_model) dlg.setWindowTitle(N_('Select file from "%s"') % model.ref) dlg.resize(parent.width() * 3 // 4, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return model.filename
def create_new_branch(revision=''): """Launches a dialog for creating a new branch""" model = MainModel() model.update_status() model.revision = revision model.local_branch = '' view = createbranch.CreateBranchView(qtutils.active_window()) ctl = CreateBranchController(model, view) model.set_revision(revision) view.show() return ctl
def browse(ref): parent = qtutils.active_window() model = BrowseModel(ref) dlg = BrowseDialog(model, parent=parent) dlg_model = GitTreeModel(ref, dlg) dlg.setModel(dlg_model) dlg.setWindowTitle('Browsing %s' % model.ref) ctrl = BrowseDialogController(model, dlg) dlg.resize(parent.width()*3/4, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return ctrl
def run(RemoteDialog): """Launches fetch/push/pull dialogs.""" # Copy global stuff over to speedup startup model = main.MainModel() global_model = main.model() model.currentbranch = global_model.currentbranch model.local_branches = global_model.local_branches model.remote_branches = global_model.remote_branches model.tags = global_model.tags model.remotes = global_model.remotes parent = qtutils.active_window() view = RemoteDialog(model, parent=parent) view.show() return view
def select_file_from_list(file_list, title=N_('Select File')): parent = qtutils.active_window() model = BrowseModel(None) dlg = BrowseDialog(model, select_file=True, parent=parent) dlg_model = GitFileTreeModel(dlg) dlg_model.add_files(file_list) dlg.setModel(dlg_model) dlg.expandAll() dlg.setWindowTitle(title) dlg.resize(parent.width() * 3 // 4, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return model.filename
def select_file_from_list(file_list, title=N_('Select File')): parent = qtutils.active_window() model = BrowseModel(None) dlg = BrowseDialog(model, select_file=True, parent=parent) dlg_model = GitFileTreeModel(dlg) dlg_model.add_files(file_list) dlg.setModel(dlg_model) dlg.expandAll() dlg.setWindowTitle(title) dlg.resize(parent.width()*3//4, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return model.filename
def browse(ref): parent = qtutils.active_window() model = BrowseModel(ref) dlg = BrowseDialog(model, parent=parent) dlg_model = GitTreeModel(ref, dlg) dlg.setModel(dlg_model) dlg.setWindowTitle(N_('Browsing %s') % model.ref) if hasattr(parent, 'width'): dlg.resize(parent.width()*3//4, 333) else: dlg.resize(420, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return dlg
def browse(ref): parent = qtutils.active_window() model = BrowseModel(ref) dlg = BrowseDialog(model, parent=parent) dlg_model = GitTreeModel(ref, dlg) dlg.setModel(dlg_model) dlg.setWindowTitle(N_('Browsing %s') % model.ref) if hasattr(parent, 'width'): dlg.resize(parent.width() * 3 // 4, 333) else: dlg.resize(420, 333) dlg.show() dlg.raise_() if dlg.exec_() != dlg.Accepted: return None return dlg
def text_dialog(text, title): """Show a wall of text in a dialog""" parent = qtutils.active_window() label = QtGui.QLabel(parent) label.setFont(qtutils.diff_font()) label.setText(text) label.setTextInteractionFlags(Qt.NoTextInteraction) widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(title) layout = qtutils.hbox(defs.margin, defs.spacing, label) widget.setLayout(layout) qtutils.add_action(widget, N_("Close"), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def text_dialog(text, title): """Show a wall of text in a dialog""" parent = qtutils.active_window() label = QtGui.QLabel(parent) label.setFont(qtutils.diff_font()) label.setText(text) label.setTextInteractionFlags(Qt.NoTextInteraction) widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) widget.setWindowTitle(title) layout = qtutils.hbox(defs.margin, defs.spacing, label) widget.setLayout(layout) qtutils.add_action(widget, N_('Close'), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def show_shortcuts(): try: from PyQt4 import QtWebKit except ImportError: # redhat disabled QtWebKit in their qt build but don't punish the # users qtutils.critical(N_('This PyQt4 does not include QtWebKit.\n' 'The keyboard shortcuts feature is unavailable.')) return try: html = show_shortcuts.html except AttributeError: hotkeys = resources.doc(N_('hotkeys.html')) html = show_shortcuts.html = utils.slurp(hotkeys) try: widget = show_shortcuts.widget except AttributeError: parent = qtutils.active_window() widget = show_shortcuts.widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) web = QtWebKit.QWebView(parent) web.setHtml(html) layout = QtGui.QHBoxLayout() layout.setMargin(0) layout.setSpacing(0) layout.addWidget(web) widget.setWindowTitle(N_('Shortcuts')) widget.setLayout(layout) widget.resize(800, min(parent.height(), 600)) qtutils.add_action(widget, N_('Close'), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def remote_action(action): """Launches fetch/push/pull dialogs.""" # TODO: subclass model model = MainModel() global_model = cola.model() model.currentbranch = global_model.currentbranch model.local_branches = global_model.local_branches model.remote_branches = global_model.remote_branches model.tags = global_model.tags model.remotes = global_model.remotes model.local_branch = '' model.remote_branch = '' model.remotename = '' model.tags_checkbox = False model.rebase_checkbox = False model.ffwd_only_checkbox = True view = remote.RemoteView(qtutils.active_window(), action) ctl = RemoteController(model, view, action) view.show() return ctl
def search(): """Return a callback to handle various search actions.""" return search_commits(qtutils.active_window())
def grep(): """Prompt and use 'git grep' to find the content.""" widget = new_grep(parent=qtutils.active_window()) widget.show() widget.raise_() return widget
def remote_editor(): view = new_remote_editor(parent=qtutils.active_window()) view.show() view.raise_() return view
def browse_recent_files(): parent = qtutils.active_window() dialog = RecentFileDialog(parent) dialog.resize(parent.width(), min(parent.height(), 420)) dialog.show()
def compare_branches(): """Launches a dialog for comparing a pair of branches""" view = CompareBranchesDialog(qtutils.active_window()) view.show() return view
def choose_from_dialog(get, title, button_text, default, icon=None): parent = qtutils.active_window() return get(title, button_text, parent, default=default, icon=icon)
def launch_about_dialog(): """Launches the Help -> About dialog""" view = AboutView(qtutils.active_window()) view.set_version(version.version()) view.show()
def manage_bookmarks(): dlg = BookmarksDialog(qtutils.active_window()) dlg.show() dlg.exec_() return dlg
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 apply_patches(): parent = qtutils.active_window() dlg = new_apply_patches(parent=parent) dlg.show() dlg.raise_() return dlg