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
Marco Bubke
flatpak-qt-creator
Commits
51a33a9f
Commit
51a33a9f
authored
Jan 19, 2010
by
Roberto Raggi
Browse files
Create completion items for the builtin snippets
parent
72a9a9fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmljseditor/qmlcodecompletion.cpp
View file @
51a33a9f
...
...
@@ -134,6 +134,17 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
}
}
// snippets completion
TextEditor
::
CompletionItem
item
(
this
);
item
.
text
=
QLatin1String
(
"Rectangle - declaration"
);
item
.
data
=
QVariant
::
fromValue
(
QString
(
"Rectangle {
\n
width: $100$;
\n
height: 100;
\n
$$
\n
}"
));
m_completions
.
append
(
item
);
item
.
text
=
QLatin1String
(
"Item - declaration"
);
item
.
data
=
QVariant
::
fromValue
(
QString
(
"Item {
\n
width: $100$;
\n
height: 100;
\n
$$
\n
}"
));
m_completions
.
append
(
item
);
return
pos
;
}
...
...
@@ -188,7 +199,23 @@ void QmlCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
void
QmlCodeCompletion
::
complete
(
const
TextEditor
::
CompletionItem
&
item
)
{
const
QString
toInsert
=
item
.
text
;
QString
toInsert
=
item
.
text
;
if
(
QmlJSTextEditor
*
edit
=
qobject_cast
<
QmlJSTextEditor
*>
(
m_editor
->
widget
()))
{
if
(
item
.
data
.
isValid
())
{
QTextCursor
tc
=
edit
->
textCursor
();
tc
.
beginEditBlock
();
tc
.
setPosition
(
m_startPosition
);
tc
.
setPosition
(
m_editor
->
position
(),
QTextCursor
::
KeepAnchor
);
tc
.
removeSelectedText
();
toInsert
=
item
.
data
.
toString
();
edit
->
insertCodeSnippet
(
toInsert
);
tc
.
endEditBlock
();
return
;
}
}
const
int
length
=
m_editor
->
position
()
-
m_startPosition
;
m_editor
->
setCurPos
(
m_startPosition
);
m_editor
->
replace
(
length
,
toInsert
);
...
...
src/plugins/texteditor/basetexteditor.cpp
View file @
51a33a9f
...
...
@@ -1246,7 +1246,7 @@ skip_event:
delete
e
;
}
void
BaseTextEditor
::
universalHelper
(
)
void
BaseTextEditor
::
insertCodeSnippet
(
const
QString
&
snippet
)
{
QList
<
QTextEdit
::
ExtraSelection
>
selections
;
...
...
@@ -1254,8 +1254,6 @@ void BaseTextEditor::universalHelper()
const
int
startCursorPosition
=
cursor
.
position
();
cursor
.
beginEditBlock
();
const
QString
snippet
=
QLatin1String
(
"for ($initializer$; $condition$; $expresssion$) {
\n
$$
\n
}
\n
"
);
if
((
snippet
.
count
(
'$'
)
%
2
)
!=
0
)
{
qWarning
()
<<
"invalid snippet"
;
return
;
...
...
@@ -1326,6 +1324,12 @@ void BaseTextEditor::universalHelper()
}
}
void
BaseTextEditor
::
universalHelper
()
{
const
QString
snippet
=
QLatin1String
(
"for ($initializer$; $condition$; $expresssion$) {
\n
$$
\n
}
\n
"
);
insertCodeSnippet
(
snippet
);
}
void
BaseTextEditor
::
setTextCursor
(
const
QTextCursor
&
cursor
)
{
// workaround for QTextControl bug
...
...
src/plugins/texteditor/basetexteditor.h
View file @
51a33a9f
...
...
@@ -379,6 +379,8 @@ public:
void
setTextCursor
(
const
QTextCursor
&
cursor
);
void
insertCodeSnippet
(
const
QString
&
snippet
);
public
slots
:
void
setDisplayName
(
const
QString
&
title
);
...
...
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