mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
MdEditor: support Attach And Insert Link action
This commit is contained in:
parent
3779dd1b81
commit
33350e6bdf
@ -240,7 +240,7 @@ inline QString VEditWindow::generateTabText(int p_index, const VEditTab *p_tab)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("%1.%2%3%4").arg(QString::number(p_index + c_tabSequenceBase, 10))
|
return QString("%1. %2%3%4").arg(QString::number(p_index + c_tabSequenceBase, 10))
|
||||||
.arg(file->getName())
|
.arg(file->getName())
|
||||||
.arg(file->isModifiable() ? "" : "#")
|
.arg(file->isModifiable() ? "" : "#")
|
||||||
.arg(p_tab->isModified() ? "*" : "");
|
.arg(p_tab->isModified() ? "*" : "");
|
||||||
|
@ -1884,7 +1884,16 @@ bool VMdEditor::processUrlFromMimeData(const QMimeData *p_source)
|
|||||||
dialog.addSelection(tr("Insert As Link"), 2);
|
dialog.addSelection(tr("Insert As Link"), 2);
|
||||||
if (isLocalFile) {
|
if (isLocalFile) {
|
||||||
dialog.addSelection(tr("Insert As Relative Link"), 3);
|
dialog.addSelection(tr("Insert As Relative Link"), 3);
|
||||||
|
|
||||||
|
// Attach as attachment.
|
||||||
|
if (m_file->getType() == FileType::Note) {
|
||||||
|
VNoteFile *note = static_cast<VNoteFile *>((VFile *)m_file);
|
||||||
|
if (-1 == note->findAttachmentByPath(url.toLocalFile(), false)) {
|
||||||
|
dialog.addSelection(tr("Attach And Insert Link"), 6);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dialog.addSelection(tr("Insert As Text"), 4);
|
dialog.addSelection(tr("Insert As Text"), 4);
|
||||||
if (!localTextFilePath.isEmpty()) {
|
if (!localTextFilePath.isEmpty()) {
|
||||||
dialog.addSelection(tr("Insert File Content"), 5);
|
dialog.addSelection(tr("Insert File Content"), 5);
|
||||||
@ -1909,6 +1918,37 @@ bool VMdEditor::processUrlFromMimeData(const QMimeData *p_source)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
// Attach And Insert Link.
|
||||||
|
QString file = url.toLocalFile();
|
||||||
|
|
||||||
|
Q_ASSERT(m_file->getType() == FileType::Note);
|
||||||
|
VNoteFile *note = static_cast<VNoteFile *>((VFile *)m_file);
|
||||||
|
QString destFile;
|
||||||
|
if (!note->addAttachment(file, &destFile)) {
|
||||||
|
VUtils::showMessage(QMessageBox::Warning,
|
||||||
|
tr("Warning"),
|
||||||
|
tr("Fail to add attachment %1 for note <span style=\"%2\">%3</span>.")
|
||||||
|
.arg(file)
|
||||||
|
.arg(g_config->c_dataTextStyle)
|
||||||
|
.arg(note->getName()),
|
||||||
|
"",
|
||||||
|
QMessageBox::Ok,
|
||||||
|
QMessageBox::Ok,
|
||||||
|
this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit m_object->statusMessage(tr("1 file added as attachment"));
|
||||||
|
|
||||||
|
// Update url to point to the attachment file.
|
||||||
|
Q_ASSERT(!destFile.isEmpty());
|
||||||
|
url = QUrl::fromLocalFile(destFile);
|
||||||
|
|
||||||
|
V_FALLTHROUGH;
|
||||||
|
}
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// Insert As Relative link.
|
// Insert As Relative link.
|
||||||
relativeLink = true;
|
relativeLink = true;
|
||||||
@ -2024,9 +2064,11 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
|
|||||||
QString suffix = info.suffix();
|
QString suffix = info.suffix();
|
||||||
QScopedPointer<QTemporaryFile> tmpFile;
|
QScopedPointer<QTemporaryFile> tmpFile;
|
||||||
|
|
||||||
if (info.exists() && info.isAbsolute()) {
|
if (info.exists()) {
|
||||||
|
if (info.isAbsolute()) {
|
||||||
// Absolute local path.
|
// Absolute local path.
|
||||||
srcImagePath = info.absoluteFilePath();
|
srcImagePath = info.absoluteFilePath();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Network path.
|
// Network path.
|
||||||
QByteArray data = VDownloader::downloadSync(QUrl(imageUrl));
|
QByteArray data = VDownloader::downloadSync(QUrl(imageUrl));
|
||||||
|
@ -235,7 +235,7 @@ bool VNoteFile::deleteInternalImages()
|
|||||||
return deleted == images.size();
|
return deleted == images.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VNoteFile::addAttachment(const QString &p_file)
|
bool VNoteFile::addAttachment(const QString &p_file, QString *p_destFile)
|
||||||
{
|
{
|
||||||
if (p_file.isEmpty() || !QFileInfo::exists(p_file)) {
|
if (p_file.isEmpty() || !QFileInfo::exists(p_file)) {
|
||||||
return false;
|
return false;
|
||||||
@ -260,6 +260,10 @@ bool VNoteFile::addAttachment(const QString &p_file)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_destFile) {
|
||||||
|
*p_destFile = destPath;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +364,28 @@ int VNoteFile::findAttachment(const QString &p_name, bool p_caseSensitive)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VNoteFile::findAttachmentByPath(const QString &p_file, bool p_caseSensitive)
|
||||||
|
{
|
||||||
|
QFileInfo fi(p_file);
|
||||||
|
int idx = findAttachment(fi.fileName(), p_caseSensitive);
|
||||||
|
if (idx == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check path.
|
||||||
|
QString attPath = QDir(fetchAttachmentFolderPath()).filePath(m_attachments[idx].m_name);
|
||||||
|
|
||||||
|
bool equal = false;
|
||||||
|
if (p_caseSensitive) {
|
||||||
|
equal = VUtils::equalPath(attPath, fi.absoluteFilePath());
|
||||||
|
} else {
|
||||||
|
equal = VUtils::equalPath(attPath.toLower(),
|
||||||
|
fi.absoluteFilePath().toLower());
|
||||||
|
}
|
||||||
|
|
||||||
|
return equal ? idx : -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool VNoteFile::sortAttachments(const QVector<int> &p_sortedIdx)
|
bool VNoteFile::sortAttachments(const QVector<int> &p_sortedIdx)
|
||||||
{
|
{
|
||||||
V_ASSERT(m_opened);
|
V_ASSERT(m_opened);
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
void setAttachments(const QVector<VAttachment> &p_attas);
|
void setAttachments(const QVector<VAttachment> &p_attas);
|
||||||
|
|
||||||
// Add @p_file as an attachment to this note.
|
// Add @p_file as an attachment to this note.
|
||||||
bool addAttachment(const QString &p_file);
|
bool addAttachment(const QString &p_file, QString *p_destFile = NULL);
|
||||||
|
|
||||||
// Fetch attachment folder path.
|
// Fetch attachment folder path.
|
||||||
// Will create it if it does not exist.
|
// Will create it if it does not exist.
|
||||||
@ -102,6 +102,8 @@ public:
|
|||||||
// -1 if not found.
|
// -1 if not found.
|
||||||
int findAttachment(const QString &p_name, bool p_caseSensitive = true);
|
int findAttachment(const QString &p_name, bool p_caseSensitive = true);
|
||||||
|
|
||||||
|
int findAttachmentByPath(const QString &p_file, bool p_caseSensitive = true);
|
||||||
|
|
||||||
// Rename attachment @p_oldName to @p_newName.
|
// Rename attachment @p_oldName to @p_newName.
|
||||||
bool renameAttachment(const QString &p_oldName, const QString &p_newName);
|
bool renameAttachment(const QString &p_oldName, const QString &p_newName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user