- enhancement: don't show folders that doesn't contain files in the project view

work save:  - enhancement: redesigned new project unit dialog
This commit is contained in:
Roy Qu 2022-04-08 17:22:24 +08:00
parent 01662a95d1
commit 2e0357e652
20 changed files with 403 additions and 50 deletions

View File

@ -10,6 +10,8 @@ Red Panda C++ Version 1.0.3
- fix: don't show tips in the editor, when selecting by mouse
- fix: auto syntax check doesn't work for new files
- change: don't auto jump to the first syntax error location when compile
- enhancement: don't show folders that doesn't contain files in the project view
- enhancement: redesigned new project unit dialog
Red Panda C++ Version 1.0.2
- enhancement: press tab in column mode won't exit column mode

View File

@ -175,6 +175,7 @@ SOURCES += \
widgets/newclassdialog.cpp \
widgets/newheaderdialog.cpp \
widgets/newprojectdialog.cpp \
widgets/newprojectunitdialog.cpp \
widgets/ojproblempropertywidget.cpp \
widgets/ojproblemsetmodel.cpp \
widgets/qconsole.cpp \
@ -321,6 +322,7 @@ HEADERS += \
widgets/newclassdialog.h \
widgets/newheaderdialog.h \
widgets/newprojectdialog.h \
widgets/newprojectunitdialog.h \
widgets/ojproblempropertywidget.h \
widgets/ojproblemsetmodel.h \
widgets/qconsole.h \
@ -384,6 +386,7 @@ FORMS += \
widgets/newclassdialog.ui \
widgets/newheaderdialog.ui \
widgets/newprojectdialog.ui \
widgets/newprojectunitdialog.ui \
widgets/ojproblempropertywidget.ui \
widgets/searchdialog.ui \
widgets/signalmessagedialog.ui

View File

