forked from qt-creator/qt-creator
Add replace action. Replace the icons for replace with text-only.
Also show "Replace", "Replace & Find" and "Replace All" in the tool bar, i.e. don't show the "Replace & Find Previous" in the tool bar to avoid it getting crowded. Reviewed-by: Thorbjørn Lindeijer
This commit is contained in:
@@ -154,6 +154,8 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void replace(const QString &, const QString &,
|
||||||
|
Find::IFindSupport::FindFlags) { }
|
||||||
bool replaceStep(const QString &, const QString &,
|
bool replaceStep(const QString &, const QString &,
|
||||||
Find::IFindSupport::FindFlags) { return false;}
|
Find::IFindSupport::FindFlags) { return false;}
|
||||||
int replaceAll(const QString &, const QString &,
|
int replaceAll(const QString &, const QString &,
|
||||||
|
|||||||
@@ -153,8 +153,15 @@ IFindSupport::Result BaseTextFind::findStep(const QString &txt, IFindSupport::Fi
|
|||||||
return found ? Found : NotFound;
|
return found ? Found : NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTextFind::replaceStep(const QString &before, const QString &after,
|
void BaseTextFind::replace(const QString &before, const QString &after,
|
||||||
IFindSupport::FindFlags findFlags)
|
IFindSupport::FindFlags findFlags)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = replaceInternal(before, after, findFlags);
|
||||||
|
setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCursor BaseTextFind::replaceInternal(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags)
|
||||||
{
|
{
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
bool usesRegExp = (findFlags & IFindSupport::FindRegularExpression);
|
bool usesRegExp = (findFlags & IFindSupport::FindRegularExpression);
|
||||||
@@ -169,6 +176,13 @@ bool BaseTextFind::replaceStep(const QString &before, const QString &after,
|
|||||||
if ((findFlags&IFindSupport::FindBackward) != 0)
|
if ((findFlags&IFindSupport::FindBackward) != 0)
|
||||||
cursor.setPosition(start);
|
cursor.setPosition(start);
|
||||||
}
|
}
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseTextFind::replaceStep(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = replaceInternal(before, after, findFlags);
|
||||||
return find(before, findFlags, cursor);
|
return find(before, findFlags, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public:
|
|||||||
|
|
||||||
Result findIncremental(const QString &txt, IFindSupport::FindFlags findFlags);
|
Result findIncremental(const QString &txt, IFindSupport::FindFlags findFlags);
|
||||||
Result findStep(const QString &txt, IFindSupport::FindFlags findFlags);
|
Result findStep(const QString &txt, IFindSupport::FindFlags findFlags);
|
||||||
|
void replace(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags);
|
||||||
bool replaceStep(const QString &before, const QString &after,
|
bool replaceStep(const QString &before, const QString &after,
|
||||||
IFindSupport::FindFlags findFlags);
|
IFindSupport::FindFlags findFlags);
|
||||||
int replaceAll(const QString &before, const QString &after,
|
int replaceAll(const QString &before, const QString &after,
|
||||||
@@ -76,6 +78,8 @@ private:
|
|||||||
bool find(const QString &txt,
|
bool find(const QString &txt,
|
||||||
IFindSupport::FindFlags findFlags,
|
IFindSupport::FindFlags findFlags,
|
||||||
QTextCursor start);
|
QTextCursor start);
|
||||||
|
QTextCursor replaceInternal(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags);
|
||||||
|
|
||||||
QTextCursor textCursor() const;
|
QTextCursor textCursor() const;
|
||||||
void setTextCursor(const QTextCursor&);
|
void setTextCursor(const QTextCursor&);
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ IFindSupport::Result CurrentDocumentFind::findStep(const QString &txt, IFindSupp
|
|||||||
return m_currentFind->findStep(txt, findFlags);
|
return m_currentFind->findStep(txt, findFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CurrentDocumentFind::replace(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_currentFind, return);
|
||||||
|
m_currentFind->replace(before, after, findFlags);
|
||||||
|
}
|
||||||
|
|
||||||
bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after,
|
bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after,
|
||||||
IFindSupport::FindFlags findFlags)
|
IFindSupport::FindFlags findFlags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public:
|
|||||||
void highlightAll(const QString &txt, IFindSupport::FindFlags findFlags);
|
void highlightAll(const QString &txt, IFindSupport::FindFlags findFlags);
|
||||||
IFindSupport::Result findIncremental(const QString &txt, IFindSupport::FindFlags findFlags);
|
IFindSupport::Result findIncremental(const QString &txt, IFindSupport::FindFlags findFlags);
|
||||||
IFindSupport::Result findStep(const QString &txt, IFindSupport::FindFlags findFlags);
|
IFindSupport::Result findStep(const QString &txt, IFindSupport::FindFlags findFlags);
|
||||||
|
void replace(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags);
|
||||||
bool replaceStep(const QString &before, const QString &after,
|
bool replaceStep(const QString &before, const QString &after,
|
||||||
IFindSupport::FindFlags findFlags);
|
IFindSupport::FindFlags findFlags);
|
||||||
int replaceAll(const QString &before, const QString &after,
|
int replaceAll(const QString &before, const QString &after,
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
m_enterFindStringAction(0),
|
m_enterFindStringAction(0),
|
||||||
m_findNextAction(0),
|
m_findNextAction(0),
|
||||||
m_findPreviousAction(0),
|
m_findPreviousAction(0),
|
||||||
|
m_replaceAction(0),
|
||||||
m_replaceNextAction(0),
|
m_replaceNextAction(0),
|
||||||
|
m_replacePreviousAction(0),
|
||||||
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
||||||
m_regexpIcon(":/find/images/regexp.png"),
|
m_regexpIcon(":/find/images/regexp.png"),
|
||||||
m_wholewordsIcon(":/find/images/wholewords.png"),
|
m_wholewordsIcon(":/find/images/wholewords.png"),
|
||||||
@@ -168,7 +170,15 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
|
||||||
m_ui.findPreviousButton->setDefaultAction(cmd->action());
|
m_ui.findPreviousButton->setDefaultAction(cmd->action());
|
||||||
|
|
||||||
m_replaceNextAction = new QAction(tr("Replace && Find Next"), this);
|
m_replaceAction = new QAction(tr("Replace"), this);
|
||||||
|
cmd = am->registerAction(m_replaceAction, Constants::REPLACE, globalcontext);
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence());
|
||||||
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
||||||
|
connect(m_replaceAction, SIGNAL(triggered()), this, SLOT(invokeReplace()));
|
||||||
|
m_ui.replaceButton->setDefaultAction(cmd->action());
|
||||||
|
|
||||||
|
m_replaceNextAction = new QAction(tr("Replace && Find"), this);
|
||||||
|
m_replaceNextAction->setIconText(tr("Replace && Find")); // work around bug in Qt that kills ampersands in tool button
|
||||||
cmd = am->registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext);
|
cmd = am->registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+=")));
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+=")));
|
||||||
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
||||||
@@ -181,7 +191,6 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+=")));
|
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+=")));
|
||||||
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
|
||||||
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
|
||||||
m_ui.replacePreviousButton->setDefaultAction(cmd->action());
|
|
||||||
|
|
||||||
m_replaceAllAction = new QAction(tr("Replace All"), this);
|
m_replaceAllAction = new QAction(tr("Replace All"), this);
|
||||||
cmd = am->registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext);
|
cmd = am->registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext);
|
||||||
@@ -315,6 +324,7 @@ void FindToolBar::updateToolBar()
|
|||||||
m_findNextAction->setEnabled(enabled);
|
m_findNextAction->setEnabled(enabled);
|
||||||
m_findPreviousAction->setEnabled(enabled);
|
m_findPreviousAction->setEnabled(enabled);
|
||||||
|
|
||||||
|
m_replaceAction->setEnabled(replaceEnabled);
|
||||||
m_replaceNextAction->setEnabled(replaceEnabled);
|
m_replaceNextAction->setEnabled(replaceEnabled);
|
||||||
m_replacePreviousAction->setEnabled(replaceEnabled);
|
m_replacePreviousAction->setEnabled(replaceEnabled);
|
||||||
m_replaceAllAction->setEnabled(replaceEnabled);
|
m_replaceAllAction->setEnabled(replaceEnabled);
|
||||||
@@ -332,7 +342,7 @@ void FindToolBar::updateToolBar()
|
|||||||
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
||||||
m_ui.replaceEdit->setVisible(replaceEnabled);
|
m_ui.replaceEdit->setVisible(replaceEnabled);
|
||||||
m_ui.replaceLabel->setVisible(replaceEnabled);
|
m_ui.replaceLabel->setVisible(replaceEnabled);
|
||||||
m_ui.replacePreviousButton->setVisible(replaceEnabled);
|
m_ui.replaceButton->setVisible(replaceEnabled);
|
||||||
m_ui.replaceNextButton->setVisible(replaceEnabled);
|
m_ui.replaceNextButton->setVisible(replaceEnabled);
|
||||||
m_ui.replaceAllButton->setVisible(replaceEnabled);
|
m_ui.replaceAllButton->setVisible(replaceEnabled);
|
||||||
layout()->invalidate();
|
layout()->invalidate();
|
||||||
@@ -433,6 +443,16 @@ void FindToolBar::invokeFindIncremental()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FindToolBar::invokeReplace()
|
||||||
|
{
|
||||||
|
setFindFlag(IFindSupport::FindBackward, false);
|
||||||
|
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
|
||||||
|
m_plugin->updateFindCompletion(getFindText());
|
||||||
|
m_plugin->updateReplaceCompletion(getReplaceText());
|
||||||
|
m_currentDocumentFind->replace(getFindText(), getReplaceText(), effectiveFindFlags());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FindToolBar::invokeReplaceNext()
|
void FindToolBar::invokeReplaceNext()
|
||||||
{
|
{
|
||||||
setFindFlag(IFindSupport::FindBackward, false);
|
setFindFlag(IFindSupport::FindBackward, false);
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ private slots:
|
|||||||
void invokeFindNext();
|
void invokeFindNext();
|
||||||
void invokeFindPrevious();
|
void invokeFindPrevious();
|
||||||
void invokeFindStep();
|
void invokeFindStep();
|
||||||
|
void invokeReplace();
|
||||||
void invokeReplaceNext();
|
void invokeReplaceNext();
|
||||||
void invokeReplacePrevious();
|
void invokeReplacePrevious();
|
||||||
void invokeReplaceStep();
|
void invokeReplaceStep();
|
||||||
@@ -120,6 +121,7 @@ private:
|
|||||||
QAction *m_enterFindStringAction;
|
QAction *m_enterFindStringAction;
|
||||||
QAction *m_findNextAction;
|
QAction *m_findNextAction;
|
||||||
QAction *m_findPreviousAction;
|
QAction *m_findPreviousAction;
|
||||||
|
QAction *m_replaceAction;
|
||||||
QAction *m_replaceNextAction;
|
QAction *m_replaceNextAction;
|
||||||
QAction *m_replacePreviousAction;
|
QAction *m_replacePreviousAction;
|
||||||
QAction *m_replaceAllAction;
|
QAction *m_replaceAllAction;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="Utils::FilterLineEdit" name="replaceEdit"/>
|
<widget class="Utils::FilterLineEdit" name="replaceEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
@@ -108,10 +108,16 @@
|
|||||||
<number>3</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="replacePreviousButton">
|
<widget class="QToolButton" name="replaceButton">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::NoFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Replace</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
</property>
|
||||||
<property name="arrowType">
|
<property name="arrowType">
|
||||||
<enum>Qt::LeftArrow</enum>
|
<enum>Qt::LeftArrow</enum>
|
||||||
</property>
|
</property>
|
||||||
@@ -125,6 +131,12 @@
|
|||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::NoFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Replace && Find</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
</property>
|
||||||
<property name="arrowType">
|
<property name="arrowType">
|
||||||
<enum>Qt::RightArrow</enum>
|
<enum>Qt::RightArrow</enum>
|
||||||
</property>
|
</property>
|
||||||
@@ -136,7 +148,7 @@
|
|||||||
<font/>
|
<font/>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>All</string>
|
<string>Replace All</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolButtonStyle">
|
<property name="toolButtonStyle">
|
||||||
<enum>Qt::ToolButtonTextOnly</enum>
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ public:
|
|||||||
virtual void highlightAll(const QString &txt, FindFlags findFlags);
|
virtual void highlightAll(const QString &txt, FindFlags findFlags);
|
||||||
virtual Result findIncremental(const QString &txt, FindFlags findFlags) = 0;
|
virtual Result findIncremental(const QString &txt, FindFlags findFlags) = 0;
|
||||||
virtual Result findStep(const QString &txt, FindFlags findFlags) = 0;
|
virtual Result findStep(const QString &txt, FindFlags findFlags) = 0;
|
||||||
|
virtual void replace(const QString &before, const QString &after,
|
||||||
|
FindFlags findFlags) = 0;
|
||||||
virtual bool replaceStep(const QString &before, const QString &after,
|
virtual bool replaceStep(const QString &before, const QString &after,
|
||||||
FindFlags findFlags) = 0;
|
FindFlags findFlags) = 0;
|
||||||
virtual int replaceAll(const QString &before, const QString &after,
|
virtual int replaceAll(const QString &before, const QString &after,
|
||||||
|
|||||||
@@ -160,6 +160,14 @@ namespace Internal {
|
|||||||
return IFindSupport::NotFound;
|
return IFindSupport::NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void replace(const QString &before, const QString &after,
|
||||||
|
IFindSupport::FindFlags findFlags)
|
||||||
|
{
|
||||||
|
Q_UNUSED(before)
|
||||||
|
Q_UNUSED(after)
|
||||||
|
Q_UNUSED(findFlags)
|
||||||
|
}
|
||||||
|
|
||||||
bool replaceStep(const QString &before, const QString &after,
|
bool replaceStep(const QString &before, const QString &after,
|
||||||
IFindSupport::FindFlags findFlags)
|
IFindSupport::FindFlags findFlags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ const char * const FIND_IN_DOCUMENT = "Find.FindInCurrentDocument";
|
|||||||
const char * const FIND_NEXT = "Find.FindNext";
|
const char * const FIND_NEXT = "Find.FindNext";
|
||||||
const char * const FIND_PREVIOUS = "Find.FindPrevious";
|
const char * const FIND_PREVIOUS = "Find.FindPrevious";
|
||||||
const char * const FIND_ALL = "Find.FindAll";
|
const char * const FIND_ALL = "Find.FindAll";
|
||||||
|
const char * const REPLACE = "Find.Replace";
|
||||||
const char * const REPLACE_NEXT = "Find.ReplaceNext";
|
const char * const REPLACE_NEXT = "Find.ReplaceNext";
|
||||||
const char * const REPLACE_PREVIOUS = "Find.ReplacePrevious";
|
const char * const REPLACE_PREVIOUS = "Find.ReplacePrevious";
|
||||||
const char * const REPLACE_ALL = "Find.ReplaceAll";
|
const char * const REPLACE_ALL = "Find.ReplaceAll";
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public:
|
|||||||
|
|
||||||
Result findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
Result findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
||||||
Result findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
Result findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
||||||
|
void replace(const QString &, const QString &,
|
||||||
|
Find::IFindSupport::FindFlags ) { }
|
||||||
bool replaceStep(const QString &, const QString &,
|
bool replaceStep(const QString &, const QString &,
|
||||||
Find::IFindSupport::FindFlags ) { return false; }
|
Find::IFindSupport::FindFlags ) { return false; }
|
||||||
int replaceAll(const QString &, const QString &,
|
int replaceAll(const QString &, const QString &,
|
||||||
@@ -85,6 +87,8 @@ public:
|
|||||||
|
|
||||||
Result findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
Result findIncremental(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
||||||
Result findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
Result findStep(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
||||||
|
void replace(const QString &, const QString &,
|
||||||
|
Find::IFindSupport::FindFlags ) { }
|
||||||
bool replaceStep(const QString &, const QString &,
|
bool replaceStep(const QString &, const QString &,
|
||||||
Find::IFindSupport::FindFlags ) { return false; }
|
Find::IFindSupport::FindFlags ) { return false; }
|
||||||
int replaceAll(const QString &, const QString &,
|
int replaceAll(const QString &, const QString &,
|
||||||
|
|||||||
Reference in New Issue
Block a user