Skip to content

Commit 3e0a3d1

Browse files
author
telwertowski
committed
Improve insertion of plugins into plugin menu. Allow any number of items 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
1 parent 2030245 commit 3e0a3d1

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

src/app/qgisapp.cpp

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,15 +1162,8 @@ void QgisApp::createMenus()
11621162
mPluginMenu = menuBar()->addMenu( tr( "&Plugins" ) );
11631163

11641164
mPluginMenu->addAction( mActionManagePlugins );
1165-
mActionPluginSeparator1 = mPluginMenu->addSeparator();
1166-
1167-
// Add the plugin manager action to it
1168-
//actionPluginManager->addTo(mPluginMenu);
1169-
// Add separator. Plugins will add their menus to this
1170-
// menu when they are loaded by the plugin manager
1171-
//mPluginMenu->insertSeparator();
1172-
// Add to the menubar
1173-
//menuBar()->insertItem(tr("&Plugins"), mPluginMenu, -1, menuBar()->count() - 1);
1165+
mActionPluginSeparator1 = NULL; // plugin list separator will be created when the first plugin is loaded
1166+
mActionPluginSeparator2 = NULL; // python separator will be created only if python is found
11741167

11751168
#ifdef Q_WS_MAC
11761169
// Window Menu
@@ -3568,21 +3561,23 @@ void QgisApp::bringAllToFront()
35683561
#endif
35693562
}
35703563

3571-
#ifdef Q_WS_MAC
35723564
void QgisApp::addWindow( QAction *action )
35733565
{
3566+
#ifdef Q_WS_MAC
35743567
mWindowActions->addAction( action );
35753568
mWindowMenu->addAction( action );
35763569
action->setCheckable( true );
35773570
action->setChecked( true );
3571+
#endif
35783572
}
35793573

35803574
void QgisApp::removeWindow( QAction *action )
35813575
{
3576+
#ifdef Q_WS_MAC
35823577
mWindowActions->removeAction( action );
35833578
mWindowMenu->removeAction( action );
3584-
}
35853579
#endif
3580+
}
35863581

