Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
825562eb
Commit
825562eb
authored
Sep 23, 2010
by
Erik Verbruggen
Browse files
QML Editor: changed extract-component to ask for a name if there is no id.
parent
a7d8b5a5
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
View file @
825562eb
...
...
@@ -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
();
setDescription
(
QCoreApplication
::
translate
(
"QmlJSEditor::ComponentFromObjectDef"
,
"Move Component into '%1.qml'"
).
arg
(
m_componentName
));
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,10 +149,8 @@ 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
;
}
result
.
append
(
QmlJSQuickFixOperation
::
Ptr
(
new
Operation
(
state
,
objDef
)));
return
result
;
}
}
}
...
...
src/plugins/qmljseditor/qmljscomponentnamedialog.cpp
0 → 100644
View file @
825562eb
/**************************************************************************
**
** 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
;
}
src/plugins/qmljseditor/qmljscomponentnamedialog.h
0 → 100644
View file @
825562eb
/**************************************************************************
**
** 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
src/plugins/qmljseditor/qmljscomponentnamedialog.ui
0 → 100644
View file @
825562eb
<?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>
src/plugins/qmljseditor/qmljseditor.pro
View file @
825562eb
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment