mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
display current file in window title
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
dcc7e6a0f7
commit
5e97ca8060
@ -24,7 +24,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void curTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
void curTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||||
bool editMode, bool modifiable);
|
bool editMode, bool modifiable, bool modified);
|
||||||
void outlineChanged(const VToc &toc);
|
void outlineChanged(const VToc &toc);
|
||||||
void curHeaderChanged(const VAnchor &anchor);
|
void curHeaderChanged(const VAnchor &anchor);
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ void VEditTab::setupUI()
|
|||||||
this, &VEditTab::updateTocFromHeaders);
|
this, &VEditTab::updateTocFromHeaders);
|
||||||
connect(textEditor, SIGNAL(curHeaderChanged(int)),
|
connect(textEditor, SIGNAL(curHeaderChanged(int)),
|
||||||
this, SLOT(updateCurHeader(int)));
|
this, SLOT(updateCurHeader(int)));
|
||||||
|
connect(textEditor, &VEdit::textChanged,
|
||||||
|
this, &VEditTab::statusChanged);
|
||||||
addWidget(textEditor);
|
addWidget(textEditor);
|
||||||
|
|
||||||
switch (noteFile->docType) {
|
switch (noteFile->docType) {
|
||||||
@ -185,6 +187,7 @@ void VEditTab::readFile()
|
|||||||
|
|
||||||
bool VEditTab::saveFile()
|
bool VEditTab::saveFile()
|
||||||
{
|
{
|
||||||
|
bool ret;
|
||||||
if (!isEditMode || !noteFile->modifiable || !textEditor->isModified()) {
|
if (!isEditMode || !noteFile->modifiable || !textEditor->isModified()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -201,7 +204,7 @@ bool VEditTab::saveFile()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textEditor->saveFile();
|
textEditor->saveFile();
|
||||||
bool ret = VUtils::writeFileToDisk(filePath, noteFile->content);
|
ret = VUtils::writeFileToDisk(filePath, 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."),
|
||||||
@ -209,9 +212,11 @@ bool VEditTab::saveFile()
|
|||||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
textEditor->setModified(true);
|
textEditor->setModified(true);
|
||||||
return false;
|
ret = false;
|
||||||
}
|
}
|
||||||
return true;
|
ret = true;
|
||||||
|
emit statusChanged();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditTab::setupMarkdownPreview()
|
void VEditTab::setupMarkdownPreview()
|
||||||
|
@ -41,6 +41,7 @@ signals:
|
|||||||
void getFocused();
|
void getFocused();
|
||||||
void outlineChanged(const VToc &toc);
|
void outlineChanged(const VToc &toc);
|
||||||
void curHeaderChanged(const VAnchor &anchor);
|
void curHeaderChanged(const VAnchor &anchor);
|
||||||
|
void statusChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleFocusChanged(QWidget *old, QWidget *now);
|
void handleFocusChanged(QWidget *old, QWidget *now);
|
||||||
|
@ -95,6 +95,7 @@ int VEditWindow::insertTabWithData(int index, QWidget *page,
|
|||||||
int idx = insertTab(index, page, label);
|
int idx = insertTab(index, page, label);
|
||||||
QTabBar *tabs = tabBar();
|
QTabBar *tabs = tabBar();
|
||||||
tabs->setTabData(idx, tabData);
|
tabs->setTabData(idx, tabData);
|
||||||
|
tabs->setTabToolTip(idx, generateTooltip(tabData));
|
||||||
noticeStatus(currentIndex());
|
noticeStatus(currentIndex());
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
@ -171,6 +172,8 @@ int VEditWindow::openFileInTab(const QString ¬ebook, const QString &relativeP
|
|||||||
this, &VEditWindow::handleOutlineChanged);
|
this, &VEditWindow::handleOutlineChanged);
|
||||||
connect(editor, &VEditTab::curHeaderChanged,
|
connect(editor, &VEditTab::curHeaderChanged,
|
||||||
this, &VEditWindow::handleCurHeaderChanged);
|
this, &VEditWindow::handleCurHeaderChanged);
|
||||||
|
connect(editor, &VEditTab::statusChanged,
|
||||||
|
this, &VEditWindow::handleTabStatusChanged);
|
||||||
|
|
||||||
QJsonObject tabJson;
|
QJsonObject tabJson;
|
||||||
tabJson["notebook"] = notebook;
|
tabJson["notebook"] = notebook;
|
||||||
@ -253,14 +256,16 @@ void VEditWindow::handleNotebookRenamed(const QVector<VNotebook> ¬ebooks,
|
|||||||
if (tabJson["notebook"] == oldName) {
|
if (tabJson["notebook"] == oldName) {
|
||||||
tabJson["notebook"] = newName;
|
tabJson["notebook"] = newName;
|
||||||
tabs->setTabData(i, tabJson);
|
tabs->setTabData(i, tabJson);
|
||||||
|
tabs->setTabToolTip(i, generateTooltip(tabJson));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateTabListMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditWindow::noticeTabStatus(int index)
|
void VEditWindow::noticeTabStatus(int index)
|
||||||
{
|
{
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
emit tabStatusChanged("", "", false, false);
|
emit tabStatusChanged("", "", false, false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +279,7 @@ void VEditWindow::noticeTabStatus(int index)
|
|||||||
bool modifiable = tabJson["modifiable"].toBool();
|
bool modifiable = tabJson["modifiable"].toBool();
|
||||||
|
|
||||||
emit tabStatusChanged(notebook, relativePath,
|
emit tabStatusChanged(notebook, relativePath,
|
||||||
editMode, modifiable);
|
editMode, modifiable, editor->isModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditWindow::requestUpdateTabStatus()
|
void VEditWindow::requestUpdateTabStatus()
|
||||||
@ -364,6 +369,7 @@ void VEditWindow::updateTabListMenu()
|
|||||||
int nrTab = tabbar->count();
|
int nrTab = tabbar->count();
|
||||||
for (int i = 0; i < nrTab; ++i) {
|
for (int i = 0; i < nrTab; ++i) {
|
||||||
QAction *action = new QAction(tabbar->tabText(i), tabListAct);
|
QAction *action = new QAction(tabbar->tabText(i), tabListAct);
|
||||||
|
action->setStatusTip(generateTooltip(tabbar->tabData(i).toJsonObject()));
|
||||||
action->setData(tabbar->tabData(i));
|
action->setData(tabbar->tabData(i));
|
||||||
menu->addAction(action);
|
menu->addAction(action);
|
||||||
}
|
}
|
||||||
@ -423,3 +429,8 @@ void VEditWindow::noticeStatus(int index)
|
|||||||
tab->requestUpdateCurHeader();
|
tab->requestUpdateCurHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VEditWindow::handleTabStatusChanged()
|
||||||
|
{
|
||||||
|
noticeTabStatus(currentIndex());
|
||||||
|
}
|
||||||
|
@ -44,7 +44,7 @@ protected:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
void tabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||||
bool editMode, bool modifiable);
|
bool editMode, bool modifiable, bool modified);
|
||||||
void requestSplitWindow(VEditWindow *curWindow);
|
void requestSplitWindow(VEditWindow *curWindow);
|
||||||
void requestRemoveSplit(VEditWindow *curWindow);
|
void requestRemoveSplit(VEditWindow *curWindow);
|
||||||
// This widget or its children get the focus
|
// This widget or its children get the focus
|
||||||
@ -61,6 +61,7 @@ private slots:
|
|||||||
void tabListJump(QAction *action);
|
void tabListJump(QAction *action);
|
||||||
void handleOutlineChanged(const VToc &toc);
|
void handleOutlineChanged(const VToc &toc);
|
||||||
void handleCurHeaderChanged(const VAnchor &anchor);
|
void handleCurHeaderChanged(const VAnchor &anchor);
|
||||||
|
void handleTabStatusChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupCornerWidget();
|
void setupCornerWidget();
|
||||||
@ -73,6 +74,7 @@ private:
|
|||||||
void noticeTabStatus(int index);
|
void noticeTabStatus(int index);
|
||||||
void updateTabListMenu();
|
void updateTabListMenu();
|
||||||
void noticeStatus(int index);
|
void noticeStatus(int index);
|
||||||
|
inline QString generateTooltip(const QJsonObject &tabData) const;
|
||||||
|
|
||||||
VNote *vnote;
|
VNote *vnote;
|
||||||
// Button in the right corner
|
// Button in the right corner
|
||||||
@ -96,4 +98,10 @@ inline VEditTab* VEditWindow::getTab(int tabIndex) const
|
|||||||
return dynamic_cast<VEditTab *>(widget(tabIndex));
|
return dynamic_cast<VEditTab *>(widget(tabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QString VEditWindow::generateTooltip(const QJsonObject &tabData) const
|
||||||
|
{
|
||||||
|
// [Notebook]relativePath
|
||||||
|
return QString("[%1] %2").arg(tabData["notebook"].toString()).arg(tabData["relative_path"].toString());
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VEDITWINDOW_H
|
#endif // VEDITWINDOW_H
|
||||||
|
@ -108,7 +108,7 @@ void VMainWindow::setupUI()
|
|||||||
connect(vnote, &VNote::notebooksRenamed,
|
connect(vnote, &VNote::notebooksRenamed,
|
||||||
editArea, &VEditArea::handleNotebookRenamed);
|
editArea, &VEditArea::handleNotebookRenamed);
|
||||||
connect(editArea, &VEditArea::curTabStatusChanged,
|
connect(editArea, &VEditArea::curTabStatusChanged,
|
||||||
this, &VMainWindow::updateToolbarFromTabChage);
|
this, &VMainWindow::handleCurTabStatusChanged);
|
||||||
|
|
||||||
connect(newNotebookBtn, &QPushButton::clicked,
|
connect(newNotebookBtn, &QPushButton::clicked,
|
||||||
this, &VMainWindow::onNewNotebookBtnClicked);
|
this, &VMainWindow::onNewNotebookBtnClicked);
|
||||||
@ -657,10 +657,9 @@ void VMainWindow::setRenderBackgroundColor(QAction *action)
|
|||||||
vnote->updateTemplate();
|
vnote->updateTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMainWindow::updateToolbarFromTabChage(const QString ¬ebook, const QString &relativePath,
|
void VMainWindow::updateToolbarFromTabChage(bool empty, bool editMode, bool modifiable)
|
||||||
bool editMode, bool modifiable)
|
|
||||||
{
|
{
|
||||||
if (notebook.isEmpty() || !modifiable) {
|
if (empty || !modifiable) {
|
||||||
editNoteAct->setEnabled(false);
|
editNoteAct->setEnabled(false);
|
||||||
saveExitAct->setVisible(false);
|
saveExitAct->setVisible(false);
|
||||||
discardExitAct->setVisible(false);
|
discardExitAct->setVisible(false);
|
||||||
@ -679,6 +678,21 @@ void VMainWindow::updateToolbarFromTabChage(const QString ¬ebook, const QStri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::handleCurTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||||
|
bool editMode, bool modifiable, bool modified)
|
||||||
|
{
|
||||||
|
updateToolbarFromTabChage(notebook.isEmpty(), editMode, modifiable);
|
||||||
|
|
||||||
|
QString title;
|
||||||
|
if (!notebook.isEmpty()) {
|
||||||
|
title = QString("[%1] %2").arg(notebook).arg(relativePath);
|
||||||
|
if (modified) {
|
||||||
|
title.append('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateWindowTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
void VMainWindow::changePanelView(QAction *action)
|
void VMainWindow::changePanelView(QAction *action)
|
||||||
{
|
{
|
||||||
if (!action) {
|
if (!action) {
|
||||||
@ -723,3 +737,12 @@ void VMainWindow::handleFileListDirectoryChanged(const QString ¬ebook, const
|
|||||||
newNoteAct->setEnabled(true);
|
newNoteAct->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::updateWindowTitle(const QString &str)
|
||||||
|
{
|
||||||
|
QString title = "VNote";
|
||||||
|
if (!str.isEmpty()) {
|
||||||
|
title = title + " - " + str;
|
||||||
|
}
|
||||||
|
setWindowTitle(title);
|
||||||
|
}
|
||||||
|
@ -46,8 +46,8 @@ private slots:
|
|||||||
void setTabStopWidth(QAction *action);
|
void setTabStopWidth(QAction *action);
|
||||||
void setEditorBackgroundColor(QAction *action);
|
void setEditorBackgroundColor(QAction *action);
|
||||||
void setRenderBackgroundColor(QAction *action);
|
void setRenderBackgroundColor(QAction *action);
|
||||||
void updateToolbarFromTabChage(const QString ¬ebook, const QString &relativePath,
|
void handleCurTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||||
bool editMode, bool modifiable);
|
bool editMode, bool modifiable, bool modified);
|
||||||
void changePanelView(QAction *action);
|
void changePanelView(QAction *action);
|
||||||
void handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath);
|
void handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath);
|
||||||
|
|
||||||
@ -65,6 +65,8 @@ private:
|
|||||||
void initRenderBackgroundMenu(QMenu *menu);
|
void initRenderBackgroundMenu(QMenu *menu);
|
||||||
void initEditorBackgroundMenu(QMenu *menu);
|
void initEditorBackgroundMenu(QMenu *menu);
|
||||||
void changeSplitterView(int nrPanel);
|
void changeSplitterView(int nrPanel);
|
||||||
|
void updateWindowTitle(const QString &str);
|
||||||
|
void updateToolbarFromTabChage(bool empty, bool editMode, bool modifiable);
|
||||||
|
|
||||||
// If true, comboBox changes will not trigger any signal out
|
// If true, comboBox changes will not trigger any signal out
|
||||||
bool notebookComboMuted;
|
bool notebookComboMuted;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user