- enhancement: auto sort files in the project view
This commit is contained in:
parent
bcd4a1ff67
commit
13ee2d7f33
1
NEWS.md
1
NEWS.md
|
@ -6,6 +6,7 @@ Red Panda C++ Version 0.12.7
|
||||||
- fix: shouldn't auto add /bin/gcc to compiler sets
|
- fix: shouldn't auto add /bin/gcc to compiler sets
|
||||||
- fix: if a dir duplicates in PATH, don't add it to compiler sets repeatedly
|
- fix: if a dir duplicates in PATH, don't add it to compiler sets repeatedly
|
||||||
- enhancement: add "--sanitize=address" to compile option in the Debug compiler set in Linux
|
- enhancement: add "--sanitize=address" to compile option in the Debug compiler set in Linux
|
||||||
|
- enhancement: auto sort files in the project view
|
||||||
|
|
||||||
Red Panda C++ Version 0.12.6
|
Red Panda C++ Version 0.12.6
|
||||||
- fix: heartbeat for gdb server async command shouldn't disable actions
|
- fix: heartbeat for gdb server async command shouldn't disable actions
|
||||||
|
|
|
@ -116,6 +116,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(mEditorList, &EditorList::editorClosed,
|
connect(mEditorList, &EditorList::editorClosed,
|
||||||
this, &MainWindow::onEditorClosed);
|
this, &MainWindow::onEditorClosed);
|
||||||
mProject = nullptr;
|
mProject = nullptr;
|
||||||
|
ui->projectView->setModel(&mProjectProxyModel);
|
||||||
|
mProjectProxyModel.setDynamicSortFilter(false);
|
||||||
setupActions();
|
setupActions();
|
||||||
ui->EditorTabsRight->setVisible(false);
|
ui->EditorTabsRight->setVisible(false);
|
||||||
|
|
||||||
|
@ -2404,7 +2406,7 @@ void MainWindow::buildContextMenus()
|
||||||
[this](){
|
[this](){
|
||||||
if (!mProject)
|
if (!mProject)
|
||||||
return;
|
return;
|
||||||
QModelIndex current = ui->projectView->currentIndex();
|
QModelIndex current = mProjectProxyModel.mapToSource(ui->projectView->currentIndex());
|
||||||
if (!current.isValid()) {
|
if (!current.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2446,7 +2448,7 @@ void MainWindow::buildContextMenus()
|
||||||
[this](){
|
[this](){
|
||||||
if (!mProject)
|
if (!mProject)
|
||||||
return;
|
return;
|
||||||
QModelIndex current = ui->projectView->currentIndex();
|
QModelIndex current = mProjectProxyModel.mapToSource(ui->projectView->currentIndex());
|
||||||
if (!current.isValid()) {
|
if (!current.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2838,7 +2840,7 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
|
||||||
bool onRoot = false;
|
bool onRoot = false;
|
||||||
bool folderEmpty = false;
|
bool folderEmpty = false;
|
||||||
int unitIndex = -1;
|
int unitIndex = -1;
|
||||||
QModelIndex current = ui->projectView->selectionModel()->currentIndex();
|
QModelIndex current = mProjectProxyModel.mapToSource(ui->projectView->selectionModel()->currentIndex());
|
||||||
if (current.isValid() && mProject) {
|
if (current.isValid() && mProject) {
|
||||||
FolderNode * node = static_cast<FolderNode*>(current.internalPointer());
|
FolderNode * node = static_cast<FolderNode*>(current.internalPointer());
|
||||||
PFolderNode pNode = mProject->pointerToNode(node);
|
PFolderNode pNode = mProject->pointerToNode(node);
|
||||||
|
@ -3465,16 +3467,36 @@ void MainWindow::closeProject(bool refreshEditor)
|
||||||
void MainWindow::updateProjectView()
|
void MainWindow::updateProjectView()
|
||||||
{
|
{
|
||||||
if (mProject) {
|
if (mProject) {
|
||||||
ui->projectView->setModel(mProject->model());
|
if (mProjectProxyModel.sourceModel()!=mProject->model()) {
|
||||||
connect(mProject->model(), &QAbstractItemModel::modelReset,
|
mProjectProxyModel.setSourceModel(mProject->model());
|
||||||
ui->projectView,&QTreeView::expandAll);
|
connect(mProject->model(),&ProjectModel::dataChanged, &mProjectProxyModel,
|
||||||
|
[this]() {
|
||||||
|
mProjectProxyModel.invalidate();
|
||||||
|
});
|
||||||
|
connect(mProject->model(),&ProjectModel::modelReset, &mProjectProxyModel,
|
||||||
|
[this]() {
|
||||||
|
mProjectProxyModel.invalidate();
|
||||||
|
});
|
||||||
|
connect(mProject->model(),&ProjectModel::rowsInserted, &mProjectProxyModel,
|
||||||
|
[this]() {
|
||||||
|
mProjectProxyModel.invalidate();
|
||||||
|
});
|
||||||
|
connect(mProject->model(),&ProjectModel::rowsRemoved, &mProjectProxyModel,
|
||||||
|
[this]() {
|
||||||
|
mProjectProxyModel.invalidate();
|
||||||
|
});
|
||||||
|
mProjectProxyModel.sort(0);
|
||||||
|
connect(mProject->model(), &QAbstractItemModel::modelReset,
|
||||||
|
ui->projectView,&QTreeView::expandAll);
|
||||||
|
}
|
||||||
|
mProjectProxyModel.invalidate();
|
||||||
ui->projectView->expandAll();
|
ui->projectView->expandAll();
|
||||||
openCloseLeftPanel(true);
|
openCloseLeftPanel(true);
|
||||||
ui->tabProject->setVisible(true);
|
ui->tabProject->setVisible(true);
|
||||||
ui->tabInfos->setCurrentWidget(ui->tabProject);
|
ui->tabInfos->setCurrentWidget(ui->tabProject);
|
||||||
} else {
|
} else {
|
||||||
// Clear project browser
|
// Clear project browser
|
||||||
ui->projectView->setModel(nullptr);
|
mProjectProxyModel.setSourceModel(nullptr);
|
||||||
ui->tabProject->setVisible(false);
|
ui->tabProject->setVisible(false);
|
||||||
}
|
}
|
||||||
updateProjectActions();
|
updateProjectActions();
|
||||||
|
@ -5033,7 +5055,7 @@ void MainWindow::on_actionAdd_to_project_triggered()
|
||||||
dialog.setFileMode(QFileDialog::ExistingFiles);
|
dialog.setFileMode(QFileDialog::ExistingFiles);
|
||||||
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
dialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||||
if (dialog.exec()) {
|
if (dialog.exec()) {
|
||||||
QModelIndex current = ui->projectView->currentIndex();
|
QModelIndex current = mProjectProxyModel.mapToSource(ui->projectView->currentIndex());
|
||||||
FolderNode * node = nullptr;
|
FolderNode * node = nullptr;
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
node = static_cast<FolderNode*>(current.internalPointer());
|
node = static_cast<FolderNode*>(current.internalPointer());
|
||||||
|
@ -5062,7 +5084,8 @@ void MainWindow::on_actionRemove_from_project_triggered()
|
||||||
foreach (const QModelIndex& index, ui->projectView->selectionModel()->selectedIndexes()){
|
foreach (const QModelIndex& index, ui->projectView->selectionModel()->selectedIndexes()){
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
continue;
|
continue;
|
||||||
FolderNode * node = static_cast<FolderNode*>(index.internalPointer());
|
QModelIndex realIndex = mProjectProxyModel.mapToSource(index);
|
||||||
|
FolderNode * node = static_cast<FolderNode*>(realIndex.internalPointer());
|
||||||
PFolderNode folderNode = mProject->pointerToNode(node);
|
PFolderNode folderNode = mProject->pointerToNode(node);
|
||||||
if (!folderNode)
|
if (!folderNode)
|
||||||
continue;
|
continue;
|
||||||
|
@ -5285,7 +5308,7 @@ void MainWindow::newProjectUnitFile()
|
||||||
if (!mProject)
|
if (!mProject)
|
||||||
return;
|
return;
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
QModelIndex current = ui->projectView->currentIndex();
|
QModelIndex current = mProjectProxyModel.mapToSource(ui->projectView->currentIndex());
|
||||||
FolderNode * node = nullptr;
|
FolderNode * node = nullptr;
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
node = static_cast<FolderNode*>(current.internalPointer());
|
node = static_cast<FolderNode*>(current.internalPointer());
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "widgets/searchresultview.h"
|
#include "widgets/searchresultview.h"
|
||||||
#include "widgets/classbrowser.h"
|
#include "widgets/classbrowser.h"
|
||||||
|
@ -673,6 +674,8 @@ private:
|
||||||
QAction * mProblem_OpenSource;
|
QAction * mProblem_OpenSource;
|
||||||
QAction * mProblem_Properties;
|
QAction * mProblem_Properties;
|
||||||
|
|
||||||
|
QSortFilterProxyModel mProjectProxyModel;
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
<enum>QTabWidget::West</enum>
|
<enum>QTabWidget::West</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>4</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="usesScrollButtons">
|
<property name="usesScrollButtons">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Project</string>
|
<string>Project</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -309,15 +309,6 @@ Editor *Project::openUnit(int index)
|
||||||
|
|
||||||
void Project::rebuildNodes()
|
void Project::rebuildNodes()
|
||||||
{
|
{
|
||||||
// Remember if folder nodes were expanded or collapsed
|
|
||||||
// Create a list of expanded folder nodes
|
|
||||||
// QStringList oldPaths := TStringList.Create;
|
|
||||||
// with MainForm.ProjectView do
|
|
||||||
// for idx := 0 to Items.Count - 1 do begin
|
|
||||||
// tempnode := Items[idx];
|
|
||||||
// if tempnode.Expanded and (tempnode.Data = Pointer(-1)) then // data=pointer(-1) - it's folder
|
|
||||||
// oldPaths.Add(GetFolderPath(tempnode));
|
|
||||||
// end;
|
|
||||||
|
|
||||||
mModel.beginUpdate();
|
mModel.beginUpdate();
|
||||||
// Delete everything
|
// Delete everything
|
||||||
|
@ -337,18 +328,6 @@ void Project::rebuildNodes()
|
||||||
mUnits[idx]->node()->unitIndex = idx;
|
mUnits[idx]->node()->unitIndex = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // expand nodes expanded before recreating the project tree
|
|
||||||
// fNode.Collapse(True);
|
|
||||||
// with MainForm.ProjectView do
|
|
||||||
// for idx := 0 to Items.Count - 1 do begin
|
|
||||||
// tempnode := Items[idx];
|
|
||||||
// if (tempnode.Data = Pointer(-1)) then //it's a folder
|
|
||||||
// if oldPaths.IndexOf(GetFolderPath(tempnode)) >= 0 then
|
|
||||||
// tempnode.Expand(False);
|
|
||||||
// end;
|
|
||||||
// FreeAndNil(oldPaths);
|
|
||||||
|
|
||||||
// fNode.Expand(False);
|
|
||||||
|
|
||||||
mModel.endUpdate();
|
mModel.endUpdate();
|
||||||
emit nodesChanged();
|
emit nodesChanged();
|
||||||
|
@ -365,6 +344,8 @@ bool Project::removeUnit(int index, bool doClose , bool removeFile)
|
||||||
|
|
||||||
PProjectUnit unit = mUnits[index];
|
PProjectUnit unit = mUnits[index];
|
||||||
|
|
||||||
|
qDebug()<<unit->fileName();
|
||||||
|
qDebug()<<(qint64)unit->editor();
|
||||||
// Attempt to close it
|
// Attempt to close it
|
||||||
if (doClose && (unit->editor())) {
|
if (doClose && (unit->editor())) {
|
||||||
if (!pMainWindow->editorList()->closeEditor(unit->editor()))
|
if (!pMainWindow->editorList()->closeEditor(unit->editor()))
|
||||||
|
@ -1816,16 +1797,18 @@ ProjectModel::ProjectModel(Project *project, QObject *parent):
|
||||||
|
|
||||||
void ProjectModel::beginUpdate()
|
void ProjectModel::beginUpdate()
|
||||||
{
|
{
|
||||||
if (mUpdateCount==0)
|
if (mUpdateCount==0) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
}
|
||||||
mUpdateCount++;
|
mUpdateCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectModel::endUpdate()
|
void ProjectModel::endUpdate()
|
||||||
{
|
{
|
||||||
mUpdateCount--;
|
mUpdateCount--;
|
||||||
if (mUpdateCount==0)
|
if (mUpdateCount==0) {
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
|
Loading…
Reference in New Issue