- enhancement: remove / rename / create new folder in the files view

This commit is contained in:
Roy Qu 2022-02-08 16:36:20 +08:00
parent c7a9698c4b
commit acbbae24c6
5 changed files with 74 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Red Panda C++ Version 0.14.2 Red Panda C++ Version 0.14.2
- enhancement: file system view mode for project - enhancement: file system view mode for project
- enhancement: remove / rename / create new folder in the files view
Red Panda C++ Version 0.14.1 Red Panda C++ Version 0.14.1
- enhancement: custom theme - enhancement: custom theme

View File

@ -285,7 +285,7 @@ MainWindow::MainWindow(QWidget *parent)
//files view //files view
ui->treeFiles->setModel(&mFileSystemModel); ui->treeFiles->setModel(&mFileSystemModel);
mFileSystemModel.setReadOnly(true); mFileSystemModel.setReadOnly(false);
setFilesViewRoot(pSettings->environment().currentFolder()); setFilesViewRoot(pSettings->environment().currentFolder());
for (int i=1;i<mFileSystemModel.columnCount();i++) { for (int i=1;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->hideColumn(i); ui->treeFiles->hideColumn(i);
@ -2649,6 +2649,18 @@ void MainWindow::buildContextMenus()
ui->treeFiles->setContextMenuPolicy(Qt::CustomContextMenu); ui->treeFiles->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treeFiles,&QWidget::customContextMenuRequested, connect(ui->treeFiles,&QWidget::customContextMenuRequested,
this, &MainWindow::onFilesViewContextMenu); this, &MainWindow::onFilesViewContextMenu);
mFilesView_CreateFolder = createActionFor(
tr("New Folder"),
ui->treeFiles);
connect(mFilesView_CreateFolder, &QAction::triggered,
this, &MainWindow::onFilesViewCreateFolder);
mFilesView_RemoveFile = createActionFor(
tr("Delete"),
ui->treeFiles);
mFilesView_RemoveFile->setShortcut(Qt::Key_Delete);
connect(mFilesView_RemoveFile, &QAction::triggered,
this, &MainWindow::onFilesViewRemoveFile);
mFilesView_Open = createActionFor( mFilesView_Open = createActionFor(
tr("Open in Editor"), tr("Open in Editor"),
ui->treeFiles); ui->treeFiles);
@ -3019,6 +3031,8 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
QMenu menu(this); QMenu menu(this);
menu.addAction(ui->actionOpen_Folder); menu.addAction(ui->actionOpen_Folder);
menu.addSeparator(); menu.addSeparator();
menu.addAction(mFilesView_CreateFolder);
menu.addSeparator();
menu.addAction(mFilesView_Open); menu.addAction(mFilesView_Open);
menu.addAction(mFilesView_OpenWithExternal); menu.addAction(mFilesView_OpenWithExternal);
menu.addSeparator(); menu.addSeparator();
@ -3295,6 +3309,51 @@ void MainWindow::onShowInsertCodeSnippetMenu()
} }
void MainWindow::onFilesViewCreateFolder()
{
QModelIndex index = ui->treeFiles->currentIndex();
QDir dir;
if (index.isValid()) {
if (mFileSystemModel.isDir(index))
dir = QDir(mFileSystemModel.fileInfo(index).absoluteFilePath());
else
dir = mFileSystemModel.fileInfo(index).absoluteDir();
} else {
dir = mFileSystemModel.rootDirectory();
}
QString folderName = tr("New Folder");
int count = 0;
while (dir.exists(folderName)) {
count++;
folderName = tr("New Folder").arg(count);
}
mFileSystemModel.mkdir(index,folderName);
}
void MainWindow::onFilesViewRemoveFile()
{
QModelIndex index = ui->treeFiles->currentIndex();
if (!index.isValid())
return;
if (QMessageBox::question(ui->treeFiles,tr("Delete")
,tr("Do you really want to delete %1?").arg(mFileSystemModel.fileName(index)),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)!=QMessageBox::Yes)
return;
if (mFileSystemModel.isDir(index)) {
QDir dir(mFileSystemModel.fileInfo(index).absoluteFilePath());
if (!dir.isEmpty() &&
QMessageBox::question(ui->treeFiles
,tr("Delete")
,tr("Folder %1 is not empty.").arg(mFileSystemModel.fileName(index))
+ tr("Do you really want to delete it?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)!=QMessageBox::Yes)
return;
dir.removeRecursively();
} else {
QFile::remove(mFileSystemModel.filePath(index));
}
}
void MainWindow::onEditorContextMenu(const QPoint& pos) void MainWindow::onEditorContextMenu(const QPoint& pos)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();

View File

@ -274,6 +274,9 @@ private slots:
void onShowInsertCodeSnippetMenu(); void onShowInsertCodeSnippetMenu();
void onFilesViewCreateFolder();
void onFilesViewRemoveFile();
void on_actionNew_triggered(); void on_actionNew_triggered();
void on_EditorTabsLeft_tabCloseRequested(int index); void on_EditorTabsLeft_tabCloseRequested(int index);
@ -667,6 +670,8 @@ private:
QAction * mFilesView_OpenInTerminal; QAction * mFilesView_OpenInTerminal;
QAction * mFilesView_OpenInExplorer; QAction * mFilesView_OpenInExplorer;
QWidget * mFilesViewToolbar; QWidget * mFilesViewToolbar;
QAction * mFilesView_CreateFolder;
QAction * mFilesView_RemoveFile;
//action for debug console //action for debug console
QAction * mDebugConsole_ShowDetailLog; QAction * mDebugConsole_ShowDetailLog;

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>3</number>
</property> </property>
<property name="usesScrollButtons"> <property name="usesScrollButtons">
<bool>true</bool> <bool>true</bool>
@ -258,8 +258,14 @@
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set> <set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property> </property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode"> <property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum> <enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::CopyAction</enum>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -311,7 +311,6 @@ Editor *Project::openUnit(int index)
void Project::rebuildNodes() void Project::rebuildNodes()
{ {
qDebug()<<(int)mOptions.modelType;
mModel.beginUpdate(); mModel.beginUpdate();
// Delete everything // Delete everything
mRootNode->children.clear(); mRootNode->children.clear();