mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
add menus and toolbars
1. Add menu item "Converter" to choose markdown converter; 2. Add menu item "About" and "About Qt"; 3. Change all QMessageBox's parent to "this"; Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
f06be44496
commit
b85bf8bdc7
@ -57,6 +57,7 @@ public:
|
|||||||
|
|
||||||
inline hoedown_extensions getMarkdownExtensions() const;
|
inline hoedown_extensions getMarkdownExtensions() const;
|
||||||
inline MarkdownConverterType getMdConverterType() const;
|
inline MarkdownConverterType getMdConverterType() const;
|
||||||
|
inline void setMarkdownConverterType(MarkdownConverterType type);
|
||||||
|
|
||||||
inline QString getPreTemplatePath() const;
|
inline QString getPreTemplatePath() const;
|
||||||
inline QString getPostTemplatePath() const;
|
inline QString getPostTemplatePath() const;
|
||||||
@ -176,4 +177,13 @@ inline QString VConfigManager::getPostTemplatePath() const
|
|||||||
return postTemplatePath;
|
return postTemplatePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void VConfigManager::setMarkdownConverterType(MarkdownConverterType type)
|
||||||
|
{
|
||||||
|
if (mdConverterType == type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mdConverterType = type;
|
||||||
|
setConfigToSettings("global", "markdown_converter", type);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
@ -136,7 +136,8 @@ void VDirectoryTree::updateDirectoryTreeTopLevel()
|
|||||||
|
|
||||||
if (!validatePath(path)) {
|
if (!validatePath(path)) {
|
||||||
qDebug() << "invalid notebook path:" << path;
|
qDebug() << "invalid notebook path:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook path."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook path."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook path \"%1\" either does not exist or is not valid.")
|
msgBox.setInformativeText(QString("Notebook path \"%1\" either does not exist or is not valid.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -146,7 +147,8 @@ void VDirectoryTree::updateDirectoryTreeTopLevel()
|
|||||||
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
||||||
if (configJson.isEmpty()) {
|
if (configJson.isEmpty()) {
|
||||||
qDebug() << "invalid notebook configuration for path:" << path;
|
qDebug() << "invalid notebook configuration for path:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook configuration."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook configuration."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook path \"%1\" does not contain a valid configuration file.")
|
msgBox.setInformativeText(QString("Notebook path \"%1\" does not contain a valid configuration file.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -177,7 +179,8 @@ void VDirectoryTree::updateDirectoryTreeOne(QTreeWidgetItem &parent, int depth)
|
|||||||
QString path(QDir::cleanPath(treePath + QDir::separator() + relativePath));
|
QString path(QDir::cleanPath(treePath + QDir::separator() + relativePath));
|
||||||
if (!validatePath(path)) {
|
if (!validatePath(path)) {
|
||||||
qDebug() << "invalide notebook directory:" << path;
|
qDebug() << "invalide notebook directory:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook directory \"%1\" either does not exist or is not a valid notebook directory.")
|
msgBox.setInformativeText(QString("Notebook directory \"%1\" either does not exist or is not a valid notebook directory.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -187,7 +190,8 @@ void VDirectoryTree::updateDirectoryTreeOne(QTreeWidgetItem &parent, int depth)
|
|||||||
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
||||||
if (configJson.isEmpty()) {
|
if (configJson.isEmpty()) {
|
||||||
qDebug() << "invalid notebook configuration for directory:" << path;
|
qDebug() << "invalid notebook configuration for directory:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory configuration."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory configuration."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook directory \"%1\" does not contain a valid configuration file.")
|
msgBox.setInformativeText(QString("Notebook directory \"%1\" does not contain a valid configuration file.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -343,9 +347,8 @@ void VDirectoryTree::deleteDirectory()
|
|||||||
QString curItemName = curItemJson["name"].toString();
|
QString curItemName = curItemJson["name"].toString();
|
||||||
|
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete directory \"%1\"?")
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete directory \"%1\"?")
|
||||||
.arg(curItemName));
|
.arg(curItemName), QMessageBox::Ok | QMessageBox::Cancel, this);
|
||||||
msgBox.setInformativeText(tr("This will delete any files under this directory."));
|
msgBox.setInformativeText(tr("This will delete any files under this directory."));
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
if (msgBox.exec() == QMessageBox::Ok) {
|
if (msgBox.exec() == QMessageBox::Ok) {
|
||||||
deleteDirectoryAndUpdateTree(curItem);
|
deleteDirectoryAndUpdateTree(curItem);
|
||||||
@ -366,7 +369,7 @@ QTreeWidgetItem* VDirectoryTree::createDirectoryAndUpdateTree(QTreeWidgetItem *p
|
|||||||
if (!dir.mkdir(name)) {
|
if (!dir.mkdir(name)) {
|
||||||
qWarning() << "error: fail to create directory" << name << "under" << path;
|
qWarning() << "error: fail to create directory" << name << "under" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Could not create directory \"%1\" under \"%2\".")
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Could not create directory \"%1\" under \"%2\".")
|
||||||
.arg(name).arg(path));
|
.arg(name).arg(path), QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Please check if there already exists a directory named \"%1\".").arg(name));
|
msgBox.setInformativeText(QString("Please check if there already exists a directory named \"%1\".").arg(name));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -139,7 +139,7 @@ void VEditor::readFile()
|
|||||||
|
|
||||||
if (textEditor->isModified()) {
|
if (textEditor->isModified()) {
|
||||||
// Need to save the changes
|
// Need to save the changes
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox(this);
|
||||||
msgBox.setText("The note has been modified.");
|
msgBox.setText("The note has been modified.");
|
||||||
msgBox.setInformativeText("Do you want to save your changes?");
|
msgBox.setInformativeText("Do you want to save your changes?");
|
||||||
msgBox.setIcon(QMessageBox::Information);
|
msgBox.setIcon(QMessageBox::Information);
|
||||||
@ -175,8 +175,8 @@ bool VEditor::saveFile()
|
|||||||
noteFile->content);
|
noteFile->content);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Fail to save to file"),
|
QMessageBox msgBox(QMessageBox::Warning, tr("Fail to save to file"),
|
||||||
QString("Fail to write to disk when saving a note. Please try it again."));
|
QString("Fail to write to disk when saving a note. Please try it again."),
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
QMessageBox::Ok, this);
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
textEditor->setModified(true);
|
textEditor->setModified(true);
|
||||||
|
@ -58,7 +58,8 @@ void VFileList::updateFileList()
|
|||||||
|
|
||||||
if (!QDir(path).exists()) {
|
if (!QDir(path).exists()) {
|
||||||
qDebug() << "invalid notebook directory:" << path;
|
qDebug() << "invalid notebook directory:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook directory \"%1\" either does not exist or is not valid.")
|
msgBox.setInformativeText(QString("Notebook directory \"%1\" either does not exist or is not valid.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -68,7 +69,8 @@ void VFileList::updateFileList()
|
|||||||
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
QJsonObject configJson = VConfigManager::readDirectoryConfig(path);
|
||||||
if (configJson.isEmpty()) {
|
if (configJson.isEmpty()) {
|
||||||
qDebug() << "invalid notebook configuration for directory:" << path;
|
qDebug() << "invalid notebook configuration for directory:" << path;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory configuration."));
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory configuration."),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Notebook directory \"%1\" does not contain a valid configuration file.")
|
msgBox.setInformativeText(QString("Notebook directory \"%1\" does not contain a valid configuration file.")
|
||||||
.arg(path));
|
.arg(path));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
@ -156,9 +158,9 @@ void VFileList::deleteFile()
|
|||||||
|
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"),
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"),
|
||||||
QString("Are you sure you want to delete note \"%1\"?")
|
QString("Are you sure you want to delete note \"%1\"?")
|
||||||
.arg(curItemName));
|
.arg(curItemName), QMessageBox::Ok | QMessageBox::Cancel,
|
||||||
|
this);
|
||||||
msgBox.setInformativeText(tr("This may be not recoverable."));
|
msgBox.setInformativeText(tr("This may be not recoverable."));
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
if (msgBox.exec() == QMessageBox::Ok) {
|
if (msgBox.exec() == QMessageBox::Ok) {
|
||||||
// First close this file forcely
|
// First close this file forcely
|
||||||
@ -209,7 +211,7 @@ QListWidgetItem* VFileList::createFileAndUpdateList(const QString &name,
|
|||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
qWarning() << "error: fail to create file:" << filePath;
|
qWarning() << "error: fail to create file:" << filePath;
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Could not create file \"%1\" under \"%2\".")
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Could not create file \"%1\" under \"%2\".")
|
||||||
.arg(name).arg(path));
|
.arg(name).arg(path), QMessageBox::Ok, this);
|
||||||
msgBox.setInformativeText(QString("Please check if there already exists a file named \"%1\".").arg(name));
|
msgBox.setInformativeText(QString("Please check if there already exists a file named \"%1\".").arg(name));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -122,6 +122,27 @@ void VMainWindow::initActions()
|
|||||||
importNoteAct->setStatusTip(tr("Import notes into current directory from files"));
|
importNoteAct->setStatusTip(tr("Import notes into current directory from files"));
|
||||||
connect(importNoteAct, &QAction::triggered,
|
connect(importNoteAct, &QAction::triggered,
|
||||||
this, &VMainWindow::importNoteFromFile);
|
this, &VMainWindow::importNoteFromFile);
|
||||||
|
|
||||||
|
converterAct = new QActionGroup(this);
|
||||||
|
markedAct = new QAction(tr("Marked"), converterAct);
|
||||||
|
markedAct->setStatusTip(tr("Use Marked to convert Markdown to HTML (Re-open current tabs to make it work)"));
|
||||||
|
markedAct->setCheckable(true);
|
||||||
|
markedAct->setData(int(MarkdownConverterType::Marked));
|
||||||
|
hoedownAct = new QAction(tr("Hoedown"), converterAct);
|
||||||
|
hoedownAct->setStatusTip(tr("Use Hoedown to convert Markdown to HTML (Re-open current tabs to make it work)"));
|
||||||
|
hoedownAct->setCheckable(true);
|
||||||
|
hoedownAct->setData(int(MarkdownConverterType::Hoedown));
|
||||||
|
connect(converterAct, &QActionGroup::triggered,
|
||||||
|
this, &VMainWindow::changeMarkdownConverter);
|
||||||
|
|
||||||
|
aboutAct = new QAction(tr("&About"), this);
|
||||||
|
aboutAct->setStatusTip(tr("Show information about VNote"));
|
||||||
|
connect(aboutAct, &QAction::triggered,
|
||||||
|
this, &VMainWindow::aboutMessage);
|
||||||
|
aboutQtAct = new QAction(tr("About &Qt"), this);
|
||||||
|
aboutQtAct->setStatusTip(tr("Show information about Qt"));
|
||||||
|
connect(aboutQtAct, &QAction::triggered,
|
||||||
|
qApp, &QApplication::aboutQt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::initToolBar()
|
void VMainWindow::initToolBar()
|
||||||
@ -136,10 +157,28 @@ void VMainWindow::initToolBar()
|
|||||||
void VMainWindow::initMenuBar()
|
void VMainWindow::initMenuBar()
|
||||||
{
|
{
|
||||||
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
QMenu *editMenu = menuBar()->addMenu(tr("&Edit"));
|
||||||
|
QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
|
||||||
|
QMenu *markdownMenu = menuBar()->addMenu(tr("&Markdown"));
|
||||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
|
|
||||||
// To be implemented
|
// File Menu
|
||||||
fileMenu->addAction(importNoteAct);
|
fileMenu->addAction(importNoteAct);
|
||||||
|
|
||||||
|
// Markdown Menu
|
||||||
|
QMenu *converterMenu = markdownMenu->addMenu(tr("&Converter"));
|
||||||
|
converterMenu->addAction(hoedownAct);
|
||||||
|
converterMenu->addAction(markedAct);
|
||||||
|
MarkdownConverterType converterType = vconfig.getMdConverterType();
|
||||||
|
if (converterType == MarkdownConverterType::Marked) {
|
||||||
|
markedAct->setChecked(true);
|
||||||
|
} else if (converterType == MarkdownConverterType::Hoedown) {
|
||||||
|
hoedownAct->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Help menu
|
||||||
|
helpMenu->addAction(aboutQtAct);
|
||||||
|
helpMenu->addAction(aboutAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::updateNotebookComboBox(const QVector<VNotebook> ¬ebooks)
|
void VMainWindow::updateNotebookComboBox(const QVector<VNotebook> ¬ebooks)
|
||||||
@ -215,9 +254,8 @@ void VMainWindow::onDeleteNotebookBtnClicked()
|
|||||||
QString curPath = vnote->getNotebooks()[curIndex].getPath();
|
QString curPath = vnote->getNotebooks()[curIndex].getPath();
|
||||||
|
|
||||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete notebook \"%1\"?")
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete notebook \"%1\"?")
|
||||||
.arg(curName));
|
.arg(curName), QMessageBox::Ok | QMessageBox::Cancel, this);
|
||||||
msgBox.setInformativeText(QString("This will delete any files in this notebook (\"%1\").").arg(curPath));
|
msgBox.setInformativeText(QString("This will delete any files in this notebook (\"%1\").").arg(curPath));
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
if (msgBox.exec() == QMessageBox::Ok) {
|
if (msgBox.exec() == QMessageBox::Ok) {
|
||||||
vnote->removeNotebook(curName);
|
vnote->removeNotebook(curName);
|
||||||
@ -240,10 +278,27 @@ void VMainWindow::importNoteFromFile()
|
|||||||
}
|
}
|
||||||
QMessageBox msgBox(QMessageBox::Information, tr("Import note from file"),
|
QMessageBox msgBox(QMessageBox::Information, tr("Import note from file"),
|
||||||
QString("Imported notes: %1 succeed, %2 failed.")
|
QString("Imported notes: %1 succeed, %2 failed.")
|
||||||
.arg(files.size() - failedFiles.size()).arg(failedFiles.size()));
|
.arg(files.size() - failedFiles.size()).arg(failedFiles.size()),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
if (!failedFiles.isEmpty()) {
|
if (!failedFiles.isEmpty()) {
|
||||||
msgBox.setInformativeText(tr("Failed to import files may be due to name conflicts."));
|
msgBox.setInformativeText(tr("Failed to import files may be due to name conflicts."));
|
||||||
}
|
}
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::changeMarkdownConverter(QAction *action)
|
||||||
|
{
|
||||||
|
if (!action) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MarkdownConverterType type = (MarkdownConverterType)action->data().toInt();
|
||||||
|
qDebug() << "switch to converter" << type;
|
||||||
|
vconfig.setMarkdownConverterType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VMainWindow::aboutMessage()
|
||||||
|
{
|
||||||
|
QMessageBox::about(this, tr("About VNote"),
|
||||||
|
tr("VNote is a Vim-inspired note taking application for Markdown.\n"
|
||||||
|
"Visit https://github.com/tamlok/vnote.git for more information."));
|
||||||
|
}
|
||||||
|
@ -16,6 +16,7 @@ class VTabWidget;
|
|||||||
class QAction;
|
class QAction;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class VNotebook;
|
class VNotebook;
|
||||||
|
class QActionGroup;
|
||||||
|
|
||||||
class VMainWindow : public QMainWindow
|
class VMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
@ -33,6 +34,8 @@ private slots:
|
|||||||
void onDeleteNotebookBtnClicked();
|
void onDeleteNotebookBtnClicked();
|
||||||
void updateNotebookComboBox(const QVector<VNotebook> ¬ebooks);
|
void updateNotebookComboBox(const QVector<VNotebook> ¬ebooks);
|
||||||
void importNoteFromFile();
|
void importNoteFromFile();
|
||||||
|
void changeMarkdownConverter(QAction *action);
|
||||||
|
void aboutMessage();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void curNotebookIndexChanged(const QString &path);
|
void curNotebookIndexChanged(const QString &path);
|
||||||
@ -61,6 +64,11 @@ private:
|
|||||||
QAction *saveNoteAct;
|
QAction *saveNoteAct;
|
||||||
QAction *readNoteAct;
|
QAction *readNoteAct;
|
||||||
QAction *importNoteAct;
|
QAction *importNoteAct;
|
||||||
|
QActionGroup *converterAct;
|
||||||
|
QAction *markedAct;
|
||||||
|
QAction *hoedownAct;
|
||||||
|
QAction *aboutAct;
|
||||||
|
QAction *aboutQtAct;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VMAINWINDOW_H
|
#endif // VMAINWINDOW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user