forked from qt-creator/qt-creator
QML Editor: changed extract-component to ask for a name if there is no id.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljscomponentfromobjectdef.h"
|
||||
#include "qmljscomponentnamedialog.h"
|
||||
#include "qmljsrefactoringchanges.h"
|
||||
|
||||
#include <coreplugin/ifile.h>
|
||||
@@ -86,16 +87,30 @@ public:
|
||||
Q_ASSERT(m_objDef != 0);
|
||||
|
||||
m_componentName = getIdProperty(m_objDef);
|
||||
m_componentName[0] = m_componentName.at(0).toUpper();
|
||||
|
||||
if (m_componentName.isEmpty()) {
|
||||
setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
|
||||
"Move Component into separate file'"));
|
||||
} else {
|
||||
m_componentName[0] = m_componentName.at(0).toUpper();
|
||||
setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
|
||||
"Move Component into '%1.qml'").arg(m_componentName));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void performChanges(QmlJSRefactoringFile *currentFile, QmlJSRefactoringChanges *refactoring)
|
||||
{
|
||||
const QString newFileName = QFileInfo(fileName()).path()
|
||||
+ QDir::separator() + m_componentName + QLatin1String(".qml");
|
||||
QString componentName = m_componentName;
|
||||
QString path = QFileInfo(fileName()).path();
|
||||
if (componentName.isEmpty()) {
|
||||
ComponentNameDialog::go(&componentName, &path, state().editor());
|
||||
}
|
||||
|
||||
if (componentName.isEmpty() || path.isEmpty())
|
||||
return;
|
||||
|
||||
const QString newFileName = path + QDir::separator() + componentName
|
||||
+ QLatin1String(".qml");
|
||||
|
||||
QString imports;
|
||||
UiProgram *prog = currentFile->qmljsDocument()->qmlProgram();
|
||||
@@ -115,7 +130,7 @@ public:
|
||||
return;
|
||||
|
||||
Utils::ChangeSet changes;
|
||||
changes.replace(start, end, m_componentName + QLatin1String(" {\n"));
|
||||
changes.replace(start, end, componentName + QLatin1String(" {\n"));
|
||||
currentFile->change(changes);
|
||||
currentFile->indent(Range(start, end + 1));
|
||||
}
|
||||
@@ -134,13 +149,11 @@ QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(const QmlJSQuic
|
||||
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
|
||||
// check that the node is not the root node
|
||||
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
||||
if (!getIdProperty(objDef).isEmpty()) {
|
||||
result.append(QmlJSQuickFixOperation::Ptr(new Operation(state, objDef)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
100
src/plugins/qmljseditor/qmljscomponentnamedialog.cpp
Normal file
100
src/plugins/qmljseditor/qmljscomponentnamedialog.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljscomponentnamedialog.h"
|
||||
#include "ui_qmljscomponentnamedialog.h"
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtGui/QFileDialog>
|
||||
|
||||
using namespace QmlJSEditor::Internal;
|
||||
|
||||
ComponentNameDialog::ComponentNameDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ComponentNameDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->choosePathButton, SIGNAL(clicked()),
|
||||
this, SLOT(choosePath()));
|
||||
connect(ui->pathEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(validate()));
|
||||
connect(ui->componentNameEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(validate()));
|
||||
}
|
||||
|
||||
ComponentNameDialog::~ComponentNameDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ComponentNameDialog::go(QString *proposedName,
|
||||
QString *proposedPath,
|
||||
QWidget *parent)
|
||||
{
|
||||
Q_ASSERT(proposedName);
|
||||
Q_ASSERT(proposedPath);
|
||||
|
||||
ComponentNameDialog d(parent);
|
||||
d.ui->componentNameEdit->setText(*proposedName);
|
||||
d.ui->pathEdit->setText(*proposedPath);
|
||||
|
||||
if (QDialog::Accepted == d.exec()) {
|
||||
*proposedName = d.ui->componentNameEdit->text();
|
||||
*proposedPath = d.ui->pathEdit->text();
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentNameDialog::choosePath()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a path"),
|
||||
ui->pathEdit->text());
|
||||
if (!dir.isEmpty())
|
||||
ui->pathEdit->setText(dir);
|
||||
}
|
||||
|
||||
void ComponentNameDialog::validate()
|
||||
{
|
||||
const QString msg = isValid();
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(msg.isEmpty());
|
||||
ui->messageLabel->setText(msg);
|
||||
}
|
||||
|
||||
QString ComponentNameDialog::isValid() const
|
||||
{
|
||||
QString compName = ui->componentNameEdit->text();
|
||||
if (compName.isEmpty() || !compName[0].isUpper())
|
||||
return tr("Invalid component name");
|
||||
|
||||
QString path = ui->pathEdit->text();
|
||||
if (path.isEmpty() || !QFileInfo(path).isDir())
|
||||
return tr("Invalid path");
|
||||
|
||||
return QString::null;
|
||||
}
|
||||
68
src/plugins/qmljseditor/qmljscomponentnamedialog.h
Normal file
68
src/plugins/qmljseditor/qmljscomponentnamedialog.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QMLJSCOMPONENTNAMEDIALOG_H
|
||||
#define QMLJSCOMPONENTNAMEDIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class ComponentNameDialog;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
class ComponentNameDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ComponentNameDialog(QWidget *parent = 0);
|
||||
~ComponentNameDialog();
|
||||
|
||||
static void go(QString *proposedName, QString *proposedPath, QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void choosePath();
|
||||
void validate();
|
||||
|
||||
protected:
|
||||
QString isValid() const;
|
||||
|
||||
private:
|
||||
Ui::ComponentNameDialog *ui;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlJSEditor
|
||||
|
||||
#endif // QMLJSCOMPONENTNAMEDIALOG_H
|
||||
124
src/plugins/qmljseditor/qmljscomponentnamedialog.ui
Normal file
124
src/plugins/qmljseditor/qmljscomponentnamedialog.ui
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ComponentNameDialog</class>
|
||||
<widget class="QDialog" name="ComponentNameDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>495</width>
|
||||
<height>130</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="horizontalSpacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="componentNameLabel">
|
||||
<property name="text">
|
||||
<string>Component name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="componentNameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="choosePathLabel">
|
||||
<property name="text">
|
||||
<string>Path:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="pathEdit"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="choosePathButton">
|
||||
<property name="text">
|
||||
<string>Choose...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QLabel" name="messageLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ComponentNameDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ComponentNameDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -30,7 +30,8 @@ HEADERS += \
|
||||
qmljseditorcodeformatter.h \
|
||||
qmljsoutlinetreeview.h \
|
||||
quicktoolbarsettingspage.h \
|
||||
quicktoolbar.h
|
||||
quicktoolbar.h \
|
||||
qmljscomponentnamedialog.h
|
||||
|
||||
SOURCES += \
|
||||
qmljscodecompletion.cpp \
|
||||
@@ -54,10 +55,12 @@ SOURCES += \
|
||||
qmljseditorcodeformatter.cpp \
|
||||
qmljsoutlinetreeview.cpp \
|
||||
quicktoolbarsettingspage.cpp \
|
||||
quicktoolbar.cpp
|
||||
quicktoolbar.cpp \
|
||||
qmljscomponentnamedialog.cpp
|
||||
|
||||
RESOURCES += qmljseditor.qrc
|
||||
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml
|
||||
|
||||
FORMS += \
|
||||
quicktoolbarsettingspage.ui
|
||||
quicktoolbarsettingspage.ui \
|
||||
qmljscomponentnamedialog.ui
|
||||
|
||||
Reference in New Issue
Block a user