@ -79,7 +79,8 @@
#include <QTextCodec>
#include "cpprefacter.h"
#include <widgets/searchdialog.h>
#include "widgets/newprojectunitdialog.h"
#include "widgets/searchdialog.h"
#ifdef Q_OS_WIN
#include <windows.h>
@ -5934,31 +5935,59 @@ void MainWindow::newProjectUnitFile()
if (current.isValid()) {
node = static_cast<ProjectModelNode*>(current.internalPointer());
}
QString newFileName;
do {
newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber());
if (mProject->options().isCpp) {
newFileName+=".cpp";
} else {
newFileName+=".c";
}
} while (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName)));
PProjectModelNode pNode = mProject->pointerToNode(node);
newFileName = QInputDialog::getText(
this,
tr("New Project File Name"),
tr("File Name:"),
QLineEdit::Normal,
newFileName);
if (newFileName.isEmpty())
return;
if (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))) {
QMessageBox::critical(this,tr("File Already Exists!"),
tr("File '%1' already exists!").arg(newFileName));
return;
while (pNode && pNode->unitIndex>0) {
pNode = pNode->parent.lock();
}
PProjectUnit newUnit = mProject->newUnit(
mProject->pointerToNode(node),newFileName);
if (!pNode) {
pNode = mProject->rootNode();
}
QString newFileName;
PProjectUnit newUnit;
if (mProject->modelType() == ProjectModelType::FileSystem) {
NewProjectUnitDialog newProjectUnitDialog;
QString folder = mProject->fileSystemNodeFolderPath(pNode);
newProjectUnitDialog.setFolder(folder);
switch (pNode->folderNodeType) {
case ProjectSpecialFolderNode::HEADERS:
newProjectUnitDialog.setSuffix("h");
break;
case ProjectSpecialFolderNode::SOURCES:
if (mProject->options().isCpp)
newProjectUnitDialog.setSuffix("cpp");
else
newProjectUnitDialog.setSuffix("c");
break;
default:
newProjectUnitDialog.setSuffix("");
}
if (newProjectUnitDialog.exec()!=QDialog::Accepted) {
return;
}
newFileName=newProjectUnitDialog.filename();
if (newFileName.isEmpty())
return;
} else {
newFileName = QInputDialog::getText(
this,
tr("New Project File Name"),
tr("File Name:"),
QLineEdit::Normal,
newFileName);
if (newFileName.isEmpty())
return;
if (fileExists(QDir(mProject->directory()).absoluteFilePath(newFileName))) {
QMessageBox::critical(this,tr("File Already Exists!"),
tr("File '%1' already exists!").arg(newFileName));
return;
}
}
newUnit = mProject->newUnit(
pNode,newFileName);
mProject->rebuildNodes();
mProject->saveAll();
updateProjectView();

View File

@ -370,6 +370,7 @@ void Project::rebuildNodes()
mUnits[idx]->node()->unitIndex = idx;
mUnits[idx]->node()->priority = mUnits[idx]->priority();
}
break;
}
@ -1290,31 +1291,58 @@ void Project::createFolderNodes()
}
}
static void addFolderRecursively(QSet<QString>& folders, QString folder) {
if (folder.isEmpty())
return;
folders.insert(excludeTrailingPathDelimiter(folder));
QString parentFolder = QFileInfo(folder).absolutePath();
if (parentFolder==folder)
return;
addFolderRecursively(folders, parentFolder);
}
void Project::createFileSystemFolderNodes()
{
QSet<QString> headerFolders;
QSet<QString> sourceFolders;
QSet<QString> otherFolders;
for (int idx=0;idx<mUnits.count();idx++) {
QFileInfo fileInfo(mUnits[idx]->fileName());
if (isHFile(fileInfo.fileName())) {
addFolderRecursively(headerFolders,fileInfo.absolutePath());
} else if (isCFile(fileInfo.fileName())) {
addFolderRecursively(sourceFolders,fileInfo.absolutePath());
} else {
addFolderRecursively(otherFolders,fileInfo.absolutePath());
}
}
PProjectModelNode node = makeNewFileNode(tr("Headers"),true,mRootNode);
node->folderNodeType = ProjectSpecialFolderNode::HEADERS;
node->priority = 1000;
createFileSystemFolderNode(ProjectSpecialFolderNode::HEADERS,folder(),node);
createFileSystemFolderNode(ProjectSpecialFolderNode::HEADERS,folder(),node, headerFolders);
mFolderNodes.append(node);
mSpecialNodes.insert(ProjectSpecialFolderNode::HEADERS,node);
node = makeNewFileNode(tr("Sources"),true,mRootNode);
node->folderNodeType = ProjectSpecialFolderNode::SOURCES;
node->priority = 900;
createFileSystemFolderNode(ProjectSpecialFolderNode::SOURCES,folder(),node);
createFileSystemFolderNode(ProjectSpecialFolderNode::SOURCES,folder(),node, sourceFolders);
mFolderNodes.append(node);
mSpecialNodes.insert(ProjectSpecialFolderNode::SOURCES,node);
node = makeNewFileNode(tr("Others"),true,mRootNode);
node->folderNodeType = ProjectSpecialFolderNode::OTHERS;
node->priority = 800;
createFileSystemFolderNode(ProjectSpecialFolderNode::OTHERS,folder(),node);
createFileSystemFolderNode(ProjectSpecialFolderNode::OTHERS,folder(),node, otherFolders);
mFolderNodes.append(node);
mSpecialNodes.insert(ProjectSpecialFolderNode::OTHERS,node);
}
void Project::createFileSystemFolderNode(ProjectSpecialFolderNode folderType, const QString &folderName, PProjectModelNode parent)
void Project::createFileSystemFolderNode(
ProjectSpecialFolderNode folderType,
const QString &folderName,
PProjectModelNode parent,
const QSet<QString>& validFolders)
{
QDirIterator iter(folderName);
while (iter.hasNext()) {
@ -1322,10 +1350,10 @@ void Project::createFileSystemFolderNode(ProjectSpecialFolderNode folderType, co
QFileInfo fileInfo = iter.fileInfo();
if (fileInfo.isHidden() || fileInfo.fileName().startsWith('.'))
continue;
if (fileInfo.isDir()) {
if (fileInfo.isDir() && validFolders.contains(fileInfo.absoluteFilePath())) {
PProjectModelNode node = makeNewFileNode(fileInfo.fileName(),true,parent);
mFileSystemFolderNodes.insert(QString("%1/%2").arg((int)folderType).arg(fileInfo.absoluteFilePath()),node);
createFileSystemFolderNode(folderType,fileInfo.absoluteFilePath(), node);
createFileSystemFolderNode(folderType,fileInfo.absoluteFilePath(), node, validFolders);
}
}
}

View File

@ -244,7 +244,7 @@ private:
void checkProjectFileForUpdate(SimpleIni& ini);
void createFolderNodes();
void createFileSystemFolderNodes();
void createFileSystemFolderNode(ProjectSpecialFolderNode folderType, const QString& folderName, PProjectModelNode parent);
void createFileSystemFolderNode(ProjectSpecialFolderNode folderType, const QString& folderName, PProjectModelNode parent, const QSet<QString>& validFolders);
PProjectModelNode getParentFolderNode(const QString& filename);
PProjectModelNode findFolderNode(const QString& folderPath, ProjectSpecialFolderNode nodeType);
PProjectModelNode folderNodeFromName(const QString& name);

View File

@ -33,8 +33,9 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &CompilerSetDirectoriesWidget::selectionChanged);
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
onUpdateIcons();
connect(pIconsManager, &IconsManager::actionIconsUpdated,
this, &CompilerSetDirectoriesWidget::updateIcons);
this, &CompilerSetDirectoriesWidget::onUpdateIcons);
}
CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget()
@ -103,7 +104,7 @@ void CompilerSetDirectoriesWidget::on_btnRemoveInvalid_pressed()
setDirList(lst);
}
void CompilerSetDirectoriesWidget::updateIcons()
void CompilerSetDirectoriesWidget::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnAdd,IconsManager::ACTION_MISC_ADD);
pIconsManager->setIcon(ui->btnDelete, IconsManager::ACTION_MISC_REMOVE);

