Skip to content

Commit

Permalink
Lots of improvements to IDE behavior.
Browse files Browse the repository at this point in the history
- Verify config is writable on startup (IDE-130)
- New From Template only requires single click (IDE-191)
- Create new home folder on installation (IDE-192)
- Prevent compilation when circular dependency is detected (IDE-193)
- Open last used device on startup (IDE-190)
- Only check and save files in the current project when building
  (IDE-194)
  • Loading branch information
bweir committed May 11, 2016
1 parent 6498959 commit 582d226
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/projectview
74 changes: 54 additions & 20 deletions src/propelleride/filemanager.cpp
Expand Up @@ -2,6 +2,7 @@

#include <QFileDialog>
#include <QRegularExpression>
#include <QStandardPaths>

FileManager::FileManager(QWidget *parent) :
QTabWidget(parent)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions src/propelleride/filemanager.h
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/propelleride/forms/newfromtemplate.ui
Expand Up @@ -186,7 +186,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Click the language, then double-click to select a template.</string>
<string>Click the language, then click to select a template.</string>
</property>
</widget>
</item>
Expand Down
9 changes: 9 additions & 0 deletions src/propelleride/main.cpp
Expand Up @@ -10,6 +10,7 @@
#include <QString>
#include <QtGlobal>
#include <QDateTime>
#include <QSettings>

#include "logging.h"

Expand Down Expand Up @@ -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;
Expand Down
25 changes: 19 additions & 6 deletions src/propelleride/mainwindow.cpp
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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())
{
Expand All @@ -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("<p>Your project has a circular dependency. "
"That means one of your objects is including <i>itself</i>.</p>"
"<p>Revise your code to build your project.</p>"));
return false;
}

setBuildControls(false);

BuildManager::Configuration config;

config.compiler = spinCompiler;
Expand Down
2 changes: 1 addition & 1 deletion src/propelleride/mainwindow.h
Expand Up @@ -100,7 +100,7 @@ public slots:
void saveSession();
void clearSession();

void checkAndSaveFiles();
void checkAndSaveFiles(QStringList files = QStringList());

bool eventFilter(QObject *target, QEvent *event);

Expand Down
12 changes: 0 additions & 12 deletions src/propelleride/templateicon.cpp
Expand Up @@ -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"));
Expand Down
2 changes: 0 additions & 2 deletions src/propelleride/templateicon.h
Expand Up @@ -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);
Expand Down

0 comments on commit 582d226

Please sign in to comment.