class CommitDialog(StandardWindow): def __init__(self, repo, win): self.repo = repo self.win = win self.confirmed = False StandardWindow.__init__(self, 'Egitu', 'Egitu', autodel=True) vbox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(vbox) vbox.show() # title en = Entry(self, editable=False, text='<title><align=center>Commit changes</align></title>', size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(en) en.show() panes = Panes(self, content_left_size = 0.2, horizontal=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) vbox.pack_end(panes) panes.show() # message entry en = Entry(self, editable=True, scrollable=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.part_text_set('guide', 'Enter commit message here') panes.part_content_set("left", en) en.show() self.msg_entry = en # diff entry self.diff_entry = DiffedEntry(self) panes.part_content_set("right", self.diff_entry) self.diff_entry.show() # buttons hbox = Box(self, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(hbox) hbox.show() bt = Button(self, text="Cancel") bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() bt = Button(self, text="Commit") bt.callback_clicked_add(self.commit_button_cb) hbox.pack_end(bt) bt.show() # show the window and give focus to the editable entry self.size = 500, 500 self.show() en.focus = True # load the diff repo.request_diff(self.diff_done_cb, only_staged=True) def diff_done_cb(self, lines, success): self.diff_entry.lines_set(lines) def commit_button_cb(self, bt): if not self.confirmed: self.confirmed = True bt.text = 'Are you sure?' else: bt.text = 'Commit' self.confirmed = False self.repo.commit(self.commit_done_cb, markup_to_utf8(self.msg_entry.text)) def commit_done_cb(self, success, err_msg=None): if success: self.delete() self.win.update_header() self.win.graph.populate(self.repo) else: ErrorPopup(self, 'Commit Failed', utf8_to_markup(err_msg))
class CommitDialog(DialogWindow): def __init__(self, app, revert_commit=None, cherrypick_commit=None): self.app = app self.confirmed = False self.revert_commit = revert_commit self.cherrypick_commit = cherrypick_commit DialogWindow.__init__(self, app.win, 'Egitu', 'Egitu', size=(500,500), autodel=True) vbox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(vbox) vbox.show() # title if revert_commit: title = 'Revert commit' elif cherrypick_commit: title = 'Cherry-pick commit' else: title = 'Commit changes' en = Entry(self, editable=False, text='<title><align=center>%s</align></title>' % title, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(en) en.show() # auto-commit checkbox (for revert and cherry-pick) if revert_commit or cherrypick_commit: ck = Check(vbox, state=True) ck.text = 'Automatically commit, in branch: %s' % \ app.repo.status.current_branch.name ck.callback_changed_add(lambda c: self.msg_entry.disabled_set(not c.state)) vbox.pack_end(ck) ck.show() self.autocommit_chk = ck # Panes panes = Panes(self, content_left_size = 0.2, horizontal=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) vbox.pack_end(panes) panes.show() # message entry en = Entry(self, editable=True, scrollable=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.part_text_set('guide', 'Enter commit message here') panes.part_content_set("left", en) if revert_commit: en.text = 'Revert "%s"<br><br>This reverts commit %s.<br><br>' % \ (utf8_to_markup(revert_commit.title), revert_commit.sha) elif cherrypick_commit: en.text = '%s<br><br>%s<br>(cherry picked from commit %s)<br>' % \ (utf8_to_markup(cherrypick_commit.title), utf8_to_markup(cherrypick_commit.message), cherrypick_commit.sha) en.cursor_end_set() en.show() self.msg_entry = en # diff entry self.diff_entry = DiffedEntry(self) panes.part_content_set('right', self.diff_entry) self.diff_entry.show() # buttons hbox = Box(self, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(hbox) hbox.show() bt = Button(self, text='Cancel') bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() if revert_commit: label = 'Revert' elif cherrypick_commit: label = 'Cherry-pick' else: label = 'Commit' bt = Button(self, text=label) bt.callback_clicked_add(self.commit_button_cb) hbox.pack_end(bt) bt.show() # show the window and give focus to the editable entry self.show() en.focus = True # load the diff if revert_commit: app.repo.request_diff(self.diff_done_cb, revert=True, ref1=revert_commit.sha) elif cherrypick_commit: app.repo.request_diff(self.diff_done_cb, ref1=cherrypick_commit.sha) else: app.repo.request_diff(self.diff_done_cb, only_staged=True) def diff_done_cb(self, lines, success): self.diff_entry.lines_set(lines) def commit_button_cb(self, bt): if not self.confirmed: self.confirmed = True bt.text = 'Are you sure?' elif self.revert_commit: bt.text = 'Revert' self.confirmed = False self.app.repo.revert(self.commit_done_cb, self.revert_commit, auto_commit=self.autocommit_chk.state, commit_msg=markup_to_utf8(self.msg_entry.text)) elif self.cherrypick_commit: bt.text = 'Cherry-pick' self.confirmed = False self.app.repo.cherrypick(self.commit_done_cb, self.cherrypick_commit, auto_commit=self.autocommit_chk.state, commit_msg=markup_to_utf8(self.msg_entry.text)) else: bt.text = 'Commit' self.confirmed = False self.app.repo.commit(self.commit_done_cb, markup_to_utf8(self.msg_entry.text)) def commit_done_cb(self, success, err_msg=None): if success: self.delete() self.app.action_update_all() else: ErrorPopup(self, 'Operation Failed', utf8_to_markup(err_msg))
class StashDialog(DialogWindow): def __init__(self, parent, app, stash=None): self.app = app self.stash = stash or app.repo.stash[0] self.idx = parseint(stash.ref) if stash else 0 DialogWindow.__init__(self, app.win, 'egitu-stash', 'stash', size=(500,500), autodel=True) # main vertical box (inside a padding frame) vbox = Box(self, padding=(0, 6), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) fr = Frame(self, style='pad_medium', size_hint_weight=EXPAND_BOTH) self.resize_object_add(fr) fr.content = vbox fr.show() vbox.show() # header horizontal box hbox = Box(self, horizontal=True, size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_HORIZ) vbox.pack_end(hbox) hbox.show() # title en = Entry(self, editable=False, scrollable=False, size_hint_expand=EXPAND_HORIZ, size_hint_align=(-1,0.0)) hbox.pack_end(en) en.show() self.title_entry = en # header separator sep = Separator(self) hbox.pack_end(sep) sep.show() # navigation table tb = Table(self, size_hint_align=(0.5,0.0)) hbox.pack_end(tb) tb.show() lb = Label(self) tb.pack(lb, 0, 0, 2, 1) lb.show() self.nav_label = lb ic = SafeIcon(self, 'go-previous') bt = Button(self, text='Prev', content=ic) bt.callback_clicked_add(self._prev_clicked_cb) tb.pack(bt, 0, 1, 1, 1) bt.show() self.prev_btn = bt ic = SafeIcon(self, 'go-next') bt = Button(self, text='Next', content=ic) bt.callback_clicked_add(self._next_clicked_cb) tb.pack(bt, 1, 1, 1, 1) bt.show() self.next_btn = bt # diff entry self.diff_entry = DiffedEntry(self) vbox.pack_end(self.diff_entry) self.diff_entry.show() # buttons sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_HORIZ) vbox.pack_end(sep) sep.show() hbox = Box(self, horizontal=True, size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_BOTH) vbox.pack_end(hbox) hbox.show() bt = Button(self, text='Apply') bt.callback_clicked_add(self._apply_clicked_cb) hbox.pack_end(bt) bt.show() bt = Button(self, text='Pop (apply & delete)') bt.callback_clicked_add(self._pop_clicked_cb) hbox.pack_end(bt) bt.show() bt = Button(self, text='Branch & Delete', content=SafeIcon(self, 'git-branch')) bt.callback_clicked_add(self._branch_clicked_cb) hbox.pack_end(bt) bt.show() bt = Button(self, text='Delete', content=SafeIcon(self, 'user-trash')) bt.callback_clicked_add(self._drop_clicked_cb) hbox.pack_end(bt) bt.show() sep = Separator(self, size_hint_expand=EXPAND_HORIZ) hbox.pack_end(sep) bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() # request the diff and show the dialog self.update(self.idx) self.show() def update(self, idx): self.idx = idx self.stash = self.app.repo.stash[idx] stash_len = len(self.app.repo.stash) self.title = self.stash.ref self.title_entry.text = \ '<name>Stash item</> #{} <name>Created</> {}<br>' \ '<subtitle>{}</>'.format(idx, format_date(self.stash.ts), self.stash.desc) self.nav_label.text = \ '{} {}<br>in the stash'.format(stash_len, 'items' if stash_len > 1 else 'item') self.prev_btn.disabled = (idx == 0) self.next_btn.disabled = (idx >= stash_len - 1) self.diff_entry.loading_set() self.app.repo.stash_request_diff(self._diff_done_cb, self.stash) def _prev_clicked_cb(self, btn): self.update(self.idx - 1) def _next_clicked_cb(self, btn): self.update(self.idx + 1) def _diff_done_cb(self, lines, success): self.diff_entry.lines_set(lines) def _drop_clicked_cb(self, btn): self.app.action_stash_drop(self.stash) self.delete() def _apply_clicked_cb(self, btn): self.app.action_stash_apply(self.stash) self.delete() def _pop_clicked_cb(self, btn): self.app.action_stash_pop(self.stash) self.delete() def _branch_clicked_cb(self, btn): self.app.action_stash_branch(self.stash) self.delete()