diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp
index 7adaf06b..2292f29d 100644
--- a/RedPandaIDE/editorlist.cpp
+++ b/RedPandaIDE/editorlist.cpp
@@ -293,6 +293,28 @@ bool EditorList::getContentFromOpenedEditor(const QString &filename, QStringList
return true;
}
+void EditorList::getVisibleEditors(Editor *&left, Editor *&right)
+{
+ switch(mLayout) {
+ case LayoutShowType::lstNone:
+ left = nullptr;
+ right = nullptr;
+ break;
+ case LayoutShowType::lstLeft:
+ left = getEditor(-1,mLeftPageWidget);
+ right = nullptr;
+ break;
+ case LayoutShowType::lstRight:
+ left = nullptr;
+ right = getEditor(-1,mRightPageWidget);
+ break;
+ case LayoutShowType::lstBoth:
+ left = getEditor(-1,mLeftPageWidget);
+ right = getEditor(-1,mRightPageWidget);
+ break;
+ }
+}
+
void EditorList::updateLayout()
{
if (mLeftPageWidget->count() ==0 && mRightPageWidget->count() == 0)
diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h
index 69a13edd..410bc601 100644
--- a/RedPandaIDE/editorlist.h
+++ b/RedPandaIDE/editorlist.h
@@ -40,6 +40,7 @@ public:
bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer);
+ void getVisibleEditors(Editor*& left, Editor*& right);
void updateLayout();
void beginUpdate();
diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp
index 793ccf5c..241e460f 100644
--- a/RedPandaIDE/mainwindow.cpp
+++ b/RedPandaIDE/mainwindow.cpp
@@ -554,6 +554,14 @@ void MainWindow::openFiles(const QStringList &files)
auto end = finally([this] {
this->mEditorList->endUpdate();
});
+ //Check if there is a project file in the list and open it
+ for (const QString& file:files) {
+ if (getFileType(file)==FileType::Project) {
+ openProject(file);
+ return;
+ }
+ }
+ //Didn't find a project? Open all files
for (const QString& file:files) {
openFile(file);
}
diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui
index 72df6ba2..c65d8c07 100644
--- a/RedPandaIDE/mainwindow.ui
+++ b/RedPandaIDE/mainwindow.ui
@@ -898,15 +898,9 @@
-
+
- toolBar_2
-
-
-
- 24
- 24
-
+ toolBar
TopToolBarArea
@@ -914,6 +908,10 @@
false
+
+
+
+
@@ -961,9 +959,15 @@
-
+
- toolBar
+ toolBar_2
+
+
+
+ 24
+ 24
+
TopToolBarArea
@@ -971,10 +975,6 @@
false
-
-
-
-
@@ -1116,9 +1116,6 @@
Ctrl+X
-
- Qt::WidgetWithChildrenShortcut
-
@@ -1132,9 +1129,6 @@
Ctrl+C
-
- Qt::WidgetWithChildrenShortcut
-
@@ -1148,9 +1142,6 @@
Ctrl+V
-
- Qt::WidgetWithChildrenShortcut
-
@@ -1159,9 +1150,6 @@
Ctrl+A
-
- Qt::WidgetWithChildrenShortcut
-
diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp
index 898f1ee0..10392041 100644
--- a/RedPandaIDE/project.cpp
+++ b/RedPandaIDE/project.cpp
@@ -13,7 +13,9 @@
#include
#include "settings.h"
-Project::Project(const QString &filename, const QString &name, QObject *parent) : QObject(parent)
+Project::Project(const QString &filename, const QString &name, QObject *parent) :
+ QObject(parent),
+ mModel(this)
{
mFilename = filename;
mIniFile = std::make_shared(filename,QSettings::IniFormat);
@@ -93,6 +95,10 @@ bool Project::modified() const
void Project::open()
{
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
QFile fileInfo(mFilename);
if (fileInfo.exists()
&& !fileInfo.isWritable()) {
@@ -279,6 +285,7 @@ void Project::rebuildNodes()
// oldPaths.Add(GetFolderPath(tempnode));
// end;
+ mModel.beginUpdate();
// Delete everything
mNode->children.clear();
@@ -309,11 +316,16 @@ void Project::rebuildNodes()
// fNode.Expand(False);
+ mModel.endUpdate();
emit nodesChanged();
}
bool Project::removeEditor(int index, bool doClose)
{
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
if (index<0 || index>=mUnits.count())
return false;
@@ -340,8 +352,10 @@ bool Project::removeEditor(int index, bool doClose)
bool Project::removeFolder(PFolderNode node)
{
- return false;
-
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
// Sanity check
if (!node)
return false;
@@ -516,6 +530,25 @@ void Project::setCompilerOption(const QString &optionString, const QChar &value)
}
}
+void Project::updateFolders()
+{
+ mFolders.clear();
+ updateFolderNode(mNode);
+ for (int idx = 0; idx < mUnits.count();idx++)
+ mUnits[idx]->setFolder(
+ getFolderPath(
+ mUnits[idx]->node()->parent.lock()
+ )
+ );
+ setModified(true);
+}
+
+void Project::updateNodeIndexes()
+{
+ for (int idx = 0;idxnode()->unitIndex = idx;
+}
+
void Project::saveOptions()
{
mIniFile->beginGroup("Project");
@@ -596,6 +629,10 @@ void Project::saveOptions()
void Project::addFolder(const QString &s)
{
if (mFolders.indexOf(s)<0) {
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
mFolders.append(s);
rebuildNodes();
//todo: MainForm.ProjectView.Select(FolderNodeFromName(s));
@@ -651,8 +688,13 @@ PProjectUnit Project::addUnit(const QString &inFileName, PFolderNode parentNode,
newUnit->setPriority(1000);
newUnit->setOverrideBuildCmd(false);
newUnit->setBuildCmd("");
- if (rebuild)
+ if (rebuild) {
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
rebuildNodes();
+ }
setModified(true);
return newUnit;
}
@@ -1258,9 +1300,26 @@ PCppParser Project::cppParser()
void Project::sortUnitsByPriority()
{
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
std::sort(mUnits.begin(),mUnits.end(),[](const PProjectUnit& u1, const PProjectUnit& u2)->bool{
return (u1->priority()>u2->priority());
});
+ rebuildNodes();
+}
+
+void Project::sortUnitsByAlpha()
+{
+ mModel.beginUpdate();
+ auto action = finally([this]{
+ mModel.endUpdate();
+ });
+ std::sort(mUnits.begin(),mUnits.end(),[](const PProjectUnit& u1, const PProjectUnit& u2)->bool{
+ return (extractFileName(u1->fileName())fileName()));
+ });
+ rebuildNodes();
}
int Project::indexInUnits(const QString &fileName) const
@@ -1306,6 +1365,17 @@ void Project::removeFolderRecurse(PFolderNode node)
}
}
+void Project::updateFolderNode(PFolderNode node)
+{
+ for (int i=0;ichildren.count();i++){
+ PFolderNode child;
+ if (child->unitIndex<0) {
+ mFolders.append(getFolderPath(child));
+ updateFolderNode(child);
+ }
+ }
+}
+
const ProjectOptions &Project::options() const
{
return mOptions;
@@ -1468,16 +1538,6 @@ void ProjectUnit::setPriority(int newPriority)
mPriority = newPriority;
}
-bool ProjectUnit::detectEncoding() const
-{
- return mDetectEncoding;
-}
-
-void ProjectUnit::setDetectEncoding(bool newDetectEncoding)
-{
- mDetectEncoding = newDetectEncoding;
-}
-
const QByteArray &ProjectUnit::encoding() const
{
return mEncoding;
@@ -1539,3 +1599,56 @@ void ProjectUnit::setNode(const PFolderNode &newNode)
{
mNode = newNode;
}
+
+ProjectModel::ProjectModel(Project *project, QObject *parent):
+ QAbstractItemModel(parent),
+ mProject(project)
+{
+ mUpdateCount = 0;
+}
+
+void ProjectModel::beginUpdate()
+{
+ if (mUpdateCount==0)
+ beginResetModel();
+ mUpdateCount++;
+}
+
+void ProjectModel::endUpdate()
+{
+ mUpdateCount--;
+ if (mUpdateCount==0)
+ endResetModel();
+}
+
+int ProjectModel::rowCount(const QModelIndex &parent) const
+{
+ if (!parent.isValid())
+ return 1;
+ FolderNode* p = static_cast(parent.internalPointer());
+ if (p) {
+ return p->children.count();
+ } else {
+ return mProject->node()->children.count();
+ }
+}
+
+int ProjectModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QVariant ProjectModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+ FolderNode* p = static_cast(index.internalPointer());
+ if (!p)
+ return QVariant();
+
+ return p->children.count();
+ } else {
+ return mProject->node()->children.count();
+ }
+
+}
diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h
index b40be457..4e5cc825 100644
--- a/RedPandaIDE/project.h
+++ b/RedPandaIDE/project.h
@@ -1,6 +1,7 @@
#ifndef PROJECT_H
#define PROJECT_H
+#include
#include
#include
#include
@@ -135,6 +136,25 @@ struct ProjectOptions{
QString encoding;
};
+class ProjectModel : public QAbstractItemModel {
+ Q_OBJECT
+public:
+ explicit ProjectModel(Project* project, QObject* parent=nullptr);
+ void beginUpdate();
+ void endUpdate();
+private:
+ Project* mProject;
+ int mUpdateCount;
+
+ // QAbstractItemModel interface
+public:
+ QModelIndex index(int row, int column, const QModelIndex &parent) const override;
+ QModelIndex parent(const QModelIndex &child) const override;
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+};
+
class Project : public QObject
{
Q_OBJECT
@@ -181,14 +201,13 @@ public:
void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions
bool saveUnits();
void setCompilerOption(const QString& optionString, const QChar& value);
-
-
+ void sortUnitsByPriority();
+ void sortUnitsByAlpha();
void updateFolders();
-
- void showOptions();
- // bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
void updateNodeIndexes();
- void setNodeValue(PFolderNode value);
+
+ //void showOptions();
+ // bool assignTemplate(const QString& aFileName, const PTemplate& aTemplate);
//void saveToLog();
std::shared_ptr cppParser();
@@ -211,10 +230,10 @@ signals:
void modifyChanged(bool value);
private:
void open();
- void sortUnitsByPriority();
int indexInUnits(const QString& fileName) const;
int indexInUnits(const Editor* editor) const;
void removeFolderRecurse(PFolderNode node);
+ void updateFolderNode(PFolderNode node);
private:
QList mUnits;
ProjectOptions mOptions;
@@ -226,6 +245,7 @@ private:
std::shared_ptr mParser;
QList mFolderNodes;
PFolderNode mNode;
+ ProjectModel mModel;
};
#endif // PROJECT_H
diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp
index 256a087d..3d2d2d20 100644
--- a/RedPandaIDE/utils.cpp
+++ b/RedPandaIDE/utils.cpp
@@ -160,6 +160,9 @@ QString excludeTrailingPathDelimiter(const QString &path)
FileType getFileType(const QString &filename)
{
+ if (filename.endsWith(".dev",PATH_SENSITIVITY)) {
+ return FileType::Project;
+ }
if (filename.endsWith(".c",PATH_SENSITIVITY)) {
return FileType::CSource;
}
@@ -689,3 +692,8 @@ QString extractAbsoluteFilePath(const QString &filePath)
QFileInfo info(filePath);
return info.absoluteFilePath();
}
+
+bool isReadOnly(const QString &filename)
+{
+ return QFile(filename).isWritable();
+}
diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h
index b61ed770..e74acfca 100644
--- a/RedPandaIDE/utils.h
+++ b/RedPandaIDE/utils.h
@@ -25,6 +25,7 @@ enum class FileType{
CHeader, // c header (.h)
CppHeader, // c++ header (.hpp)
WindowsResourceSource, // resource source (.res)
+ Project, //Red Panda Dev-C++ Project (.dev)
Other // any others
};
@@ -166,6 +167,7 @@ QString extractFileName(const QString& fileName);
QString extractFilePath(const QString& filePath);
QString extractAbsoluteFilePath(const QString& filePath);
QString getSizeString(int size);
+bool isReadOnly(const QString& filename);
int getNewFileNumber();