1
# Copyright (C) 2009 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from PyQt4 import QtCore, QtGui
19
from bzrlib.plugins.explorer.lib import tools
20
from bzrlib.plugins.explorer.lib.i18n import gettext, N_
23
class AddToolDialog(QtGui.QDialog):
25
def __init__(self, parent=None):
26
super(AddToolDialog, self).__init__(parent)
27
self.setWindowTitle(gettext("Add Tool"))
28
self.setLayout(self._build_layout())
30
def _build_layout(self):
32
self.title_field = QtGui.QLineEdit()
33
self.type_field = self._build_combo([
34
('bzr', gettext("Bazaar Command")),
35
('link', gettext("Web Link")),
36
('application', gettext("Local Application")),
38
self.action_field = QtGui.QLineEdit()
39
form = QtGui.QFormLayout()
40
form.addRow(gettext("Title"), self.title_field)
41
form.addRow(gettext("Type"), self.type_field)
42
form.addRow(gettext("Command"), self.action_field)
45
buttons = QtGui.QDialogButtonBox(
46
QtGui.QDialogButtonBox.Ok |
47
QtGui.QDialogButtonBox.Cancel)
48
self.connect(buttons, QtCore.SIGNAL("accepted()"), self,
49
QtCore.SLOT("accept()"))
50
self.connect(buttons, QtCore.SIGNAL("rejected()"), self,
51
QtCore.SLOT("reject()"))
54
layout = QtGui.QVBoxLayout()
55
layout.addLayout(form)
56
layout.addWidget(buttons)
59
def _build_combo(self, data_label_tuples):
60
combo = QtGui.QComboBox()
61
for data, label in data_label_tuples:
62
combo.addItem(label, data)
66
"""Get the added tool."""
67
title = unicode(self.title_field.text()).strip()
68
type_index = self.type_field.currentIndex()
69
type = unicode(self.type_field.itemData(type_index).toString())
70
action = unicode(self.action_field.text()).strip()
71
return tools.Tool(title, type, action)