35873582
void QgisApp::stopRendering()
35883583
{
@@ -4193,9 +4188,10 @@ void QgisApp::loadPythonSupport()
41934188

41944189
if ( mPythonUtils && mPythonUtils->isEnabled() )
41954190
{
4196-
mActionShowPythonDialog = new QAction( tr( "Python console" ), this );
4191+
mActionShowPythonDialog = new QAction( tr( "Python Console" ), this );
41974192
connect( mActionShowPythonDialog, SIGNAL( triggered() ), this, SLOT( showPythonDialog() ) );
41984193

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

@@ -4729,32 +4725,38 @@ void QgisApp::whatsThis()
47294725

47304726
QMenu* QgisApp::getPluginMenu( QString menuName )
47314727
{
4732-
// This is going to record the menu item that the potentially new
4733-
// menu item is going to be inserted before. A value of 0 will a new
4734-
// menu item to be appended.
4735-
QAction* before = 0;
4736-
4737-
QList<QAction*> actions = mPluginMenu->actions();
4738-
// Avoid 1 because the first item (number 0) is 'Plugin Manager',
4739-
// which we want to stay first. Search in reverse order as that
4740-
// makes it easier to find out where which item a new menu item
4741-
// should go before (since the insertMenu() function requires a
4742-
// 'before' argument).
4743-
for ( unsigned int i = actions.count() - 1; i > 0; --i )
4744-
{
4745-
if ( actions.at( i )->text() == menuName )
4728+
/* Plugin menu items are below the plugin separator (which may not exist yet
4729+
* if no plugins are loaded) and above the python separator. If python is not
4730+
* present, there is no python separator and the plugin list is at the bottom
4731+
* of the menu.
4732+
*/
4733+
QAction *before = mActionPluginSeparator2; // python separator or end of list
4734+
if ( !mActionPluginSeparator1 )
4735+
{
4736+
// First plugin - create plugin list separator
4737+
mActionPluginSeparator1 = mPluginMenu->insertSeparator( before );
4738+
}
4739+
else
4740+
{
4741+
// Plugins exist - search between plugin separator and python separator or end of list
4742+
QList<QAction*> actions = mPluginMenu->actions();
4743+
int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
4744+
for ( int i = actions.indexOf( mActionPluginSeparator1 ) + 1; i < end; i++ )
47464745
{
4747-
return actions.at( i )->menu();
4746+
int comp = menuName.localeAwareCompare( actions.at( i )->text() );
4747+
if ( comp < 0 )
4748+
{
4749+
// Add item before this one
4750+
before = actions.at( i );
4751+
break;
4752+
}
4753+
else if ( comp == 0 )
4754+
{
4755+
// Plugin menu item already exists
4756+
return actions.at( i )->menu();
4757+
}
47484758
}
4749-
// Find out where to put the menu item, assuming that it is a new one
4750-
//
4751-
// This bit of code assumes that the menu items are already in
4752-
// alphabetical order, which they will be if the menus are all
4753-
// created using this function.
4754-
if ( menuName.localeAwareCompare( actions.at( i )->text() ) <= 0 )
4755-
before = actions.at( i );
47564759
}
4757-
47584760
// It doesn't exist, so create
47594761
QMenu* menu = new QMenu( menuName, this );
47604762
// Where to put it? - we worked that out above...
@@ -4777,6 +4779,14 @@ void QgisApp::removePluginMenu( QString name, QAction* action )
47774779
{
47784780
mPluginMenu->removeAction( menu->menuAction() );
47794781
}
4782+
// Remove separator above plugins in Plugin menu if no plugins remain
4783+
QList<QAction*> actions = mPluginMenu->actions();
4784+
int end = mActionPluginSeparator2 ? actions.indexOf( mActionPluginSeparator2 ) : actions.count();
4785+
if ( actions.indexOf( mActionPluginSeparator1 ) + 1 == end )
4786+
{
4787+
mPluginMenu->removeAction( mActionPluginSeparator1 );
4788+
mActionPluginSeparator1 = NULL;
4789+
}
47804790
}
47814791

47824792
int QgisApp::addPluginToolBarIcon( QAction * qAction )

src/app/qgisapp.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ class QgisApp : public QMainWindow
180180
* parent class, it will also add it to the View menu list of toolbars.*/
181181
QToolBar *addToolBar( QString name );
182182

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

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

261261
QAction *actionManagePlugins() { return mActionManagePlugins; }
262262
QAction *actionPluginSeparator1() { return mActionPluginSeparator1; }
263+
QAction *actionPluginListSeparator() { return mActionPluginSeparator1; }
264+
QAction *actionPluginSeparator2() { return mActionPluginSeparator2; }
265+
QAction *actionPluginPythonSeparator() { return mActionPluginSeparator2; }
263266
QAction *actionShowPythonDialog() { return mActionShowPythonDialog; }
264267

265268
QAction *actionToggleFullScreen() { return mActionToggleFullScreen; }
@@ -290,7 +293,11 @@ class QgisApp : public QMainWindow
290293
QMenu *settingsMenu() { return mSettingsMenu; }
291294
QMenu *pluginMenu() { return mPluginMenu; }
292295
#ifdef Q_WS_MAC
296+
QMenu *firstRightStandardMenu() { return mWindowMenu; }
293297
QMenu *windowMenu() { return mWindowMenu; }
298+
#else
299+
QMenu *firstRightStandardMenu() { return mHelpMenu; }
300+
QMenu *windowMenu() { return NULL; }
294301
#endif
295302
QMenu *helpMenu() { return mHelpMenu; }
296303

@@ -718,6 +725,7 @@ class QgisApp : public QMainWindow
718725

719726
QAction *mActionManagePlugins;
720727
QAction *mActionPluginSeparator1;
728+
QAction *mActionPluginSeparator2;
721729
QAction *mActionShowPythonDialog;
722730

723731
QAction *mActionToggleFullScreen;

0 commit comments

Comments
 (0)