View File

@ -50,7 +50,7 @@ private slots:
void on_btnRemoveInvalid_pressed();
void updateIcons();
void onUpdateIcons();
private:
Ui::CompilerSetDirectoriesWidget *ui;

View File

@ -15,7 +15,7 @@ GitRemoteDialog::GitRemoteDialog(const QString& folder, QWidget *parent) :
mRemotes = manager.listRemotes(folder);
ui->lstRemotes->addItems(mRemotes);
connect(pIconsManager, &IconsManager::actionIconsUpdated,
this, &GitRemoteDialog::updateIcons);
this, &GitRemoteDialog::onUpdateIcons);
ui->btnRemove->setEnabled(false);
ui->pnlProcess->setVisible(false);
ui->grpDetail->setEnabled(false);
@ -42,7 +42,7 @@ QString GitRemoteDialog::chooseRemote()
return "";
}
void GitRemoteDialog::updateIcons()
void GitRemoteDialog::onUpdateIcons()
{
ui->btnAdd->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_ADD));
ui->btnRemove->setIcon(pIconsManager->getIcon(IconsManager::ACTION_MISC_REMOVE));

View File

@ -17,7 +17,7 @@ public:
QString chooseRemote();
private slots:
void updateIcons();
void onUpdateIcons();
void onRemotesSelectionChanged();
void checkDetails();
void refresh();

View File

