mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support sorting notebooks
This commit is contained in:
parent
eeb1d59e36
commit
b97b908e0b
@ -65,7 +65,9 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info)
|
|||||||
|
|
||||||
// Tags.
|
// Tags.
|
||||||
QLineEdit *tagEdit = new QLineEdit(m_file->getTags().join(", "));
|
QLineEdit *tagEdit = new QLineEdit(m_file->getTags().join(", "));
|
||||||
tagEdit->setToolTip(tr("Tags of this note separated by ,"));
|
QString tagTip = tr("Add tags to a note at the right bottom status bar when it is opened");
|
||||||
|
tagEdit->setPlaceholderText(tagTip);
|
||||||
|
tagEdit->setToolTip(tr("Tags of this note separated by , (%1)").arg(tagTip));
|
||||||
tagEdit->setReadOnly(true);
|
tagEdit->setReadOnly(true);
|
||||||
|
|
||||||
QFormLayout *topLayout = new QFormLayout();
|
QFormLayout *topLayout = new QFormLayout();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "vmainwindow.h"
|
#include "vmainwindow.h"
|
||||||
#include "utils/vimnavigationforwidget.h"
|
#include "utils/vimnavigationforwidget.h"
|
||||||
#include "utils/viconutils.h"
|
#include "utils/viconutils.h"
|
||||||
|
#include "dialog/vsortdialog.h"
|
||||||
|
|
||||||
extern VConfigManager *g_config;
|
extern VConfigManager *g_config;
|
||||||
|
|
||||||
@ -428,6 +429,16 @@ void VNotebookSelector::popupListContextMenuRequested(QPoint p_pos)
|
|||||||
this, SLOT(deleteNotebook()));
|
this, SLOT(deleteNotebook()));
|
||||||
menu.addAction(deleteNotebookAct);
|
menu.addAction(deleteNotebookAct);
|
||||||
|
|
||||||
|
if (m_notebooks.size() > 1) {
|
||||||
|
QAction *sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
|
||||||
|
tr("&Sort"),
|
||||||
|
&menu);
|
||||||
|
sortAct->setToolTip(tr("Sort notebooks"));
|
||||||
|
connect(sortAct, SIGNAL(triggered(bool)),
|
||||||
|
this, SLOT(sortItems()));
|
||||||
|
menu.addAction(sortAct);
|
||||||
|
}
|
||||||
|
|
||||||
if (nb->isValid()) {
|
if (nb->isValid()) {
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
@ -680,3 +691,58 @@ VNotebook *VNotebookSelector::currentNotebook() const
|
|||||||
{
|
{
|
||||||
return getNotebook(currentIndex());
|
return getNotebook(currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VNotebookSelector::sortItems()
|
||||||
|
{
|
||||||
|
if (m_notebooks.size() < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VSortDialog dialog(tr("Sort Notebooks"),
|
||||||
|
tr("Sort notebooks in the configuration file."),
|
||||||
|
this);
|
||||||
|
QTreeWidget *tree = dialog.getTreeWidget();
|
||||||
|
tree->clear();
|
||||||
|
tree->setColumnCount(1);
|
||||||
|
QStringList headers;
|
||||||
|
headers << tr("Name");
|
||||||
|
tree->setHeaderLabels(headers);
|
||||||
|
for (int i = 0; i < m_notebooks.size(); ++i) {
|
||||||
|
QStringList cols;
|
||||||
|
cols << m_notebooks[i]->getName();
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem(tree, cols);
|
||||||
|
item->setData(0, Qt::UserRole, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.treeUpdated();
|
||||||
|
|
||||||
|
if (dialog.exec()) {
|
||||||
|
QVector<QVariant> data = dialog.getSortedData();
|
||||||
|
Q_ASSERT(data.size() == m_notebooks.size());
|
||||||
|
QVector<int> sortedIdx(data.size(), -1);
|
||||||
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
|
sortedIdx[i] = data[i].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort m_notebooks.
|
||||||
|
auto ori = m_notebooks;
|
||||||
|
auto curNotebook = currentNotebook();
|
||||||
|
int curNotebookIdx = -1;
|
||||||
|
for (int i = 0; i < sortedIdx.size(); ++i) {
|
||||||
|
m_notebooks[i] = ori[sortedIdx[i]];
|
||||||
|
if (m_notebooks[i] == curNotebook) {
|
||||||
|
curNotebookIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(ori.size() == m_notebooks.size());
|
||||||
|
Q_ASSERT(curNotebookIdx != -1);
|
||||||
|
|
||||||
|
g_config->setNotebooks(m_notebooks);
|
||||||
|
g_config->setCurNotebookIndex(curNotebookIdx);
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
setCurrentItemToNotebook(m_notebooks[curNotebookIdx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -65,6 +65,9 @@ private slots:
|
|||||||
// View and edit notebook information of selected notebook.
|
// View and edit notebook information of selected notebook.
|
||||||
void editNotebookInfo();
|
void editNotebookInfo();
|
||||||
|
|
||||||
|
// Sort notebooks.
|
||||||
|
void sortItems();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Update Combox from m_notebooks.
|
// Update Combox from m_notebooks.
|
||||||
void updateComboBox();
|
void updateComboBox();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user