- enhancement: use icon to indicate missing project files in the project view

This commit is contained in:
Roy Qu 2022-03-28 16:57:58 +08:00
parent 7e0e9873f6
commit a40c818e54
5 changed files with 81 additions and 73 deletions

View File

@ -7,6 +7,7 @@ Red Panda C++ Version 1.0.2
- fix: auto syntax check use wrong charset, if a file in editing is not encoded with ANSI encoding - fix: auto syntax check use wrong charset, if a file in editing is not encoded with ANSI encoding
- enhancement: timeout for problem case test - enhancement: timeout for problem case test
- enhancement: slightly reduce start up time - enhancement: slightly reduce start up time
- enhancement: use icon to indicate missing project files in the project view
Red Panda C++ Version 1.0.1 Red Panda C++ Version 1.0.1
- fix: only convert project icon file when it's filename doesn't end with ".ico" - fix: only convert project icon file when it's filename doesn't end with ".ico"

View File

@ -53,6 +53,8 @@ QIcon CustomFileIconProvider::icon(const QFileInfo &info) const
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE); icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER_VCS_NOCHANGE);
} else } else
icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER); icon = pIconsManager->getIcon(IconsManager::FILESYSTEM_FOLDER);
} else if (!info.exists()) {
icon = pIconsManager->getIcon(IconsManager::ACTION_MISC_CROSS);
} else if (isHFile(info.fileName())) { } else if (isHFile(info.fileName())) {
if (mVCSRepository->isFileInRepository(info)) { if (mVCSRepository->isFileInRepository(info)) {
if (mVCSRepository->isFileConflicting(info)) if (mVCSRepository->isFileConflicting(info))

View File

@ -160,14 +160,15 @@ void Project::open()
newUnit->setFileName( newUnit->setFileName(
dir.absoluteFilePath( dir.absoluteFilePath(
fromByteArray(ini.GetValue(groupName,"FileName","")))); fromByteArray(ini.GetValue(groupName,"FileName",""))));
if (!QFileInfo(newUnit->fileName()).exists()) { // if (!QFileInfo(newUnit->fileName()).exists()) {
QMessageBox::critical(nullptr, // QMessageBox::critical(nullptr,
tr("File Not Found"), // tr("File Not Found"),
tr("Project file '%1' can't be found!") // tr("Project file '%1' can't be found!")
.arg(newUnit->fileName()), // .arg(newUnit->fileName()),
QMessageBox::Ok); // QMessageBox::Ok);
newUnit->setModified(true); // newUnit->setModified(true);
} else { // } else {
newUnit->setFileMissing(!QFileInfo(newUnit->fileName()).exists());
newUnit->setFolder(fromByteArray(ini.GetValue(groupName,"Folder",""))); newUnit->setFolder(fromByteArray(ini.GetValue(groupName,"Folder","")));
newUnit->setCompile(ini.GetBoolValue(groupName,"Compile", true)); newUnit->setCompile(ini.GetBoolValue(groupName,"Compile", true));
newUnit->setCompileCpp( newUnit->setCompileCpp(
@ -191,7 +192,6 @@ void Project::open()
newUnit->node()->unitIndex = mUnits.count(); newUnit->node()->unitIndex = mUnits.count();
mUnits.append(newUnit); mUnits.append(newUnit);
} }
}
rebuildNodes(); rebuildNodes();
} }
@ -296,9 +296,8 @@ Editor *Project::openUnit(int index)
PProjectUnit unit = mUnits[index]; PProjectUnit unit = mUnits[index];
if (!unit->fileName().isEmpty()) { if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
QString fullPath = unitFullPath(unit); Editor * editor = mEditorList->getOpenedEditorByFilename(unit->fileName());
Editor * editor = mEditorList->getOpenedEditorByFilename(fullPath);
if (editor) {//already opened in the editors if (editor) {//already opened in the editors
editor->setInProject(true); editor->setInProject(true);
editor->activate(); editor->activate();
@ -306,36 +305,26 @@ Editor *Project::openUnit(int index)
} }
QByteArray encoding; QByteArray encoding;
encoding = unit->encoding(); encoding = unit->encoding();
editor = mEditorList->newEditor(fullPath, encoding, true, unit->isNew()); editor = mEditorList->newEditor(unit->fileName(), encoding, true, unit->isNew());
if (editor) {
editor->setInProject(true); editor->setInProject(true);
//unit->setEncoding(encoding); //unit->setEncoding(encoding);
editor->activate(); editor->activate();
loadUnitLayout(editor,index); loadUnitLayout(editor,index);
return editor; return editor;
} }
}
return nullptr; return nullptr;
} }
QString Project::unitFullPath(const PProjectUnit &unit) const
{
QDir dir(directory());
return dir.absoluteFilePath(unit->fileName());
}
QString Project::unitFullPath(const ProjectUnit *unit) const
{
QDir dir(directory());
return dir.absoluteFilePath(unit->fileName());
}
Editor *Project::unitEditor(const PProjectUnit &unit) const Editor *Project::unitEditor(const PProjectUnit &unit) const
{ {
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit)); return mEditorList->getOpenedEditorByFilename(unit->fileName());
} }
Editor *Project::unitEditor(const ProjectUnit *unit) const Editor *Project::unitEditor(const ProjectUnit *unit) const
{ {
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit)); return mEditorList->getOpenedEditorByFilename(unit->fileName());
} }
void Project::rebuildNodes() void Project::rebuildNodes()
@ -570,8 +559,9 @@ bool Project::saveUnits()
return false; return false;
for (int idx = 0; idx < mUnits.count(); idx++) { for (int idx = 0; idx < mUnits.count(); idx++) {
PProjectUnit unit = mUnits[idx]; PProjectUnit unit = mUnits[idx];
bool rd_only = false;
QByteArray groupName = toByteArray(QString("Unit%1").arg(count+1)); QByteArray groupName = toByteArray(QString("Unit%1").arg(count+1));
if (!unit->FileMissing()) {
bool rd_only = false;
if (unit->modified() && fileExists(unit->fileName()) if (unit->modified() && fileExists(unit->fileName())
&& isReadOnly(unit->fileName())) { && isReadOnly(unit->fileName())) {
// file is read-only // file is read-only
@ -586,6 +576,7 @@ bool Project::saveUnits()
if (!unit->save() && unit->isNew()) if (!unit->save() && unit->isNew())
return false; return false;
} }
}
// saved new file or an existing file add to project file // saved new file or an existing file add to project file
ini.SetValue( ini.SetValue(
@ -758,7 +749,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
} }
Editor * editor = mEditorList->newEditor( Editor * editor = mEditorList->newEditor(
unitFullPath(unit), unit->fileName(),
unit->encoding(), unit->encoding(),
true, true,
true); true);
@ -1458,6 +1449,7 @@ void Project::loadLayout()
} }
if (topLeft>=0 && topLeft<mUnits.count()) { if (topLeft>=0 && topLeft<mUnits.count()) {
Editor * editor = unitEditor(mUnits[topLeft]); Editor * editor = unitEditor(mUnits[topLeft]);
if (editor)
editor->activate(); editor->activate();
} }
} }
@ -1746,6 +1738,7 @@ ProjectUnit::ProjectUnit(Project* parent)
{ {
mNode = nullptr; mNode = nullptr;
mParent = parent; mParent = parent;
mFileMissing = false;
} }
Project *ProjectUnit::parent() const Project *ProjectUnit::parent() const
@ -1929,6 +1922,16 @@ void ProjectUnit::setNode(const PProjectModelNode &newNode)
mNode = newNode; mNode = newNode;
} }
bool ProjectUnit::FileMissing() const
{
return mFileMissing;
}
void ProjectUnit::setFileMissing(bool newDontSave)
{
mFileMissing = newDontSave;
}
ProjectModel::ProjectModel(Project *project, QObject *parent): ProjectModel::ProjectModel(Project *project, QObject *parent):
QAbstractItemModel(parent), QAbstractItemModel(parent),
mProject(project) mProject(project)

