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
Tobias Hunger
qt-creator
Commits
29af23cd
Commit
29af23cd
authored
Jul 14, 2010
by
hjk
Browse files
fakevim: implement some of the :bn/bp commands
parent
8a2aa96f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/fakevim/fakevimhandler.cpp
View file @
29af23cd
...
...
@@ -299,7 +299,7 @@ QDebug operator<<(QDebug ts, const Range &range)
ExCommand
::
ExCommand
(
const
QString
&
c
,
const
QString
&
a
,
const
Range
&
r
)
:
cmd
(
c
),
hasBang
(
false
),
args
(
a
),
range
(
r
)
:
cmd
(
c
),
hasBang
(
false
),
args
(
a
),
range
(
r
)
,
count
(
1
)
{}
QDebug
operator
<<
(
QDebug
ts
,
const
ExCommand
&
cmd
)
...
...
@@ -3449,7 +3449,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &line0)
if
(
line
.
startsWith
(
QLatin1Char
(
'%'
)))
line
=
"1,$"
+
line
.
mid
(
1
);
int
beginLine
=
readLineCode
(
line
);
const
int
beginLine
=
readLineCode
(
line
);
int
endLine
=
-
1
;
if
(
line
.
startsWith
(
','
))
{
line
=
line
.
mid
(
1
);
...
...
@@ -3467,6 +3467,8 @@ void FakeVimHandler::Private::handleExCommand(const QString &line0)
cmd
.
hasBang
=
arg0
.
endsWith
(
'!'
);
if
(
cmd
.
hasBang
)
cmd
.
cmd
.
chop
(
1
);
if
(
beginLine
!=
-
1
)
cmd
.
count
=
beginLine
;
//qDebug() << "CMD: " << cmd;
enterCommandMode
();
...
...
src/plugins/fakevim/fakevimhandler.h
View file @
29af23cd
...
...
@@ -60,7 +60,7 @@ struct Range
struct
ExCommand
{
ExCommand
()
:
hasBang
(
false
)
{}
ExCommand
()
:
hasBang
(
false
)
,
count
(
1
)
{}
ExCommand
(
const
QString
&
cmd
,
const
QString
&
args
=
QString
(),
const
Range
&
range
=
Range
());
...
...
@@ -68,6 +68,7 @@ struct ExCommand
bool
hasBang
;
QString
args
;
Range
range
;
int
count
;
};
class
FakeVimHandler
:
public
QObject
...
...
src/plugins/fakevim/fakevimplugin.cpp
View file @
29af23cd
...
...
@@ -102,8 +102,6 @@ const char * const SETTINGS_CATEGORY = "D.FakeVim";
const
char
*
const
SETTINGS_CATEGORY_FAKEVIM_ICON
=
":/core/images/category_fakevim.png"
;
const
char
*
const
SETTINGS_ID
=
"A.General"
;
const
char
*
const
SETTINGS_EX_CMDS_ID
=
"B.ExCommands"
;
const
char
*
const
CMD_FILE_NEXT
=
"FakeVim.SwitchFileNext"
;
const
char
*
const
CMD_FILE_PREV
=
"FakeVim.SwitchFilePrev"
;
}
// namespace Constants
}
// namespace FakeVim
...
...
@@ -514,9 +512,8 @@ private slots:
void
handleDelayedQuitAll
(
bool
forced
);
void
handleDelayedQuit
(
bool
forced
,
Core
::
IEditor
*
editor
);
void
switchFile
(
bool
previous
);
void
switchFileNext
();
void
switchFilePrev
();
void
switchToFile
(
int
n
);
int
currentFile
()
const
;
signals:
void
delayedQuitRequested
(
bool
forced
,
Core
::
IEditor
*
editor
);
...
...
@@ -550,10 +547,6 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
q
=
plugin
;
m_fakeVimOptionsPage
=
0
;
m_fakeVimExCommandsPage
=
0
;
defaultExCommandMap
()[
Constants
::
CMD_FILE_NEXT
]
=
QRegExp
(
"^n(ext)?!?( (.*))?$"
);
defaultExCommandMap
()[
Constants
::
CMD_FILE_PREV
]
=
QRegExp
(
"^(N(ext)?|prev(ious)?)!?( (.*))?$"
);
defaultExCommandMap
()[
CppTools
::
Constants
::
SWITCH_HEADER_SOURCE
]
=
QRegExp
(
"^A$"
);
defaultExCommandMap
()[
"Coreplugin.OutputPane.previtem"
]
=
...
...
@@ -622,16 +615,6 @@ bool FakeVimPluginPrivate::initialize()
connect
(
theFakeVimSetting
(
ConfigReadVimRc
),
SIGNAL
(
valueChanged
(
QVariant
)),
this
,
SLOT
(
maybeReadVimRc
()));
QAction
*
switchFileNextAction
=
new
QAction
(
tr
(
"Switch to next file"
),
this
);
cmd
=
actionManager
->
registerAction
(
switchFileNextAction
,
Constants
::
CMD_FILE_NEXT
,
globalcontext
);
cmd
->
setAttribute
(
Command
::
CA_Hide
);
connect
(
switchFileNextAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
switchFileNext
()));
QAction
*
switchFilePrevAction
=
new
QAction
(
tr
(
"Switch to previous file"
),
this
);
cmd
=
actionManager
->
registerAction
(
switchFilePrevAction
,
Constants
::
CMD_FILE_PREV
,
globalcontext
);
cmd
->
setAttribute
(
Command
::
CA_Hide
);
connect
(
switchFilePrevAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
switchFilePrev
()));
// Delayed operations.
connect
(
this
,
SIGNAL
(
delayedQuitRequested
(
bool
,
Core
::
IEditor
*
)),
this
,
SLOT
(
handleDelayedQuit
(
bool
,
Core
::
IEditor
*
)),
Qt
::
QueuedConnection
);
...
...
@@ -916,7 +899,7 @@ void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c)
void
FakeVimPluginPrivate
::
handleExCommand
(
bool
*
handled
,
const
ExCommand
&
cmd
)
{
using
namespace
Core
;
//qDebug() << "PLUGIN HANDLE: " << cmd.cmd;
//qDebug() << "PLUGIN HANDLE: " << cmd.cmd
<< cmd.count
;
*
handled
=
false
;
...
...
@@ -983,6 +966,20 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
setActionChecked
(
Find
::
Constants
::
CASE_SENSITIVE
,
true
);
*
handled
=
false
;
// Let the handler see it as well.
}
}
else
if
(
cmd
.
cmd
==
"n"
||
cmd
.
cmd
==
"next"
)
{
// :n[ext]
switchToFile
(
currentFile
()
+
cmd
.
count
);
}
else
if
(
cmd
.
cmd
==
"prev"
||
cmd
.
cmd
==
"previous"
||
cmd
.
cmd
==
"N"
||
cmd
.
cmd
==
"Next"
)
{
// :prev[ious]
switchToFile
(
currentFile
()
-
cmd
.
count
);
}
else
if
(
cmd
.
cmd
==
"bn"
||
cmd
.
cmd
==
"bnext"
)
{
// :bn[ext]
switchToFile
(
currentFile
()
+
cmd
.
count
);
}
else
if
(
cmd
.
cmd
==
"bp"
||
cmd
.
cmd
==
"bprevious"
||
cmd
.
cmd
==
"bN"
||
cmd
.
cmd
==
"bNext"
)
{
// :bp[revious]
switchToFile
(
currentFile
()
-
cmd
.
count
);
}
else
{
// Check whether one of the configure commands matches.
typedef
CommandMap
::
const_iterator
Iterator
;
...
...
@@ -1125,23 +1122,22 @@ void FakeVimPluginPrivate::changeSelection
bt
->
setExtraSelections
(
BaseTextEditor
::
FakeVimSelection
,
selection
);
}
void
FakeVimPluginPrivate
::
switchFile
(
bool
previous
)
int
FakeVimPluginPrivate
::
currentFile
()
const
{
Core
::
OpenEditorsModel
*
model
=
editorManager
()
->
openedEditorsModel
();
IEditor
*
cur
=
Core
::
EditorManager
::
instance
()
->
currentEditor
();
int
curIdx
=
model
->
indexOf
(
cur
).
row
();
int
nIdx
=
(
curIdx
+
model
->
rowCount
()
+
(
previous
?
-
1
:
1
))
%
model
->
rowCount
();
editorManager
()
->
activateEditor
(
model
->
index
(
nIdx
,
0
),
0
);
}
void
FakeVimPluginPrivate
::
switchFileNext
()
{
switchFile
(
false
);
return
model
->
indexOf
(
cur
).
row
();
}
void
FakeVimPluginPrivate
::
switchFile
Prev
(
)
void
FakeVimPluginPrivate
::
switch
To
File
(
int
n
)
{
switchFile
(
true
);
Core
::
OpenEditorsModel
*
model
=
editorManager
()
->
openedEditorsModel
();
int
size
=
model
->
rowCount
();
QTC_ASSERT
(
size
,
return
);
n
=
n
%
size
;
if
(
n
<
0
)
n
+=
size
;
editorManager
()
->
activateEditor
(
model
->
index
(
n
,
0
),
0
);
}
CommandMap
&
FakeVimExCommandsPage
::
exCommandMap
()
...
...
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