- 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
- enhancement: timeout for problem case test
- 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
- fix: only convert project icon file when it's filename doesn't end with ".ico"

View File

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

View File

@ -160,37 +160,37 @@ void Project::open()
newUnit->setFileName(
dir.absoluteFilePath(
fromByteArray(ini.GetValue(groupName,"FileName",""))));
if (!QFileInfo(newUnit->fileName()).exists()) {
QMessageBox::critical(nullptr,
tr("File Not Found"),
tr("Project file '%1' can't be found!")
.arg(newUnit->fileName()),
QMessageBox::Ok);
newUnit->setModified(true);
} else {
newUnit->setFolder(fromByteArray(ini.GetValue(groupName,"Folder","")));
newUnit->setCompile(ini.GetBoolValue(groupName,"Compile", true));
newUnit->setCompileCpp(
ini.GetBoolValue(groupName,"CompileCpp",mOptions.isCpp));
// if (!QFileInfo(newUnit->fileName()).exists()) {
// QMessageBox::critical(nullptr,
// tr("File Not Found"),
// tr("Project file '%1' can't be found!")
// .arg(newUnit->fileName()),
// QMessageBox::Ok);
// newUnit->setModified(true);
// } else {
newUnit->setFileMissing(!QFileInfo(newUnit->fileName()).exists());
newUnit->setFolder(fromByteArray(ini.GetValue(groupName,"Folder","")));
newUnit->setCompile(ini.GetBoolValue(groupName,"Compile", true));
newUnit->setCompileCpp(
ini.GetBoolValue(groupName,"CompileCpp",mOptions.isCpp));
newUnit->setLink(ini.GetBoolValue(groupName,"Link", true));
newUnit->setPriority(ini.GetLongValue(groupName,"Priority", 1000));
newUnit->setOverrideBuildCmd(ini.GetBoolValue(groupName,"OverrideBuildCmd", false));
newUnit->setBuildCmd(fromByteArray(ini.GetValue(groupName,"BuildCmd", "")));
QByteArray defaultEncoding = toByteArray(mOptions.encoding);
if (ini.GetBoolValue(groupName,"DetectEncoding",true)){
defaultEncoding = ENCODING_AUTO_DETECT;
}
newUnit->setEncoding(ini.GetValue(groupName, "FileEncoding",defaultEncoding));
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
newUnit->setEncoding(ENCODING_AUTO_DETECT);
}
newUnit->setNew(false);
newUnit->setParent(this);
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()), false, folderNodeFromName(newUnit->folder())));
newUnit->node()->unitIndex = mUnits.count();
mUnits.append(newUnit);
newUnit->setLink(ini.GetBoolValue(groupName,"Link", true));
newUnit->setPriority(ini.GetLongValue(groupName,"Priority", 1000));
newUnit->setOverrideBuildCmd(ini.GetBoolValue(groupName,"OverrideBuildCmd", false));
newUnit->setBuildCmd(fromByteArray(ini.GetValue(groupName,"BuildCmd", "")));
QByteArray defaultEncoding = toByteArray(mOptions.encoding);
if (ini.GetBoolValue(groupName,"DetectEncoding",true)){
defaultEncoding = ENCODING_AUTO_DETECT;
}
newUnit->setEncoding(ini.GetValue(groupName, "FileEncoding",defaultEncoding));
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
newUnit->setEncoding(ENCODING_AUTO_DETECT);
}
newUnit->setNew(false);
newUnit->setParent(this);
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()), false, folderNodeFromName(newUnit->folder())));
newUnit->node()->unitIndex = mUnits.count();
mUnits.append(newUnit);
}
rebuildNodes();
}
@ -296,9 +296,8 @@ Editor *Project::openUnit(int index)
PProjectUnit unit = mUnits[index];
if (!unit->fileName().isEmpty()) {
QString fullPath = unitFullPath(unit);
Editor * editor = mEditorList->getOpenedEditorByFilename(fullPath);
if (!unit->fileName().isEmpty() && fileExists(unit->fileName())) {
Editor * editor = mEditorList->getOpenedEditorByFilename(unit->fileName());
if (editor) {//already opened in the editors
editor->setInProject(true);
editor->activate();
@ -306,36 +305,26 @@ Editor *Project::openUnit(int index)
}
QByteArray encoding;
encoding = unit->encoding();
editor = mEditorList->newEditor(fullPath, encoding, true, unit->isNew());
editor->setInProject(true);
//unit->setEncoding(encoding);
editor->activate();
loadUnitLayout(editor,index);
return editor;
editor = mEditorList->newEditor(unit->fileName(), encoding, true, unit->isNew());
if (editor) {
editor->setInProject(true);
//unit->setEncoding(encoding);
editor->activate();
loadUnitLayout(editor,index);
return editor;
}
}
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
{
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit));
return mEditorList->getOpenedEditorByFilename(unit->fileName());
}
Editor *Project::unitEditor(const ProjectUnit *unit) const
{
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit));
return mEditorList->getOpenedEditorByFilename(unit->fileName());
}
void Project::rebuildNodes()
@ -570,21 +559,23 @@ bool Project::saveUnits()
return false;
for (int idx = 0; idx < mUnits.count(); idx++) {
PProjectUnit unit = mUnits[idx];
bool rd_only = false;
QByteArray groupName = toByteArray(QString("Unit%1").arg(count+1));
if (unit->modified() && fileExists(unit->fileName())
&& isReadOnly(unit->fileName())) {
// file is read-only
QMessageBox::critical(nullptr,
tr("Can't save file"),
tr("Can't save file '%1'").arg(unit->fileName()),
QMessageBox::Ok
);
rd_only = true;
}
if (!rd_only) {
if (!unit->save() && unit->isNew())
return false;
if (!unit->FileMissing()) {
bool rd_only = false;
if (unit->modified() && fileExists(unit->fileName())
&& isReadOnly(unit->fileName())) {
// file is read-only
QMessageBox::critical(nullptr,
tr("Can't save file"),
tr("Can't save file '%1'").arg(unit->fileName()),
QMessageBox::Ok
);
rd_only = true;
}
if (!rd_only) {
if (!unit->save() && unit->isNew())
return false;
}
}
// saved new file or an existing file add to project file
@ -758,7 +749,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
}
Editor * editor = mEditorList->newEditor(
unitFullPath(unit),
unit->fileName(),
unit->encoding(),
true,
true);
@ -1458,7 +1449,8 @@ void Project::loadLayout()
}
if (topLeft>=0 && topLeft<mUnits.count()) {
Editor * editor = unitEditor(mUnits[topLeft]);
editor->activate();
if (editor)
editor->activate();
}
}
@ -1746,6 +1738,7 @@ ProjectUnit::ProjectUnit(Project* parent)
{
mNode = nullptr;
mParent = parent;
mFileMissing = false;
}
Project *ProjectUnit::parent() const
@ -1929,6 +1922,16 @@ void ProjectUnit::setNode(const PProjectModelNode &newNode)
mNode = newNode;
}
bool ProjectUnit::FileMissing() const
{
return mFileMissing;
}
void ProjectUnit::setFileMissing(bool newDontSave)
{
mFileMissing = newDontSave;
}
ProjectModel::ProjectModel(Project *project, QObject *parent):
QAbstractItemModel(parent),
mProject(project)

View File

@ -83,6 +83,9 @@ public:
PProjectModelNode &node();
void setNode(const PProjectModelNode &newNode);
bool FileMissing() const;
void setFileMissing(bool newDontSave);
private:
Project* mParent;
QString mFileName;
@ -96,6 +99,7 @@ private:
int mPriority;
QByteArray mEncoding;
PProjectModelNode mNode;
bool mFileMissing;
};
using PProjectUnit = std::shared_ptr<ProjectUnit>;
@ -183,8 +187,6 @@ public:
PProjectUnit newUnit(PProjectModelNode parentNode,
const QString& customFileName="");
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 ProjectUnit* unit) 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");
#endif
mCaseEditorFontSize = intValue("case_editor_font_size",12);
mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",false);
mCaseTimeout = intValue("case_timeout", 1);
mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true);
mCaseTimeout = intValue("case_timeout", 3);
mEnableCaseTimeout = boolValue("enable_case_timeout", true);
}