Skip to content

Commit

Permalink
Improve insertion of plugins into plugin menu. Allow any number of it…
Browse files Browse the repository at this point in the history
…ems at top and start inserting below them but above the Python separator if it exists at the bottom.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9257 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Sep 5, 2008
1 parent 2030245 commit 3e0a3d1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
80 changes: 45 additions & 35 deletions src/app/qgisapp.cpp
Expand Up @@ -1162,15 +1162,8 @@ void QgisApp::createMenus()
mPluginMenu = menuBar()->addMenu( tr( "&Plugins" ) );

mPluginMenu->addAction( mActionManagePlugins );
mActionPluginSeparator1 = mPluginMenu->addSeparator();

// Add the plugin manager action to it
//actionPluginManager->addTo(mPluginMenu);
// Add separator. Plugins will add their menus to this
// menu when they are loaded by the plugin manager
//mPluginMenu->insertSeparator();
// Add to the menubar
//menuBar()->insertItem(tr("&Plugins"), mPluginMenu, -1, menuBar()->count() - 1);
mActionPluginSeparator1 = NULL; // plugin list separator will be created when the first plugin is loaded
mActionPluginSeparator2 = NULL; // python separator will be created only if python is found

#ifdef Q_WS_MAC
// Window Menu
Expand Down Expand Up @@ -3568,21 +3561,23 @@ void QgisApp::bringAllToFront()
#endif
}

#ifdef Q_WS_MAC
void QgisApp::addWindow( QAction *action )
{
#ifdef Q_WS_MAC
mWindowActions->addAction( action );
mWindowMenu->addAction( action );
action->setCheckable( true );
action->setChecked( true );
#endif
}

void QgisApp::removeWindow( QAction *action )
{
#ifdef Q_WS_MAC
mWindowActions->removeAction( action );
mWindowMenu->removeAction( action );
}
#endif
}

void QgisApp::stopRendering()
{
Expand Down Expand Up @@ -4193,9 +4188,10 @@ void QgisApp::loadPythonSupport()

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
mActionShowPythonDialog = new QAction( tr( "Python console" ), this );
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
connect( mActionShowPythonDialog, SIGNAL( triggered() ), this, SLOT( showPythonDialog() ) );

mActionPluginSeparator2 = mPluginMenu->addSeparator();
mPluginMenu->addAction( mActionShowPythonDialog );
std::cout << "Python support ENABLED :-) " << std::endl; // OK

Expand Down Expand Up @@ -4729,32 +4725,38 @@ void QgisApp::whatsThis()

QMenu* QgisApp::getPluginMenu( QString menuName )
{
// This is going to record the menu item that the potentially new
// menu item is going to be inserted before. A value of 0 will a new
// menu item to be appended.
QAction* before = 0;

QList<QAction*> actions = mPluginMenu->actions();
// Avoid 1 because the first item (number 0) is 'Plugin Manager',
// which we want to stay first. Search in reverse order as that
// makes it easier to find out where which item a new menu item
// should go before (since the insertMenu() function requires a
// 'before' argument).
for ( unsigned int i = actions.count() - 1; i > 0; --i )
{
if ( actions.at( i )->text() == menuName )
/* Plugin menu items are below the plugin separator (which may not exist yet
* if no plugins are loaded) and above the python separator. If python is not
* present, there is no python separator and the plugin list is at the bottom
* of the menu.
*/
QAction *before = mActionPluginSeparator2; // python separator or end of list
if ( !mActionPluginSeparator1 )
{
// First plugin - create plugin list separator
mActionPluginSeparator1 = mPluginMenu->insertSeparator( before );
}
else
{
// Plugins exist - search between plugin separator and python separator or end of list
QList<QAction*> actions = mPluginMenu->actions();
int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
for ( int i = actions.indexOf( mActionPluginSeparator1 ) + 1; i < end; i++ )
{
return actions.at( i )->menu();
int comp = menuName.localeAwareCompare( actions.at( i )->text() );
if ( comp < 0 )
{
// Add item before this one
before = actions.at( i );
break;
}
else if ( comp == 0 )
{
// Plugin menu item already exists
return actions.at( i )->menu();
}
}
// Find out where to put the menu item, assuming that it is a new one
//
// This bit of code assumes that the menu items are already in
// alphabetical order, which they will be if the menus are all
// created using this function.
if ( menuName.localeAwareCompare( actions.at( i )->text() ) <= 0 )
before = actions.at( i );
}

// It doesn't exist, so create
QMenu* menu = new QMenu( menuName, this );
// Where to put it? - we worked that out above...
Expand All @@ -4777,6 +4779,14 @@ void QgisApp::removePluginMenu( QString name, QAction* action )
{
mPluginMenu->removeAction( menu->menuAction() );
}
// Remove separator above plugins in Plugin menu if no plugins remain
QList<QAction*> actions = mPluginMenu->actions();
int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
if ( actions.indexOf( mActionPluginSeparator1 ) + 1 == end )
{
mPluginMenu->removeAction( mActionPluginSeparator1 );
mActionPluginSeparator1 = NULL;
}
}

int QgisApp::addPluginToolBarIcon( QAction * qAction )
Expand Down
16 changes: 12 additions & 4 deletions src/app/qgisapp.h
Expand Up @@ -180,12 +180,12 @@ class QgisApp : public QMainWindow
* parent class, it will also add it to the View menu list of toolbars.*/
QToolBar *addToolBar( QString name );

#ifdef Q_WS_MAC
//! Add window item to Window menu
/** Add window to Window menu. The action title is the window title
* and the action should raise, unminimize and activate the window. */
void addWindow( QAction *action );
//! Remove window item from Window menu
/** Remove window from Window menu. Calling this is necessary only for
* windows which are hidden rather than deleted when closed. */
void removeWindow( QAction *action );
#endif

//! Actions to be inserted in menus and toolbars
QAction *actionNewProject() { return mActionNewProject; }
Expand Down Expand Up @@ -260,6 +260,9 @@ class QgisApp : public QMainWindow

QAction *actionManagePlugins() { return mActionManagePlugins; }
QAction *actionPluginSeparator1() { return mActionPluginSeparator1; }
QAction *actionPluginListSeparator() { return mActionPluginSeparator1; }
QAction *actionPluginSeparator2() { return mActionPluginSeparator2; }
QAction *actionPluginPythonSeparator() { return mActionPluginSeparator2; }
QAction *actionShowPythonDialog() { return mActionShowPythonDialog; }

QAction *actionToggleFullScreen() { return mActionToggleFullScreen; }
Expand Down Expand Up @@ -290,7 +293,11 @@ class QgisApp : public QMainWindow
QMenu *settingsMenu() { return mSettingsMenu; }
QMenu *pluginMenu() { return mPluginMenu; }
#ifdef Q_WS_MAC
QMenu *firstRightStandardMenu() { return mWindowMenu; }
QMenu *windowMenu() { return mWindowMenu; }
#else
QMenu *firstRightStandardMenu() { return mHelpMenu; }
QMenu *windowMenu() { return NULL; }
#endif
QMenu *helpMenu() { return mHelpMenu; }

Expand Down Expand Up @@ -718,6 +725,7 @@ class QgisApp : public QMainWindow

QAction *mActionManagePlugins;
QAction *mActionPluginSeparator1;
QAction *mActionPluginSeparator2;
QAction *mActionShowPythonDialog;

QAction *mActionToggleFullScreen;
Expand Down

0 comments on commit 3e0a3d1

Please sign in to comment.