Permalink
Browse files

Made the project system much friendlier

  • Loading branch information...
1 parent c466b3b commit 2722ada393d231ffb09ef371bc1bb2d7492478c0 @bmcdorman bmcdorman committed Oct 11, 2013
Showing with 69 additions and 14 deletions.
  1. +5 −0 buildinfo.cmake
  2. +3 −0 include/main_window.hpp
  3. +24 −4 src/main_window.cpp
  4. +20 −4 src/menus/target_menu.cpp
  5. +1 −1 src/project/project.cpp
  6. +16 −5 src/project/project_model.cpp
View
5 buildinfo.cmake
@@ -0,0 +1,5 @@
+execute_process(COMMAND uname -a OUTPUT_VARIABLE UNAME_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE)
+file(WRITE build_defines.h "
+ #define UNAME \"${UNAME_OUTPUT}\"
+ #define
+")
View
3 include/main_window.hpp
@@ -157,6 +157,8 @@ namespace kiss
QStringList standardMenus() const;
templates::Manager *templateManager() const;
+
+ project::Manager *projectManager();
bool canClose();
bool canGoPrevious();
@@ -210,6 +212,7 @@ namespace kiss
private slots:
void on_ui_tabWidget_currentChanged(int i);
void projectAddNew();
+ void projectAddNew(const project::ProjectPtr &project);
void projectAddExisting();
void projectAddExisting(QStringList files);
void projectRenameFile();
View
28 src/main_window.cpp
@@ -171,7 +171,18 @@ project::ProjectPtr MainWindow::newProject()
if(ret == QMessageBox::No) return project::ProjectPtr();
}
- return newProject(saveLocation);
+ project::ProjectPtr ret = newProject(saveLocation);
+ if(ret.isNull()) return ret;
+
+ // Prompt the user to add a new file to their empty project
+ {
+ QMessageBox::StandardButton r = QMessageBox::question(this, tr("Add a New File?"),
+ tr("You just created an empty project. Do you want to add a new file?"),
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+ if(r == QMessageBox::Yes) projectAddNew(ret);
+ }
+
+ return ret;
}
void MainWindow::newFile()
@@ -673,7 +684,11 @@ void MainWindow::projectAddNew()
{
project::ProjectPtr project = m_projectsModel.project(ui_projects->currentIndex());
if(!project) return;
+ projectAddNew(project);
+}
+void MainWindow::projectAddNew(const project::ProjectPtr &project)
+{
SourceFile *const sourceFile = new SourceFile(this);
sourceFile->setProject(project);
if(!sourceFile->selectTemplate()) {
@@ -694,9 +709,9 @@ void MainWindow::projectAddNew()
fileName += sourceFile->templateExt();
}
- sourceFile->setFile(QDir(project->location()).filePath(fileName));
- addTab(sourceFile);
- sourceFile->save();
+ sourceFile->setFile(QDir(project->location()).filePath(fileName));
+ addTab(sourceFile);
+ sourceFile->save();
}
void MainWindow::projectAddExisting()
@@ -1035,6 +1050,11 @@ QList<QObject*> MainWindow::tabs(const QString &name)
return ret;
}
+project::Manager *MainWindow::projectManager()
+{
+ return &m_projectManager;
+}
+
bool MainWindow::canClose()
{
return ui_tabWidget->count() > 0;
View
24 src/menus/target_menu.cpp
@@ -71,10 +71,26 @@ void TargetMenu::deactivated()
void TargetMenu::update()
{
- const bool enabled = target::CommunicationManager::ref().isIdle();
- compileNode->rawAction->setEnabled(enabled);
- downloadNode->rawAction->setEnabled(enabled);
- runNode->rawAction->setEnabled(enabled);
+ const bool enabled = target::CommunicationManager::ref().isIdle();
+ compileNode->rawAction->setEnabled(enabled);
+ downloadNode->rawAction->setEnabled(enabled);
+ runNode->rawAction->setEnabled(enabled);
+
+ {
+ kiss::widget::MainWindow *window = qobject_cast<kiss::widget::MainWindow *>(active());
+ const project::ProjectPtr project = window->projectManager()->activeProject();
+ QString extra;
+ if(!project.isNull()) {
+ const QString &name = project->name();
+ const int size = name.length();
+ const static int maxSize = 8;
+ extra += " " + name.left(maxSize);
+ }
+ compileNode->rawAction->setText(tr("Compile%1").arg(extra));
+ downloadNode->rawAction->setText(tr("Download%1").arg(extra));
+ runNode->rawAction->setText(tr("Run%1").arg(extra));
+ }
+
refresh();
}
View
2 src/project/project.cpp
@@ -262,7 +262,7 @@ kiss::KarPtr kiss::project::Project::archive() const
{
kiss::KarPtr archive = kiss::Kar::create();
QStringList paths = files();
- foreach(QString path, paths) {
+ foreach(const QString &path, paths) {
QFile file(path);
QFileInfo fileInfo(file);
if(fileInfo.suffix() == LINKS_EXT) continue;
View
21 src/project/project_model.cpp
@@ -46,6 +46,16 @@ class PathItem : public QStandardItem
virtual void refresh()
{
}
+
+ virtual void setActive(bool active)
+ {
+ setForeground(active ? Qt::black : Qt::lightGray);
+ for(int i = 0; i < rowCount(); ++i) {
+ PathItem *pathItem = PathItem::pathitem_cast(child(i));
+ if(!pathItem) continue;
+ pathItem->setActive(active);
+ }
+ }
template<typename T>
static PathItem *pathitem_cast(T *item)
@@ -135,11 +145,12 @@ class ProjectItem : public FolderItem
return dynamic_cast<ProjectItem *>(item);
}
- void setActive(bool active)
- {
- if(active) setIcon(ResourceHelper::ref().icon("folder_heart.png"));
- else setIcon(ResourceHelper::ref().icon("folder.png"));
- }
+ virtual void setActive(bool active)
+ {
+ FolderItem::setActive(active);
+ if(active) setIcon(ResourceHelper::ref().icon("folder_heart.png"));
+ else setIcon(ResourceHelper::ref().icon("folder.png"));
+ }
virtual void refresh()
{

0 comments on commit 2722ada

Please sign in to comment.