~kvilhaugsvik/qbzr/qshelve_all

918.2.1 by Ian Clatworthy
first cut at quncommit
1
# -*- coding: utf-8 -*-
2
#
3
# QBzr - Qt frontend to Bazaar commands
4
# Copyright (C) 2009 Canonical Ltd
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20
from PyQt4 import QtCore, QtGui
21
1166 by Gary van der Merwe
Clean up pyflakes errors.
22
from bzrlib import bzrdir, errors, log
23
from bzrlib.revisionspec import RevisionSpec
918.2.1 by Ian Clatworthy
first cut at quncommit
24
25
from bzrlib.plugins.qbzr.lib.html_log import log_as_html
26
from bzrlib.plugins.qbzr.lib.i18n import gettext
27
from bzrlib.plugins.qbzr.lib.subprocess import SubProcessDialog
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
28
from bzrlib.plugins.qbzr.lib.trace import (
29
   reports_exception,
30
   SUB_LOAD_METHOD,
31
   )
918.2.5 by Ian Clatworthy
Display the branch location & ensure restoration instructions are displayed
32
from bzrlib.plugins.qbzr.lib.util import url_for_display
918.2.1 by Ian Clatworthy
first cut at quncommit
33
34
35
class QBzrUncommitWindow(SubProcessDialog):
36
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
37
    def __init__(self, location, dialog=True, ui_mode=True, parent=None,
918.2.1 by Ian Clatworthy
first cut at quncommit
38
            local=None, message=None):
39
        super(QBzrUncommitWindow, self).__init__(
40
                                  gettext("Uncommit"),
41
                                  name="uncommit",
42
                                  default_size=(400, 400),
43
                                  ui_mode=ui_mode,
44
                                  dialog=dialog,
45
                                  parent=parent,
46
                                  hide_progress=True,
47
                                  )
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
48
        self.tree, self.branch = bzrdir.BzrDir.open_tree_or_branch(location)
918.2.5 by Ian Clatworthy
Display the branch location & ensure restoration instructions are displayed
49
 
50
        # Display the branch
51
        branch_label = QtGui.QLabel(gettext("Branch: %s") %
52
            url_for_display(self.branch.base))
53
918.2.1 by Ian Clatworthy
first cut at quncommit
54
        # Display the revision selection section. We nearly always
55
        # want to just uncommit the last revision (to tweak the
56
        # commit message say) so we make that the default.
57
        groupbox = QtGui.QGroupBox(gettext("Move tip to"), self)
58
        self.last_radio = QtGui.QRadioButton(
59
            gettext("Parent of current tip revision"))
60
        self.last_radio.setChecked(QtCore.Qt.Checked)
61
        self.other_radio = QtGui.QRadioButton(gettext("Other revision:"))
62
        self.other_revision = QtGui.QLineEdit()
63
        other = QtGui.QHBoxLayout()
64
        other.addWidget(self.other_radio)
65
        other.addWidget(self.other_revision)
66
        vbox = QtGui.QVBoxLayout(groupbox)
67
        vbox.addWidget(self.last_radio)
68
        vbox.addLayout(other)
918.2.4 by Ian Clatworthy
Implicitly set the other revision radio button if the user starts entering one
69
 
70
        # If the user starts entering a value in the 'other revision' field,
71
        # set the matching radio button implicitly
72
        QtCore.QObject.connect(self.other_revision,
73
                               QtCore.SIGNAL("textChanged(QString)"),
74
                               self.do_other_revision_changed)
918.2.1 by Ian Clatworthy
first cut at quncommit
75
        
76
        # groupbox gets disabled as we are executing.
77
        QtCore.QObject.connect(self,
78
                               QtCore.SIGNAL("subprocessStarted(bool)"),
79
                               groupbox,
80
                               QtCore.SLOT("setDisabled(bool)"))
81
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
82
        # Put the form together
918.2.1 by Ian Clatworthy
first cut at quncommit
83
        layout = QtGui.QVBoxLayout(self)
918.2.5 by Ian Clatworthy
Display the branch location & ensure restoration instructions are displayed
84
        layout.addWidget(branch_label)
918.2.2 by Ian Clatworthy
Fix up layout issues
85
        layout.addWidget(groupbox)
86
        layout.addWidget(self.make_default_status_box())
918.2.1 by Ian Clatworthy
first cut at quncommit
87
        layout.addWidget(self.buttonbox)
88
918.2.4 by Ian Clatworthy
Implicitly set the other revision radio button if the user starts entering one
89
    def do_other_revision_changed(self, text):
90
        if text and not self.other_radio.isChecked():
91
            self.other_radio.setChecked(True)
92
918.2.1 by Ian Clatworthy
first cut at quncommit
93
    def _revision_identifier(self):
94
        """What revision did the user select?
95
96
        :return: None for the last revision.
97
          Otherwise the revision identifier as a string.
98
        """
99
        if self.other_radio.isChecked():
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
100
            result = unicode(self.other_revision.text())
101
            if result:
102
                return result
103
            else:
104
                msg = gettext("No other revision specified.")
105
                raise errors.BzrError(msg)
918.2.1 by Ian Clatworthy
first cut at quncommit
106
        # Default is the tip revision
107
        return None
108
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
109
    @reports_exception(type=SUB_LOAD_METHOD)
918.2.1 by Ian Clatworthy
first cut at quncommit
110
    def validate(self):
111
        """Check that the user really wants to uncommit the given revisions."""
112
        revision = self._revision_identifier()
113
        if revision is None:
114
            log_rqst = log.make_log_request_dict(limit=1)
115
        else:
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
116
            rev_spec = RevisionSpec.from_string(revision)
117
            revno = rev_spec.in_history(self.branch).revno
918.2.1 by Ian Clatworthy
first cut at quncommit
118
            # We need to offset the revno by +1 because we'll be uncommitting
119
            # *back* to revno, meaning those after it are 'deleted'
120
            log_rqst = log.make_log_request_dict(start_revision=revno+1)
121
        log_data = log_as_html(self.branch, log_rqst)
122
        question = gettext("Do you really want to uncommit these revisions?")
123
        btn = QtGui.QMessageBox.warning(self,
124
            "QBzr - " + gettext("Uncommit"),
125
            '<font color="red">%s</font><br/>%s' % (question, log_data),
126
            gettext("&Yes"), gettext("&No"), '',
127
            0, 1)
128
        if btn == 0: # QtGui.QMessageBox.Yes:
129
            return True
130
        return False
131
132
    def do_start(self):
918.2.5 by Ian Clatworthy
Display the branch location & ensure restoration instructions are displayed
133
        args = ['--force']
918.2.1 by Ian Clatworthy
first cut at quncommit
134
        revision = self._revision_identifier()
135
        if revision:
136
            args.append('--revision')
137
            args.append(revision)
918.2.3 by Ian Clatworthy
uncommit against the working tree, not branch, if there is one; report illegal revision identifiers to the user
138
        if self.tree:
139
            dest = self.tree.basedir
140
        else:
141
            dest = self.branch.base
142
        args.append(dest)
918.2.1 by Ian Clatworthy
first cut at quncommit
143
        self.process_widget.do_start(None, 'uncommit', *args)