Commit c75ae84d authored by jhammen's avatar jhammen

save open files for each project in settings

parent 47ec0d1d
......@@ -31,8 +31,9 @@
#include <QTime>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), audioEngine(AudioEngine::instance()), transportPosition(0),
ui(new Ui::MainWindow), timeWidget(this), bbtWidget(this) {
: QMainWindow(parent), projectList(ProjectList::instance()),
audioEngine(AudioEngine::instance()), transportPosition(0), ui(new Ui::MainWindow),
timeWidget(this), bbtWidget(this) {
ui->setupUi(this);
// time in MM:SS + BBT + engine config
......@@ -59,7 +60,6 @@ MainWindow::MainWindow(QWidget *parent)
ui->leftTabWidget->addTab(searchWidget, "Search");
connect(searchWidget, SIGNAL(searchCurrent(QString)), this, SLOT(searchCurrent(QString)));
ProjectList &projectList = ProjectList::getProjectList();
projectList.load();
if (projectList.currentExists()) {
loadProject();
......@@ -82,7 +82,7 @@ MainWindow::~MainWindow() { delete ui; }
void MainWindow::closeEvent(QCloseEvent *event) {
// save settings
ProjectList::getProjectList().save();
projectList.save();
// close tabs
if (!saveAllTabs()) {
event->ignore();
......@@ -112,6 +112,7 @@ void MainWindow::changeProject() {
void MainWindow::closeEditorTab(int index) {
EditorWidget *editor = qobject_cast<EditorWidget *>(ui->tabWidget->widget(index));
if (saveOrAbandon(editor)) {
projectList.currentProject().closeFile(editor->path());
delete editor;
}
}
......@@ -155,12 +156,14 @@ void MainWindow::createOrOpenEditor(NamedFile &file) {
connect(editor, SIGNAL(redoAvailable(bool)), ui->actionRedo, SLOT(setEnabled(bool)));
connect(editor, SIGNAL(copyAvailable(bool)), ui->actionCut, SLOT(setEnabled(bool)));
connect(editor, SIGNAL(copyAvailable(bool)), ui->actionCopy, SLOT(setEnabled(bool)));
// add to project list as open file
projectList.currentProject().openFile(file.path);
}
selectedFolder = nullptr;
enableFileActions(editor);
}
void MainWindow::createOrOpenEditor(QString &path) {
void MainWindow::createOrOpenEditor(const QString &path) {
QFileInfo fileInfo(path);
NamedFile file(fileInfo.fileName(), fileInfo.filePath());
createOrOpenEditor(file);
......@@ -223,10 +226,12 @@ void MainWindow::showTime(Position pos) {
void MainWindow::tabChanged(int i) {
EditorWidget *editor = qobject_cast<EditorWidget *>(ui->tabWidget->widget(i));
Project &project = projectList.currentProject();
if (editor == nullptr) { // all tabs closed
ui->folderTree->clearSelection();
setWindowTitle(QCoreApplication::applicationName());
enableFileActions(nullptr);
project.activeFile(nullptr);
} else {
QTreeWidgetItem *item = findTreeItem(editor->path());
if (item) {
......@@ -237,6 +242,7 @@ void MainWindow::tabChanged(int i) {
setWindowTitle(QString("%1[*]").arg(editor->name()));
setWindowModified(editor->isDirty());
enableFileActions(editor);
project.activeFile(editor->path());
}
}
......@@ -397,7 +403,6 @@ void MainWindow::on_actionJackConnect_toggled(bool connected) {
}
void MainWindow::on_actionOpenFile_triggered() {
ProjectList &projectList = ProjectList::getProjectList();
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setDirectory(projectList.commonRoot());
......@@ -418,8 +423,7 @@ void MainWindow::on_actionOpenProject_triggered() {
void MainWindow::on_actionPaste_triggered() { currentEditor()->paste(); }
void MainWindow::on_actionProjectOptions_triggered() {
ProjectList &projects = ProjectList::getProjectList();
Project &project = projects.currentProject();
Project &project = projectList.currentProject();
QString value = project.executable();
QString message("Executable Path");
bool ok;
......@@ -569,13 +573,17 @@ QTreeWidgetItem *MainWindow::findTreeItem(const QString &path) {
}
void MainWindow::loadProject() {
ProjectList &projects = ProjectList::getProjectList();
Project &project = projects.currentProject();
Project &project = projectList.currentProject();
ScriptRun::setExecutable(project.executable());
for (int i = 0; i < project.folderCount(); ++i) {
NamedFile &folder = project.folder(i);
ui->folderTree->addTopLevelItem(toTreeFolder(folder));
}
foreach (const QString &path, project.openFiles()) { createOrOpenEditor(path); }
EditorWidget *editor = findEditor(project.activeFile());
if (editor) {
ui->tabWidget->setCurrentWidget(editor);
}
}
bool MainWindow::saveAllTabs() {
......
......@@ -83,6 +83,7 @@ class MainWindow : public QMainWindow {
void on_actionFocusFind_triggered();
private:
ProjectList &projectList;
QString *selectedFolder;
AudioEngine &audioEngine;
AudioTimerService *atimer;
......@@ -95,7 +96,7 @@ class MainWindow : public QMainWindow {
QLabel engineWidget;
// private methods
void createOrOpenEditor(NamedFile &);
void createOrOpenEditor(QString &);
void createOrOpenEditor(const QString &);
EditorWidget *currentEditor();
void enableFileActions(EditorWidget *editor);
void enableTransportControls(bool enabled);
......
......@@ -38,6 +38,7 @@ void ProjectList::load() {
settings.setArrayIndex(i);
Project project;
project.executable(settings.value("exec").toString());
// folders
int fsize = settings.beginReadArray("folders");
for (int j = 0; j < fsize; j++) {
settings.setArrayIndex(j);
......@@ -47,6 +48,14 @@ void ProjectList::load() {
project.addFolder(folder);
}
settings.endArray();
// files
fsize = settings.beginReadArray("open");
for (int j = 0; j < fsize; j++) {
settings.setArrayIndex(j);
project.openFile(settings.value("path").toString());
}
settings.endArray();
project.activeFile(settings.value("active").toString());
projects.append(project);
}
settings.endArray();
......@@ -62,6 +71,7 @@ void ProjectList::save() {
for (int i = 0; i < projects.size(); i++) {
settings.setArrayIndex(i);
settings.setValue("exec", projects[i].executable());
// folders
settings.beginWriteArray("folders");
for (int j = 0; j < projects[i].folderCount(); j++) {
settings.setArrayIndex(j);
......@@ -70,6 +80,15 @@ void ProjectList::save() {
settings.setValue("path", folder.path);
}
settings.endArray();
// files
int count = 0;
settings.beginWriteArray("open");
foreach (const QString &path, projects[i].openFiles()) {
settings.setArrayIndex(count++);
settings.setValue("path", path);
}
settings.endArray();
settings.setValue("active", projects[i].activeFile());
}
settings.endArray();
settings.setValue("appstate/project", openIndex);
......
......@@ -20,19 +20,27 @@
#include "namedfile.h"
#include <QList>
#include <QSet>
#include <QString>
class Project {
QList<NamedFile> folders;
QSet<QString> mopenFiles;
QString mexecutable;
QString mactiveFile;
public:
Project();
int folderCount() { return folders.size(); }
NamedFile &folder(int index) { return folders[index]; }
void addFolder(NamedFile folder) { folders.append(folder); }
void openFile(const QString &path) { mopenFiles.insert(path); }
void closeFile(const QString &path) { mopenFiles.remove(path); }
QSet<QString> openFiles() { return mopenFiles; }
QString &executable() { return mexecutable; }
void executable(const QString &exec) { mexecutable = exec; }
QString &activeFile() { return mactiveFile; }
void activeFile(const QString &active) { mactiveFile = active; }
bool exists();
};
......@@ -46,7 +54,7 @@ class ProjectList {
QString commonRoot(QString &path1, QString &path2);
public:
static ProjectList &getProjectList() {
static ProjectList &instance() {
static ProjectList *instance = nullptr;
if (instance == nullptr) {
instance = new ProjectList();
......
......@@ -22,7 +22,7 @@
#include <QMessageBox>
ProjectsDialog::ProjectsDialog(QWidget *parent)
: QDialog(parent), data(ProjectList::getProjectList()), ui(new Ui::ProjectsDialog) {
: QDialog(parent), data(ProjectList::instance()), ui(new Ui::ProjectsDialog) {
ui->setupUi(this);
// populate list
syncList();
......
/*
* This file is part of Bipscript-IDE.
*
* Bipscript-IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bipscript-IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Bipscript-IDE. If not, see <http://www.gnu.org/licenses/>.
*/
#include "searchwidget.h"
#include "ui_searchwidget.h"
......
/*
* This file is part of Bipscript-IDE.
*
* Bipscript-IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bipscript-IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Bipscript-IDE. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SEARCHWIDGET_H
#define SEARCHWIDGET_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment