1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "qmljscomponentnamedialog.h"
35 #include "ui_qmljscomponentnamedialog.h"
37 #include <QtCore/QFileInfo>
38 #include <QtGui/QFileDialog>
40 using namespace QmlJSEditor::Internal;
42 ComponentNameDialog::ComponentNameDialog(QWidget *parent) :
44 ui(new Ui::ComponentNameDialog)
48 connect(ui->choosePathButton, SIGNAL(clicked()),
49 this, SLOT(choosePath()));
50 connect(ui->pathEdit, SIGNAL(textChanged(QString)),
51 this, SLOT(validate()));
52 connect(ui->componentNameEdit, SIGNAL(textChanged(QString)),
53 this, SLOT(validate()));
56 ComponentNameDialog::~ComponentNameDialog()
61 void ComponentNameDialog::go(QString *proposedName,
62 QString *proposedPath,
65 Q_ASSERT(proposedName);
66 Q_ASSERT(proposedPath);
68 ComponentNameDialog d(parent);
69 d.ui->componentNameEdit->setText(*proposedName);
70 d.ui->pathEdit->setText(*proposedPath);
72 if (QDialog::Accepted == d.exec()) {
73 *proposedName = d.ui->componentNameEdit->text();
74 *proposedPath = d.ui->pathEdit->text();
78 void ComponentNameDialog::choosePath()
80 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a path"),
81 ui->pathEdit->text());
83 ui->pathEdit->setText(dir);
86 void ComponentNameDialog::validate()
88 const QString msg = isValid();
89 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(msg.isEmpty());
90 ui->messageLabel->setText(msg);
93 QString ComponentNameDialog::isValid() const
95 QString compName = ui->componentNameEdit->text();
96 if (compName.isEmpty() || !compName[0].isUpper())
97 return tr("Invalid component name");
99 QString path = ui->pathEdit->text();
100 if (path.isEmpty() || !QFileInfo(path).isDir())
101 return tr("Invalid path");