summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklós Márton <martonmiklosqdev@gmail.com>2022-04-01 21:42:29 +0200
committerMiklos Marton <martonmiklosqdev@gmail.com>2022-04-07 14:53:47 +0200
commit463aed10c7b62fc03133a02e7d7d98bc750393d9 (patch)
treeec1cfca1ab682939fb628ff8c6ca656f53ca95aa
parentf3131ec7e7a6bd451706155e349306247b0e70c9 (diff)
linguist: Add Find Previous action
Change-Id: I061b5f79cc9cd0999ec8a4c343e248f284b2f82d Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/linguist/linguist/mainwindow.cpp16
-rw-r--r--src/linguist/linguist/mainwindow.h3
-rw-r--r--src/linguist/linguist/mainwindow.ui12
3 files changed, 26 insertions, 5 deletions
diff --git a/src/linguist/linguist/mainwindow.cpp b/src/linguist/linguist/mainwindow.cpp
index 7a1a3bb8d..91cc694bb 100644
--- a/src/linguist/linguist/mainwindow.cpp
+++ b/src/linguist/linguist/mainwindow.cpp
@@ -569,6 +569,7 @@ void MainWindow::modelCountChanged()
m_ui.actionFind->setEnabled(m_dataModel->contextCount() > 0);
m_ui.actionFindNext->setEnabled(false);
+ m_ui.actionFindPrev->setEnabled(false);
m_formPreviewView->setSourceContext(-1, 0);
}
@@ -986,13 +987,15 @@ bool MainWindow::searchItem(DataModel::FindLocation where, const QString &search
? Qt::CaseSensitive : Qt::CaseInsensitive) >= 0;
}
-void MainWindow::findAgain()
+void MainWindow::findAgain(FindDirection direction)
{
if (m_dataModel->contextCount() == 0)
return;
const QModelIndex &startIndex = m_messageView->currentIndex();
- QModelIndex index = nextMessage(startIndex);
+ QModelIndex index = (direction == FindNext
+ ? nextMessage(startIndex)
+ : prevMessage(startIndex));
while (index.isValid()) {
QModelIndex realIndex = m_sortedMessagesModel->mapToSource(index);
@@ -1052,7 +1055,9 @@ void MainWindow::findAgain()
if (index == startIndex)
break;
- index = nextMessage(index);
+ index = (direction == FindNext
+ ? nextMessage(index)
+ : prevMessage(index));
}
qApp->beep();
@@ -1792,6 +1797,7 @@ void MainWindow::findNext(const QString &text, DataModel::FindLocation where,
: QRegularExpression::CaseInsensitiveOption);
}
m_ui.actionFindNext->setEnabled(true);
+ m_ui.actionFindPrev->setEnabled(true);
findAgain();
}
@@ -1905,7 +1911,9 @@ void MainWindow::setupMenuBar()
connect(m_ui.actionFind, &QAction::triggered,
m_findDialog, &FindDialog::find);
connect(m_ui.actionFindNext, &QAction::triggered,
- this, &MainWindow::findAgain);
+ this, [this] {findAgain(FindNext);});
+ connect(m_ui.actionFindPrev, &QAction::triggered,
+ this, [this] {findAgain(FindPrev);});
connect(m_ui.actionSearchAndTranslate, &QAction::triggered,
this, &MainWindow::showTranslateDialog);
connect(m_ui.actionBatchTranslation, &QAction::triggered,
diff --git a/src/linguist/linguist/mainwindow.h b/src/linguist/linguist/mainwindow.h
index 3baca252c..0af722db8 100644
--- a/src/linguist/linguist/mainwindow.h
+++ b/src/linguist/linguist/mainwindow.h
@@ -72,6 +72,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
enum {PhraseCloseMenu, PhraseEditMenu, PhrasePrintMenu};
+ enum FindDirection {FindNext, FindPrev};
MainWindow();
~MainWindow();
@@ -107,7 +108,6 @@ private slots:
void print();
void closeFile();
bool closeAll();
- void findAgain();
void showTranslateDialog();
void showBatchTranslateDialog();
void showTranslationSettings();
@@ -170,6 +170,7 @@ private:
QModelIndex prevMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
bool doNext(bool checkUnfinished);
bool doPrev(bool checkUnfinished);
+ void findAgain(FindDirection direction = FindNext);
void updateStatistics();
void initViewHeaders();
diff --git a/src/linguist/linguist/mainwindow.ui b/src/linguist/linguist/mainwindow.ui
index 3c6ba951a..88d81868f 100644
--- a/src/linguist/linguist/mainwindow.ui
+++ b/src/linguist/linguist/mainwindow.ui
@@ -192,6 +192,7 @@
<addaction name="actionSelectAll"/>
<addaction name="separator"/>
<addaction name="actionFind"/>
+ <addaction name="actionFindPrev"/>
<addaction name="actionFindNext"/>
<addaction name="actionSearchAndTranslate"/>
<addaction name="actionBatchTranslation"/>
@@ -978,6 +979,17 @@
<enum>QAction::NoRole</enum>
</property>
</action>
+ <action name="actionFindPrev">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Find P&amp;revious</string>
+ </property>
+ <property name="shortcut">
+ <string>Shift+F3</string>
+ </property>
+ </action>
</widget>
<resources/>
<connections/>