View File

@ -83,6 +83,9 @@ public:
PProjectModelNode &node(); PProjectModelNode &node();
void setNode(const PProjectModelNode &newNode); void setNode(const PProjectModelNode &newNode);
bool FileMissing() const;
void setFileMissing(bool newDontSave);
private: private:
Project* mParent; Project* mParent;
QString mFileName; QString mFileName;
@ -96,6 +99,7 @@ private:
int mPriority; int mPriority;
QByteArray mEncoding; QByteArray mEncoding;
PProjectModelNode mNode; PProjectModelNode mNode;
bool mFileMissing;
}; };
using PProjectUnit = std::shared_ptr<ProjectUnit>; using PProjectUnit = std::shared_ptr<ProjectUnit>;
@ -183,8 +187,6 @@ public:
PProjectUnit newUnit(PProjectModelNode parentNode, PProjectUnit newUnit(PProjectModelNode parentNode,
const QString& customFileName=""); const QString& customFileName="");
Editor* openUnit(int index); Editor* openUnit(int index);
QString unitFullPath(const PProjectUnit& unit) const;
QString unitFullPath(const ProjectUnit* unit) const;
Editor* unitEditor(const PProjectUnit& unit) const; Editor* unitEditor(const PProjectUnit& unit) const;
Editor* unitEditor(const ProjectUnit* unit) const; Editor* unitEditor(const ProjectUnit* unit) const;
Editor* unitEditor(int index) const { Editor* unitEditor(int index) const {

View File

@ -3334,8 +3334,8 @@ void Settings::Executor::doLoad()
mCaseEditorFontName = stringValue("case_editor_font_name","Dejavu Sans Mono"); mCaseEditorFontName = stringValue("case_editor_font_name","Dejavu Sans Mono");
#endif #endif
mCaseEditorFontSize = intValue("case_editor_font_size",12); mCaseEditorFontSize = intValue("case_editor_font_size",12);
mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",false); mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true);
mCaseTimeout = intValue("case_timeout", 1); mCaseTimeout = intValue("case_timeout", 3);
mEnableCaseTimeout = boolValue("enable_case_timeout", true); mEnableCaseTimeout = boolValue("enable_case_timeout", true);
} }