Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
8580234e
Commit
8580234e
authored
Dec 10, 2008
by
mae
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Move Line Up and Move Line Down actions. Can be extended to
support statements later.
parent
e665fc82
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
1 deletion
+88
-1
src/plugins/texteditor/basetexteditor.cpp
src/plugins/texteditor/basetexteditor.cpp
+63
-1
src/plugins/texteditor/basetexteditor.h
src/plugins/texteditor/basetexteditor.h
+4
-0
src/plugins/texteditor/texteditoractionhandler.cpp
src/plugins/texteditor/texteditoractionhandler.cpp
+15
-0
src/plugins/texteditor/texteditoractionhandler.h
src/plugins/texteditor/texteditoractionhandler.h
+4
-0
src/plugins/texteditor/texteditorconstants.h
src/plugins/texteditor/texteditorconstants.h
+2
-0
No files found.
src/plugins/texteditor/basetexteditor.cpp
View file @
8580234e
...
...
@@ -684,6 +684,64 @@ void BaseTextEditor::selectBlockDown()
_q_matchParentheses
();
}
void
BaseTextEditor
::
moveLineUp
()
{
moveLineUpDown
(
true
);
}
void
BaseTextEditor
::
moveLineDown
()
{
moveLineUpDown
(
false
);
}
void
BaseTextEditor
::
moveLineUpDown
(
bool
up
)
{
QTextCursor
cursor
=
textCursor
();
QTextCursor
move
=
cursor
;
move
.
beginEditBlock
();
bool
hasSelection
=
cursor
.
hasSelection
();
if
(
cursor
.
hasSelection
())
{
move
.
setPosition
(
cursor
.
selectionStart
());
move
.
movePosition
(
QTextCursor
::
StartOfBlock
);
move
.
setPosition
(
cursor
.
selectionEnd
(),
QTextCursor
::
KeepAnchor
);
move
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
}
else
{
move
.
movePosition
(
QTextCursor
::
StartOfBlock
);
move
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
}
QString
text
=
move
.
selectedText
();
move
.
movePosition
(
QTextCursor
::
Right
,
QTextCursor
::
KeepAnchor
);
move
.
removeSelectedText
();
if
(
up
)
{
move
.
movePosition
(
QTextCursor
::
PreviousBlock
);
move
.
insertBlock
();
move
.
movePosition
(
QTextCursor
::
Left
);
}
else
{
move
.
movePosition
(
QTextCursor
::
EndOfBlock
);
if
(
move
.
atBlockStart
())
{
// empty block
move
.
movePosition
(
QTextCursor
::
NextBlock
);
move
.
insertBlock
();
move
.
movePosition
(
QTextCursor
::
Left
);
}
else
{
move
.
insertBlock
();
}
}
int
start
=
move
.
position
();
move
.
clearSelection
();
move
.
insertText
(
text
);
int
end
=
move
.
position
();
move
.
endEditBlock
();
if
(
hasSelection
)
{
move
.
setPosition
(
start
);
move
.
setPosition
(
end
,
QTextCursor
::
KeepAnchor
);
}
setTextCursor
(
move
);
}
void
BaseTextEditor
::
cleanWhitespace
()
{
...
...
@@ -740,9 +798,13 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
QTextCursor
cursor
=
textCursor
();
if
(
d
->
m_inBlockSelectionMode
)
cursor
.
clearSelection
();
cursor
.
insertBlock
();
if
(
d
->
m_document
->
tabSettings
().
m_autoIndent
)
{
cursor
.
beginEditBlock
();
cursor
.
insertBlock
();
indent
(
document
(),
cursor
,
QChar
::
Null
);
cursor
.
endEditBlock
();
}
else
{
cursor
.
insertBlock
();
}
e
->
accept
();
setTextCursor
(
cursor
);
...
...
src/plugins/texteditor/basetexteditor.h
View file @
8580234e
...
...
@@ -329,6 +329,9 @@ public slots:
void
selectBlockUp
();
void
selectBlockDown
();
void
moveLineUp
();
void
moveLineDown
();
void
cleanWhitespace
();
signals:
...
...
@@ -447,6 +450,7 @@ private:
void
indentOrUnindent
(
bool
doIndent
);
void
handleHomeKey
(
bool
anchor
);
void
handleBackspaceKey
();
void
moveLineUpDown
(
bool
up
);
void
toggleBlockVisible
(
const
QTextBlock
&
block
);
QRect
collapseBox
(
const
QTextBlock
&
block
);
...
...
src/plugins/texteditor/texteditoractionhandler.cpp
View file @
8580234e
...
...
@@ -71,6 +71,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core,
=
m_gotoBlockStartAction
=
m_gotoBlockStartWithSelectionAction
=
m_gotoBlockEndAction
=
m_gotoBlockEndWithSelectionAction
=
m_selectBlockUpAction
=
m_selectBlockDownAction
=
m_moveLineUpAction
=
m_moveLineDownAction
=
0
;
m_contextId
<<
m_core
->
uniqueIDManager
()
->
uniqueIdentifier
(
context
);
...
...
@@ -223,6 +224,16 @@ void TextEditorActionHandler::createActions()
command
=
am
->
registerAction
(
m_selectBlockDownAction
,
Constants
::
SELECT_BLOCK_DOWN
,
m_contextId
);
command
->
setDefaultKeySequence
(
QKeySequence
(
tr
(
"Ctrl+Shift+U"
)));
connect
(
m_selectBlockDownAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
selectBlockDown
()));
m_moveLineUpAction
=
new
QAction
(
tr
(
"Move Line Up"
),
this
);
command
=
am
->
registerAction
(
m_moveLineUpAction
,
Constants
::
MOVE_LINE_UP
,
m_contextId
);
command
->
setDefaultKeySequence
(
QKeySequence
(
tr
(
"Ctrl+Shift+Up"
)));
connect
(
m_moveLineUpAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
moveLineUp
()));
m_moveLineDownAction
=
new
QAction
(
tr
(
"Move Line Down"
),
this
);
command
=
am
->
registerAction
(
m_moveLineDownAction
,
Constants
::
MOVE_LINE_DOWN
,
m_contextId
);
command
->
setDefaultKeySequence
(
QKeySequence
(
tr
(
"Ctrl+Shift+Down"
)));
connect
(
m_moveLineDownAction
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
moveLineDown
()));
}
bool
TextEditorActionHandler
::
supportsAction
(
const
QString
&
/*id */
)
const
...
...
@@ -287,6 +298,8 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
m_gotoBlockEndWithSelectionAction
->
setEnabled
(
um
!=
NoEditor
);
m_selectBlockUpAction
->
setEnabled
(
um
!=
NoEditor
);
m_selectBlockDownAction
->
setEnabled
(
um
!=
NoEditor
);
m_moveLineUpAction
->
setEnabled
(
um
!=
NoEditor
);
m_moveLineDownAction
->
setEnabled
(
um
!=
NoEditor
);
m_visualizeWhitespaceAction
->
setEnabled
(
um
!=
NoEditor
);
if
(
m_currentEditor
)
...
...
@@ -390,6 +403,8 @@ FUNCTION(gotoBlockStartWithSelection)
FUNCTION
(
gotoBlockEndWithSelection
)
FUNCTION
(
selectBlockUp
)
FUNCTION
(
selectBlockDown
)
FUNCTION
(
moveLineUp
)
FUNCTION
(
moveLineDown
)
void
TextEditorActionHandler
::
updateCurrentEditor
(
Core
::
IContext
*
object
)
{
...
...
src/plugins/texteditor/texteditoractionhandler.h
View file @
8580234e
...
...
@@ -116,6 +116,8 @@ private slots:
void
gotoBlockEndWithSelection
();
void
selectBlockUp
();
void
selectBlockDown
();
void
moveLineUp
();
void
moveLineDown
();
void
updateCurrentEditor
(
Core
::
IContext
*
object
);
private:
...
...
@@ -145,6 +147,8 @@ private:
QAction
*
m_gotoBlockEndWithSelectionAction
;
QAction
*
m_selectBlockUpAction
;
QAction
*
m_selectBlockDownAction
;
QAction
*
m_moveLineUpAction
;
QAction
*
m_moveLineDownAction
;
uint
m_optionalActions
;
QPointer
<
BaseTextEditor
>
m_currentEditor
;
...
...
src/plugins/texteditor/texteditorconstants.h
View file @
8580234e
...
...
@@ -55,6 +55,8 @@ const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd";
const
char
*
const
GOTO_BLOCK_END_WITH_SELECTION
=
"TextEditor.GotoBlockEndWithSelection"
;
const
char
*
const
SELECT_BLOCK_UP
=
"TextEditor.SelectBlockUp"
;
const
char
*
const
SELECT_BLOCK_DOWN
=
"TextEditor.SelectBlockDown"
;
const
char
*
const
MOVE_LINE_UP
=
"TextEditor.MoveLineUp"
;
const
char
*
const
MOVE_LINE_DOWN
=
"TextEditor.MoveLineDown"
;
const
char
*
const
DELETE_LINE
=
"TextEditor.DeleteLine"
;
const
char
*
const
DELETE_WORD
=
"TextEditor.DeleteWord"
;
const
char
*
const
SELECT_ENCODING
=
"TextEditor.SelectEncoding"
;
...
...
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