diff --git a/src/projectview b/src/projectview index 41051a5..f2c37f4 160000 --- a/src/projectview +++ b/src/projectview @@ -1 +1 @@ -Subproject commit 41051a5a9842d8a1fefa2fb5ec10cb16148a4527 +Subproject commit f2c37f4c68d32b8ded34d3657e640930c91b0a48 diff --git a/src/propelleride/filemanager.cpp b/src/propelleride/filemanager.cpp index 5e4da3b..1c66c42 100644 --- a/src/propelleride/filemanager.cpp +++ b/src/propelleride/filemanager.cpp @@ -2,6 +2,7 @@ #include #include +#include FileManager::FileManager(QWidget *parent) : QTabWidget(parent) @@ -13,8 +14,53 @@ FileManager::FileManager(QWidget *parent) : connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeFile(int))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int))); + + createHome(); +} + +bool FileManager::createHome() +{ + QSettings settings; + settings.beginGroup("Paths"); + + QDir projects(QDir::homePath() + "/" + tr("PropellerIDE Projects")); + + if (!projects.exists()) + { + if (!QDir().mkdir(projects.path())) + { + qCWarning(logfilemanager) << "failed to create projects folder:" << projects.path(); + return false; + } + } + + settings.setValue("homeDirectory", projects.path()); + + if (settings.value("lastDirectory").toString().isEmpty()) + settings.setValue("lastDirectory", projects.path()); + + settings.endGroup(); + + return true; +} + +QString FileManager::getDirectory() +{ + QSettings settings; + settings.beginGroup("Paths"); + + return settings.value("lastDirectory", + settings.value("homeDirectory", QDir::homePath()).toString()).toString(); } +void FileManager::setDirectory(QString dir) +{ + QSettings settings; + settings.beginGroup("Paths"); + settings.setValue("lastDirectory", dir); +} + + // THIS IS A HACK OMG SUCH A HACK void FileManager::setLanguage(Language * language) { @@ -66,23 +112,15 @@ void FileManager::setCopy(bool available) void FileManager::open() { - QSettings settings; - settings.beginGroup("Paths"); - - QString lastDir = settings.value("lastDirectory", - QDir(tabToolTip(currentIndex())).path()).toString(); - QStringList fileNames = QFileDialog::getOpenFileNames(this, - tr("Open File"), lastDir, "Spin Files (*.spin);;All Files (*)"); + tr("Open File"), getDirectory(), "Spin Files (*.spin);;All Files (*)"); - if (fileNames.size()) - settings.setValue("lastDirectory",QDir(fileNames[0]).path()); + setDirectory(QDir(fileNames[0]).path()); for (int i = 0; i < fileNames.size(); i++) if (!fileNames.at(i).isEmpty()) openFile(fileNames.at(i)); - settings.endGroup(); } @@ -163,19 +201,11 @@ int FileManager::openFile(const QString & fileName) void FileManager::newFromFile() { - QSettings settings; - settings.beginGroup("Paths"); - - QString lastDir = settings.value("lastDirectory", - QDir(tabToolTip(currentIndex())).path()).toString(); - QString fileName = QFileDialog::getOpenFileName(this, - tr("New From File..."), lastDir, "Spin Files (*.spin);;All Files (*)"); + tr("New From File..."), getDirectory(), "Spin Files (*.spin);;All Files (*)"); if (!fileName.isEmpty()) newFromFile(fileName); - - settings.endGroup(); } @@ -236,12 +266,16 @@ void FileManager::saveAs(int index) { QString fileName = tabToolTip(index); + QString lastDir = QDir(fileName).path(); if (fileName.isEmpty()) + { fileName = tr("Untitled.spin"); + lastDir = getDirectory(); + } fileName = QFileDialog::getSaveFileName(this, tr("Save File As..."), - QDir(fileName).path(), + lastDir, tr("Spin Files (*.spin)")); if (fileName.isEmpty()) diff --git a/src/propelleride/filemanager.h b/src/propelleride/filemanager.h index a192a6a..4acf556 100644 --- a/src/propelleride/filemanager.h +++ b/src/propelleride/filemanager.h @@ -25,6 +25,10 @@ class FileManager : public QTabWidget int isFileEmpty(int index); void setLanguage(Language * language); + bool createHome(); + QString getDirectory(); + void setDirectory(QString dir); + public slots: int newFile(); void newFromFile(); diff --git a/src/propelleride/forms/newfromtemplate.ui b/src/propelleride/forms/newfromtemplate.ui index 3b3ada5..932d4f6 100644 --- a/src/propelleride/forms/newfromtemplate.ui +++ b/src/propelleride/forms/newfromtemplate.ui @@ -186,7 +186,7 @@ - Click the language, then double-click to select a template. + Click the language, then click to select a template. diff --git a/src/propelleride/main.cpp b/src/propelleride/main.cpp index 1f958a0..daa0882 100644 --- a/src/propelleride/main.cpp +++ b/src/propelleride/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "logging.h" @@ -67,6 +68,14 @@ int main(int argc, char *argv[]) QCoreApplication::setApplicationVersion("0.0.0"); #endif + QSettings settings; + if (settings.status() == QSettings::AccessError) + { + QMessageBox::critical(0, QObject::tr("Can't open application settings!"), QObject::tr("Unable to open the PropellerIDE settings stored at:\n\n%1\n\nTry deleting the file and restarting PropellerIDE.").arg(settings.fileName())); + qCCritical(logmain) << "can't access:" << settings.fileName() << ". Is it writable?"; + return 1; + } + QString description = QObject::tr("An easy-to-use, cross-platform IDE for the Parallax Propeller"); QCommandLineParser parser; diff --git a/src/propelleride/mainwindow.cpp b/src/propelleride/mainwindow.cpp index 8e5b456..0ecec14 100644 --- a/src/propelleride/mainwindow.cpp +++ b/src/propelleride/mainwindow.cpp @@ -336,13 +336,16 @@ void MainWindow::showBrowser() } } -void MainWindow::checkAndSaveFiles() +void MainWindow::checkAndSaveFiles(QStringList files) { for (int i = 0; i < ui.editorTabs->count(); i++) { - if (ui.editorTabs->getEditor(i)->contentChanged()) + if (files == QStringList() || files.contains(ui.editorTabs->tabToolTip(i))) { - ui.editorTabs->save(i); + if (ui.editorTabs->getEditor(i)->contentChanged()) + { + ui.editorTabs->save(i); + } } } } @@ -383,8 +386,6 @@ bool MainWindow::runCompiler(bool load, bool write, const QString & name) if(!ui.editorTabs->count()) return false; - setBuildControls(false); - QString filename = name; if (name.isEmpty()) { @@ -394,9 +395,21 @@ bool MainWindow::runCompiler(bool load, bool write, const QString & name) getApplicationSettings(); - checkAndSaveFiles(); + checkAndSaveFiles(parser->getFileList()); setProject(); + if (parser->status() == ProjectParser::CircularDependencyError) + { + QMessageBox::critical(0, + QObject::tr("Circular dependency!"), + QObject::tr("

Your project has a circular dependency. " + "That means one of your objects is including itself.

" + "

Revise your code to build your project.

")); + return false; + } + + setBuildControls(false); + BuildManager::Configuration config; config.compiler = spinCompiler; diff --git a/src/propelleride/mainwindow.h b/src/propelleride/mainwindow.h index 77c4148..d0cb827 100644 --- a/src/propelleride/mainwindow.h +++ b/src/propelleride/mainwindow.h @@ -100,7 +100,7 @@ public slots: void saveSession(); void clearSession(); - void checkAndSaveFiles(); + void checkAndSaveFiles(QStringList files = QStringList()); bool eventFilter(QObject *target, QEvent *event); diff --git a/src/propelleride/templateicon.cpp b/src/propelleride/templateicon.cpp index cd1fb03..250e124 100644 --- a/src/propelleride/templateicon.cpp +++ b/src/propelleride/templateicon.cpp @@ -44,18 +44,6 @@ void TemplateIcon::leaveEvent(QEvent * e) } void TemplateIcon::mousePressEvent(QMouseEvent * e) -{ - Q_UNUSED(e); - setColor(QColor("#2D83DE")); -} - -void TemplateIcon::mouseReleaseEvent(QMouseEvent * e) -{ - Q_UNUSED(e); - setColor(QColor("#97C9FD")); -} - -void TemplateIcon::mouseDoubleClickEvent(QMouseEvent * e) { Q_UNUSED(e); setColor(QColor("#2D83DE")); diff --git a/src/propelleride/templateicon.h b/src/propelleride/templateicon.h index 6450b6f..d12eff2 100644 --- a/src/propelleride/templateicon.h +++ b/src/propelleride/templateicon.h @@ -24,8 +24,6 @@ public slots: virtual void enterEvent(QEvent * e); virtual void leaveEvent(QEvent * e); virtual void mousePressEvent(QMouseEvent * e); - virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void mouseDoubleClickEvent(QMouseEvent * e); signals: void templateSelected(const QString & filename);