mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
close all files before closing app
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
1ed324fd20
commit
3722e6cb71
@ -196,6 +196,19 @@ bool VEditArea::closeFile(QJsonObject fileJson)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool VEditArea::closeAllFiles(bool p_forced)
|
||||
{
|
||||
int nrWin = splitter->count();
|
||||
for (int i = 0; i < nrWin; ++i) {
|
||||
VEditWindow *win = getWindow(i);
|
||||
setCurrentWindow(i, false);
|
||||
if (!win->closeAllFiles(p_forced)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void VEditArea::editFile()
|
||||
{
|
||||
VEditWindow *win = getWindow(curWindowIndex);
|
||||
@ -267,7 +280,7 @@ void VEditArea::handleSplitWindowRequest(VEditWindow *curWindow)
|
||||
|
||||
void VEditArea::handleRemoveSplitRequest(VEditWindow *curWindow)
|
||||
{
|
||||
if (!curWindow) {
|
||||
if (!curWindow || splitter->count() <= 1) {
|
||||
return;
|
||||
}
|
||||
int idx = splitter->indexOf(curWindow);
|
||||
|
@ -22,6 +22,7 @@ class VEditArea : public QWidget
|
||||
public:
|
||||
explicit VEditArea(VNote *vnote, QWidget *parent = 0);
|
||||
bool isFileOpened(const QString ¬ebook, const QString &relativePath);
|
||||
bool closeAllFiles(bool p_forced);
|
||||
|
||||
signals:
|
||||
void curTabStatusChanged(const QString ¬ebook, const QString &relativePath,
|
||||
|
@ -359,6 +359,7 @@ void VEditTab::scrollToAnchor(const VAnchor &anchor)
|
||||
document.scrollToAnchor(anchor.anchor.mid(1));
|
||||
}
|
||||
}
|
||||
curHeader = anchor;
|
||||
}
|
||||
|
||||
void VEditTab::updateCurHeader(const QString &anchor)
|
||||
|
@ -71,7 +71,7 @@ void VEditWindow::removeSplit()
|
||||
{
|
||||
// Close all the files one by one
|
||||
// If user do not want to close a file, just stop removing
|
||||
if (closeAllFiles()) {
|
||||
if (closeAllFiles(false)) {
|
||||
Q_ASSERT(count() == 0);
|
||||
emit requestRemoveSplit(this);
|
||||
}
|
||||
@ -124,18 +124,21 @@ out:
|
||||
return idx;
|
||||
}
|
||||
|
||||
// Return true if we closed the file
|
||||
bool VEditWindow::closeFile(const QString ¬ebook, const QString &relativePath, bool isForced)
|
||||
{
|
||||
// Find if it has been opened already
|
||||
int idx = findTabByFile(notebook, relativePath);
|
||||
if (idx == -1) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
VEditTab *editor = getTab(idx);
|
||||
Q_ASSERT(editor);
|
||||
bool ok = true;
|
||||
if (!isForced) {
|
||||
setCurrentIndex(idx);
|
||||
noticeStatus(idx);
|
||||
ok = editor->requestClose();
|
||||
}
|
||||
if (ok) {
|
||||
@ -146,16 +149,31 @@ bool VEditWindow::closeFile(const QString ¬ebook, const QString &relativePath
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool VEditWindow::closeAllFiles()
|
||||
bool VEditWindow::closeAllFiles(bool p_forced)
|
||||
{
|
||||
int nrTab = count();
|
||||
bool ret = true;
|
||||
for (int i = 0; i < nrTab; ++i) {
|
||||
// Always close the first tab
|
||||
if (!handleTabCloseRequest(0)) {
|
||||
return false;
|
||||
VEditTab *editor = getTab(0);
|
||||
bool ok = true;
|
||||
if (!p_forced) {
|
||||
setCurrentIndex(0);
|
||||
noticeStatus(0);
|
||||
ok = editor->requestClose();
|
||||
}
|
||||
if (ok) {
|
||||
removeTab(0);
|
||||
delete editor;
|
||||
} else {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
updateTabListMenu();
|
||||
if (ret) {
|
||||
emit requestRemoveSplit(this);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VEditWindow::openFileInTab(const QString ¬ebook, const QString &relativePath,
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
void saveAndReadFile();
|
||||
void handleNotebookRenamed(const QVector<VNotebook> ¬ebooks, const QString &oldName,
|
||||
const QString &newName);
|
||||
bool closeAllFiles();
|
||||
bool closeAllFiles(bool p_forced);
|
||||
void setRemoveSplitEnable(bool enabled);
|
||||
void requestUpdateTabStatus();
|
||||
void requestUpdateOutline();
|
||||
|
@ -800,6 +800,11 @@ void VMainWindow::deleteCurNote()
|
||||
|
||||
void VMainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!editArea->closeAllFiles(false)) {
|
||||
// Fail to close all the opened files, cancel closing app
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
saveStateAndGeometry();
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
@ -89,9 +89,6 @@ void VOutline::handleItemClicked(QTreeWidgetItem *item, int column)
|
||||
|
||||
void VOutline::updateCurHeader(const VAnchor &anchor)
|
||||
{
|
||||
if (anchor == curHeader) {
|
||||
return;
|
||||
}
|
||||
curHeader = anchor;
|
||||
if (outline.type == VHeaderType::Anchor) {
|
||||
selectAnchor(anchor.anchor);
|
||||
|
@ -26,19 +26,11 @@ struct VAnchor
|
||||
VAnchor() : lineNumber(-1) {}
|
||||
VAnchor(const QString filePath, const QString &anchor, int lineNumber)
|
||||
: filePath(filePath), anchor(anchor), lineNumber(lineNumber) {}
|
||||
inline bool operator ==(const VAnchor &p_anchor) const;
|
||||
QString filePath;
|
||||
QString anchor;
|
||||
int lineNumber;
|
||||
};
|
||||
|
||||
inline bool VAnchor::operator ==(const VAnchor &p_anchor) const
|
||||
{
|
||||
return p_anchor.filePath == filePath &&
|
||||
p_anchor.anchor == anchor &&
|
||||
p_anchor.lineNumber == lineNumber;
|
||||
}
|
||||
|
||||
class VToc
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user