keep focus in VFileList once click an item

This commit is contained in:
Le Tan 2018-01-21 14:51:36 +08:00
parent 06cac36412
commit d630ff7bf2
2 changed files with 15 additions and 5 deletions

View File

@ -611,21 +611,28 @@ QListWidgetItem* VFileList::findItem(const VNoteFile *p_file)
return NULL;
}
void VFileList::handleItemClicked(QListWidgetItem *currentItem)
void VFileList::handleItemClicked(QListWidgetItem *p_item)
{
activateItem(p_item);
fileList->setFocus();
}
void VFileList::activateItem(QListWidgetItem *p_item)
{
Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
if (modifiers != Qt::NoModifier) {
return;
}
if (!currentItem) {
if (!p_item) {
emit fileClicked(NULL);
return;
}
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
fileList->update();
emit fileClicked(getVFile(currentItem), g_config->getNoteOpenMode());
emit fileClicked(getVFile(p_item), g_config->getNoteOpenMode());
}
bool VFileList::importFiles(const QStringList &p_files, QString *p_errMsg)
@ -852,7 +859,7 @@ void VFileList::keyPressEvent(QKeyEvent *p_event)
if (p_event->key() == Qt::Key_Return) {
QListWidgetItem *item = fileList->currentItem();
if (item) {
handleItemClicked(item);
activateItem(item);
}
}

View File

@ -73,7 +73,8 @@ signals:
private slots:
void contextMenuRequested(QPoint pos);
void handleItemClicked(QListWidgetItem *currentItem);
void handleItemClicked(QListWidgetItem *p_item);
// View and edit information of selected file.
// Valid only when there is only one selected file.
@ -161,6 +162,8 @@ private:
// Init Open With menu.
void initOpenWithMenu();
void activateItem(QListWidgetItem *p_item);
VEditArea *editArea;
QListWidget *fileList;
QPointer<VDirectory> m_directory;