- enhancement: remove / rename / create new folder in the files view
This commit is contained in:
parent
c7a9698c4b
commit
acbbae24c6
1
NEWS.md
1
NEWS.md
|
@ -1,5 +1,6 @@
|
|||
Red Panda C++ Version 0.14.2
|
||||
- enhancement: file system view mode for project
|
||||
- enhancement: remove / rename / create new folder in the files view
|
||||
|
||||
Red Panda C++ Version 0.14.1
|
||||
- enhancement: custom theme
|
||||
|
|
|
@ -285,7 +285,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
//files view
|
||||
ui->treeFiles->setModel(&mFileSystemModel);
|
||||
mFileSystemModel.setReadOnly(true);
|
||||
mFileSystemModel.setReadOnly(false);
|
||||
setFilesViewRoot(pSettings->environment().currentFolder());
|
||||
for (int i=1;i<mFileSystemModel.columnCount();i++) {
|
||||
ui->treeFiles->hideColumn(i);
|
||||
|
@ -2649,6 +2649,18 @@ void MainWindow::buildContextMenus()
|
|||
ui->treeFiles->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->treeFiles,&QWidget::customContextMenuRequested,
|
||||
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(
|
||||
tr("Open in Editor"),
|
||||
ui->treeFiles);
|
||||
|
@ -3019,6 +3031,8 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
|
|||
QMenu menu(this);
|
||||
menu.addAction(ui->actionOpen_Folder);
|
||||
menu.addSeparator();
|
||||
menu.addAction(mFilesView_CreateFolder);
|
||||
menu.addSeparator();
|
||||
menu.addAction(mFilesView_Open);
|
||||
menu.addAction(mFilesView_OpenWithExternal);
|
||||
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)
|
||||
{
|
||||
Editor * editor = mEditorList->getEditor();
|
||||
|
|
|
@ -274,6 +274,9 @@ private slots:
|
|||
|
||||
void onShowInsertCodeSnippetMenu();
|
||||
|
||||
void onFilesViewCreateFolder();
|
||||
void onFilesViewRemoveFile();
|
||||
|
||||
void on_actionNew_triggered();
|
||||
|
||||
void on_EditorTabsLeft_tabCloseRequested(int index);
|
||||
|
@ -667,6 +670,8 @@ private:
|
|||
QAction * mFilesView_OpenInTerminal;
|
||||
QAction * mFilesView_OpenInExplorer;
|
||||
QWidget * mFilesViewToolbar;
|
||||
QAction * mFilesView_CreateFolder;
|
||||
QAction * mFilesView_RemoveFile;
|
||||
|
||||
//action for debug console
|
||||
QAction * mDebugConsole_ShowDetailLog;
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
<enum>QTabWidget::West</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="usesScrollButtons">
|
||||
<bool>true</bool>
|
||||
|
@ -258,8 +258,14 @@
|
|||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
<enum>QAbstractItemView::DragDrop</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::CopyAction</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -311,7 +311,6 @@ Editor *Project::openUnit(int index)
|
|||
|
||||
void Project::rebuildNodes()
|
||||
{
|
||||
qDebug()<<(int)mOptions.modelType;
|
||||
mModel.beginUpdate();
|
||||
// Delete everything
|
||||
mRootNode->children.clear();
|
||||
|
|
Loading…
Reference in New Issue