Skip to content
GitLab
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
f2940adb
Commit
f2940adb
authored
Feb 03, 2009
by
Martin Aumueller
Browse files
fakevim: implement indenting a block and autoindent
parent
c446f9ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/fakevim/fakevimhandler.cpp
View file @
f2940adb
...
...
@@ -40,8 +40,6 @@
// Qt Creator. The idea is to keep this file here in a "clean" state that
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
//#include <indenter.h>
#include
<QtCore/QDebug>
#include
<QtCore/QFile>
#include
<QtCore/QObject>
...
...
@@ -1718,11 +1716,15 @@ int FakeVimHandler::Private::indentDist() const
const TextEditor::TextBlockIterator end(m_tc.block().next());
return indenter.indentForBottomLine(current, begin, end, QChar(' '));
#endif
return
0
;
int
amount
=
0
;
emit
q
->
indentRegion
(
&
amount
,
m_tc
.
block
(),
m_tc
.
block
(),
QChar
(
' '
));
return
amount
;
}
void
FakeVimHandler
::
Private
::
indentRegion
(
QTextBlock
begin
,
QTextBlock
end
,
QChar
typedChar
)
{
int
amount
=
0
;
emit
q
->
indentRegion
(
&
amount
,
begin
,
end
,
typedChar
);
#if 0
// FIXME: Make independent of TextEditor
if (!m_texteditor)
...
...
src/plugins/fakevim/fakevimhandler.h
View file @
f2940adb
...
...
@@ -36,6 +36,7 @@
#include
<QtCore/QObject>
#include
<QtGui/QTextEdit>
#include
<QtGui/QTextBlock>
QT_BEGIN_NAMESPACE
class
QString
;
...
...
@@ -80,6 +81,7 @@ signals:
void
writeFileRequested
(
bool
*
handled
,
const
QString
&
fileName
,
const
QString
&
contents
);
void
moveToMatchingParenthesis
(
bool
*
moved
,
bool
*
forward
,
QTextCursor
*
cursor
);
void
indentRegion
(
int
*
amount
,
QTextBlock
begin
,
QTextBlock
end
,
QChar
typedChar
);
private:
bool
eventFilter
(
QObject
*
ob
,
QEvent
*
ev
);
...
...
src/plugins/fakevim/fakevimplugin.cpp
View file @
f2940adb
...
...
@@ -56,9 +56,12 @@
#include
<texteditor/interactionsettings.h>
#include
<texteditor/tabsettings.h>
#include
<texteditor/texteditorsettings.h>
#include
<texteditor/textblockiterator.h>
#include
<utils/qtcassert.h>
#include
<indenter.h>
#include
<QtCore/QDebug>
#include
<QtCore/QtPlugin>
#include
<QtCore/QObject>
...
...
@@ -123,6 +126,7 @@ private slots:
void
changeSelection
(
const
QList
<
QTextEdit
::
ExtraSelection
>
&
selections
);
void
writeFile
(
bool
*
handled
,
const
QString
&
fileName
,
const
QString
&
contents
);
void
moveToMatchingParenthesis
(
bool
*
moved
,
bool
*
forward
,
QTextCursor
*
cursor
);
void
indentRegion
(
int
*
amount
,
QTextBlock
begin
,
QTextBlock
end
,
QChar
typedChar
);
private:
FakeVimPlugin
*
q
;
...
...
@@ -206,6 +210,8 @@ void FakeVimPluginPrivate::installHandler(Core::IEditor *editor)
this
,
SLOT
(
changeSelection
(
QList
<
QTextEdit
::
ExtraSelection
>
)));
connect
(
handler
,
SIGNAL
(
moveToMatchingParenthesis
(
bool
*
,
bool
*
,
QTextCursor
*
)),
this
,
SLOT
(
moveToMatchingParenthesis
(
bool
*
,
bool
*
,
QTextCursor
*
)));
connect
(
handler
,
SIGNAL
(
indentRegion
(
int
*
,
QTextBlock
,
QTextBlock
,
QChar
)),
this
,
SLOT
(
indentRegion
(
int
*
,
QTextBlock
,
QTextBlock
,
QChar
)));
handler
->
setupWidget
();
handler
->
setExtraData
(
editor
);
...
...
@@ -289,6 +295,45 @@ void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward,
}
}
void
FakeVimPluginPrivate
::
indentRegion
(
int
*
amount
,
QTextBlock
begin
,
QTextBlock
end
,
QChar
typedChar
)
{
FakeVimHandler
*
handler
=
qobject_cast
<
FakeVimHandler
*>
(
sender
());
if
(
!
handler
)
return
;
BaseTextEditor
*
bt
=
qobject_cast
<
BaseTextEditor
*>
(
handler
->
widget
());
if
(
!
bt
)
return
;
typedef
SharedTools
::
Indenter
<
TextEditor
::
TextBlockIterator
>
Indenter
;
Indenter
&
indenter
=
Indenter
::
instance
();
indenter
.
setIndentSize
(
bt
->
tabSettings
().
m_indentSize
);
indenter
.
setTabSize
(
bt
->
tabSettings
().
m_tabSize
);
const
QTextDocument
*
doc
=
begin
.
document
();
const
TextEditor
::
TextBlockIterator
docStart
(
doc
->
begin
());
QTextBlock
cur
=
begin
;
do
{
if
(
typedChar
==
0
&&
cur
.
text
().
simplified
().
isEmpty
())
{
*
amount
=
0
;
if
(
cur
!=
end
)
{
QTextCursor
cursor
(
cur
);
while
(
!
cursor
.
atBlockEnd
())
cursor
.
deleteChar
();
}
}
else
{
const
TextEditor
::
TextBlockIterator
current
(
cur
);
const
TextEditor
::
TextBlockIterator
next
(
cur
.
next
());
*
amount
=
indenter
.
indentForBottomLine
(
current
,
docStart
,
next
,
typedChar
);
if
(
cur
!=
end
)
bt
->
tabSettings
().
indentLine
(
cur
,
*
amount
);
}
if
(
cur
!=
end
)
cur
=
cur
.
next
();
}
while
(
cur
!=
end
);
}
void
FakeVimPluginPrivate
::
removeHandler
()
{
if
(
FakeVimHandler
*
handler
=
qobject_cast
<
FakeVimHandler
*>
(
sender
()))
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment