Skip to content

app: presentation tweaks and improvements #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
34 changes: 28 additions & 6 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mainwindow.h"

#include <QApplication>
#include <QFileDialog>
#include <QLineEdit>
#include <QMenuBar>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -176,18 +177,20 @@ 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());
if (filename.isEmpty()) {
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);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -278,18 +283,34 @@ 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()
{
QString s = GetOpenFileName();
if (!s.isEmpty()) {
OpenFilename(s);
UpdateWindowTitle(s);
}
}

Expand All @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class MainWindow : public QMainWindow

bool ExtractAllRecursiveInternal(const QDir &dir, const si::Core *obj);

void TrimOffDirectory(QString &s);

void UpdateWindowTitle(QString filename);

static const QString kFileFilter;

QStackedWidget *config_stack_;
Expand Down