work save
This commit is contained in:
parent
166e045636
commit
668e42458e
|
@ -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)
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer);
|
||||
|
||||
void getVisibleEditors(Editor*& left, Editor*& right);
|
||||
void updateLayout();
|
||||
|
||||
void beginUpdate();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -898,15 +898,9 @@
|
|||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAll"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolbarCompilerSet">
|
||||
<widget class="QToolBar" name="toolbarCode">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar_2</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
|
@ -914,6 +908,10 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionBack"/>
|
||||
<addaction name="actionForward"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionReformat_Code"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolbarCompile">
|
||||
<property name="windowTitle">
|
||||
|
@ -961,9 +959,15 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="actionAdd_Watch"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolbarCode">
|
||||
<widget class="QToolBar" name="toolbarCompilerSet">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
<string>toolBar_2</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
|
@ -971,10 +975,6 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionBack"/>
|
||||
<addaction name="actionForward"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionReformat_Code"/>
|
||||
</widget>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
|
@ -1116,9 +1116,6 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+X</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
<property name="icon">
|
||||
|
@ -1132,9 +1129,6 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+C</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste">
|
||||
<property name="icon">
|
||||
|
@ -1148,9 +1142,6 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+V</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSelectAll">
|
||||
<property name="text">
|
||||
|
@ -1159,9 +1150,6 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+A</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionIndent">
|
||||
<property name="icon">
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
#include <QMessageBox>
|
||||
#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<QSettings>(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;idx<mUnits.count();idx++)
|
||||
mUnits[idx]->node()->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())<extractFileName(u2->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;i<node->children.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<FolderNode*>(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<FolderNode*>(index.internalPointer());
|
||||
if (!p)
|
||||
return QVariant();
|
||||
|
||||
return p->children.count();
|
||||
} else {
|
||||
return mProject->node()->children.count();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef PROJECT_H
|
||||
#define PROJECT_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <memory>
|
||||
|
@ -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> 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<PProjectUnit> mUnits;
|
||||
ProjectOptions mOptions;
|
||||
|
@ -226,6 +245,7 @@ private:
|
|||
std::shared_ptr<CppParser> mParser;
|
||||
QList<PFolderNode> mFolderNodes;
|
||||
PFolderNode mNode;
|
||||
ProjectModel mModel;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue