@@ -1162,15 +1162,8 @@ void QgisApp::createMenus()
1162
1162
mPluginMenu = menuBar ()->addMenu ( tr ( " &Plugins" ) );
1163
1163
1164
1164
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
1174
1167
1175
1168
#ifdef Q_WS_MAC
1176
1169
// Window Menu
@@ -3568,21 +3561,23 @@ void QgisApp::bringAllToFront()
3568
3561
#endif
3569
3562
}
3570
3563
3571
- #ifdef Q_WS_MAC
3572
3564
void QgisApp::addWindow ( QAction *action )
3573
3565
{
3566
+ #ifdef Q_WS_MAC
3574
3567
mWindowActions ->addAction ( action );
3575
3568
mWindowMenu ->addAction ( action );
3576
3569
action->setCheckable ( true );
3577
3570
action->setChecked ( true );
3571
+ #endif
3578
3572
}
3579
3573
3580
3574
void QgisApp::removeWindow ( QAction *action )
3581
3575
{
3576
+ #ifdef Q_WS_MAC
3582
3577
mWindowActions ->removeAction ( action );
3583
3578
mWindowMenu ->removeAction ( action );
3584
- }
3585
3579
#endif
3580
+ }
3586
3581
3587
3582
void QgisApp::stopRendering ()
3588
3583
{
@@ -4193,9 +4188,10 @@ void QgisApp::loadPythonSupport()
4193
4188
4194
4189
if ( mPythonUtils && mPythonUtils ->isEnabled () )
4195
4190
{
4196
- mActionShowPythonDialog = new QAction ( tr ( " Python console " ), this );
4191
+ mActionShowPythonDialog = new QAction ( tr ( " Python Console " ), this );
4197
4192
connect ( mActionShowPythonDialog , SIGNAL ( triggered () ), this , SLOT ( showPythonDialog () ) );
4198
4193
4194
+ mActionPluginSeparator2 = mPluginMenu ->addSeparator ();
4199
4195
mPluginMenu ->addAction ( mActionShowPythonDialog );
4200
4196
std::cout << " Python support ENABLED :-) " << std::endl; // OK
4201
4197
@@ -4729,32 +4725,38 @@ void QgisApp::whatsThis()
4729
4725
4730
4726
QMenu* QgisApp::getPluginMenu ( QString menuName )
4731
4727
{
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++ )
4746
4745
{
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
+ }
4748
4758
}
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 );
4756
4759
}
4757
-
4758
4760
// It doesn't exist, so create
4759
4761
QMenu* menu = new QMenu ( menuName, this );
4760
4762
// Where to put it? - we worked that out above...
@@ -4777,6 +4779,14 @@ void QgisApp::removePluginMenu( QString name, QAction* action )
4777
4779
{
4778
4780
mPluginMenu ->removeAction ( menu->menuAction () );
4779
4781
}
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
+ }
4780
4790
}
4781
4791
4782
4792
int QgisApp::addPluginToolBarIcon ( QAction * qAction )
0 commit comments