예제 #1
0
void VNotebookSelector::popupListContextMenuRequested(QPoint p_pos)
{
    QListWidgetItem *item = m_listWidget->itemAt(p_pos);
    if (!item) {
        return;
    }

    const VNotebook *nb = getNotebook(item);
    if (!nb) {
        return;
    }

    m_listWidget->clearSelection();
    item->setSelected(true);

    QMenu menu(this);
    menu.setToolTipsVisible(true);
    menu.addAction(m_deleteNotebookAct);
    if (nb->isValid()) {
        menu.addSeparator();
        menu.addAction(m_recycleBinAct);
        menu.addAction(m_emptyRecycleBinAct);
    }

    menu.addSeparator();
    menu.addAction(m_openLocationAct);

    if (nb->isValid()) {
        menu.addAction(m_notebookInfoAct);
    }

    menu.exec(m_listWidget->mapToGlobal(p_pos));
}
예제 #2
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
bool VNoteFile::deleteFile(QString *p_errMsg)
{
    Q_ASSERT(!m_opened);
    Q_ASSERT(parent());

    bool ret = true;

    // Delete local images if it is Markdown.
    if (m_docType == DocType::Markdown) {
        if (!deleteInternalImages()) {
            ret = false;
            VUtils::addErrMsg(p_errMsg, tr("Fail to delete images of this note."));
        }
    }

    // Delete attachments.
    if (!deleteAttachments()) {
        ret = false;
        VUtils::addErrMsg(p_errMsg, tr("Fail to delete attachments of this note."));
    }

    // Delete the file.
    QString filePath = fetchPath();
    if (VUtils::deleteFile(getNotebook(), filePath, false)) {
        qDebug() << "deleted" << m_name << filePath;
    } else {
        ret = false;
        VUtils::addErrMsg(p_errMsg, tr("Fail to delete the note file."));
        qWarning() << "fail to delete" << m_name << filePath;
    }

    return ret;
}
예제 #3
0
void TextFrame::setTitle(const wxString& title)
{
    wxAuiNotebook* notebook = getNotebook();
    if(notebook)
    {
        int idx = notebook->GetPageIndex(this);
        if(idx!=wxNOT_FOUND)
        {
            notebook->SetPageText(idx, title);
        }
    }
}
예제 #4
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
bool VNoteFile::deleteAttachments(const QVector<QString> &p_names,
                                  bool p_omitMissing)
{
    if (p_names.isEmpty()) {
        return true;
    }

    QDir dir(fetchAttachmentFolderPath());
    bool ret = true;
    for (int i = 0; i < p_names.size(); ++i) {
        int idx = findAttachment(p_names[i]);
        if (idx == -1) {
            ret = false;
            continue;
        }

        m_attachments.remove(idx);

        QString filePath = dir.filePath(p_names[i]);
        if (p_omitMissing
            && !QFileInfo::exists(filePath)) {
            // The attachment file does not exist. We skip it to avoid error.
            continue;
        }

        if (!VUtils::deleteFile(getNotebook(), filePath, false)) {
            ret = false;
            qWarning() << "fail to delete attachment" << p_names[i]
                       << "for note" << m_name;
        }
    }

    // Delete the attachment folder if m_attachments is empty now.
    if (m_attachments.isEmpty()) {
        dir.cdUp();
        if (!dir.rmdir(m_attachmentFolder)) {
            ret = false;
            qWarning() << "fail to delete attachment folder" << m_attachmentFolder
                       << "for note" << m_name;
        }
    }

    if (!getDirectory()->updateFileConfig(this)) {
        ret = false;
        qWarning() << "fail to update config of file" << m_name
                   << "in directory" << fetchBasePath();
    }

    return ret;
}
예제 #5
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
QString VNoteFile::fetchAttachmentFolderPath()
{
    QString folderPath = QDir(fetchBasePath()).filePath(getNotebook()->getAttachmentFolder());
    if (m_attachmentFolder.isEmpty()) {
        m_attachmentFolder = VUtils::getRandomFileName(folderPath);
    }

    folderPath = QDir(folderPath).filePath(m_attachmentFolder);
    if (!QFileInfo::exists(folderPath)) {
        QDir dir;
        if (!dir.mkpath(folderPath)) {
            qWarning() << "fail to create attachment folder of notebook" << m_name << folderPath;
        }
    }

    return folderPath;
}
예제 #6
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
bool VNoteFile::deleteInternalImages()
{
    Q_ASSERT(parent() && m_docType == DocType::Markdown);

    QVector<ImageLink> images = VUtils::fetchImagesFromMarkdownFile(this,
                                                                    ImageLink::LocalRelativeInternal);
    int deleted = 0;
    for (int i = 0; i < images.size(); ++i) {
        if (VUtils::deleteFile(getNotebook(), images[i].m_path, false)) {
            ++deleted;
        }
    }

    qDebug() << "delete" << deleted << "images for" << m_name << fetchPath();

    return deleted == images.size();
}
예제 #7
0
void VNotebookSelector::deleteNotebook()
{
    QList<QListWidgetItem *> items = m_listWidget->selectedItems();
    if (items.isEmpty()) {
        return;
    }

    Q_ASSERT(items.size() == 1);

    VNotebook *notebook = getNotebook(items[0]);
    Q_ASSERT(notebook);

    VDeleteNotebookDialog dialog(tr("Delete Notebook"), notebook, this);
    if (dialog.exec() == QDialog::Accepted) {
        bool deleteFiles = dialog.getDeleteFiles();
        g_mainWin->getEditArea()->closeFile(notebook, true);
        deleteNotebook(notebook, deleteFiles);
    }
}
예제 #8
0
void VNotebookSelector::editNotebookInfo()
{
    QList<QListWidgetItem *> items = m_listWidget->selectedItems();
    if (items.isEmpty()) {
        return;
    }

    Q_ASSERT(items.size() == 1);

    VNotebook *notebook = getNotebook(items[0]);
    VNotebookInfoDialog dialog(tr("Notebook Information"),
                               "",
                               notebook,
                               m_notebooks,
                               this);
    if (dialog.exec() == QDialog::Accepted) {
        bool updated = false;
        bool configUpdated = false;
        QString name = dialog.getName();
        if (name != notebook->getName()) {
            updated = true;
            notebook->rename(name);
            g_config->setNotebooks(m_notebooks);
        }

        QString imageFolder = dialog.getImageFolder();
        if (imageFolder != notebook->getImageFolderConfig()) {
            configUpdated = true;
            notebook->setImageFolder(imageFolder);
        }

        if (configUpdated) {
            updated = true;
            notebook->writeConfigNotebook();
        }

        if (updated) {
            fillItem(items[0], notebook);
            emit notebookUpdated(notebook);
        }
    }
}
예제 #9
0
void VNotebookSelector::handleCurIndexChanged(int p_index)
{
    if (m_muted) {
        return;
    }

    QString tooltip = tr("View and edit notebooks");
    VNotebook *nb = NULL;
    if (p_index > -1) {
        nb = getNotebook(p_index);
        if (!nb) {
            // Add notebook.
            setToolTip(tooltip);

            if (m_lastValidIndex != p_index && m_lastValidIndex > -1) {
                setCurrentIndex(m_lastValidIndex);
            }

            if (!m_notebooks.isEmpty()) {
                newNotebook();
            }

            return;
        }
    }

    m_lastValidIndex = p_index;

    int nbIdx = -1;
    if (nb) {
        tooltip = nb->getName();

        nbIdx = m_notebooks.indexOf(nb);
        Q_ASSERT(nbIdx > -1);
    }

    g_config->setCurNotebookIndex(nbIdx);

    setToolTip(tooltip);

    emit curNotebookChanged(nb);
}
예제 #10
0
void EditorFrame::onDocumentAdded(Document* document)
{
	if( !document ) return;

	eventManager->onDocumentCreate(*document);

	wxWindow* window = (wxWindow*) document->getWindow();

	if( !window )
	{
		LogDebug("Invalid window in document");
		return;
	}

	String name = PathGetFile( document->getPath() );
	if( name.empty() ) name = "untitled";
	
	getNotebook()->AddPage(window, name, true, document->getBitmap());

	getAUI()->Update();
}
예제 #11
0
void VNotebookSelector::initActions()
{
    m_deleteNotebookAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_notebook.svg"),
                                      tr("&Delete"), this);
    m_deleteNotebookAct->setToolTip(tr("Delete current notebook"));
    connect(m_deleteNotebookAct, SIGNAL(triggered(bool)),
            this, SLOT(deleteNotebook()));

    m_notebookInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/notebook_info.svg"),
                                    tr("&Info"), this);
    m_notebookInfoAct->setToolTip(tr("View and edit current notebook's information"));
    connect(m_notebookInfoAct, SIGNAL(triggered(bool)),
            this, SLOT(editNotebookInfo()));

    m_openLocationAct = new QAction(tr("&Open Notebook Location"), this);
    m_openLocationAct->setToolTip(tr("Open the root folder of this notebook in operating system"));
    connect(m_openLocationAct, &QAction::triggered,
            this, [this]() {
                QList<QListWidgetItem *> items = this->m_listWidget->selectedItems();
                if (items.isEmpty()) {
                    return;
                }

                Q_ASSERT(items.size() == 1);
                VNotebook *notebook = getNotebook(items[0]);
                QUrl url = QUrl::fromLocalFile(notebook->getPath());
                QDesktopServices::openUrl(url);
            });

    m_recycleBinAct = new QAction(VIconUtils::menuIcon(":/resources/icons/recycle_bin.svg"),
                                  tr("&Recycle Bin"), this);
    m_recycleBinAct->setToolTip(tr("Open the recycle bin of this notebook"));
    connect(m_recycleBinAct, &QAction::triggered,
            this, [this]() {
                QList<QListWidgetItem *> items = this->m_listWidget->selectedItems();
                if (items.isEmpty()) {
                    return;
                }

                Q_ASSERT(items.size() == 1);
                VNotebook *notebook = getNotebook(items[0]);
                QUrl url = QUrl::fromLocalFile(notebook->getRecycleBinFolderPath());
                QDesktopServices::openUrl(url);
            });

    m_emptyRecycleBinAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/empty_recycle_bin.svg"),
                                       tr("&Empty Recycle Bin"), this);
    m_emptyRecycleBinAct->setToolTip(tr("Empty the recycle bin of this notebook"));
    connect(m_emptyRecycleBinAct, &QAction::triggered,
            this, [this]() {
                QList<QListWidgetItem *> items = this->m_listWidget->selectedItems();
                if (items.isEmpty()) {
                    return;
                }

                Q_ASSERT(items.size() == 1);
                VNotebook *notebook = getNotebook(items[0]);
                QString binPath = notebook->getRecycleBinFolderPath();

                int ret = VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
                                              tr("Are you sure to empty recycle bin of notebook "
                                                 "<span style=\"%1\">%2</span>?")
                                                .arg(g_config->c_dataTextStyle)
                                                .arg(notebook->getName()),
                                              tr("<span style=\"%1\">WARNING</span>: "
                                                 "VNote will delete all the files in directory "
                                                 "<span style=\"%2\">%3</span>."
                                                 "<br>It may be UNRECOVERABLE!")
                                                .arg(g_config->c_warningTextStyle)
                                                .arg(g_config->c_dataTextStyle)
                                                .arg(binPath),
                                              QMessageBox::Ok | QMessageBox::Cancel,
                                              QMessageBox::Ok,
                                              this,
                                              MessageBoxType::Danger);
                if (ret == QMessageBox::Ok) {
                    QString info;
                    if (VUtils::emptyDirectory(notebook, binPath, true)) {
                        info = tr("Successfully emptied recycle bin of notebook "
                                  "<span style=\"%1\">%2</span>!")
                                 .arg(g_config->c_dataTextStyle)
                                 .arg(notebook->getName());
                    } else {
                        info = tr("Fail to empty recycle bin of notebook "
                                  "<span style=\"%1\">%2</span>!")
                                 .arg(g_config->c_dataTextStyle)
                                 .arg(notebook->getName());
                    }

                    VUtils::showMessage(QMessageBox::Information,
                                        tr("Information"),
                                        info,
                                        "",
                                        QMessageBox::Ok,
                                        QMessageBox::Ok,
                                        this);
                }
            });
}
예제 #12
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
QString VNoteFile::getImageFolderInLink() const
{
    return getNotebook()->getImageFolder();
}
예제 #13
0
파일: vnotefile.cpp 프로젝트: vscanf/vnote
QString VNoteFile::fetchImageFolderPath() const
{
    return QDir(fetchBasePath()).filePath(getNotebook()->getImageFolder());
}