forked from qt-creator/qt-creator
File System view: Add "New Folder" to context menu
Task-number: QTCREATORBUG-17358 Change-Id: I64b3d34ca0432369630382c40cf749f3cc1a08df Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -726,6 +726,13 @@ bool FileName::operator>=(const FileName &other) const
|
|||||||
return other <= *this;
|
return other <= *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileName FileName::operator+(const QString &s) const
|
||||||
|
{
|
||||||
|
FileName result(*this);
|
||||||
|
result.appendString(s);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// \returns whether FileName is a child of \a s
|
/// \returns whether FileName is a child of \a s
|
||||||
bool FileName::isChildOf(const FileName &s) const
|
bool FileName::isChildOf(const FileName &s) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ public:
|
|||||||
bool operator<=(const FileName &other) const;
|
bool operator<=(const FileName &other) const;
|
||||||
bool operator>(const FileName &other) const;
|
bool operator>(const FileName &other) const;
|
||||||
bool operator>=(const FileName &other) const;
|
bool operator>=(const FileName &other) const;
|
||||||
|
FileName operator+(const QString &s) const;
|
||||||
|
|
||||||
bool isChildOf(const FileName &s) const;
|
bool isChildOf(const FileName &s) const;
|
||||||
bool isChildOf(const QDir &dir) const;
|
bool isChildOf(const QDir &dir) const;
|
||||||
|
|||||||
@@ -49,10 +49,12 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/filecrumblabel.h>
|
#include <utils/filecrumblabel.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/navigationtreeview.h>
|
#include <utils/navigationtreeview.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/removefiledialog.h>
|
#include <utils/removefiledialog.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
@@ -609,6 +611,26 @@ void FolderNavigationWidget::openProjectsInDirectory(const QModelIndex &index)
|
|||||||
Core::ICore::instance()->openFiles(projectFiles);
|
Core::ICore::instance()->openFiles(projectFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FolderNavigationWidget::createNewFolder(const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
static const QString baseName = tr("New Folder");
|
||||||
|
// find non-existing name
|
||||||
|
const QDir dir(m_fileSystemModel->filePath(parent));
|
||||||
|
const QSet<Utils::FileName> existingItems
|
||||||
|
= Utils::transform<QSet>(dir.entryList({baseName + '*'}, QDir::AllEntries),
|
||||||
|
[](const QString &entry) {
|
||||||
|
return Utils::FileName::fromString(entry);
|
||||||
|
});
|
||||||
|
const Utils::FileName name = Utils::makeUniquelyNumbered(Utils::FileName::fromString(baseName),
|
||||||
|
existingItems);
|
||||||
|
// create directory and edit
|
||||||
|
const QModelIndex index = m_fileSystemModel->mkdir(parent, name.toString());
|
||||||
|
if (!index.isValid())
|
||||||
|
return;
|
||||||
|
m_listView->setCurrentIndex(index);
|
||||||
|
m_listView->edit(index);
|
||||||
|
}
|
||||||
|
|
||||||
void FolderNavigationWidget::setCrumblePath(const QModelIndex &index, const QModelIndex &)
|
void FolderNavigationWidget::setCrumblePath(const QModelIndex &index, const QModelIndex &)
|
||||||
{
|
{
|
||||||
const int width = m_crumbLabel->width();
|
const int width = m_crumbLabel->width();
|
||||||
@@ -645,6 +667,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
QAction *actionOpenFile = nullptr;
|
QAction *actionOpenFile = nullptr;
|
||||||
QAction *actionOpenProjects = nullptr;
|
QAction *actionOpenProjects = nullptr;
|
||||||
QAction *actionOpenAsProject = nullptr;
|
QAction *actionOpenAsProject = nullptr;
|
||||||
|
QAction *newFolder = nullptr;
|
||||||
const bool isDir = m_fileSystemModel->isDir(current);
|
const bool isDir = m_fileSystemModel->isDir(current);
|
||||||
const Utils::FileName filePath = hasCurrentItem ? Utils::FileName::fromString(
|
const Utils::FileName filePath = hasCurrentItem ? Utils::FileName::fromString(
|
||||||
m_fileSystemModel->filePath(current))
|
m_fileSystemModel->filePath(current))
|
||||||
@@ -676,6 +699,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
menu.addAction(Core::ActionManager::command(Constants::REMOVEFILE)->action());
|
menu.addAction(Core::ActionManager::command(Constants::REMOVEFILE)->action());
|
||||||
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
|
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
|
||||||
menu.addAction(Core::ActionManager::command(Constants::RENAMEFILE)->action());
|
menu.addAction(Core::ActionManager::command(Constants::RENAMEFILE)->action());
|
||||||
|
newFolder = menu.addAction(tr("New Folder"));
|
||||||
if (!isDir && Core::DiffService::instance()) {
|
if (!isDir && Core::DiffService::instance()) {
|
||||||
menu.addAction(
|
menu.addAction(
|
||||||
TextEditor::TextDocument::createDiffAgainstCurrentFileAction(&menu, [filePath]() {
|
TextEditor::TextDocument::createDiffAgainstCurrentFileAction(&menu, [filePath]() {
|
||||||
@@ -695,6 +719,12 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
ProjectExplorerPlugin::openProject(filePath.toString());
|
ProjectExplorerPlugin::openProject(filePath.toString());
|
||||||
else if (action == actionOpenProjects)
|
else if (action == actionOpenProjects)
|
||||||
openProjectsInDirectory(current);
|
openProjectsInDirectory(current);
|
||||||
|
else if (action == newFolder) {
|
||||||
|
if (isDir)
|
||||||
|
createNewFolder(current);
|
||||||
|
else
|
||||||
|
createNewFolder(current.parent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FolderNavigationWidget::rootAutoSynchronization() const
|
bool FolderNavigationWidget::rootAutoSynchronization() const
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ private:
|
|||||||
void openItem(const QModelIndex &index);
|
void openItem(const QModelIndex &index);
|
||||||
QStringList projectsInDirectory(const QModelIndex &index) const;
|
QStringList projectsInDirectory(const QModelIndex &index) const;
|
||||||
void openProjectsInDirectory(const QModelIndex &index);
|
void openProjectsInDirectory(const QModelIndex &index);
|
||||||
|
void createNewFolder(const QModelIndex &parent);
|
||||||
void setCrumblePath(const QModelIndex &index, const QModelIndex &);
|
void setCrumblePath(const QModelIndex &index, const QModelIndex &);
|
||||||
|
|
||||||
Core::IContext *m_context = nullptr;
|
Core::IContext *m_context = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user