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
21073563
Commit
21073563
authored
Jun 03, 2010
by
Roberto Raggi
Browse files
Introduced quickfix support for QML/JS files.
parent
bcf50a0a
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmljseditor/qmljseditor.cpp
View file @
21073563
...
...
@@ -685,6 +685,14 @@ int QmlJSTextEditor::documentRevision() const
return
document
()
->
revision
();
}
bool
QmlJSTextEditor
::
isOutdated
()
const
{
if
(
m_semanticInfo
.
revision
()
!=
documentRevision
())
return
true
;
return
false
;
}
Core
::
IEditor
*
QmlJSEditorEditable
::
duplicate
(
QWidget
*
parent
)
{
QmlJSTextEditor
*
newEditor
=
new
QmlJSTextEditor
(
parent
);
...
...
src/plugins/qmljseditor/qmljseditor.h
View file @
21073563
...
...
@@ -211,6 +211,7 @@ public:
SemanticInfo
semanticInfo
()
const
;
int
documentRevision
()
const
;
bool
isOutdated
()
const
;
public
slots
:
void
followSymbolUnderCursor
();
...
...
src/plugins/qmljseditor/qmljseditor.pro
View file @
21073563
...
...
@@ -22,7 +22,8 @@ HEADERS += \
qmljshoverhandler
.
h
\
qmljsmodelmanager
.
h
\
qmljsmodelmanagerinterface
.
h
\
qmljspreviewrunner
.
h
qmljspreviewrunner
.
h
\
qmljsquickfix
.
h
SOURCES
+=
\
qmljscodecompletion
.
cpp
\
...
...
@@ -36,7 +37,8 @@ SOURCES += \
qmljshoverhandler
.
cpp
\
qmljsmodelmanager
.
cpp
\
qmljsmodelmanagerinterface
.
cpp
\
qmljspreviewrunner
.
cpp
qmljspreviewrunner
.
cpp
\
qmljsquickfix
.
cpp
RESOURCES
+=
qmljseditor
.
qrc
OTHER_FILES
+=
QmlJSEditor
.
pluginspec
QmlJSEditor
.
mimetypes
.
xml
src/plugins/qmljseditor/qmljseditorplugin.cpp
View file @
21073563
...
...
@@ -37,6 +37,7 @@
#include "qmljsmodelmanager.h"
#include "qmlfilewizard.h"
#include "qmljspreviewrunner.h"
#include "qmljsquickfix.h"
#include <qmldesigner/qmldesignerconstants.h>
...
...
@@ -64,6 +65,7 @@
#include <QtCore/QSettings>
#include <QtCore/QDir>
#include <QtCore/QCoreApplication>
#include <QtCore/QTimer>
#include <QtGui/QMenu>
#include <QtGui/QAction>
...
...
@@ -71,6 +73,10 @@ using namespace QmlJSEditor;
using
namespace
QmlJSEditor
::
Internal
;
using
namespace
QmlJSEditor
::
Constants
;
enum
{
QUICKFIX_INTERVAL
=
20
};
QmlJSEditorPlugin
*
QmlJSEditorPlugin
::
m_instance
=
0
;
QmlJSEditorPlugin
::
QmlJSEditorPlugin
()
:
...
...
@@ -80,6 +86,12 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() :
m_actionHandler
(
0
)
{
m_instance
=
this
;
m_quickFixCollector
=
0
;
m_quickFixTimer
=
new
QTimer
(
this
);
m_quickFixTimer
->
setInterval
(
20
);
m_quickFixTimer
->
setSingleShot
(
true
);
connect
(
m_quickFixTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
quickFixNow
()));
}
QmlJSEditorPlugin
::~
QmlJSEditorPlugin
()
...
...
@@ -163,6 +175,9 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
Core
::
FileIconProvider
*
iconProvider
=
Core
::
FileIconProvider
::
instance
();
iconProvider
->
registerIconOverlayForSuffix
(
QIcon
(
":/qmljseditor/images/qmlfile.png"
),
"qml"
);
m_quickFixCollector
=
new
QmlJSQuickFixCollector
;
addAutoReleasedObject
(
m_quickFixCollector
);
return
true
;
}
...
...
@@ -190,6 +205,10 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::Internal::QmlJSTextEditor
// auto completion
connect
(
editor
,
SIGNAL
(
requestAutoCompletion
(
TextEditor
::
ITextEditable
*
,
bool
)),
TextEditor
::
Internal
::
CompletionSupport
::
instance
(),
SLOT
(
autoComplete
(
TextEditor
::
ITextEditable
*
,
bool
)));
// quick fix
connect
(
editor
,
SIGNAL
(
requestQuickFix
(
TextEditor
::
ITextEditable
*
)),
this
,
SLOT
(
quickFix
(
TextEditor
::
ITextEditable
*
)));
}
void
QmlJSEditorPlugin
::
followSymbolUnderCursor
()
...
...
@@ -211,5 +230,33 @@ Core::Command *QmlJSEditorPlugin::addToolAction(QAction *a, Core::ActionManager
return
command
;
}
QmlJSQuickFixCollector
*
QmlJSEditorPlugin
::
quickFixCollector
()
const
{
return
m_quickFixCollector
;
}
void
QmlJSEditorPlugin
::
quickFix
(
TextEditor
::
ITextEditable
*
editable
)
{
m_currentTextEditable
=
editable
;
quickFixNow
();
}
void
QmlJSEditorPlugin
::
quickFixNow
()
{
if
(
!
m_currentTextEditable
)
return
;
Core
::
EditorManager
*
em
=
Core
::
EditorManager
::
instance
();
QmlJSTextEditor
*
currentEditor
=
qobject_cast
<
QmlJSTextEditor
*>
(
em
->
currentEditor
()
->
widget
());
if
(
QmlJSTextEditor
*
editor
=
qobject_cast
<
QmlJSTextEditor
*>
(
m_currentTextEditable
->
widget
()))
{
if
(
currentEditor
==
editor
)
{
if
(
editor
->
isOutdated
())
{
// qDebug() << "TODO: outdated document" << editor->documentRevision() << editor->semanticInfo().revision();
// ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL);
m_quickFixTimer
->
stop
();
}
else
TextEditor
::
Internal
::
CompletionSupport
::
instance
()
->
quickFix
(
m_currentTextEditable
);
}
}
}
Q_EXPORT_PLUGIN
(
QmlJSEditorPlugin
)
src/plugins/qmljseditor/qmljseditorplugin.h
View file @
21073563
...
...
@@ -31,8 +31,10 @@
#define QMLJSEDITORPLUGIN_H
#include <extensionsystem/iplugin.h>
#include <QtCore/QPointer>
QT_FORWARD_DECLARE_CLASS
(
QAction
)
QT_FORWARD_DECLARE_CLASS
(
QTimer
)
namespace
TextEditor
{
class
TextEditorActionHandler
;
...
...
@@ -44,6 +46,10 @@ class ActionContainer;
class
ActionManager
;
}
namespace
TextEditor
{
class
ITextEditable
;
}
namespace
QmlJSEditor
{
class
ModelManagerInterface
;
...
...
@@ -54,6 +60,7 @@ namespace Internal {
class
QmlJSEditorFactory
;
class
QmlJSTextEditor
;
class
QmlJSPreviewRunner
;
class
QmlJSQuickFixCollector
;
class
QmlJSEditorPlugin
:
public
ExtensionSystem
::
IPlugin
{
...
...
@@ -70,6 +77,8 @@ public:
static
QmlJSEditorPlugin
*
instance
()
{
return
m_instance
;
}
QmlJSQuickFixCollector
*
quickFixCollector
()
const
;
void
initializeEditor
(
QmlJSTextEditor
*
editor
);
public
Q_SLOTS
:
...
...
@@ -77,6 +86,8 @@ public Q_SLOTS:
private
Q_SLOTS
:
void
openPreview
();
void
quickFix
(
TextEditor
::
ITextEditable
*
editable
);
void
quickFixNow
();
private:
Core
::
Command
*
addToolAction
(
QAction
*
a
,
Core
::
ActionManager
*
am
,
const
QList
<
int
>
&
context
,
const
QString
&
name
,
...
...
@@ -91,6 +102,11 @@ private:
QmlFileWizard
*
m_wizard
;
QmlJSEditorFactory
*
m_editor
;
TextEditor
::
TextEditorActionHandler
*
m_actionHandler
;
QmlJSQuickFixCollector
*
m_quickFixCollector
;
QTimer
*
m_quickFixTimer
;
QPointer
<
TextEditor
::
ITextEditable
>
m_currentTextEditable
;
};
}
// namespace Internal
...
...
src/plugins/qmljseditor/qmljsquickfix.cpp
0 → 100644
View file @
21073563
/**************************************************************************
**
** 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 "qmljsquickfix.h"
#include "qmljseditor.h"
#include <QtCore/QDebug>
using
namespace
QmlJSEditor
::
Internal
;
QmlJSQuickFixCollector
::
QmlJSQuickFixCollector
()
{
}
QmlJSQuickFixCollector
::~
QmlJSQuickFixCollector
()
{
}
TextEditor
::
QuickFixState
*
QmlJSQuickFixCollector
::
initializeCompletion
(
TextEditor
::
ITextEditable
*
editable
)
{
if
(
QmlJSTextEditor
*
editor
=
qobject_cast
<
QmlJSTextEditor
*>
(
editable
->
widget
()))
{
const
SemanticInfo
info
=
editor
->
semanticInfo
();
if
(
editor
->
isOutdated
())
{
// outdated
qWarning
()
<<
"TODO: outdated semantic info, force a reparse."
;
return
0
;
}
// ### TODO create the quickfix state
return
0
;
}
return
0
;
}
QList
<
TextEditor
::
QuickFixOperation
::
Ptr
>
QmlJSQuickFixCollector
::
quickFixOperations
(
TextEditor
::
BaseTextEditor
*
)
const
{
QList
<
TextEditor
::
QuickFixOperation
::
Ptr
>
quickFixOperations
;
return
quickFixOperations
;
}
src/plugins/qmljseditor/qmljsquickfix.h
0 → 100644
View file @
21073563
/**************************************************************************
**
** 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 QMLJSQUICKFIX_H
#define QMLJSQUICKFIX_H
#include <texteditor/quickfix.h>
namespace
QmlJSEditor
{
class
ModelManagerInterface
;
namespace
Internal
{
class
QmlJSQuickFixCollector
:
public
TextEditor
::
QuickFixCollector
{
Q_OBJECT
public:
QmlJSQuickFixCollector
();
virtual
~
QmlJSQuickFixCollector
();
virtual
TextEditor
::
QuickFixState
*
initializeCompletion
(
TextEditor
::
ITextEditable
*
editable
);
virtual
QList
<
TextEditor
::
QuickFixOperation
::
Ptr
>
quickFixOperations
(
TextEditor
::
BaseTextEditor
*
editor
)
const
;
};
}
// end of namespace Internal
}
// end of namespace QmlJSEditor
#endif // QMLJSQUICKFIX_H
Write
Preview
Supports
Markdown
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