diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 2fa47fc..066e0b2 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" +#include <QApplication> #include <QFileDialog> #include <QLineEdit> #include <QMenuBar> @@ -104,7 +105,7 @@ MainWindow::MainWindow(QWidget *parent) : splitter->setSizes({99999, 99999}); - setWindowTitle(tr("SI Editor")); + setWindowTitle(QApplication::applicationName()); } void MainWindow::OpenFilename(const QString &s) @@ -183,11 +184,7 @@ void MainWindow::ExtractObject(si::Object *obj) filename = QString::fromStdString(obj->name()); filename.append(QStringLiteral(".bin")); } else { - // Strip off directory - int index = filename.lastIndexOf('\\'); - if (index != -1) { - filename = filename.mid(index+1); - } + TrimOffDirectory(filename); } QString s = QFileDialog::getSaveFileName(this, tr("Export Object"), filename); @@ -278,6 +275,17 @@ bool MainWindow::ExtractAllRecursiveInternal(const QDir &dir, const si::Core *ob return true; } +void MainWindow::TrimOffDirectory(QString& s) +{ + int bSlashIndex = s.lastIndexOf('\\'); + int fSlashIndex = s.lastIndexOf('/'); + int lastIndex = (bSlashIndex > fSlashIndex) ? bSlashIndex : fSlashIndex; + + if (lastIndex != -1) { + s = s.mid(lastIndex + 1); + } +} + void MainWindow::NewFile() { model_.SetCore(nullptr); @@ -290,6 +298,9 @@ void MainWindow::OpenFile() QString s = GetOpenFileName(); if (!s.isEmpty()) { OpenFilename(s); + TrimOffDirectory(s); + + setWindowTitle(QStringLiteral("%1 - %2").arg(QApplication::applicationName(), s)); } } diff --git a/app/mainwindow.h b/app/mainwindow.h index cb8c99e..ee85b2b 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -39,6 +39,8 @@ private: bool ExtractAllRecursiveInternal(const QDir &dir, const si::Core *obj); + void TrimOffDirectory(QString &s); + static const QString kFileFilter; QStackedWidget *config_stack_;