@ -68,9 +68,9 @@ CPUDialog::CPUDialog(QWidget *parent) :
sizes[1] = std::max(1,totalSize - sizes[0]);
ui->splitter->setSizes(sizes);
updateIcons();
onUpdateIcons();
connect(pIconsManager,&IconsManager::actionIconsUpdated,
this, &CPUDialog::updateIcons);
this, &CPUDialog::onUpdateIcons);
}
CPUDialog::~CPUDialog()
@ -192,7 +192,7 @@ void CPUDialog::on_btnStepIntoInstruction_clicked()
pMainWindow->debugger()->sendCommand("-exec-step-instruction","");
}
void CPUDialog::updateIcons()
void CPUDialog::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnStepIntoInstruction, IconsManager::ACTION_RUN_STEP_INTO_INSTRUCTION);
pIconsManager->setIcon(ui->btnStepOverInstruction, IconsManager::ACTION_RUN_STEP_OVER_INSTRUCTION);

View File

@ -51,7 +51,7 @@ private slots:
void on_chkBlendMode_stateChanged(int arg1);
void on_btnStepOverInstruction_clicked();
void on_btnStepIntoInstruction_clicked();
void updateIcons();
void onUpdateIcons();
};
#endif // CPUDIALOG_H

View File

@ -11,7 +11,9 @@ NewClassDialog::NewClassDialog(QWidget *parent) :
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
ui->setupUi(this);
resize(pSettings->ui().newClassDialogWidth(),pSettings->ui().newClassDialogHeight());
updateIcons();
onUpdateIcons();
connect(pIconsManager,&IconsManager::actionIconsUpdated,
this, &NewClassDialog::onUpdateIcons);
ui->txtClassName->setFocus();
}
@ -65,7 +67,7 @@ void NewClassDialog::on_btnCreate_clicked()
this->accept();
}
void NewClassDialog::updateIcons()
void NewClassDialog::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnBrowsePath, IconsManager::ACTION_FILE_OPEN_FOLDER);
}

View File

@ -35,7 +35,7 @@ private:
Ui::NewClassDialog *ui;
private:
void updateIcons();
void onUpdateIcons();
// QWidget interface
protected:

View File

@ -12,7 +12,9 @@ NewHeaderDialog::NewHeaderDialog(QWidget *parent) :
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
ui->setupUi(this);
resize(pSettings->ui().newHeaderDialogWidth(),pSettings->ui().newHeaderDialogHeight());
updateIcons();
onUpdateIcons();
connect(pIconsManager,&IconsManager::actionIconsUpdated,
this, &NewHeaderDialog::onUpdateIcons);
ui->txtHeader->setFocus();
}
@ -36,7 +38,7 @@ void NewHeaderDialog::setPath(const QString &location)
ui->txtPath->setText(location);
}
void NewHeaderDialog::updateIcons()
void NewHeaderDialog::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER);
}

View File

@ -22,7 +22,7 @@ private:
Ui::NewHeaderDialog *ui;
private:
void updateIcons();
void onUpdateIcons();
// QWidget interface
protected:

View File

@ -61,6 +61,10 @@ NewProjectDialog::NewProjectDialog(QWidget *parent) :
this,
&NewProjectDialog::updateProjectLocation);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
onUpdateIcons();
connect(pIconsManager,&IconsManager::actionIconsUpdated,
this, &NewProjectDialog::onUpdateIcons);
}
NewProjectDialog::~NewProjectDialog()
@ -242,7 +246,7 @@ void NewProjectDialog::on_btnBrowse_clicked()
}
QString dir = QFileDialog::getExistingDirectory(
this,
"Choose directory",
tr("Choose directory"),
dirPath
);
if (!dir.isEmpty()) {
@ -254,7 +258,7 @@ void NewProjectDialog::on_btnBrowse_clicked()
}
}
void NewProjectDialog::updateIcons()
void NewProjectDialog::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER);
}

View File

@ -47,7 +47,7 @@ private slots:
void on_lstTemplates_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
void on_btnBrowse_clicked();
void updateIcons();
void onUpdateIcons();
void on_btnOk_clicked();

View File

