Fix keyboard search
This commit is contained in:
parent
fefbe8a738
commit
3a4257c51f
6 changed files with 33 additions and 40 deletions
|
@ -70,7 +70,8 @@ bool ShortCut::eventFilter(QObject *obj, QEvent *e)
|
|||
emit refresh();
|
||||
} else if (keyEvent->key() >= Qt::Key_A && keyEvent->key() <= Qt::Key_Z) {
|
||||
// Handle select
|
||||
KeyboardSearchManager::self()->addKeys(keyEvent->text());
|
||||
// KeyboardSearchManager::self()->addKeys(keyEvent->text());
|
||||
emit keyPressed(keyEvent->text());
|
||||
keyEvent->ignore();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ signals:
|
|||
void selectAll();
|
||||
void backspace();
|
||||
void deleteFile();
|
||||
void keyPressed(const QString &text);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||
|
|
|
@ -90,7 +90,6 @@ FolderModel::FolderModel(QObject *parent)
|
|||
, m_viewAdapter(nullptr)
|
||||
, m_mimeAppManager(MimeAppManager::self())
|
||||
, m_sizeJob(nullptr)
|
||||
, m_keyboardSearchManager(KeyboardSearchManager::self())
|
||||
{
|
||||
QSettings settings("cutefishos", qApp->applicationName());
|
||||
m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool();
|
||||
|
@ -120,9 +119,6 @@ FolderModel::FolderModel(QObject *parent)
|
|||
connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged()));
|
||||
connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged()));
|
||||
connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
|
||||
|
||||
connect(m_keyboardSearchManager, &KeyboardSearchManager::searchTextChanged,
|
||||
this, &FolderModel::keyboardSearchChanged);
|
||||
}
|
||||
|
||||
FolderModel::~FolderModel()
|
||||
|
@ -1164,6 +1160,29 @@ void FolderModel::updateSelectedItemsSize()
|
|||
{
|
||||
}
|
||||
|
||||
void FolderModel::keyboardSearch(const QString &text)
|
||||
{
|
||||
if (rowCount() == 0)
|
||||
return;
|
||||
|
||||
int index;
|
||||
int currentIndex = -1;
|
||||
|
||||
if (m_selectionModel->hasSelection()) {
|
||||
currentIndex = m_selectionModel->selectedIndexes().first().row();
|
||||
}
|
||||
|
||||
index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
|
||||
|
||||
if (index < 0 || currentIndex == index)
|
||||
return;
|
||||
|
||||
if (index >= 0) {
|
||||
clearSelection();
|
||||
setSelected(index);
|
||||
}
|
||||
}
|
||||
|
||||
void FolderModel::restoreFromTrash()
|
||||
{
|
||||
if (!m_selectionModel->hasSelection())
|
||||
|
@ -1298,37 +1317,6 @@ void FolderModel::dragSelectedInternal(int x, int y)
|
|||
}
|
||||
}
|
||||
|
||||
void FolderModel::keyboardSearchChanged(const QString &text, bool searchFromNextItem)
|
||||
{
|
||||
Q_UNUSED(searchFromNextItem);
|
||||
|
||||
if (rowCount() == 0)
|
||||
return;
|
||||
|
||||
int index;
|
||||
int currentIndex = -1;
|
||||
|
||||
if (m_selectionModel->hasSelection()) {
|
||||
currentIndex = m_selectionModel->selectedIndexes().first().row();
|
||||
}
|
||||
|
||||
// if (searchFromNextItem) {
|
||||
// index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
|
||||
// } else {
|
||||
// index = indexForKeyboardSearch(text, 0);
|
||||
// }
|
||||
|
||||
index = indexForKeyboardSearch(text, (currentIndex + 1) % rowCount());
|
||||
|
||||
if (index < 0 || currentIndex == index)
|
||||
return;
|
||||
|
||||
if (index >= 0) {
|
||||
clearSelection();
|
||||
setSelected(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool FolderModel::isSupportThumbnails(const QString &mimeType) const
|
||||
{
|
||||
const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web",
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define FOLDERMODEL_H
|
||||
|
||||
#include "../widgets/itemviewadapter.h"
|
||||
#include "../helper/keyboardsearchmanager.h"
|
||||
#include "../helper/pathhistory.h"
|
||||
#include "../mimetype/mimeappmanager.h"
|
||||
|
||||
|
@ -207,6 +206,7 @@ public:
|
|||
Q_INVOKABLE void openDeleteDialog();
|
||||
|
||||
Q_INVOKABLE void updateSelectedItemsSize();
|
||||
Q_INVOKABLE void keyboardSearch(const QString &text);
|
||||
|
||||
void restoreFromTrash();
|
||||
|
||||
|
@ -242,7 +242,6 @@ signals:
|
|||
private slots:
|
||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void dragSelectedInternal(int x, int y);
|
||||
void keyboardSearchChanged(const QString &text, bool searchFromNextItem);
|
||||
|
||||
private:
|
||||
void invalidateIfComplete();
|
||||
|
@ -299,8 +298,6 @@ private:
|
|||
MimeAppManager *m_mimeAppManager;
|
||||
|
||||
CFileSizeJob *m_sizeJob;
|
||||
|
||||
KeyboardSearchManager *m_keyboardSearchManager;
|
||||
};
|
||||
|
||||
#endif // FOLDERMODEL_H
|
||||
|
|
|
@ -134,6 +134,9 @@ Item {
|
|||
onDeleteFile: {
|
||||
dirModel.keyDeletePress()
|
||||
}
|
||||
onKeyPressed: {
|
||||
dirModel.keyboardSearch(text)
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
|
|
|
@ -394,6 +394,9 @@ Item {
|
|||
onRefresh: {
|
||||
dirModel.refresh()
|
||||
}
|
||||
onKeyPressed: {
|
||||
dirModel.keyboardSearch(text)
|
||||
}
|
||||
}
|
||||
|
||||
function openUrl(url) {
|
||||
|
|
Loading…
Reference in a new issue