Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flatpak-qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
7196c94c
Commit
7196c94c
authored
Jul 02, 2009
by
Thorbjørn Lindeijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unduplicated code that applies an edit operation to all occurrences
parent
b11d3606
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
97 deletions
+81
-97
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+72
-97
src/plugins/cppeditor/cppeditor.h
src/plugins/cppeditor/cppeditor.h
+9
-0
No files found.
src/plugins/cppeditor/cppeditor.cpp
View file @
7196c94c
...
...
@@ -654,6 +654,48 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
static_cast
<
QHBoxLayout
*>
(
w
->
layout
())
->
insertWidget
(
0
,
m_methodCombo
,
1
);
}
void
CPPEditor
::
inAllRenameSelections
(
EditOperation
operation
,
const
QTextEdit
::
ExtraSelection
&
currentRenameSelection
,
QTextCursor
cursor
,
const
QString
&
text
)
{
m_inRename
=
true
;
cursor
.
beginEditBlock
();
const
int
offset
=
cursor
.
position
()
-
currentRenameSelection
.
cursor
.
anchor
();
for
(
int
i
=
0
;
i
<
m_renameSelections
.
size
();
++
i
)
{
QTextEdit
::
ExtraSelection
&
s
=
m_renameSelections
[
i
];
int
pos
=
s
.
cursor
.
anchor
();
int
endPos
=
s
.
cursor
.
position
();
s
.
cursor
.
setPosition
(
s
.
cursor
.
anchor
()
+
offset
);
switch
(
operation
)
{
case
DeletePreviousChar
:
s
.
cursor
.
deletePreviousChar
();
--
endPos
;
break
;
case
DeleteChar
:
s
.
cursor
.
deleteChar
();
--
endPos
;
break
;
case
InsertText
:
s
.
cursor
.
insertText
(
text
);
endPos
+=
text
.
length
();
break
;
}
s
.
cursor
.
setPosition
(
pos
);
s
.
cursor
.
setPosition
(
endPos
,
QTextCursor
::
KeepAnchor
);
}
cursor
.
endEditBlock
();
m_inRename
=
false
;
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
setTextCursor
(
cursor
);
}
void
CPPEditor
::
abortRename
()
{
m_currentRenameSelection
=
-
1
;
...
...
@@ -816,6 +858,9 @@ void CPPEditor::renameInPlace()
void
CPPEditor
::
onContentsChanged
(
int
position
,
int
charsRemoved
,
int
charsAdded
)
{
Q_UNUSED
(
position
)
Q_UNUSED
(
charsAdded
)
if
(
!
m_inRename
)
abortRename
();
...
...
@@ -1372,10 +1417,6 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
foreach
(
QAction
*
action
,
contextMenu
->
actions
())
menu
->
addAction
(
action
);
QAction
*
simplifyDeclarations
=
new
QAction
(
tr
(
"Simplify Declarations"
),
menu
);
connect
(
simplifyDeclarations
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
simplifyDeclarations
()));
menu
->
addAction
(
simplifyDeclarations
);
const
QList
<
QTextEdit
::
ExtraSelection
>
selections
=
extraSelections
(
BaseTextEditor
::
CodeSemanticsSelection
);
...
...
@@ -1458,9 +1499,10 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
return
;
}
QTextEdit
::
ExtraSelection
currentRenameSelection
=
m_renameSelections
.
at
(
m_currentRenameSelection
);
QTextCursor
::
MoveMode
moveMode
=
(
e
->
modifiers
()
&
Qt
::
ShiftModifier
)
?
QTextCursor
::
KeepAnchor
:
QTextCursor
::
MoveAnchor
;
const
QTextEdit
::
ExtraSelection
&
currentRenameSelection
=
m_renameSelections
.
at
(
m_currentRenameSelection
);
QTextCursor
cursor
=
textCursor
();
const
QTextCursor
::
MoveMode
moveMode
=
(
e
->
modifiers
()
&
Qt
::
ShiftModifier
)
?
QTextCursor
::
KeepAnchor
:
QTextCursor
::
MoveAnchor
;
switch
(
e
->
key
())
{
case
Qt
::
Key_Enter
:
...
...
@@ -1470,94 +1512,50 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
e
->
accept
();
return
;
case
Qt
::
Key_Home
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
>
currentRenameSelection
.
cursor
.
anchor
()
&&
c
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
c
.
setPosition
(
currentRenameSelection
.
cursor
.
anchor
(),
moveMode
);
setTextCursor
(
c
);
// Send home to start of name when within the name and not at the start
if
(
c
ursor
.
position
()
>
currentRenameSelection
.
cursor
.
anchor
()
&&
c
ursor
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
c
ursor
.
setPosition
(
currentRenameSelection
.
cursor
.
anchor
(),
moveMode
);
setTextCursor
(
c
ursor
);
e
->
accept
();
return
;
}
break
;
}
case
Qt
::
Key_End
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
c
.
position
()
<
currentRenameSelection
.
cursor
.
position
())
{
c
.
setPosition
(
currentRenameSelection
.
cursor
.
position
(),
moveMode
);
setTextCursor
(
c
);
// Send end to end of name when within the name and not at the end
if
(
c
ursor
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
c
ursor
.
position
()
<
currentRenameSelection
.
cursor
.
position
())
{
c
ursor
.
setPosition
(
currentRenameSelection
.
cursor
.
position
(),
moveMode
);
setTextCursor
(
c
ursor
);
e
->
accept
();
return
;
}
break
;
}
case
Qt
::
Key_Backspace
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
==
currentRenameSelection
.
cursor
.
anchor
())
{
// Eat
if
(
cursor
.
position
()
==
currentRenameSelection
.
cursor
.
anchor
())
{
// Eat backspace at start of name
e
->
accept
();
return
;
}
else
if
(
c
.
position
()
>
currentRenameSelection
.
cursor
.
anchor
()
&&
c
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
int
offset
=
c
.
position
()
-
currentRenameSelection
.
cursor
.
anchor
();
m_inRename
=
true
;
c
.
beginEditBlock
();
for
(
int
i
=
0
;
i
<
m_renameSelections
.
size
();
++
i
)
{
QTextEdit
::
ExtraSelection
&
s
=
m_renameSelections
[
i
];
int
pos
=
s
.
cursor
.
anchor
();
int
endPos
=
s
.
cursor
.
position
();
s
.
cursor
.
setPosition
(
s
.
cursor
.
anchor
()
+
offset
);
s
.
cursor
.
deletePreviousChar
();
s
.
cursor
.
setPosition
(
pos
);
s
.
cursor
.
setPosition
(
endPos
-
1
,
QTextCursor
::
KeepAnchor
);
}
c
.
endEditBlock
();
m_inRename
=
false
;
setTextCursor
(
c
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
}
else
if
(
cursor
.
position
()
>
currentRenameSelection
.
cursor
.
anchor
()
&&
cursor
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
inAllRenameSelections
(
DeletePreviousChar
,
currentRenameSelection
,
cursor
);
e
->
accept
();
return
;
}
break
;
}
case
Qt
::
Key_Delete
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
==
currentRenameSelection
.
cursor
.
position
())
{
// Eat
if
(
cursor
.
position
()
==
currentRenameSelection
.
cursor
.
position
())
{
// Eat delete at end of name
e
->
accept
();
return
;
}
else
if
(
c
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
c
.
position
()
<
currentRenameSelection
.
cursor
.
position
())
{
int
offset
=
c
.
position
()
-
currentRenameSelection
.
cursor
.
anchor
();
m_inRename
=
true
;
c
.
beginEditBlock
();
for
(
int
i
=
0
;
i
<
m_renameSelections
.
size
();
++
i
)
{
QTextEdit
::
ExtraSelection
&
s
=
m_renameSelections
[
i
];
int
pos
=
s
.
cursor
.
anchor
();
int
endPos
=
s
.
cursor
.
position
();
s
.
cursor
.
setPosition
(
s
.
cursor
.
anchor
()
+
offset
);
s
.
cursor
.
deleteChar
();
s
.
cursor
.
setPosition
(
pos
);
s
.
cursor
.
setPosition
(
endPos
-
1
,
QTextCursor
::
KeepAnchor
);
}
c
.
endEditBlock
();
m_inRename
=
false
;
setTextCursor
(
c
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
}
else
if
(
cursor
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
cursor
.
position
()
<
currentRenameSelection
.
cursor
.
position
())
{
inAllRenameSelections
(
DeleteChar
,
currentRenameSelection
,
cursor
);
e
->
accept
();
return
;
}
...
...
@@ -1565,34 +1563,11 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
}
default:
{
QString
text
=
e
->
text
();
if
(
!
text
.
isEmpty
()
&&
text
.
at
(
0
).
isPrint
())
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
c
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
int
offset
=
c
.
position
()
-
currentRenameSelection
.
cursor
.
anchor
();
m_inRename
=
true
;
c
.
beginEditBlock
();
for
(
int
i
=
0
;
i
<
m_renameSelections
.
size
();
++
i
)
{
QTextEdit
::
ExtraSelection
&
s
=
m_renameSelections
[
i
];
int
pos
=
s
.
cursor
.
anchor
();
int
endPos
=
s
.
cursor
.
position
();
s
.
cursor
.
setPosition
(
s
.
cursor
.
anchor
()
+
offset
);
s
.
cursor
.
insertText
(
text
);
s
.
cursor
.
setPosition
(
pos
);
s
.
cursor
.
setPosition
(
endPos
+
text
.
length
(),
QTextCursor
::
KeepAnchor
);
}
c
.
endEditBlock
();
m_inRename
=
false
;
setTextCursor
(
c
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
if
(
cursor
.
position
()
>=
currentRenameSelection
.
cursor
.
anchor
()
&&
cursor
.
position
()
<=
currentRenameSelection
.
cursor
.
position
())
{
inAllRenameSelections
(
InsertText
,
currentRenameSelection
,
cursor
,
text
);
e
->
accept
();
return
;
}
...
...
src/plugins/cppeditor/cppeditor.h
View file @
7196c94c
...
...
@@ -143,6 +143,15 @@ private:
void
createToolBar
(
CPPEditorEditable
*
editable
);
enum
EditOperation
{
DeleteChar
,
DeletePreviousChar
,
InsertText
};
void
inAllRenameSelections
(
EditOperation
operation
,
const
QTextEdit
::
ExtraSelection
&
currentRenameSelection
,
QTextCursor
cursor
,
const
QString
&
text
=
QString
());
void
abortRename
();
struct
Link
...
...
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