Skip to content

Commit 582d226

Browse files
committed
Lots of improvements to IDE behavior.
- 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)
1 parent 6498959 commit 582d226

File tree

9 files changed

+89
-43
lines changed

9 files changed

+89
-43
lines changed

src/projectview

src/propelleride/filemanager.cpp

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <QFileDialog>
44
#include <QRegularExpression>
5+
#include <QStandardPaths>
56

67
FileManager::FileManager(QWidget *parent) :
78
QTabWidget(parent)
@@ -13,8 +14,53 @@ FileManager::FileManager(QWidget *parent) :
1314

1415
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeFile(int)));
1516
connect(this, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int)));
17+
18+
createHome();
19+
}
20+
21+
bool FileManager::createHome()
22+
{
23+
QSettings settings;
24+
settings.beginGroup("Paths");
25+
26+
QDir projects(QDir::homePath() + "/" + tr("PropellerIDE Projects"));
27+
28+
if (!projects.exists())
29+
{
30+
if (!QDir().mkdir(projects.path()))
31+
{
32+
qCWarning(logfilemanager) << "failed to create projects folder:" << projects.path();
33+
return false;
34+
}
35+
}
36+
37+
settings.setValue("homeDirectory", projects.path());
38+
39+
if (settings.value("lastDirectory").toString().isEmpty())
40+
settings.setValue("lastDirectory", projects.path());
41+
42+
settings.endGroup();
43+
44+
return true;
45+
}
46+
47+
QString FileManager::getDirectory()
48+
{
49+
QSettings settings;
50+
settings.beginGroup("Paths");
51+
52+
return settings.value("lastDirectory",
53+
settings.value("homeDirectory", QDir::homePath()).toString()).toString();
1654
}
1755

56+
void FileManager::setDirectory(QString dir)
57+
{
58+
QSettings settings;
59+
settings.beginGroup("Paths");
60+
settings.setValue("lastDirectory", dir);
61+
}
62+
63+
1864
// THIS IS A HACK OMG SUCH A HACK
1965
void FileManager::setLanguage(Language * language)
2066
{
@@ -66,23 +112,15 @@ void FileManager::setCopy(bool available)
66112

67113
void FileManager::open()
68114
{
69-
QSettings settings;
70-
settings.beginGroup("Paths");
71-
72-
QString lastDir = settings.value("lastDirectory",
73-
QDir(tabToolTip(currentIndex())).path()).toString();
74-
75115
QStringList fileNames = QFileDialog::getOpenFileNames(this,
76-
tr("Open File"), lastDir, "Spin Files (*.spin);;All Files (*)");
116+
tr("Open File"), getDirectory(), "Spin Files (*.spin);;All Files (*)");
77117

78-
if (fileNames.size())
79-
settings.setValue("lastDirectory",QDir(fileNames[0]).path());
118+
setDirectory(QDir(fileNames[0]).path());
80119

81120
for (int i = 0; i < fileNames.size(); i++)
82121
if (!fileNames.at(i).isEmpty())
83122
openFile(fileNames.at(i));
84123

85-
settings.endGroup();
86124
}
87125

88126

@@ -163,19 +201,11 @@ int FileManager::openFile(const QString & fileName)
163201

164202
void FileManager::newFromFile()
165203
{
166-
QSettings settings;
167-
settings.beginGroup("Paths");
168-
169-
QString lastDir = settings.value("lastDirectory",
170-
QDir(tabToolTip(currentIndex())).path()).toString();
171-
172204
QString fileName = QFileDialog::getOpenFileName(this,
173-
tr("New From File..."), lastDir, "Spin Files (*.spin);;All Files (*)");
205+
tr("New From File..."), getDirectory(), "Spin Files (*.spin);;All Files (*)");
174206

175207
if (!fileName.isEmpty())
176208
newFromFile(fileName);
177-
178-
settings.endGroup();
179209
}
180210

181211

