Parcourir la source

enable multiple selection in file list

Signed-off-by: Le Tan <[email protected]>
Le Tan il y a 9 ans
Parent
commit
46c8025215
3 fichiers modifiés avec 20 ajouts et 5 suppressions
  1. 11 0
      src/vdirectorytree.cpp
  2. 1 0
      src/vdirectorytree.h
  3. 8 5
      src/vfilelist.cpp

+ 11 - 0
src/vdirectorytree.cpp

@@ -483,6 +483,17 @@ void VDirectoryTree::mousePressEvent(QMouseEvent *event)
     QTreeWidget::mousePressEvent(event);
     QTreeWidget::mousePressEvent(event);
 }
 }
 
 
+void VDirectoryTree::keyPressEvent(QKeyEvent *event)
+{
+    if (event->key() == Qt::Key_Return) {
+        QTreeWidgetItem *item = currentItem();
+        if (item) {
+            item->setExpanded(!item->isExpanded());
+        }
+    }
+    QTreeWidget::keyPressEvent(event);
+}
+
 bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destName,
 bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destName,
                                    VDirectory *p_srcDir, bool p_cut)
                                    VDirectory *p_srcDir, bool p_cut)
 {
 {

+ 1 - 0
src/vdirectorytree.h

@@ -38,6 +38,7 @@ private slots:
 
 
 protected:
 protected:
     void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
     void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+    void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
 
 
 private:
 private:
     void updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth);
     void updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth);

+ 8 - 5
src/vfilelist.cpp

@@ -20,6 +20,7 @@ void VFileList::setupUI()
 {
 {
     fileList = new QListWidget(this);
     fileList = new QListWidget(this);
     fileList->setContextMenuPolicy(Qt::CustomContextMenu);
     fileList->setContextMenuPolicy(Qt::CustomContextMenu);
+    fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
 
     QVBoxLayout *mainLayout = new QVBoxLayout;
     QVBoxLayout *mainLayout = new QVBoxLayout;
     mainLayout->addWidget(fileList);
     mainLayout->addWidget(fileList);
@@ -27,7 +28,7 @@ void VFileList::setupUI()
 
 
     connect(fileList, &QListWidget::customContextMenuRequested,
     connect(fileList, &QListWidget::customContextMenuRequested,
             this, &VFileList::contextMenuRequested);
             this, &VFileList::contextMenuRequested);
-    connect(fileList, &QListWidget::itemClicked,
+    connect(fileList, &QListWidget::itemActivated,
             this, &VFileList::handleItemClicked);
             this, &VFileList::handleItemClicked);
 
 
     setLayout(mainLayout);
     setLayout(mainLayout);
@@ -221,9 +222,11 @@ QVector<QListWidgetItem *> VFileList::updateFileListAdded()
 // Delete the file related to current item
 // Delete the file related to current item
 void VFileList::deleteFile()
 void VFileList::deleteFile()
 {
 {
-    QListWidgetItem *curItem = fileList->currentItem();
-    Q_ASSERT(curItem);
-    deleteFile(getVFile(curItem));
+    QList<QListWidgetItem *> items = fileList->selectedItems();
+    Q_ASSERT(!items.isEmpty());
+    for (int i = 0; i < items.size(); ++i) {
+        deleteFile(getVFile(items.at(i)));
+    }
 }
 }
 
 
 // @p_file may or may not be listed in VFileList
 // @p_file may or may not be listed in VFileList
@@ -274,7 +277,7 @@ void VFileList::contextMenuRequested(QPoint pos)
         menu.addAction(pasteAct);
         menu.addAction(pasteAct);
     }
     }
 
 
-    if (item) {
+    if (item && fileList->selectedItems().size() == 1) {
         menu.addSeparator();
         menu.addSeparator();
         menu.addAction(fileInfoAct);
         menu.addAction(fileInfoAct);
     }
     }