Browse Source

support copy file path in context menu

Le Tan 7 years ago
parent
commit
72bb72477e
3 changed files with 21 additions and 2 deletions
  1. 6 2
      src/dialog/vfileinfodialog.cpp
  2. 2 0
      src/dialog/vorphanfileinfodialog.cpp
  3. 13 0
      src/vfilelist.cpp

+ 6 - 2
src/dialog/vfileinfodialog.cpp

@@ -44,6 +44,10 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info)
     // Select without suffix.
     m_nameEdit->setSelection(baseStart, baseLength);
 
+    // File path.
+    QLineEdit *filePathEdit = new QLineEdit(m_file->fetchPath());
+    filePathEdit->setReadOnly(true);
+
     // Attachment folder.
     VLineEdit *attachmentFolderEdit = new VLineEdit(m_file->getAttachmentFolder());
     attachmentFolderEdit->setPlaceholderText(tr("Will be assigned when adding attachments"));
@@ -60,13 +64,13 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info)
     modifiedTimeLabel->setToolTip(tr("Last modified time within VNote"));
 
     // Tags.
-    QLineEdit *tagEdit = new QLineEdit();
+    QLineEdit *tagEdit = new QLineEdit(m_file->getTags().join(", "));
     tagEdit->setToolTip(tr("Tags of this note separated by ,"));
     tagEdit->setReadOnly(true);
-    tagEdit->setText(m_file->getTags().join(", "));
 
     QFormLayout *topLayout = new QFormLayout();
     topLayout->addRow(tr("Note &name:"), m_nameEdit);
+    topLayout->addRow(tr("File path:"), filePathEdit);
     topLayout->addRow(tr("Attachment folder:"), attachmentFolderEdit);
     topLayout->addRow(tr("Created time:"), createdTimeLabel);
     topLayout->addRow(tr("Modified time:"), modifiedTimeLabel);

+ 2 - 0
src/dialog/vorphanfileinfodialog.cpp

@@ -24,6 +24,8 @@ void VOrphanFileInfoDialog::setupUI()
     QFormLayout *topLayout = new QFormLayout();
 
     QLabel *fileLabel = new QLabel(m_file->fetchPath());
+    fileLabel->setTextInteractionFlags(fileLabel->textInteractionFlags() | Qt::TextSelectableByMouse);
+    fileLabel->setWordWrap(true);
     topLayout->addRow(tr("File:"), fileLabel);
 
     m_imageFolderEdit = new VLineEdit(m_file->getImageFolder());

+ 13 - 0
src/vfilelist.cpp

@@ -633,6 +633,19 @@ void VFileList::contextMenuRequested(QPoint pos)
             connect(openLocationAct, &QAction::triggered,
                     this, &VFileList::openFileLocation);
             menu.addAction(openLocationAct);
+
+            QAction *copyPathAct = new QAction(tr("Copy File Path"), &menu);
+            connect(copyPathAct, &QAction::triggered,
+                    this, [this]() {
+                        QList<QListWidgetItem *> items = fileList->selectedItems();
+                        if (items.size() == 1) {
+                            QString filePath = getVFile(items[0])->fetchPath();
+                            QClipboard *clipboard = QApplication::clipboard();
+                            clipboard->setText(filePath);
+                            g_mainWin->showStatusMessage(tr("File path copied %1").arg(filePath));
+                        }
+                    });
+            menu.addAction(copyPathAct);
         }
 
         QAction *addToCartAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cart.svg"),