- fix: project files that lies in project include folder is wrongly openned in Read-only mode
This commit is contained in:
parent
e22f3f0684
commit
c1b414d10a
5
NEWS.md
5
NEWS.md
|
@ -1,3 +1,8 @@
|
||||||
|
Red Panda C++ Version 1.5
|
||||||
|
|
||||||
|
- fix: project files that lies in project include folder is wrongly openned in Read-only mode
|
||||||
|
|
||||||
|
|
||||||
Red Panda C++ Version 1.4
|
Red Panda C++ Version 1.4
|
||||||
|
|
||||||
- fix: "Encode in UTF-8" is not correctly checked, when the editor is openned using UTF-8 encoding.
|
- fix: "Encode in UTF-8" is not correctly checked, when the editor is openned using UTF-8 encoding.
|
||||||
|
|
|
@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmpty(APP_VERSION) {
|
isEmpty(APP_VERSION) {
|
||||||
APP_VERSION=1.4
|
APP_VERSION=1.5
|
||||||
}
|
}
|
||||||
|
|
||||||
macos: {
|
macos: {
|
||||||
|
|
|
@ -125,8 +125,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
initParser();
|
initParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSettings->editor().readOnlySytemHeader()
|
if (shouldOpenInReadonly()) {
|
||||||
&& mParser && (mParser->isSystemHeaderFile(mFilename) || mParser->isProjectHeaderFile(mFilename))) {
|
|
||||||
this->setModified(false);
|
this->setModified(false);
|
||||||
setReadOnly(true);
|
setReadOnly(true);
|
||||||
}
|
}
|
||||||
|
@ -394,8 +393,7 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
reparseTodo();
|
reparseTodo();
|
||||||
|
|
||||||
|
|
||||||
if (pSettings->editor().readOnlySytemHeader()
|
if (!shouldOpenInReadonly()) {
|
||||||
&& (!mParser->isSystemHeaderFile(mFilename) && !mParser->isProjectHeaderFile(mFilename))) {
|
|
||||||
setReadOnly(false);
|
setReadOnly(false);
|
||||||
updateCaption();
|
updateCaption();
|
||||||
}
|
}
|
||||||
|
@ -1740,6 +1738,14 @@ bool Editor::isBraceChar(QChar ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Editor::shouldOpenInReadonly()
|
||||||
|
{
|
||||||
|
if (pMainWindow->project() && pMainWindow->project()->findUnitByFilename(mFilename))
|
||||||
|
return false;
|
||||||
|
return pSettings->editor().readOnlySytemHeader()
|
||||||
|
&& mParser && (mParser->isSystemHeaderFile(mFilename) || mParser->isProjectHeaderFile(mFilename));
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::resetBookmarks()
|
void Editor::resetBookmarks()
|
||||||
{
|
{
|
||||||
mBookmarkLines=pMainWindow->bookmarkModel()->bookmarksInFile(mFilename);
|
mBookmarkLines=pMainWindow->bookmarkModel()->bookmarksInFile(mFilename);
|
||||||
|
|
|
@ -239,6 +239,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isBraceChar(QChar ch);
|
bool isBraceChar(QChar ch);
|
||||||
|
bool shouldOpenInReadonly();
|
||||||
void resetBookmarks();
|
void resetBookmarks();
|
||||||
QChar getCurrentChar();
|
QChar getCurrentChar();
|
||||||
bool handleSymbolCompletion(QChar key);
|
bool handleSymbolCompletion(QChar key);
|
||||||
|
|
|
@ -6155,7 +6155,7 @@ void MainWindow::newProjectUnitFile()
|
||||||
PProjectUnit newUnit;
|
PProjectUnit newUnit;
|
||||||
if (mProject->modelType() == ProjectModelType::FileSystem) {
|
if (mProject->modelType() == ProjectModelType::FileSystem) {
|
||||||
PProjectModelNode modelTypeNode = pNode;
|
PProjectModelNode modelTypeNode = pNode;
|
||||||
while (modelTypeNode && modelTypeNode->folderNodeType==ProjectSpecialFolderNode::NonSpecial) {
|
while (modelTypeNode && modelTypeNode->folderNodeType==ProjectModelNodeType::Folder) {
|
||||||
modelTypeNode=modelTypeNode->parent.lock();
|
modelTypeNode=modelTypeNode->parent.lock();
|
||||||
}
|
}
|
||||||
if (!modelTypeNode) {
|
if (!modelTypeNode) {
|
||||||
|
@ -6169,10 +6169,10 @@ void MainWindow::newProjectUnitFile()
|
||||||
newProjectUnitDialog.setSuffix("c");
|
newProjectUnitDialog.setSuffix("c");
|
||||||
} else {
|
} else {
|
||||||
switch (modelTypeNode->folderNodeType) {
|
switch (modelTypeNode->folderNodeType) {
|
||||||
case ProjectSpecialFolderNode::HEADERS:
|
case ProjectModelNodeType::DUMMY_HEADERS_FOLDER:
|
||||||
newProjectUnitDialog.setSuffix("h");
|
newProjectUnitDialog.setSuffix("h");
|
||||||
break;
|
break;
|
||||||
case ProjectSpecialFolderNode::SOURCES:
|
case ProjectModelNodeType::DUMMY_SOURCES_FOLDER:
|
||||||
if (mProject->options().isCpp)
|
if (mProject->options().isCpp)
|
||||||
newProjectUnitDialog.setSuffix("cpp");
|
newProjectUnitDialog.setSuffix("cpp");
|
||||||
else
|
else
|
||||||
|
|
|
@ -230,9 +230,9 @@ PProjectModelNode Project::makeNewFileNode(const QString &s, bool isFolder, PPro
|
||||||
if (isFolder) {
|
if (isFolder) {
|
||||||
node->unitIndex = -1;
|
node->unitIndex = -1;
|
||||||
node->priority = 0;
|
node->priority = 0;
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::NonSpecial;
|
node->folderNodeType = ProjectModelNodeType::Folder;
|
||||||
} else {
|
} else {
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::NotFolder;
|
node->folderNodeType = ProjectModelNodeType::File;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ PProjectModelNode Project::makeProjectNode()
|
||||||
node->text = mName;
|
node->text = mName;
|
||||||
node->level = 0;
|
node->level = 0;
|
||||||
node->unitIndex = -1;
|
node->unitIndex = -1;
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::NonSpecial;
|
node->folderNodeType = ProjectModelNodeType::Folder;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,29 +1499,29 @@ void Project::createFileSystemFolderNodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PProjectModelNode node = makeNewFileNode(tr("Headers"),true,mRootNode);
|
PProjectModelNode node = makeNewFileNode(tr("Headers"),true,mRootNode);
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::HEADERS;
|
node->folderNodeType = ProjectModelNodeType::DUMMY_HEADERS_FOLDER;
|
||||||
node->priority = 1000;
|
node->priority = 1000;
|
||||||
createFileSystemFolderNode(ProjectSpecialFolderNode::HEADERS,folder(),node, headerFolders);
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_HEADERS_FOLDER,folder(),node, headerFolders);
|
||||||
mFolderNodes.append(node);
|
mFolderNodes.append(node);
|
||||||
mSpecialNodes.insert(ProjectSpecialFolderNode::HEADERS,node);
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_HEADERS_FOLDER,node);
|
||||||
|
|
||||||
node = makeNewFileNode(tr("Sources"),true,mRootNode);
|
node = makeNewFileNode(tr("Sources"),true,mRootNode);
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::SOURCES;
|
node->folderNodeType = ProjectModelNodeType::DUMMY_SOURCES_FOLDER;
|
||||||
node->priority = 900;
|
node->priority = 900;
|
||||||
createFileSystemFolderNode(ProjectSpecialFolderNode::SOURCES,folder(),node, sourceFolders);
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_SOURCES_FOLDER,folder(),node, sourceFolders);
|
||||||
mFolderNodes.append(node);
|
mFolderNodes.append(node);
|
||||||
mSpecialNodes.insert(ProjectSpecialFolderNode::SOURCES,node);
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_SOURCES_FOLDER,node);
|
||||||
|
|
||||||
node = makeNewFileNode(tr("Others"),true,mRootNode);
|
node = makeNewFileNode(tr("Others"),true,mRootNode);
|
||||||
node->folderNodeType = ProjectSpecialFolderNode::OTHERS;
|
node->folderNodeType = ProjectModelNodeType::DUMMY_OTHERS_FOLDER;
|
||||||
node->priority = 800;
|
node->priority = 800;
|
||||||
createFileSystemFolderNode(ProjectSpecialFolderNode::OTHERS,folder(),node, otherFolders);
|
createFileSystemFolderNode(ProjectModelNodeType::DUMMY_OTHERS_FOLDER,folder(),node, otherFolders);
|
||||||
mFolderNodes.append(node);
|
mFolderNodes.append(node);
|
||||||
mSpecialNodes.insert(ProjectSpecialFolderNode::OTHERS,node);
|
mSpecialNodes.insert(ProjectModelNodeType::DUMMY_OTHERS_FOLDER,node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::createFileSystemFolderNode(
|
void Project::createFileSystemFolderNode(
|
||||||
ProjectSpecialFolderNode folderType,
|
ProjectModelNodeType folderType,
|
||||||
const QString &folderName,
|
const QString &folderName,
|
||||||
PProjectModelNode parent,
|
PProjectModelNode parent,
|
||||||
const QSet<QString>& validFolders)
|
const QSet<QString>& validFolders)
|
||||||
|
@ -1554,7 +1554,7 @@ bool Project::fileAlreadyExists(const QString &s)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PProjectModelNode Project::findFolderNode(const QString &folderPath, ProjectSpecialFolderNode nodeType)
|
PProjectModelNode Project::findFolderNode(const QString &folderPath, ProjectModelNodeType nodeType)
|
||||||
{
|
{
|
||||||
PProjectModelNode node = mFileSystemFolderNodes.value(QString("%1/%2").arg((int)nodeType).arg(folderPath),
|
PProjectModelNode node = mFileSystemFolderNodes.value(QString("%1/%2").arg((int)nodeType).arg(folderPath),
|
||||||
PProjectModelNode());
|
PProjectModelNode());
|
||||||
|
@ -1603,13 +1603,13 @@ int Project::getUnitFromString(const QString &s)
|
||||||
PProjectModelNode Project::getParentFolderNode(const QString &filename)
|
PProjectModelNode Project::getParentFolderNode(const QString &filename)
|
||||||
{
|
{
|
||||||
QFileInfo fileInfo(filename);
|
QFileInfo fileInfo(filename);
|
||||||
ProjectSpecialFolderNode folderNodeType;
|
ProjectModelNodeType folderNodeType;
|
||||||
if (isHFile(fileInfo.fileName())) {
|
if (isHFile(fileInfo.fileName())) {
|
||||||
folderNodeType = ProjectSpecialFolderNode::HEADERS;
|
folderNodeType = ProjectModelNodeType::DUMMY_HEADERS_FOLDER;
|
||||||
} else if (isCFile(fileInfo.fileName())) {
|
} else if (isCFile(fileInfo.fileName())) {
|
||||||
folderNodeType = ProjectSpecialFolderNode::SOURCES;
|
folderNodeType = ProjectModelNodeType::DUMMY_SOURCES_FOLDER;
|
||||||
} else {
|
} else {
|
||||||
folderNodeType = ProjectSpecialFolderNode::OTHERS;
|
folderNodeType = ProjectModelNodeType::DUMMY_OTHERS_FOLDER;
|
||||||
}
|
}
|
||||||
return findFolderNode(fileInfo.absolutePath(),folderNodeType);
|
return findFolderNode(fileInfo.absolutePath(),folderNodeType);
|
||||||
}
|
}
|
||||||
|
@ -1996,7 +1996,7 @@ QString Project::fileSystemNodeFolderPath(const PProjectModelNode &node)
|
||||||
QString result;
|
QString result;
|
||||||
if (node != mRootNode) {
|
if (node != mRootNode) {
|
||||||
PProjectModelNode pNode = node;
|
PProjectModelNode pNode = node;
|
||||||
while (pNode && pNode->folderNodeType == ProjectSpecialFolderNode::NonSpecial) {
|
while (pNode && pNode->folderNodeType == ProjectModelNodeType::Folder) {
|
||||||
result = node->text + "/" +result;
|
result = node->text + "/" +result;
|
||||||
pNode = pNode->parent.lock();
|
pNode = pNode->parent.lock();
|
||||||
}
|
}
|
||||||
|
@ -2378,10 +2378,10 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
||||||
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT);
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT);
|
||||||
} else {
|
} else {
|
||||||
switch(p->folderNodeType) {
|
switch(p->folderNodeType) {
|
||||||
case ProjectSpecialFolderNode::HEADERS:
|
case ProjectModelNodeType::DUMMY_HEADERS_FOLDER:
|
||||||
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HEADERS_FOLDER);
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_HEADERS_FOLDER);
|
||||||
break;
|
break;
|
||||||
case ProjectSpecialFolderNode::SOURCES:
|
case ProjectModelNodeType::DUMMY_SOURCES_FOLDER:
|
||||||
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_SOURCES_FOLDER);
|
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_SOURCES_FOLDER);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -2526,6 +2526,23 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex ProjectModel::getNodeIndex(ProjectModelNode *node) const
|
||||||
|
{
|
||||||
|
PProjectModelNode parent = node->parent.lock();
|
||||||
|
if (!parent) // root node
|
||||||
|
return QModelIndex();
|
||||||
|
int row = -1;
|
||||||
|
for (int i=0;i<parent->children.count();i++) {
|
||||||
|
const PProjectModelNode& pNode=parent->children[i];
|
||||||
|
if (pNode.get()==node) {
|
||||||
|
row = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (row<0)
|
||||||
|
return QModelIndex();
|
||||||
|
return createIndex(row,0,node);
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex ProjectModel::getParentIndex(ProjectModelNode * node) const
|
QModelIndex ProjectModel::getParentIndex(ProjectModelNode * node) const
|
||||||
{
|
{
|
||||||
PProjectModelNode parent = node->parent.lock();
|
PProjectModelNode parent = node->parent.lock();
|
||||||
|
|
|
@ -29,13 +29,12 @@ class CppParser;
|
||||||
class EditorList;
|
class EditorList;
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
|
enum ProjectModelNodeType {
|
||||||
enum ProjectSpecialFolderNode {
|
DUMMY_HEADERS_FOLDER,
|
||||||
HEADERS,
|
DUMMY_SOURCES_FOLDER,
|
||||||
SOURCES,
|
DUMMY_OTHERS_FOLDER,
|
||||||
OTHERS,
|
Folder,
|
||||||
NonSpecial,
|
File
|
||||||
NotFolder
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProjectModelNode;
|
struct ProjectModelNode;
|
||||||
|
@ -46,7 +45,7 @@ struct ProjectModelNode {
|
||||||
int unitIndex;
|
int unitIndex;
|
||||||
int priority;
|
int priority;
|
||||||
QList<PProjectModelNode> children;
|
QList<PProjectModelNode> children;
|
||||||
ProjectSpecialFolderNode folderNodeType;
|
ProjectModelNodeType folderNodeType;
|
||||||
int level;
|
int level;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -129,8 +128,11 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
|
||||||
|
QModelIndex getNodeIndex(ProjectModelNode *node) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QModelIndex getParentIndex(ProjectModelNode * node) const;
|
QModelIndex getParentIndex(ProjectModelNode * node) const;
|
||||||
|
|
||||||
// QAbstractItemModel interface
|
// QAbstractItemModel interface
|
||||||
public:
|
public:
|
||||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||||
|
@ -253,9 +255,9 @@ private:
|
||||||
void checkProjectFileForUpdate(SimpleIni& ini);
|
void checkProjectFileForUpdate(SimpleIni& ini);
|
||||||
void createFolderNodes();
|
void createFolderNodes();
|
||||||
void createFileSystemFolderNodes();
|
void createFileSystemFolderNodes();
|
||||||
void createFileSystemFolderNode(ProjectSpecialFolderNode folderType, const QString& folderName, PProjectModelNode parent, const QSet<QString>& validFolders);
|
void createFileSystemFolderNode(ProjectModelNodeType folderType, const QString& folderName, PProjectModelNode parent, const QSet<QString>& validFolders);
|
||||||
PProjectModelNode getParentFolderNode(const QString& filename);
|
PProjectModelNode getParentFolderNode(const QString& filename);
|
||||||
PProjectModelNode findFolderNode(const QString& folderPath, ProjectSpecialFolderNode nodeType);
|
PProjectModelNode findFolderNode(const QString& folderPath, ProjectModelNodeType nodeType);
|
||||||
PProjectModelNode folderNodeFromName(const QString& name);
|
PProjectModelNode folderNodeFromName(const QString& name);
|
||||||
void loadOptions(SimpleIni& ini);
|
void loadOptions(SimpleIni& ini);
|
||||||
void loadLayout(); // load all [UnitX]
|
void loadLayout(); // load all [UnitX]
|
||||||
|
@ -279,7 +281,7 @@ private:
|
||||||
std::shared_ptr<CppParser> mParser;
|
std::shared_ptr<CppParser> mParser;
|
||||||
QList<PProjectModelNode> mFolderNodes;
|
QList<PProjectModelNode> mFolderNodes;
|
||||||
PProjectModelNode mRootNode;
|
PProjectModelNode mRootNode;
|
||||||
QHash<ProjectSpecialFolderNode, PProjectModelNode> mSpecialNodes;
|
QHash<ProjectModelNodeType, PProjectModelNode> mSpecialNodes;
|
||||||
QHash<QString, PProjectModelNode> mFileSystemFolderNodes;
|
QHash<QString, PProjectModelNode> mFileSystemFolderNodes;
|
||||||
ProjectModel mModel;
|
ProjectModel mModel;
|
||||||
EditorList *mEditorList;
|
EditorList *mEditorList;
|
||||||
|
|
|
@ -33,7 +33,7 @@ RedPandaIDE.depends += redpanda-git-askpass
|
||||||
|
|
||||||
APP_NAME = RedPandaCPP
|
APP_NAME = RedPandaCPP
|
||||||
|
|
||||||
APP_VERSION = 1.4
|
APP_VERSION = 1.5
|
||||||
|
|
||||||
linux: {
|
linux: {
|
||||||
isEmpty(PREFIX) {
|
isEmpty(PREFIX) {
|
||||||
|
|
|
@ -649,3 +649,10 @@ void decodeKey(const int combinedKey, int &key, Qt::KeyboardModifiers &modifiers
|
||||||
}
|
}
|
||||||
key = combinedKey & ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier);
|
key = combinedKey & ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isInFolder(const QString &folderpath, const QString &filepath)
|
||||||
|
{
|
||||||
|
QDir folder(folderpath);
|
||||||
|
QFileInfo fileInfo(filepath);
|
||||||
|
return fileInfo.absoluteFilePath().startsWith(includeTrailingPathDelimiter(folder.absolutePath()));
|
||||||
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ bool directoryExists(const QString& file);
|
||||||
bool removeFile(const QString& filename);
|
bool removeFile(const QString& filename);
|
||||||
void copyFolder(const QString &fromDir, const QString& toDir);
|
void copyFolder(const QString &fromDir, const QString& toDir);
|
||||||
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
|
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
|
||||||
|
bool isInFolder(const QString& folderpath, const QString& filepath);
|
||||||
|
|
||||||
QString includeTrailingPathDelimiter(const QString& path);
|
QString includeTrailingPathDelimiter(const QString& path);
|
||||||
QString excludeTrailingPathDelimiter(const QString& path);
|
QString excludeTrailingPathDelimiter(const QString& path);
|
||||||
|
|
Loading…
Reference in New Issue