mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +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:
|
||||
void curTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||
bool editMode, bool modifiable);
|
||||
bool editMode, bool modifiable, bool modified);
|
||||
void outlineChanged(const VToc &toc);
|
||||
void curHeaderChanged(const VAnchor &anchor);
|
||||
|
||||
|
@ -53,6 +53,8 @@ void VEditTab::setupUI()
|
||||
this, &VEditTab::updateTocFromHeaders);
|
||||
connect(textEditor, SIGNAL(curHeaderChanged(int)),
|
||||
this, SLOT(updateCurHeader(int)));
|
||||
connect(textEditor, &VEdit::textChanged,
|
||||
this, &VEditTab::statusChanged);
|
||||
addWidget(textEditor);
|
||||
|
||||
switch (noteFile->docType) {
|
||||
@ -185,6 +187,7 @@ void VEditTab::readFile()
|
||||
|
||||
bool VEditTab::saveFile()
|
||||
{
|
||||
bool ret;
|
||||
if (!isEditMode || !noteFile->modifiable || !textEditor->isModified()) {
|
||||
return true;
|
||||
}
|
||||
@ -201,7 +204,7 @@ bool VEditTab::saveFile()
|
||||
return false;
|
||||
}
|
||||
textEditor->saveFile();
|
||||
bool ret = VUtils::writeFileToDisk(filePath, noteFile->content);
|
||||
ret = VUtils::writeFileToDisk(filePath, noteFile->content);
|
||||
if (!ret) {
|
||||
QMessageBox msgBox(QMessageBox::Warning, tr("Fail to save to file"),
|
||||
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.exec();
|
||||
textEditor->setModified(true);
|
||||
return false;
|
||||
ret = false;
|
||||
}
|
||||
return true;
|
||||
ret = true;
|
||||
emit statusChanged();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void VEditTab::setupMarkdownPreview()
|
||||
|
@ -41,6 +41,7 @@ signals:
|
||||
void getFocused();
|
||||
void outlineChanged(const VToc &toc);
|
||||
void curHeaderChanged(const VAnchor &anchor);
|
||||
void statusChanged();
|
||||
|
||||
private slots:
|
||||
void handleFocusChanged(QWidget *old, QWidget *now);
|
||||
|
@ -95,6 +95,7 @@ int VEditWindow::insertTabWithData(int index, QWidget *page,
|
||||
int idx = insertTab(index, page, label);
|
||||
QTabBar *tabs = tabBar();
|
||||
tabs->setTabData(idx, tabData);
|
||||
tabs->setTabToolTip(idx, generateTooltip(tabData));
|
||||
noticeStatus(currentIndex());
|
||||
return idx;
|
||||
}
|
||||
@ -171,6 +172,8 @@ int VEditWindow::openFileInTab(const QString ¬ebook, const QString &relativeP
|
||||
this, &VEditWindow::handleOutlineChanged);
|
||||
connect(editor, &VEditTab::curHeaderChanged,
|
||||
this, &VEditWindow::handleCurHeaderChanged);
|
||||
connect(editor, &VEditTab::statusChanged,
|
||||
this, &VEditWindow::handleTabStatusChanged);
|
||||
|
||||
QJsonObject tabJson;
|
||||
tabJson["notebook"] = notebook;
|
||||
@ -253,14 +256,16 @@ void VEditWindow::handleNotebookRenamed(const QVector<VNotebook> ¬ebooks,
|
||||
if (tabJson["notebook"] == oldName) {
|
||||
tabJson["notebook"] = newName;
|
||||
tabs->setTabData(i, tabJson);
|
||||
tabs->setTabToolTip(i, generateTooltip(tabJson));
|
||||
}
|
||||
}
|
||||
updateTabListMenu();
|
||||
}
|
||||
|
||||
void VEditWindow::noticeTabStatus(int index)
|
||||
{
|
||||
if (index == -1) {
|
||||
emit tabStatusChanged("", "", false, false);
|
||||
emit tabStatusChanged("", "", false, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,7 +279,7 @@ void VEditWindow::noticeTabStatus(int index)
|
||||
bool modifiable = tabJson["modifiable"].toBool();
|
||||
|
||||
emit tabStatusChanged(notebook, relativePath,
|
||||
editMode, modifiable);
|
||||
editMode, modifiable, editor->isModified());
|
||||
}
|
||||
|
||||
void VEditWindow::requestUpdateTabStatus()
|
||||
@ -364,6 +369,7 @@ void VEditWindow::updateTabListMenu()
|
||||
int nrTab = tabbar->count();
|
||||
for (int i = 0; i < nrTab; ++i) {
|
||||
QAction *action = new QAction(tabbar->tabText(i), tabListAct);
|
||||
action->setStatusTip(generateTooltip(tabbar->tabData(i).toJsonObject()));
|
||||
action->setData(tabbar->tabData(i));
|
||||
menu->addAction(action);
|
||||
}
|
||||
@ -423,3 +429,8 @@ void VEditWindow::noticeStatus(int index)
|
||||
tab->requestUpdateCurHeader();
|
||||
}
|
||||
}
|
||||
|
||||
void VEditWindow::handleTabStatusChanged()
|
||||
{
|
||||
noticeTabStatus(currentIndex());
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ protected:
|
||||
|
||||
signals:
|
||||
void tabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||
bool editMode, bool modifiable);
|
||||
bool editMode, bool modifiable, bool modified);
|
||||
void requestSplitWindow(VEditWindow *curWindow);
|
||||
void requestRemoveSplit(VEditWindow *curWindow);
|
||||
// This widget or its children get the focus
|
||||
@ -61,6 +61,7 @@ private slots:
|
||||
void tabListJump(QAction *action);
|
||||
void handleOutlineChanged(const VToc &toc);
|
||||
void handleCurHeaderChanged(const VAnchor &anchor);
|
||||
void handleTabStatusChanged();
|
||||
|
||||
private:
|
||||
void setupCornerWidget();
|
||||
@ -73,6 +74,7 @@ private:
|
||||
void noticeTabStatus(int index);
|
||||
void updateTabListMenu();
|
||||
void noticeStatus(int index);
|
||||
inline QString generateTooltip(const QJsonObject &tabData) const;
|
||||
|
||||
VNote *vnote;
|
||||
// Button in the right corner
|
||||
@ -96,4 +98,10 @@ inline VEditTab* VEditWindow::getTab(int tabIndex) const
|
||||
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
|
||||
|
@ -108,7 +108,7 @@ void VMainWindow::setupUI()
|
||||
connect(vnote, &VNote::notebooksRenamed,
|
||||
editArea, &VEditArea::handleNotebookRenamed);
|
||||
connect(editArea, &VEditArea::curTabStatusChanged,
|
||||
this, &VMainWindow::updateToolbarFromTabChage);
|
||||
this, &VMainWindow::handleCurTabStatusChanged);
|
||||
|
||||
connect(newNotebookBtn, &QPushButton::clicked,
|
||||
this, &VMainWindow::onNewNotebookBtnClicked);
|
||||
@ -657,10 +657,9 @@ void VMainWindow::setRenderBackgroundColor(QAction *action)
|
||||
vnote->updateTemplate();
|
||||
}
|
||||
|
||||
void VMainWindow::updateToolbarFromTabChage(const QString ¬ebook, const QString &relativePath,
|
||||
bool editMode, bool modifiable)
|
||||
void VMainWindow::updateToolbarFromTabChage(bool empty, bool editMode, bool modifiable)
|
||||
{
|
||||
if (notebook.isEmpty() || !modifiable) {
|
||||
if (empty || !modifiable) {
|
||||
editNoteAct->setEnabled(false);
|
||||
saveExitAct->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)
|
||||
{
|
||||
if (!action) {
|
||||
@ -723,3 +737,12 @@ void VMainWindow::handleFileListDirectoryChanged(const QString ¬ebook, const
|
||||
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 setEditorBackgroundColor(QAction *action);
|
||||
void setRenderBackgroundColor(QAction *action);
|
||||
void updateToolbarFromTabChage(const QString ¬ebook, const QString &relativePath,
|
||||
bool editMode, bool modifiable);
|
||||
void handleCurTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||
bool editMode, bool modifiable, bool modified);
|
||||
void changePanelView(QAction *action);
|
||||
void handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath);
|
||||
|
||||
@ -65,6 +65,8 @@ private:
|
||||
void initRenderBackgroundMenu(QMenu *menu);
|
||||
void initEditorBackgroundMenu(QMenu *menu);
|
||||
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
|
||||
bool notebookComboMuted;
|
||||
|
Loading…
x
Reference in New Issue
Block a user