mirror of
https://github.com/isledecomp/SIEdit.git
synced 2025-04-01 23:49:44 -04:00
app: greatly simplify title update logic
This commit is contained in:
parent
61ca9a2958
commit
f237d0e1ae
2 changed files with 17 additions and 18 deletions
|
@ -177,21 +177,18 @@ void MainWindow::SetPanel(Panel *panel, si::Object *chunk)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::UpdateWindowTitleFlag(bool isFileModified)
|
||||
void MainWindow::UpdateWindowTitle(QString filename)
|
||||
{
|
||||
TrimOffDirectory(filename);
|
||||
setWindowTitle(QStringLiteral("%1 - %2").arg(QApplication::applicationName(), filename));
|
||||
}
|
||||
|
||||
void MainWindow::AppendModifiedTitleIndicator()
|
||||
{
|
||||
QString title = windowTitle();
|
||||
title.append("*");
|
||||
|
||||
if (isFileModified) {
|
||||
if (!title.endsWith("*")) {
|
||||
title.append("*");
|
||||
setWindowTitle(title);
|
||||
}
|
||||
} else {
|
||||
if (title.endsWith("*")) {
|
||||
// trim off asterisk
|
||||
setWindowTitle(title.left(title.length() - 1));
|
||||
}
|
||||
}
|
||||
setWindowTitle(title);
|
||||
}
|
||||
|
||||
void MainWindow::ExtractObject(si::Object *obj)
|
||||
|
@ -230,7 +227,7 @@ void MainWindow::ReplaceObject(si::Object *obj)
|
|||
#endif
|
||||
)) {
|
||||
static_cast<Panel*>(config_stack_->currentWidget())->ResetData();
|
||||
UpdateWindowTitleFlag(true);
|
||||
AppendModifiedTitleIndicator();
|
||||
} else {
|
||||
QMessageBox::critical(this, QString(), tr("Failed to open to file \"%1\".").arg(s));
|
||||
}
|
||||
|
@ -309,6 +306,8 @@ void MainWindow::NewFile()
|
|||
model_.SetCore(nullptr);
|
||||
interleaf_.Clear();
|
||||
model_.SetCore(&interleaf_);
|
||||
|
||||
UpdateWindowTitle(tr("UNTITLED.SI"));
|
||||
}
|
||||
|
||||
void MainWindow::OpenFile()
|
||||
|
@ -316,9 +315,7 @@ void MainWindow::OpenFile()
|
|||
QString s = GetOpenFileName();
|
||||
if (!s.isEmpty()) {
|
||||
OpenFilename(s);
|
||||
TrimOffDirectory(s);
|
||||
|
||||
setWindowTitle(QStringLiteral("%1 - %2").arg(QApplication::applicationName(), s));
|
||||
UpdateWindowTitle(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,7 +333,7 @@ bool MainWindow::SaveFile()
|
|||
);
|
||||
|
||||
if (r == Interleaf::ERROR_SUCCESS) {
|
||||
UpdateWindowTitleFlag(false);
|
||||
UpdateWindowTitle(current_filename_);
|
||||
return true;
|
||||
} else {
|
||||
QMessageBox::critical(this, QString(), tr("Failed to write SI file: %1").arg(r));
|
||||
|
|
|
@ -29,7 +29,6 @@ private:
|
|||
void InitializeMenuBar();
|
||||
|
||||
void SetPanel(Panel *panel, si::Object *chunk);
|
||||
void UpdateWindowTitleFlag(bool isFileModified);
|
||||
|
||||
void ExtractObject(si::Object *obj);
|
||||
void ReplaceObject(si::Object *obj);
|
||||
|
@ -42,6 +41,9 @@ private:
|
|||
|
||||
void TrimOffDirectory(QString &s);
|
||||
|
||||
void UpdateWindowTitle(QString filename);
|
||||
void AppendModifiedTitleIndicator();
|
||||
|
||||
static const QString kFileFilter;
|
||||
|
||||
QStackedWidget *config_stack_;
|
||||
|
|
Loading…
Add table
Reference in a new issue