Skip to content

Commit

Permalink
[FEATURE] allow manual addition of browser favorite directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Sep 25, 2012
1 parent 4c97806 commit 4247440
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QMenu>
#include <QSettings>
#include <QToolButton>
#include <QFileDialog>

#include "qgsbrowsermodel.h"
#include "qgsdataitem.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
if ( !item )
return;

QMenu* menu = new QMenu( this );
QMenu *menu = new QMenu( this );

if ( item->type() == QgsDataItem::Directory )
{
Expand All @@ -188,13 +189,19 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
// only favourites can be removed
menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) );
}
}

}
else if ( item->type() == QgsDataItem::Layer )
{
menu->addAction( tr( "Add Layer" ), this, SLOT( addCurrentLayer( ) ) );
menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) );
menu->addAction( tr( "Properties" ), this, SLOT( showProperties( ) ) );

}
else if ( item->type() == QgsDataItem::Favourites )
{
menu->addAction( tr( "Add a directory" ), this, SLOT( addFavouriteDirectory() ) );

}

QList<QAction*> actions = item->actions();
Expand All @@ -220,14 +227,27 @@ void QgsBrowserDockWidget::addFavourite()
QgsDataItem* item = mModel->dataItem( mBrowserView->currentIndex() );
if ( !item )
return;

if ( item->type() != QgsDataItem::Directory )
return;

QString newFavDir = item->path();
addFavouriteDirectory( item->path() );
}

void QgsBrowserDockWidget::addFavouriteDirectory()
{
QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favourites" ) );
if ( !directory.isEmpty() )
{
addFavouriteDirectory( directory );
}
}

void QgsBrowserDockWidget::addFavouriteDirectory( QString favDir )
{
QSettings settings;
QStringList favDirs = settings.value( "/browser/favourites" ).toStringList();
favDirs.append( newFavDir );
favDirs.append( favDir );
settings.setValue( "/browser/favourites", favDirs );

// reload the browser model so that the newly added favourite directory is shown
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsbrowserdockwidget.h
Expand Up @@ -35,6 +35,7 @@ class QgsBrowserDockWidget : public QDockWidget
void showContextMenu( const QPoint & );

void addFavourite();
void addFavouriteDirectory();
void removeFavourite();

void refresh();
Expand All @@ -45,6 +46,7 @@ class QgsBrowserDockWidget : public QDockWidget
void showProperties();

protected:
void addFavouriteDirectory( QString favDir );

void refreshModel( const QModelIndex& index );

Expand Down

0 comments on commit 4247440

Please sign in to comment.