groundwork for opening window with project

master
zetaPRIME 2022-03-13 17:51:06 -04:00
parent c41ffbfcce
commit 638c7e5c12
2 changed files with 17 additions and 8 deletions

View File

@ -72,7 +72,7 @@ namespace {
std::unordered_set<MainWindow*> MainWindow::openWindows;
MainWindow::MainWindow(QWidget *parent) :
MainWindow::MainWindow(QWidget *parent, const QString& fileName) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
socket = new UISocket(); // create this first
@ -502,11 +502,19 @@ MainWindow::MainWindow(QWidget *parent) :
selectSampleForEditing(nullptr); // init blank
//bool isFirst = openWindows.empty();
bool isFirst = openWindows.empty();
openWindows.insert(this);
// and start with a new project
menuFileNew();
if (fileName.isEmpty()) {
// start with a new project
menuFileNew();
} else {
openProject(fileName, isFirst);
if (!project) {
if (!isFirst) close();
else menuFileNew();
}
}
}
MainWindow::~MainWindow() {
@ -539,10 +547,10 @@ bool MainWindow::eventFilter(QObject *obj [[maybe_unused]], QEvent *event) {
return false;
}
void MainWindow::openProject(const QString& fileName) {
void MainWindow::openProject(const QString& fileName, bool failSilent) {
auto np = FileOps::loadProject(fileName);
if (!np) {
QMessageBox::critical(this, "Error", "Error loading project");
if (!failSilent) QMessageBox::critical(this, "Error", "Error loading project");
return;
}
if (audioEngine->playingProject() == project) audioEngine->stop();
@ -561,6 +569,7 @@ void MainWindow::openRecentProject(size_t idx) {
}
bool MainWindow::promptSave() {
if (!project) return false; // window closing on open
if (!undoStack->isClean()) {
auto ftxt = project->fileName.isEmpty() ? qs("unsaved project") : qs("project \"%1\"").arg(QFileInfo(project->fileName).fileName());
auto r = QMessageBox::warning(this, qs("Unsaved changes"), qs("Save changes to %1?").arg(ftxt),

View File

@ -21,7 +21,7 @@ namespace Xybrid {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
explicit MainWindow(QWidget *parent = nullptr, const QString& fileName = QString());
~MainWindow() override;
static std::unordered_set<MainWindow*> openWindows;
@ -36,7 +36,7 @@ namespace Xybrid {
QUndoStack* undoStack;
std::vector<QAction*> recentFileActions;
void openProject(const QString& fileName);
void openProject(const QString& fileName, bool failSilent = false);
void openRecentProject(size_t idx);
bool promptSave();