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
c55eb917
Commit
c55eb917
authored
Jul 01, 2009
by
Thorbjørn Lindeijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abort rename when text is changed due to unsupported actions
Done with Roberto Raggi and mae.
parent
d9c8f945
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
34 deletions
+83
-34
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cppeditor/cppeditor.cpp
+79
-34
src/plugins/cppeditor/cppeditor.h
src/plugins/cppeditor/cppeditor.h
+4
-0
No files found.
src/plugins/cppeditor/cppeditor.cpp
View file @
c55eb917
...
...
@@ -656,6 +656,7 @@ CPPEditor::CPPEditor(QWidget *parent)
,
m_mouseNavigationEnabled
(
true
)
,
m_showingLink
(
false
)
,
m_currentRenameSelection
(
-
1
)
,
m_inRename
(
false
)
{
setParenthesesMatchingEnabled
(
true
);
setMarksVisible
(
true
);
...
...
@@ -748,6 +749,7 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
connect
(
this
,
SIGNAL
(
cursorPositionChanged
()),
this
,
SLOT
(
updateMethodBoxIndex
()));
connect
(
this
,
SIGNAL
(
cursorPositionChanged
()),
this
,
SLOT
(
updateUses
()));
connect
(
m_methodCombo
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
updateMethodBoxToolTip
()));
connect
(
document
(),
SIGNAL
(
contentsChange
(
int
,
int
,
int
)),
this
,
SLOT
(
onContentsChanged
(
int
,
int
,
int
)));
connect
(
file
(),
SIGNAL
(
changed
()),
this
,
SLOT
(
updateFileName
()));
...
...
@@ -757,6 +759,13 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
static_cast
<
QHBoxLayout
*>
(
w
->
layout
())
->
insertWidget
(
0
,
m_methodCombo
,
1
);
}
void
CPPEditor
::
abortRename
()
{
m_currentRenameSelection
=
-
1
;
m_renameSelections
.
clear
();
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
}
int
CPPEditor
::
previousBlockState
(
QTextBlock
block
)
const
{
block
=
block
.
previous
();
...
...
@@ -905,6 +914,8 @@ void CPPEditor::simplifyDeclarations()
void
CPPEditor
::
renameInPlace
()
{
updateUsesNow
();
QTextCursor
c
=
textCursor
();
m_currentRenameSelection
=
-
1
;
...
...
@@ -921,6 +932,15 @@ void CPPEditor::renameInPlace()
}
}
void
CPPEditor
::
onContentsChanged
(
int
position
,
int
charsRemoved
,
int
charsAdded
)
{
if
(
!
m_inRename
)
abortRename
();
if
(
charsRemoved
>
0
)
updateUses
();
}
void
CPPEditor
::
updateFileName
()
{
}
...
...
@@ -1442,11 +1462,7 @@ bool CPPEditor::event(QEvent *e)
{
switch
(
e
->
type
())
{
case
QEvent
::
ShortcutOverride
:
qDebug
()
<<
"Override?"
;
if
(
static_cast
<
QKeyEvent
*>
(
e
)
->
key
()
==
Qt
::
Key_Escape
&&
m_currentRenameSelection
!=
-
1
)
{
qDebug
()
<<
"Accept!"
;
if
(
static_cast
<
QKeyEvent
*>
(
e
)
->
key
()
==
Qt
::
Key_Escape
&&
m_currentRenameSelection
!=
-
1
)
{
e
->
accept
();
return
true
;
}
...
...
@@ -1560,7 +1576,6 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
return
;
}
QString
text
=
e
->
text
();
QTextEdit
::
ExtraSelection
currentRenameSelection
=
m_renameSelections
.
at
(
m_currentRenameSelection
);
QTextCursor
::
MoveMode
moveMode
=
(
e
->
modifiers
()
&
Qt
::
ShiftModifier
)
?
QTextCursor
::
KeepAnchor
:
QTextCursor
::
MoveAnchor
;
...
...
@@ -1569,47 +1584,37 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
case
Qt
::
Key_Enter
:
case
Qt
::
Key_Return
:
case
Qt
::
Key_Escape
:
m_currentRenameSelection
=
-
1
;
m_renameSelections
.
clear
();
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
abortRename
();
e
->
accept
();
break
;
return
;
case
Qt
::
Key_Home
:
{
QTextCursor
c
=
textCursor
();
c
.
setPosition
(
currentRenameSelection
.
cursor
.
anchor
(),
moveMode
);
setTextCursor
(
c
);
e
->
accept
();
break
;
return
;
}
case
Qt
::
Key_End
:
{
QTextCursor
c
=
textCursor
();
c
.
setPosition
(
currentRenameSelection
.
cursor
.
position
(),
moveMode
);
setTextCursor
(
c
);
e
->
accept
();
break
;
}
case
Qt
::
Key_Left
:
{
QTextCursor
c
=
textCursor
();
c
.
setPosition
(
qMax
(
c
.
position
()
-
1
,
currentRenameSelection
.
cursor
.
anchor
()),
moveMode
);
setTextCursor
(
c
);
e
->
accept
();
break
;
}
case
Qt
::
Key_Right
:
{
QTextCursor
c
=
textCursor
();
c
.
setPosition
(
qMin
(
c
.
position
()
+
1
,
currentRenameSelection
.
cursor
.
position
()),
moveMode
);
setTextCursor
(
c
);
e
->
accept
();
break
;
return
;
}
case
Qt
::
Key_Backspace
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
>
currentRenameSelection
.
cursor
.
anchor
()
if
(
c
.
position
()
==
currentRenameSelection
.
cursor
.
anchor
())
{
// Eat
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
];
...
...
@@ -1622,17 +1627,55 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
}
c
.
endEditBlock
();
m_inRename
=
false
;
setTextCursor
(
c
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
e
->
accept
();
}
else
{
return
;
}
break
;
}
case
Qt
::
Key_Delete
:
{
QTextCursor
c
=
textCursor
();
if
(
c
.
position
()
==
currentRenameSelection
.
cursor
.
position
())
{
// Eat
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
);
e
->
accept
();
qWarning
()
<<
"Backspace outside of where you can be"
;
return
;
}
break
;
}
default:
{
QString
text
=
e
->
text
();
if
(
!
text
.
isEmpty
()
&&
text
.
at
(
0
).
isPrint
())
{
QTextCursor
c
=
textCursor
();
...
...
@@ -1641,6 +1684,8 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
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
];
...
...
@@ -1653,20 +1698,20 @@ void CPPEditor::keyPressEvent(QKeyEvent *e)
}
c
.
endEditBlock
();
m_inRename
=
false
;
setTextCursor
(
c
);
setExtraSelections
(
CodeSemanticsSelection
,
m_renameSelections
);
e
->
accept
();
}
else
{
e
->
accept
();
qWarning
()
<<
"Whaa!"
;
return
;
}
}
else
{
e
->
accept
();
}
break
;
}
}
TextEditor
::
BaseTextEditor
::
keyPressEvent
(
e
);
}
void
CPPEditor
::
showLink
(
const
Link
&
link
)
...
...
src/plugins/cppeditor/cppeditor.h
View file @
c55eb917
...
...
@@ -128,6 +128,7 @@ private slots:
void
reformatDocument
();
void
simplifyDeclarations
();
void
renameInPlace
();
void
onContentsChanged
(
int
position
,
int
charsRemoved
,
int
charsAdded
);
private:
bool
sortedMethodOverview
()
const
;
...
...
@@ -143,6 +144,8 @@ private:
void
createToolBar
(
CPPEditorEditable
*
editable
);
void
abortRename
();
struct
Link
{
Link
(
const
QString
&
fileName
=
QString
(),
...
...
@@ -186,6 +189,7 @@ private:
QList
<
QTextEdit
::
ExtraSelection
>
m_renameSelections
;
int
m_currentRenameSelection
;
bool
m_inRename
;
};
}
// namespace Internal
...
...
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