This commit is contained in:
Ramen2X 2024-12-18 23:15:31 +01:00 committed by GitHub
commit ac5d3cbde4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 6 deletions

View file

@ -40,6 +40,7 @@ int main(int argc, char *argv[])
qInstallMessageHandler(DebugHandler);
QApplication a(argc, argv);
a.setApplicationName(QCoreApplication::translate("main", "SI Editor"));
MainWindow w;

View file

@ -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)
@ -176,6 +177,12 @@ void MainWindow::SetPanel(Panel *panel, si::Object *chunk)
}
}
void MainWindow::UpdateWindowTitle(QString filename)
{
TrimOffDirectory(filename);
setWindowTitle(QStringLiteral("%1 - %2[*]").arg(QApplication::applicationName(), filename));
}
void MainWindow::ExtractObject(si::Object *obj)
{
QString filename = QString::fromStdString(obj->filename());
@ -183,11 +190,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);
@ -216,6 +219,8 @@ void MainWindow::ReplaceObject(si::Object *obj)
#endif
)) {
static_cast<Panel*>(config_stack_->currentWidget())->ResetData();
setWindowModified(true);
} else {
QMessageBox::critical(this, QString(), tr("Failed to open to file \"%1\".").arg(s));
}
@ -278,11 +283,26 @@ 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()
{
tree_->clearSelection();
SetPanel(panel_blank_, nullptr);
model_.SetCore(nullptr);
interleaf_.Clear();
model_.SetCore(&interleaf_);
UpdateWindowTitle(tr("UNTITLED.SI"));
}
void MainWindow::OpenFile()
@ -290,6 +310,7 @@ void MainWindow::OpenFile()
QString s = GetOpenFileName();
if (!s.isEmpty()) {
OpenFilename(s);
UpdateWindowTitle(s);
}
}
@ -307,6 +328,7 @@ bool MainWindow::SaveFile()
);
if (r == Interleaf::ERROR_SUCCESS) {
UpdateWindowTitle(current_filename_);
return true;
} else {
QMessageBox::critical(this, QString(), tr("Failed to write SI file: %1").arg(r));

View file

@ -39,6 +39,10 @@ private:
bool ExtractAllRecursiveInternal(const QDir &dir, const si::Core *obj);
void TrimOffDirectory(QString &s);
void UpdateWindowTitle(QString filename);
static const QString kFileFilter;
QStackedWidget *config_stack_;