@ -0,0 +1,113 @@
#include "newprojectunitdialog.h"
#include "ui_newprojectunitdialog.h"
#include "../iconsmanager.h"
#include "../utils.h"
#include <QFileDialog>
NewProjectUnitDialog::NewProjectUnitDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewProjectUnitDialog),
mSuffix("cpp")
{
ui->setupUi(this);
onUpdateIcons();
connect(pIconsManager,&IconsManager::actionIconsUpdated,
this, &NewProjectUnitDialog::onUpdateIcons);
}
NewProjectUnitDialog::~NewProjectUnitDialog()
{
delete ui;
}
QString NewProjectUnitDialog::folder() const
{
return ui->txtFolder->text();
}
void NewProjectUnitDialog::setFolder(const QString &folderName)
{
if (folderName!=folder()) {
ui->txtFolder->setText(folderName);
QDir dir(folder());
if (dir.exists(filename()) || filename().isEmpty()) {
//todo change filename
QString newFileName;
QString ext;
if (filename().isEmpty()) {
ext = mSuffix;
} else {
ext = QFileInfo(filename()).suffix();
}
do {
newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber());
if (!ext.isEmpty())
newFileName += "." + ext;
} while (dir.exists(newFileName));
setFilename(newFileName);
}
}
}
void NewProjectUnitDialog::onUpdateIcons()
{
pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER);
}
void NewProjectUnitDialog::on_btnBrowse_clicked()
{
QString dir = QFileDialog::getExistingDirectory(
this,
tr("Choose directory"),
folder()
);
if (!dir.isEmpty()) {
setFolder(dir);
}
}
void NewProjectUnitDialog::on_btnOk_clicked()
{
accept();
}
void NewProjectUnitDialog::on_btnCancel_clicked()
{
reject();
}
void NewProjectUnitDialog::on_txtFilename_textChanged(const QString &/*arg1*/)
{
updateBtnOkStatus();
}
void NewProjectUnitDialog::updateBtnOkStatus()
{
ui->btnOk->setEnabled(!ui->txtFilename->text().isEmpty()
&& QFileInfo(ui->txtFolder->text()).isDir());
}
void NewProjectUnitDialog::closeEvent(QCloseEvent *event)
{
reject();
}
bool NewProjectUnitDialog::suffix() const
{
return mSuffix;
}
void NewProjectUnitDialog::setSuffix(bool newSuffix)
{
mSuffix = newSuffix;
}
void NewProjectUnitDialog::on_txtFolder_textChanged(const QString &/*arg1*/)
{
updateBtnOkStatus();
}

View File

@ -0,0 +1,50 @@
#ifndef NEWPROJECTUNITDIALOG_H
#define NEWPROJECTUNITDIALOG_H
#include <QDialog>
namespace Ui {
class NewProjectUnitDialog;
}
class NewProjectUnitDialog : public QDialog
{
Q_OBJECT
public:
explicit NewProjectUnitDialog(QWidget *parent = nullptr);
~NewProjectUnitDialog();
QString folder() const;
void setFolder(const QString& folderName);
QString filename() const;
void setFilename(const QString& filename);
bool suffix() const;
void setSuffix(bool newSuffix);
private slots:
void onUpdateIcons();
void on_btnBrowse_clicked();
void on_btnOk_clicked();
void on_btnCancel_clicked();
void on_txtFilename_textChanged(const QString &arg1);
void on_txtFolder_textChanged(const QString &arg1);
private:
void updateBtnOkStatus();
private:
Ui::NewProjectUnitDialog *ui;
private:
bool mSuffix;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
};
#endif // NEWPROJECTUNITDIALOG_H

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewProjectUnitDialog</class>
<widget class="QDialog" name="NewProjectUnitDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Folder</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtFolder">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Filename</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="btnBrowse">
<property name="toolTip">
<string>Browse</string>
</property>
<property name="text">
<string>Browse</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/images/newlook24/053-open.png</normaloff>:/icons/images/newlook24/053-open.png</iconset>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="txtFilename"/>
</item>
<item row="3" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnOk">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>