Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
acea5c55
Commit
acea5c55
authored
16 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Some work on the syntax checker.
parent
cf09ca0f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/qtscripteditor/qtscripteditor.cpp
+69
-0
69 additions, 0 deletions
src/plugins/qtscripteditor/qtscripteditor.cpp
src/plugins/qtscripteditor/qtscripteditor.h
+7
-0
7 additions, 0 deletions
src/plugins/qtscripteditor/qtscripteditor.h
with
76 additions
and
0 deletions
src/plugins/qtscripteditor/qtscripteditor.cpp
+
69
−
0
View file @
acea5c55
...
...
@@ -32,6 +32,13 @@
#include
"qtscripthighlighter.h"
#include
"qtscripteditorplugin.h"
#include
"parser/javascriptengine_p.h"
#include
"parser/javascriptparser_p.h"
#include
"parser/javascriptlexer_p.h"
#include
"parser/javascriptnodepool_p.h"
#include
"parser/javascriptastvisitor_p.h"
#include
"parser/javascriptast_p.h"
#include
<indenter.h>
#include
<coreplugin/icore.h>
...
...
@@ -42,6 +49,11 @@
#include
<texteditor/texteditorconstants.h>
#include
<QtGui/QMenu>
#include
<QtCore/QTimer>
enum
{
UPDATE_DOCUMENT_DEFAULT_INTERVAL
=
100
};
namespace
QtScriptEditor
{
namespace
Internal
{
...
...
@@ -64,6 +76,14 @@ ScriptEditor::ScriptEditor(const Context &context,
setCodeFoldingVisible
(
true
);
setMimeType
(
QtScriptEditor
::
Constants
::
C_QTSCRIPTEDITOR_MIMETYPE
);
m_updateDocumentTimer
=
new
QTimer
(
this
);
m_updateDocumentTimer
->
setInterval
(
UPDATE_DOCUMENT_DEFAULT_INTERVAL
);
m_updateDocumentTimer
->
setSingleShot
(
true
);
connect
(
m_updateDocumentTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
updateDocumentNow
()));
connect
(
this
,
SIGNAL
(
textChanged
()),
this
,
SLOT
(
updateDocument
()));
baseTextDocument
()
->
setSyntaxHighlighter
(
new
QtScriptHighlighter
);
}
...
...
@@ -94,6 +114,55 @@ ScriptEditor::Context ScriptEditorEditable::context() const
return
m_context
;
}
void
ScriptEditor
::
updateDocument
()
{
m_updateDocumentTimer
->
start
(
UPDATE_DOCUMENT_DEFAULT_INTERVAL
);
}
void
ScriptEditor
::
updateDocumentNow
()
{
// ### move in the parser thread.
m_updateDocumentTimer
->
stop
();
const
QString
fileName
=
file
()
->
fileName
();
const
QString
code
=
toPlainText
();
JavaScriptParser
parser
;
JavaScriptEnginePrivate
driver
;
JavaScript
::
NodePool
nodePool
(
fileName
,
&
driver
);
driver
.
setNodePool
(
&
nodePool
);
JavaScript
::
Lexer
lexer
(
&
driver
);
lexer
.
setCode
(
code
,
/*line = */
1
);
driver
.
setLexer
(
&
lexer
);
QList
<
QTextEdit
::
ExtraSelection
>
selections
;
if
(
parser
.
parse
(
&
driver
))
{
// do something here
}
else
{
QTextEdit
::
ExtraSelection
sel
;
sel
.
format
.
setUnderlineColor
(
Qt
::
red
);
sel
.
format
.
setUnderlineStyle
(
QTextCharFormat
::
WaveUnderline
);
const
int
line
=
parser
.
errorLineNumber
();
QTextCursor
c
(
document
()
->
findBlockByNumber
(
line
-
1
));
sel
.
cursor
=
c
;
if
(
parser
.
errorColumnNumber
()
>
1
)
sel
.
cursor
.
setPosition
(
c
.
position
()
+
parser
.
errorColumnNumber
()
-
1
);
sel
.
cursor
.
movePosition
(
QTextCursor
::
EndOfWord
,
QTextCursor
::
KeepAnchor
);
selections
.
append
(
sel
);
}
setExtraSelections
(
CodeWarningsSelection
,
selections
);
}
void
ScriptEditor
::
setFontSettings
(
const
TextEditor
::
FontSettings
&
fs
)
{
TextEditor
::
BaseTextEditor
::
setFontSettings
(
fs
);
...
...
This diff is collapsed.
Click to expand it.
src/plugins/qtscripteditor/qtscripteditor.h
+
7
−
0
View file @
acea5c55
...
...
@@ -31,6 +31,7 @@
#define QTSCRIPTDITORW_H
#include
<texteditor/basetexteditor.h>
#include
<QTimer>
namespace
Core
{
class
ICore
;
...
...
@@ -76,6 +77,10 @@ public:
public
slots
:
virtual
void
setFontSettings
(
const
TextEditor
::
FontSettings
&
);
private
slots
:
void
updateDocument
();
void
updateDocumentNow
();
protected:
void
contextMenuEvent
(
QContextMenuEvent
*
e
);
TextEditor
::
BaseTextEditorEditable
*
createEditableInterface
()
{
return
new
ScriptEditorEditable
(
this
,
m_context
);
}
...
...
@@ -86,6 +91,8 @@ private:
const
Context
m_context
;
TextEditor
::
TextEditorActionHandler
*
m_ah
;
QTimer
*
m_updateDocumentTimer
;
};
}
// namespace Internal
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment