diff --git a/src/app/browser/qgsinbuiltdataitemproviders.cpp b/src/app/browser/qgsinbuiltdataitemproviders.cpp index 70de98b08f80..c49b04b0b218 100644 --- a/src/app/browser/qgsinbuiltdataitemproviders.cpp +++ b/src/app/browser/qgsinbuiltdataitemproviders.cpp @@ -65,6 +65,7 @@ #include "qgsdbrelationshipwidget.h" #include "qgsdbqueryhistoryprovider.h" #include "qgshistoryproviderregistry.h" +#include "qgslogger.h" #include #include @@ -82,345 +83,373 @@ QString QgsAppDirectoryItemGuiProvider::name() void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList &, QgsDataItemGuiContext context ) { - if ( item->type() != Qgis::BrowserItemType::Directory ) - return; - - QgsDirectoryItem *directoryItem = qobject_cast< QgsDirectoryItem * >( item ); + bool inFavDirs = item->parent() && item->parent()->type() == Qgis::BrowserItemType::Favorites; + if ( inFavDirs ) + QgsDebugMsgLevel( QStringLiteral( "inFavDirs true" ), 3 ); - QgsSettings settings; + if ( item->type() == Qgis::BrowserItemType::Directory ) + { + QgsDebugMsgLevel( QStringLiteral( "Qgis::BrowserItemType::Directory" ), 3 ); + QgsDirectoryItem *directoryItem = qobject_cast< QgsDirectoryItem * >( item ); - QAction *actionRefresh = new QAction( tr( "Refresh" ), menu ); - connect( actionRefresh, &QAction::triggered, this, [ = ] { directoryItem->refresh(); } ); - menu->addAction( actionRefresh ); + QgsSettings settings; - menu->addSeparator(); + QAction *actionRefresh = new QAction( tr( "Refresh" ), menu ); + connect( actionRefresh, &QAction::triggered, this, [ = ] { directoryItem->refresh(); } ); + menu->addAction( actionRefresh ); - QMenu *newMenu = new QMenu( tr( "New" ), menu ); + menu->addSeparator(); - QAction *createFolder = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewFolder.svg" ) ), tr( "Directory…" ), menu ); - connect( createFolder, &QAction::triggered, this, [ = ] - { - bool ok = false; + QMenu *newMenu = new QMenu( tr( "New" ), menu ); - const QString name = QInputDialog::getText( QgisApp::instance(), tr( "Create Directory" ), tr( "Directory name" ), QLineEdit::Normal, QString(), &ok ); - if ( ok && !name.isEmpty() ) + QAction *createFolder = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewFolder.svg" ) ), tr( "Directory…" ), menu ); + connect( createFolder, &QAction::triggered, this, [ = ] { - QDir dir( directoryItem->dirPath() ); - if ( QFileInfo::exists( dir.absoluteFilePath( name ) ) ) - { - notify( tr( "Create Directory" ), tr( "The path “%1” already exists." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ), context, Qgis::MessageLevel::Warning ); - } - else if ( !dir.mkdir( name ) ) - { - notify( tr( "Create Directory" ), tr( "Could not create directory “%1”." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ), context, Qgis::MessageLevel::Critical ); - } - else + bool ok = false; + + const QString name = QInputDialog::getText( QgisApp::instance(), tr( "Create Directory" ), tr( "Directory name" ), QLineEdit::Normal, QString(), &ok ); + if ( ok && !name.isEmpty() ) { - directoryItem->refresh(); + QDir dir( directoryItem->dirPath() ); + if ( QFileInfo::exists( dir.absoluteFilePath( name ) ) ) + { + notify( tr( "Create Directory" ), tr( "The path “%1” already exists." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ), context, Qgis::MessageLevel::Warning ); + } + else if ( !dir.mkdir( name ) ) + { + notify( tr( "Create Directory" ), tr( "Could not create directory “%1”." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ), context, Qgis::MessageLevel::Critical ); + } + else + { + directoryItem->refresh(); + } } - } - } ); - newMenu->addAction( createFolder ); - - QAction *createGpkg = new QAction( tr( "GeoPackage…" ), newMenu ); - createGpkg->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewGeoPackageLayer.svg" ) ) ); - connect( createGpkg, &QAction::triggered, this, [ = ] - { - QDir dir( directoryItem->dirPath() ); - QString newName = tr( "New GeoPackage.gpkg" ); - int i = 1; - while ( QFileInfo::exists( dir.absoluteFilePath( newName ) ) ) - { - i += 1; - newName = tr( "New GeoPackage (%1).gpkg" ).arg( i ); - } + } ); + newMenu->addAction( createFolder ); - const QString fileName = dir.absoluteFilePath( newName ); - if ( QgsProviderMetadata *ogrMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) ) + QAction *createGpkg = new QAction( tr( "GeoPackage…" ), newMenu ); + createGpkg->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewGeoPackageLayer.svg" ) ) ); + connect( createGpkg, &QAction::triggered, this, [ = ] { - QString error; - if ( ! ogrMetadata->createDatabase( fileName, error ) ) + QDir dir( directoryItem->dirPath() ); + QString newName = tr( "New GeoPackage.gpkg" ); + int i = 1; + while ( QFileInfo::exists( dir.absoluteFilePath( newName ) ) ) { - context.messageBar()->pushCritical( tr( "New GeoPackage" ), tr( "GeoPackage creation failed: %1" ).arg( error ) ); + i += 1; + newName = tr( "New GeoPackage (%1).gpkg" ).arg( i ); } - else + + const QString fileName = dir.absoluteFilePath( newName ); + if ( QgsProviderMetadata *ogrMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) ) { - QObject *contextObject = new QObject(); - connect( directoryItem, &QgsDataItem::stateChanged, contextObject, [contextObject, fileName, context]( QgsDataItem * item, Qgis::BrowserItemState ) + QString error; + if ( ! ogrMetadata->createDatabase( fileName, error ) ) + { + context.messageBar()->pushCritical( tr( "New GeoPackage" ), tr( "GeoPackage creation failed: %1" ).arg( error ) ); + } + else { - if ( item->state() == Qgis::BrowserItemState::Populated ) + QObject *contextObject = new QObject(); + connect( directoryItem, &QgsDataItem::stateChanged, contextObject, [contextObject, fileName, context]( QgsDataItem * item, Qgis::BrowserItemState ) { - // find the new item and select it - const QVector children = item->children(); - for ( QgsDataItem *child : children ) + if ( item->state() == Qgis::BrowserItemState::Populated ) { - if ( child->path() == fileName ) + // find the new item and select it + const QVector children = item->children(); + for ( QgsDataItem *child : children ) { - if ( QgsBrowserTreeView *view = context.view() ) + if ( child->path() == fileName ) { - if ( view->setSelectedItem( child ) ) - view->edit( view->currentIndex() ); + if ( QgsBrowserTreeView *view = context.view() ) + { + if ( view->setSelectedItem( child ) ) + view->edit( view->currentIndex() ); + } + break; } - break; } + contextObject->deleteLater(); } - contextObject->deleteLater(); - } - } ); - directoryItem->refresh(); + } ); + directoryItem->refresh(); + } } - } - } ); - newMenu->addAction( createGpkg ); + } ); + newMenu->addAction( createGpkg ); - QAction *createShp = new QAction( tr( "ShapeFile…" ), newMenu ); - createShp->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewVectorLayer.svg" ) ) ); - connect( createShp, &QAction::triggered, this, [ = ] - { - QString enc; - QDir dir( directoryItem->dirPath() ); - QString error; - const QString newFile = QgsNewVectorLayerDialog::execAndCreateLayer( error, QgisApp::instance(), dir.filePath( QStringLiteral( "new_layer.shp" ) ), &enc, QgsProject::instance()->defaultCrsForNewLayers() ); - if ( !newFile.isEmpty() ) - { - context.messageBar()->pushSuccess( tr( "New ShapeFile" ), tr( "Created %2" ).arg( - QUrl::fromLocalFile( newFile ).toString(), QDir::toNativeSeparators( newFile ) ) ); - item->refresh(); - } - else if ( !error.isEmpty() ) + QAction *createShp = new QAction( tr( "ShapeFile…" ), newMenu ); + createShp->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewVectorLayer.svg" ) ) ); + connect( createShp, &QAction::triggered, this, [ = ] { - context.messageBar()->pushCritical( tr( "New ShapeFile" ), tr( "Layer creation failed: %1" ).arg( error ) ); - } - } ); - newMenu->addAction( createShp ); + QString enc; + QDir dir( directoryItem->dirPath() ); + QString error; + const QString newFile = QgsNewVectorLayerDialog::execAndCreateLayer( error, QgisApp::instance(), dir.filePath( QStringLiteral( "new_layer.shp" ) ), &enc, QgsProject::instance()->defaultCrsForNewLayers() ); + if ( !newFile.isEmpty() ) + { + context.messageBar()->pushSuccess( tr( "New ShapeFile" ), tr( "Created %2" ).arg( + QUrl::fromLocalFile( newFile ).toString(), QDir::toNativeSeparators( newFile ) ) ); + item->refresh(); + } + else if ( !error.isEmpty() ) + { + context.messageBar()->pushCritical( tr( "New ShapeFile" ), tr( "Layer creation failed: %1" ).arg( error ) ); + } + } ); + newMenu->addAction( createShp ); #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,6,0) - QAction *createFgdb = new QAction( tr( "ESRI FileGeodatabase…" ), newMenu ); - createFgdb->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewFileGeodatabase.svg" ) ) ); - connect( createFgdb, &QAction::triggered, this, [ = ] - { - QDir dir( directoryItem->dirPath() ); - QString newName = tr( "New File Geodatabase.gdb" ); - int i = 1; - while ( QFileInfo::exists( dir.absoluteFilePath( newName ) ) ) - { - i += 1; - newName = tr( "New File Geodatabase (%1).gdb" ).arg( i ); - } - - const QString fileName = dir.absoluteFilePath( newName ); - if ( QgsProviderMetadata *ogrMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) ) + QAction *createFgdb = new QAction( tr( "ESRI FileGeodatabase…" ), newMenu ); + createFgdb->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionNewFileGeodatabase.svg" ) ) ); + connect( createFgdb, &QAction::triggered, this, [ = ] { - QString error; - if ( ! ogrMetadata->createDatabase( fileName, error ) ) + QDir dir( directoryItem->dirPath() ); + QString newName = tr( "New File Geodatabase.gdb" ); + int i = 1; + while ( QFileInfo::exists( dir.absoluteFilePath( newName ) ) ) { - context.messageBar()->pushCritical( tr( "New ESRI File Geodatabase" ), tr( "Database creation failed: %1" ).arg( error ) ); + i += 1; + newName = tr( "New File Geodatabase (%1).gdb" ).arg( i ); } - else + + const QString fileName = dir.absoluteFilePath( newName ); + if ( QgsProviderMetadata *ogrMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ogr" ) ) ) { - QObject *contextObject = new QObject(); - connect( directoryItem, &QgsDataItem::stateChanged, contextObject, [contextObject, fileName, context]( QgsDataItem * item, Qgis::BrowserItemState ) + QString error; + if ( ! ogrMetadata->createDatabase( fileName, error ) ) + { + context.messageBar()->pushCritical( tr( "New ESRI File Geodatabase" ), tr( "Database creation failed: %1" ).arg( error ) ); + } + else { - if ( item->state() == Qgis::BrowserItemState::Populated ) + QObject *contextObject = new QObject(); + connect( directoryItem, &QgsDataItem::stateChanged, contextObject, [contextObject, fileName, context]( QgsDataItem * item, Qgis::BrowserItemState ) { - // find the new item and select it - const QVector children = item->children(); - for ( QgsDataItem *child : children ) + if ( item->state() == Qgis::BrowserItemState::Populated ) { - if ( child->path() == fileName ) + // find the new item and select it + const QVector children = item->children(); + for ( QgsDataItem *child : children ) { - if ( QgsBrowserTreeView *view = context.view() ) + if ( child->path() == fileName ) { - if ( view->setSelectedItem( child ) ) - view->edit( view->currentIndex() ); + if ( QgsBrowserTreeView *view = context.view() ) + { + if ( view->setSelectedItem( child ) ) + view->edit( view->currentIndex() ); + } + break; } - break; } + contextObject->deleteLater(); } - contextObject->deleteLater(); - } - } ); - directoryItem->refresh(); + } ); + directoryItem->refresh(); + } } - } - } ); - newMenu->addAction( createFgdb ); + } ); + newMenu->addAction( createFgdb ); #endif - menu->addMenu( newMenu ); + menu->addMenu( newMenu ); - menu->addSeparator(); + menu->addSeparator(); - bool inFavDirs = item->parent() && item->parent()->type() == Qgis::BrowserItemType::Favorites; - if ( item->parent() && !inFavDirs ) - { - // only non-root directories can be added as favorites - QAction *addAsFavorite = new QAction( tr( "Add as a Favorite" ), menu ); - addAsFavorite->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFavorites.svg" ) ) ); - menu->addAction( addAsFavorite ); - connect( addAsFavorite, &QAction::triggered, this, [ = ] - { - addFavorite( directoryItem ); - } ); - } - else if ( inFavDirs ) - { - if ( QgsFavoriteItem *favoriteItem = qobject_cast< QgsFavoriteItem * >( item ) ) + if ( item->parent() && !inFavDirs ) { - QAction *actionRename = new QAction( tr( "Rename Favorite…" ), menu ); - connect( actionRename, &QAction::triggered, this, [ = ] + // only non-root directories can be added as favorites + QAction *addAsFavorite = new QAction( tr( "Add as a Favorite" ), menu ); + addAsFavorite->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFavorites.svg" ) ) ); + menu->addAction( addAsFavorite ); + connect( addAsFavorite, &QAction::triggered, this, [ = ] { - renameFavorite( favoriteItem ); + addFavorite( directoryItem ); } ); - menu->addAction( actionRename ); + } + else if ( inFavDirs ) + { + QgsDebugMsgLevel( QStringLiteral( "inFavDirs" ), 3 ); + if ( QgsFavoriteItem *favoriteItem = qobject_cast< QgsFavoriteItem * >( item ) ) + { + QgsDebugMsgLevel( QStringLiteral( "QgsFavoriteItem" ), 3 ); + QAction *actionRename = new QAction( tr( "Rename Favorite…" ), menu ); + connect( actionRename, &QAction::triggered, this, [ = ] + { + renameFavorite( favoriteItem ); + } ); + menu->addAction( actionRename ); - QAction *removeFavoriteAction = new QAction( tr( "Remove Favorite" ), menu ); - connect( removeFavoriteAction, &QAction::triggered, this, [ = ] + QAction *removeFavoriteAction = new QAction( tr( "Remove Favorite" ), menu ); + connect( removeFavoriteAction, &QAction::triggered, this, [ = ] + { + removeFavorite( favoriteItem ); + } ); + menu->addAction( removeFavoriteAction ); + menu->addSeparator(); + } + } + QAction *hideAction = new QAction( tr( "Hide from Browser" ), menu ); + connect( hideAction, &QAction::triggered, this, [ = ] + { + hideDirectory( directoryItem ); + } ); + menu->addAction( hideAction ); + + QMenu *hiddenMenu = new QMenu( tr( "Hidden Items" ), menu ); + int count = 0; + const QStringList hiddenPathList = settings.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); + static int MAX_HIDDEN_ENTRIES = 5; + for ( const QString &path : hiddenPathList ) + { + QAction *action = new QAction( QDir::toNativeSeparators( path ), hiddenMenu ); + connect( action, &QAction::triggered, this, [ = ] { - removeFavorite( favoriteItem ); + QgsSettings s; + QStringList pathsList = s.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); + pathsList.removeAll( path ); + s.setValue( QStringLiteral( "/browser/hiddenPaths" ), pathsList ); + + // get parent path and refresh corresponding node + int idx = path.lastIndexOf( QLatin1Char( '/' ) ); + if ( idx != -1 && path.count( QStringLiteral( "/" ) ) > 1 ) + { + QString parentPath = path.left( idx ); + QgisApp::instance()->browserModel()->refresh( parentPath ); + } + else + { + // top-level (drive or root) node + QgisApp::instance()->browserModel()->refreshDrives(); + } } ); - menu->addAction( removeFavoriteAction ); - menu->addSeparator(); + hiddenMenu->addAction( action ); + count += 1; + if ( count == MAX_HIDDEN_ENTRIES ) + { + break; + } } - } - QAction *hideAction = new QAction( tr( "Hide from Browser" ), menu ); - connect( hideAction, &QAction::triggered, this, [ = ] - { - hideDirectory( directoryItem ); - } ); - menu->addAction( hideAction ); - QMenu *hiddenMenu = new QMenu( tr( "Hidden Items" ), menu ); - int count = 0; - const QStringList hiddenPathList = settings.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); - static int MAX_HIDDEN_ENTRIES = 5; - for ( const QString &path : hiddenPathList ) - { - QAction *action = new QAction( QDir::toNativeSeparators( path ), hiddenMenu ); - connect( action, &QAction::triggered, this, [ = ] + if ( hiddenPathList.size() > MAX_HIDDEN_ENTRIES ) { - QgsSettings s; - QStringList pathsList = s.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); - pathsList.removeAll( path ); - s.setValue( QStringLiteral( "/browser/hiddenPaths" ), pathsList ); + hiddenMenu->addSeparator(); - // get parent path and refresh corresponding node - int idx = path.lastIndexOf( QLatin1Char( '/' ) ); - if ( idx != -1 && path.count( QStringLiteral( "/" ) ) > 1 ) - { - QString parentPath = path.left( idx ); - QgisApp::instance()->browserModel()->refresh( parentPath ); - } - else + QAction *moreAction = new QAction( tr( "Show More…" ), hiddenMenu ); + connect( moreAction, &QAction::triggered, this, [ = ] { - // top-level (drive or root) node - QgisApp::instance()->browserModel()->refreshDrives(); - } + QgisApp::instance()->showOptionsDialog( QgisApp::instance(), QStringLiteral( "mOptionsPageDataSources" ) ); + } ); + hiddenMenu->addAction( moreAction ); + } + if ( count > 0 ) + { + menu->addMenu( hiddenMenu ); + } + + QAction *actionSetIconColor = new QAction( tr( "Set Color…" ), menu ); + if ( directoryItem->iconColor().isValid() ) + { + const QPixmap icon = QgsColorButton::createMenuIcon( directoryItem->iconColor(), true ); + actionSetIconColor->setIcon( icon ); + } + connect( actionSetIconColor, &QAction::triggered, this, [ = ] + { + changeDirectoryColor( directoryItem ); } ); - hiddenMenu->addAction( action ); - count += 1; - if ( count == MAX_HIDDEN_ENTRIES ) + menu->addAction( actionSetIconColor ); + if ( directoryItem->iconColor().isValid() ) { - break; + QAction *actionClearIconColor = new QAction( tr( "Clear Custom Color" ), menu ); + connect( actionClearIconColor, &QAction::triggered, this, [ = ] + { + clearDirectoryColor( directoryItem ); + } ); + menu->addAction( actionClearIconColor ); } - } - if ( hiddenPathList.size() > MAX_HIDDEN_ENTRIES ) - { - hiddenMenu->addSeparator(); + QMenu *scanningMenu = new QMenu( tr( "Scanning" ), menu ); - QAction *moreAction = new QAction( tr( "Show More…" ), hiddenMenu ); - connect( moreAction, &QAction::triggered, this, [ = ] + QAction *monitorAction = new QAction( tr( "Monitor for Changes" ), scanningMenu ); + connect( monitorAction, &QAction::triggered, this, [ = ] { - QgisApp::instance()->showOptionsDialog( QgisApp::instance(), QStringLiteral( "mOptionsPageDataSources" ) ); + toggleMonitor( directoryItem ); } ); - hiddenMenu->addAction( moreAction ); - } - if ( count > 0 ) - { - menu->addMenu( hiddenMenu ); - } + monitorAction->setCheckable( true ); + monitorAction->setChecked( directoryItem->isMonitored() ); + scanningMenu->addAction( monitorAction ); - QAction *actionSetIconColor = new QAction( tr( "Set Color…" ), menu ); - if ( directoryItem->iconColor().isValid() ) - { - const QPixmap icon = QgsColorButton::createMenuIcon( directoryItem->iconColor(), true ); - actionSetIconColor->setIcon( icon ); - } - connect( actionSetIconColor, &QAction::triggered, this, [ = ] - { - changeDirectoryColor( directoryItem ); - } ); - menu->addAction( actionSetIconColor ); - if ( directoryItem->iconColor().isValid() ) - { - QAction *actionClearIconColor = new QAction( tr( "Clear Custom Color" ), menu ); - connect( actionClearIconColor, &QAction::triggered, this, [ = ] + QAction *fastScanAction = new QAction( tr( "Fast Scan this Directory" ), scanningMenu ); + connect( fastScanAction, &QAction::triggered, this, [ = ] { - clearDirectoryColor( directoryItem ); + toggleFastScan( directoryItem ); } ); - menu->addAction( actionClearIconColor ); - } - - QMenu *scanningMenu = new QMenu( tr( "Scanning" ), menu ); - - QAction *monitorAction = new QAction( tr( "Monitor for Changes" ), scanningMenu ); - connect( monitorAction, &QAction::triggered, this, [ = ] - { - toggleMonitor( directoryItem ); - } ); - monitorAction->setCheckable( true ); - monitorAction->setChecked( directoryItem->isMonitored() ); - scanningMenu->addAction( monitorAction ); + fastScanAction->setCheckable( true ); + fastScanAction->setChecked( settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ), + QStringList() ).toStringList().contains( item->path() ) ); - QAction *fastScanAction = new QAction( tr( "Fast Scan this Directory" ), scanningMenu ); - connect( fastScanAction, &QAction::triggered, this, [ = ] - { - toggleFastScan( directoryItem ); - } ); - fastScanAction->setCheckable( true ); - fastScanAction->setChecked( settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ), - QStringList() ).toStringList().contains( item->path() ) ); + scanningMenu->addAction( fastScanAction ); + menu->addMenu( scanningMenu ); - scanningMenu->addAction( fastScanAction ); - menu->addMenu( scanningMenu ); + menu->addSeparator(); - menu->addSeparator(); + QAction *openFolder = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mIconFolder.svg" ) ), tr( "Open Directory…" ), menu ); + connect( openFolder, &QAction::triggered, this, [ = ] + { + QDesktopServices::openUrl( QUrl::fromLocalFile( directoryItem->dirPath() ) ); + } ); + menu->addAction( openFolder ); - QAction *openFolder = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mIconFolder.svg" ) ), tr( "Open Directory…" ), menu ); - connect( openFolder, &QAction::triggered, this, [ = ] - { - QDesktopServices::openUrl( QUrl::fromLocalFile( directoryItem->dirPath() ) ); - } ); - menu->addAction( openFolder ); + if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeOpenTerminalAtPath ) + { + QAction *openTerminal = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionTerminal.svg" ) ), tr( "Open in Terminal…" ), menu ); + connect( openTerminal, &QAction::triggered, this, [ = ] + { + QgsGui::nativePlatformInterface()->openTerminalAtPath( directoryItem->dirPath() ); + } ); + menu->addAction( openTerminal ); + menu->addSeparator(); + } - if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeOpenTerminalAtPath ) - { - QAction *openTerminal = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionTerminal.svg" ) ), tr( "Open in Terminal…" ), menu ); - connect( openTerminal, &QAction::triggered, this, [ = ] + QAction *propertiesAction = new QAction( tr( "Properties…" ), menu ); + connect( propertiesAction, &QAction::triggered, this, [ = ] { - QgsGui::nativePlatformInterface()->openTerminalAtPath( directoryItem->dirPath() ); + showProperties( directoryItem, context ); } ); - menu->addAction( openTerminal ); - menu->addSeparator(); - } + menu->addAction( propertiesAction ); - QAction *propertiesAction = new QAction( tr( "Properties…" ), menu ); - connect( propertiesAction, &QAction::triggered, this, [ = ] - { - showProperties( directoryItem, context ); - } ); - menu->addAction( propertiesAction ); - - if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog ) + if ( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeFilePropertiesDialog ) + { + if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item ) ) + { + QAction *action = menu->addAction( tr( "Directory Properties…" ) ); + connect( action, &QAction::triggered, dirItem, [ dirItem ] + { + QgsGui::nativePlatformInterface()->showFileProperties( dirItem->dirPath() ); + } ); + } + } + } + else if ( inFavDirs ) { - if ( QgsDirectoryItem *dirItem = qobject_cast< QgsDirectoryItem * >( item ) ) + QgsDebugMsgLevel( QStringLiteral( "inFavDirs 2" ), 3 ); + if ( QgsFavoriteItem *favoriteItem = qobject_cast< QgsFavoriteItem * >( item ) ) { - QAction *action = menu->addAction( tr( "Directory Properties…" ) ); - connect( action, &QAction::triggered, dirItem, [ dirItem ] + QgsDebugMsgLevel( QStringLiteral( "QgsFavoriteItem 2" ), 3 ); + QAction *actionRename = new QAction( tr( "Rename Favorite…" ), menu ); + connect( actionRename, &QAction::triggered, this, [ = ] { - QgsGui::nativePlatformInterface()->showFileProperties( dirItem->dirPath() ); + renameFavorite( favoriteItem ); } ); + menu->addAction( actionRename ); + + QAction *removeFavoriteAction = new QAction( tr( "Remove Favorite" ), menu ); + connect( removeFavoriteAction, &QAction::triggered, this, [ = ] + { + removeFavorite( favoriteItem ); + } ); + menu->addAction( removeFavoriteAction ); + menu->addSeparator(); } } }