@@ -236,12 +266,16 @@ void FileManager::saveAs(int index)
236266
{
237267
QString fileName = tabToolTip(index);
238268

269+
QString lastDir = QDir(fileName).path();
239270
if (fileName.isEmpty())
271+
{
240272
fileName = tr("Untitled.spin");
273+
lastDir = getDirectory();
274+
}
241275

242276
fileName = QFileDialog::getSaveFileName(this,
243277
tr("Save File As..."),
244-
QDir(fileName).path(),
278+
lastDir,
245279
tr("Spin Files (*.spin)"));
246280

247281
if (fileName.isEmpty())

src/propelleride/filemanager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class FileManager : public QTabWidget
2525
int isFileEmpty(int index);
2626
void setLanguage(Language * language);
2727

28+
bool createHome();
29+
QString getDirectory();
30+
void setDirectory(QString dir);
31+
2832
public slots:
2933
int newFile();
3034
void newFromFile();

src/propelleride/forms/newfromtemplate.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
<item>
187187
<widget class="QLabel" name="label">
188188
<property name="text">
189-
<string>Click the language, then double-click to select a template.</string>
189+
<string>Click the language, then click to select a template.</string>
190190
</property>
191191
</widget>
192192
</item>

src/propelleride/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QString>
1111
#include <QtGlobal>
1212
#include <QDateTime>
13+
#include <QSettings>
1314

1415
#include "logging.h"
1516

@@ -67,6 +68,14 @@ int main(int argc, char *argv[])
6768
QCoreApplication::setApplicationVersion("0.0.0");
6869
#endif
6970

71+
QSettings settings;
72+
if (settings.status() == QSettings::AccessError)
73+
{
74+
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()));
75+
qCCritical(logmain) << "can't access:" << settings.fileName() << ". Is it writable?";
76+
return 1;
77+
}
78+
7079
QString description = QObject::tr("An easy-to-use, cross-platform IDE for the Parallax Propeller");
7180

7281
QCommandLineParser parser;

src/propelleride/mainwindow.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,16 @@ void MainWindow::showBrowser()
336336
}
337337
}
338338

339-
void MainWindow::checkAndSaveFiles()
339+
void MainWindow::checkAndSaveFiles(QStringList files)
340340
{
341341
for (int i = 0; i < ui.editorTabs->count(); i++)
342342
{
343-
if (ui.editorTabs->getEditor(i)->contentChanged())
343+
if (files == QStringList() || files.contains(ui.editorTabs->tabToolTip(i)))
344344
{
345-
ui.editorTabs->save(i);
345+
if (ui.editorTabs->getEditor(i)->contentChanged())
346+
{
347+
ui.editorTabs->save(i);
348+
}
346349
}
347350
}
348351
}
@@ -383,8 +386,6 @@ bool MainWindow::runCompiler(bool load, bool write, const QString & name)
383386
if(!ui.editorTabs->count())
384387
return false;
385388

386-
setBuildControls(false);
387-
388389
QString filename = name;
389390
if (name.isEmpty())
390391
{
@@ -394,9 +395,21 @@ bool MainWindow::runCompiler(bool load, bool write, const QString & name)
394395

395396
getApplicationSettings();
396397

397-
checkAndSaveFiles();
398+
checkAndSaveFiles(parser->getFileList());
398399
setProject();
399400

401+
if (parser->status() == ProjectParser::CircularDependencyError)
402+
{
403+
QMessageBox::critical(0,
404+
QObject::tr("Circular dependency!"),
405+
QObject::tr("<p>Your project has a circular dependency. "
406+
"That means one of your objects is including <i>itself</i>.</p>"
407+
"<p>Revise your code to build your project.</p>"));
408+
return false;
409+
}
410+
411+
setBuildControls(false);
412+
400413
BuildManager::Configuration config;
401414

402415
config.compiler = spinCompiler;

src/propelleride/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public slots:
100100
void saveSession();
101101
void clearSession();
102102

103-
void checkAndSaveFiles();
103+
void checkAndSaveFiles(QStringList files = QStringList());
104104

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

src/propelleride/templateicon.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ void TemplateIcon::leaveEvent(QEvent * e)
4444
}
4545

4646
void TemplateIcon::mousePressEvent(QMouseEvent * e)
47-
{
48-
Q_UNUSED(e);
49-
setColor(QColor("#2D83DE"));
50-
}
51-
52-
void TemplateIcon::mouseReleaseEvent(QMouseEvent * e)
53-
{
54-
Q_UNUSED(e);
55-
setColor(QColor("#97C9FD"));
56-
}
57-
58-
void TemplateIcon::mouseDoubleClickEvent(QMouseEvent * e)
5947
{
6048
Q_UNUSED(e);
6149
setColor(QColor("#2D83DE"));

src/propelleride/templateicon.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public slots:
2424
virtual void enterEvent(QEvent * e);
2525
virtual void leaveEvent(QEvent * e);
2626
virtual void mousePressEvent(QMouseEvent * e);
27-
virtual void mouseReleaseEvent(QMouseEvent * e);
28-
virtual void mouseDoubleClickEvent(QMouseEvent * e);
2927

3028
signals:
3129
void templateSelected(const QString & filename);

0 commit comments

Comments
 (0)