mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
minor-fix: VFileList and VNotebookSelector
1. Bug fix: after deleting last folder, the file list won't be cleared; 2. Move cursor one line down after inserting title automatically; 3. Prompt user to create a root folder after creating a notebook; 4. Autocomplete the folder name from the chosen path when creating a notebook; 5. Add "Open Notebook Location" action in the context menu of VNotebookSelector;
This commit is contained in:
parent
4ad79e4d92
commit
d6ca4245d9
@ -258,6 +258,20 @@ void VNewNotebookDialog::handleInputChanged()
|
||||
bool VNewNotebookDialog::autoComplete()
|
||||
{
|
||||
if (m_manualPath) {
|
||||
if (m_manualName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the name according to user-chosen path.
|
||||
QString pathText = pathEdit->text();
|
||||
if (!pathText.isEmpty()) {
|
||||
QString autoName = VUtils::directoryNameFromPath(pathText);
|
||||
if (autoName != nameEdit->text()) {
|
||||
nameEdit->setText(autoName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "utils/vutils.h"
|
||||
#include "vfile.h"
|
||||
#include "vconfigmanager.h"
|
||||
#include "vmdedit.h"
|
||||
|
||||
extern VConfigManager *g_config;
|
||||
extern VNote *g_vnote;
|
||||
@ -131,9 +132,17 @@ void VFileList::initActions()
|
||||
|
||||
void VFileList::setDirectory(VDirectory *p_directory)
|
||||
{
|
||||
// QPointer will be set to NULL automatically once the directory was deleted.
|
||||
// If the last directory is deleted, m_directory and p_directory will both
|
||||
// be NULL.
|
||||
if (m_directory == p_directory) {
|
||||
if (!m_directory) {
|
||||
fileList->clear();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_directory = p_directory;
|
||||
if (!m_directory) {
|
||||
fileList->clear();
|
||||
@ -280,7 +289,8 @@ void VFileList::newFile()
|
||||
}
|
||||
|
||||
// Write title if needed.
|
||||
if (dialog.getInsertTitleInput()) {
|
||||
bool contentInserted = false;
|
||||
if (dialog.getInsertTitleInput() && file->getDocType() == DocType::Markdown) {
|
||||
if (!file->open()) {
|
||||
qWarning() << "fail to open newly-created note" << file->getName();
|
||||
} else {
|
||||
@ -289,6 +299,8 @@ void VFileList::newFile()
|
||||
file->setContent(content);
|
||||
if (!file->save()) {
|
||||
qWarning() << "fail to write to newly-created note" << file->getName();
|
||||
} else {
|
||||
contentInserted = true;
|
||||
}
|
||||
|
||||
file->close();
|
||||
@ -303,6 +315,17 @@ void VFileList::newFile()
|
||||
|
||||
// Open it in edit mode
|
||||
emit fileCreated(file, OpenFileMode::Edit);
|
||||
|
||||
// Move cursor down if content has been inserted.
|
||||
if (contentInserted) {
|
||||
QWidget *wid = QApplication::focusWidget();
|
||||
VMdEdit *edit = dynamic_cast<VMdEdit *>(wid);
|
||||
if (edit && edit->getFile() == file) {
|
||||
QKeyEvent *downEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down,
|
||||
Qt::NoModifier);
|
||||
QCoreApplication::postEvent(edit, downEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,8 @@ void VMainWindow::setupUI()
|
||||
|
||||
connect(notebookSelector, &VNotebookSelector::notebookUpdated,
|
||||
editArea, &VEditArea::handleNotebookUpdated);
|
||||
connect(notebookSelector, &VNotebookSelector::notebookCreated,
|
||||
directoryTree, &VDirectoryTree::newRootDirectory);
|
||||
|
||||
connect(fileList, &VFileList::fileClicked,
|
||||
editArea, &VEditArea::openFile);
|
||||
|
@ -64,6 +64,23 @@ void VNotebookSelector::initActions()
|
||||
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);
|
||||
QListWidgetItem *item = items[0];
|
||||
int index = this->indexOfListItem(item);
|
||||
VNotebook *notebook = this->getNotebookFromComboIndex(index);
|
||||
QUrl url = QUrl::fromLocalFile(notebook->getPath());
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
}
|
||||
|
||||
void VNotebookSelector::updateComboBox()
|
||||
@ -183,6 +200,8 @@ bool VNotebookSelector::newNotebook()
|
||||
dialog.getPathInput(),
|
||||
dialog.isImportExistingNotebook(),
|
||||
dialog.getImageFolder());
|
||||
|
||||
emit notebookCreated();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -350,6 +369,7 @@ void VNotebookSelector::requestPopupListContextMenu(QPoint p_pos)
|
||||
QMenu menu(this);
|
||||
menu.setToolTipsVisible(true);
|
||||
menu.addAction(m_deleteNotebookAct);
|
||||
menu.addAction(m_openLocationAct);
|
||||
menu.addAction(m_notebookInfoAct);
|
||||
|
||||
menu.exec(m_listWidget->mapToGlobal(p_pos));
|
||||
|
@ -33,9 +33,13 @@ public:
|
||||
|
||||
signals:
|
||||
void curNotebookChanged(VNotebook *p_notebook);
|
||||
|
||||
// Info of current notebook was changed.
|
||||
void notebookUpdated(const VNotebook *p_notebook);
|
||||
|
||||
// Emit after creating a new notebook.
|
||||
void notebookCreated();
|
||||
|
||||
public slots:
|
||||
bool newNotebook();
|
||||
|
||||
@ -85,6 +89,7 @@ private:
|
||||
// Actions
|
||||
QAction *m_deleteNotebookAct;
|
||||
QAction *m_notebookInfoAct;
|
||||
QAction *m_openLocationAct;
|
||||
|
||||
// We will add several special action item in the combobox. This is the start index
|
||||
// of the real notebook items related to m_notebooks.
|
||||
|
Loading…
x
Reference in New Issue
Block a user