Add "Add New..." to file system view

Since we do not have a specific project node where to add the file(s),
the user has to rely on the guess that is already done by the project
management wizard page.

Task-number: QTCREATORBUG-19213
Change-Id: I4ee2f81cd7b8d7ac2391d2c11eb53a695968233c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2017-12-13 12:23:14 +01:00
parent 6c02588f39
commit 44ee8b9068
4 changed files with 26 additions and 2 deletions

View File

@@ -41,6 +41,7 @@
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/iwizardfactory.h>
#include <extensionsystem/pluginmanager.h>
@@ -392,6 +393,20 @@ void FolderNavigationWidget::removeRootDirectory(const QString &id)
setCurrentEditor(Core::EditorManager::currentEditor());
}
void FolderNavigationWidget::addNewItem()
{
const QModelIndex current = m_listView->currentIndex();
if (!current.isValid())
return;
const auto filePath = Utils::FileName::fromString(m_fileSystemModel->filePath(current));
const Utils::FileName path = filePath.toFileInfo().isDir() ? filePath : filePath.parentDir();
Core::ICore::showNewItemDialog(ProjectExplorerPlugin::tr("New File", "Title of dialog"),
Utils::filtered(Core::IWizardFactory::allWizardFactories(),
Utils::equal(&Core::IWizardFactory::kind,
Core::IWizardFactory::FileWizard)),
path.toString());
}
void FolderNavigationWidget::editCurrentItem()
{
const QModelIndex current = m_listView->currentIndex();
@@ -608,6 +623,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry);
if (hasCurrentItem) {
menu.addAction(Core::ActionManager::command(Constants::ADDNEWFILE)->action());
if (!isDir)
menu.addAction(Core::ActionManager::command(Constants::REMOVEFILE)->action());
if (m_fileSystemModel->flags(current) & Qt::ItemIsEditable)
@@ -772,6 +788,13 @@ void FolderNavigationWidgetFactory::registerActions()
{
Core::Context context(C_FOLDERNAVIGATIONWIDGET);
auto add = new QAction(this);
Core::ActionManager::registerAction(add, Constants::ADDNEWFILE, context);
connect(add, &QAction::triggered, Core::ICore::instance(), [] {
if (auto navWidget = currentFolderNavigationWidget())
navWidget->addNewItem();
});
auto rename = new QAction(this);
Core::ActionManager::registerAction(rename, Constants::RENAMEFILE, context);
connect(rename, &QAction::triggered, Core::ICore::instance(), [] {