Convert MENU_BROWSER_DEFAULTCONTEXT to xml

Change-Id: If59ecb4ea92d9daf423aef870e79248f5bc93e6d
This commit is contained in:
Maxim Monastirsky
2017-02-01 16:44:29 +02:00
parent 1028e5192c
commit 53be223421
14 changed files with 65 additions and 219 deletions
+1
View File
@@ -14,6 +14,7 @@ $(eval $(call gb_UIConfig_add_menubarfiles,modules/dbbrowser,\
))
$(eval $(call gb_UIConfig_add_popupmenufiles,modules/dbbrowser,\
dbaccess/uiconfig/dbbrowser/popupmenu/explorer \
dbaccess/uiconfig/dbbrowser/popupmenu/refreshdata \
))
-20
View File
@@ -32,8 +32,6 @@
#define HID_BROWSER_COLUMNWIDTH "DBACCESS_HID_BROWSER_COLUMNWIDTH"
#define HID_BROWSER_TABLEFORMAT "DBACCESS_HID_BROWSER_TABLEFORMAT"
#define HID_BROWSER_ROWHEIGHT "DBACCESS_HID_BROWSER_ROWHEIGHT"
#define HID_BROWSER_EDIT_DATABASE "DBACCESS_HID_BROWSER_EDIT_DATABASE"
#define HID_BROWSER_CLOSECONN "DBACCESS_HID_BROWSER_CLOSECONN"
#define HID_CTL_QRYSQLEDIT "DBACCESS_HID_CTL_QRYSQLEDIT"
@@ -124,24 +122,6 @@
#define HID_DBWIZ_CANCEL "DBACCESS_HID_DBWIZ_CANCEL"
#define HID_DBWIZ_FINISH "DBACCESS_HID_DBWIZ_FINISH"
#define HID_BROWSER_ADMINISTRATE "DBACCESS_HID_BROWSER_ADMINISTRATE"
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-5
View File
@@ -2281,11 +2281,6 @@ OUString OApplicationController::getContextMenuResourceName( Control& /*_rContro
return OUString("edit");
}
VclPtr<PopupMenu> OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
{
return nullptr;
}
IController& OApplicationController::getCommandController()
{
return *this;
+1 -2
View File
@@ -497,8 +497,7 @@ namespace dbaui
// IContextMenuProvider
virtual OUString getContextMenuResourceName( Control& _rControl ) const override;
virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const override;
virtual IController& getCommandController() override;
virtual IController& getCommandController() override;
virtual ::comphelper::OInterfaceContainerHelper2*
getContextMenuInterceptors() override;
virtual css::uno::Any
@@ -156,6 +156,10 @@ void SbaTableQueryBrowser::describeSupportedFeatures()
implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE );
if ( !m_bShowMenu )
{
implDescribeSupportedFeature( ".uno:DSBEditDB", ID_TREE_EDIT_DATABASE );
implDescribeSupportedFeature( ".uno:DSBCloseConnection", ID_TREE_CLOSE_CONN );
implDescribeSupportedFeature( ".uno:DSBAdministrate", ID_TREE_ADMINISTRATE );
implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW );
implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT );
-38
View File
@@ -55,44 +55,6 @@ String RID_STR_TABLES_CONTAINER
Text [ en-US ] = "Tables";
};
Menu MENU_BROWSER_DEFAULTCONTEXT
{
ItemList =
{
MenuItem
{
Identifier = ID_TREE_EDIT_DATABASE ;
HelpId = HID_BROWSER_EDIT_DATABASE ;
Text [ en-US ] = "Edit ~Database File..." ;
};
MenuItem
{
Identifier = ID_TREE_CLOSE_CONN ;
HelpId = HID_BROWSER_CLOSECONN ;
Text [ en-US ] = "Disco~nnect" ;
};
MenuItem
{
Separator = TRUE;
};
MenuItem {
Identifier = SID_COPY ;
Command = ".uno:Copy" ;
Text [ en-US ] = "~Copy" ;
};
MenuItem
{
Separator = TRUE;
};
MenuItem
{
Identifier = ID_TREE_ADMINISTRATE ;
HelpId = HID_BROWSER_ADMINISTRATE;
Text [ en-US ] = "Registered databases ..." ;
};
};
};
String STR_TITLE_CONFIRM_DELETION
{
Text [ en-US ] = "Confirm Deletion" ;
+4 -9
View File
@@ -3468,19 +3468,14 @@ bool SbaTableQueryBrowser::requestQuickHelp( const SvTreeListEntry* _pEntry, OUS
return false;
}
OUString SbaTableQueryBrowser::getContextMenuResourceName( Control& ) const
{
return OUString();
}
VclPtr<PopupMenu> SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
OUString SbaTableQueryBrowser::getContextMenuResourceName( Control& _rControl ) const
{
OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
"SbaTableQueryBrowser::getContextMenu: where does this come from?" );
"SbaTableQueryBrowser::getContextMenuResourceName: where does this come from?" );
if ( &m_pTreeView->getListBox() != &_rControl )
return nullptr;
return OUString();
return VclPtr<PopupMenu>::Create( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
return OUString("explorer");
}
IController& SbaTableQueryBrowser::getCommandController()
+18 -132
View File
@@ -33,7 +33,6 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <vcl/help.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <dbaccess/IController.hxx>
#include <framework/actiontriggerhelper.hxx>
#include <toolkit/awt/vclxmenu.hxx>
@@ -411,98 +410,6 @@ IMPL_LINK_NOARG( DBTreeListBox, ScrollDownHdl, LinkParamNone*, void )
namespace
{
void lcl_enableEntries( PopupMenu* _pPopup, IController& _rController )
{
if ( !_pPopup )
return;
sal_uInt16 nCount = _pPopup->GetItemCount();
for (sal_uInt16 i=0; i < nCount; ++i)
{
if ( _pPopup->GetItemType(i) != MenuItemType::SEPARATOR )
{
sal_uInt16 nId = _pPopup->GetItemId(i);
PopupMenu* pSubPopUp = _pPopup->GetPopupMenu(nId);
if ( pSubPopUp )
{
lcl_enableEntries( pSubPopUp, _rController );
_pPopup->EnableItem(nId,pSubPopUp->HasValidEntries());
}
else
{
OUString sCommandURL( _pPopup->GetItemCommand( nId ) );
bool bEnabled = sCommandURL.isEmpty()
? _rController.isCommandEnabled( nId )
: _rController.isCommandEnabled( sCommandURL );
_pPopup->EnableItem( nId, bEnabled );
}
}
}
_pPopup->RemoveDisabledEntries();
}
}
namespace
{
void lcl_adjustMenuItemIDs( Menu& _rMenu, IController& _rCommandController )
{
sal_uInt16 nCount = _rMenu.GetItemCount();
for ( sal_uInt16 pos = 0; pos < nCount; ++pos )
{
// do not adjust separators
if ( _rMenu.GetItemType( pos ) == MenuItemType::SEPARATOR )
continue;
sal_uInt16 nId = _rMenu.GetItemId(pos);
OUString aCommand = _rMenu.GetItemCommand( nId );
PopupMenu* pPopup = _rMenu.GetPopupMenu( nId );
if ( pPopup )
{
lcl_adjustMenuItemIDs( *pPopup, _rCommandController );
continue;
}
const sal_uInt16 nCommandId = _rCommandController.registerCommandURL( aCommand );
_rMenu.InsertItem( nCommandId, _rMenu.GetItemText( nId ), _rMenu.GetItemImage( nId ),
_rMenu.GetItemBits( nId ), OString(), pos );
// more things to preserve:
// - the help command
OUString sHelpURL = _rMenu.GetHelpCommand( nId );
if ( !sHelpURL.isEmpty() )
_rMenu.SetHelpCommand( nCommandId, sHelpURL );
// remove the "old" item
_rMenu.RemoveItem( pos+1 );
}
}
void lcl_insertMenuItemImages( Menu& _rMenu, IController& _rCommandController )
{
uno::Reference< frame::XController > xController = _rCommandController.getXController();
uno::Reference< frame::XFrame> xFrame;
if ( xController.is() )
xFrame = xController->getFrame();
sal_uInt16 nCount = _rMenu.GetItemCount();
for ( sal_uInt16 pos = 0; pos < nCount; ++pos )
{
// do not adjust separators
if ( _rMenu.GetItemType( pos ) == MenuItemType::SEPARATOR )
continue;
sal_uInt16 nId = _rMenu.GetItemId(pos);
OUString aCommand = _rMenu.GetItemCommand( nId );
PopupMenu* pPopup = _rMenu.GetPopupMenu( nId );
if ( pPopup )
{
lcl_insertMenuItemImages( *pPopup, _rCommandController );
continue;
}
if ( xFrame.is() )
_rMenu.SetItemImage(nId, vcl::CommandInfoProvider::Instance().GetImageForCommand(aCommand, xFrame));
}
}
// SelectionSupplier
typedef ::cppu::WeakImplHelper< XSelectionSupplier
> SelectionSupplier_Base;
@@ -554,51 +461,37 @@ namespace
VclPtr<PopupMenu> DBTreeListBox::CreateContextMenu()
{
VclPtr< PopupMenu > pContextMenu;
if ( !m_pContextMenuProvider )
return pContextMenu;
return nullptr;
OUString aResourceName( m_pContextMenuProvider->getContextMenuResourceName( *this ) );
OUString aMenuIdentifier;
if ( aResourceName.isEmpty() )
{
// the basic context menu
pContextMenu.reset( m_pContextMenuProvider->getContextMenu( *this ) );
// disable what is not available currently
lcl_enableEntries( pContextMenu.get(), m_pContextMenuProvider->getCommandController() );
// set images
lcl_insertMenuItemImages( *pContextMenu, m_pContextMenuProvider->getCommandController() );
}
else
{
css::uno::Sequence< css::uno::Any > aArgs( 3 );
aArgs[0] <<= comphelper::makePropertyValue( "Value", aResourceName );
aArgs[1] <<= comphelper::makePropertyValue( "Frame", m_pContextMenuProvider->getCommandController().getXController()->getFrame() );
aArgs[2] <<= comphelper::makePropertyValue( "IsContextMenu", true );
return nullptr;
css::uno::Reference< css::uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
m_xMenuController.set( xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext ), css::uno::UNO_QUERY );
css::uno::Sequence< css::uno::Any > aArgs( 3 );
aArgs[0] <<= comphelper::makePropertyValue( "Value", aResourceName );
aArgs[1] <<= comphelper::makePropertyValue( "Frame", m_pContextMenuProvider->getCommandController().getXController()->getFrame() );
aArgs[2] <<= comphelper::makePropertyValue( "IsContextMenu", true );
css::uno::Reference< css::awt::XPopupMenu > xPopupMenu( xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.awt.PopupMenu", xContext ), css::uno::UNO_QUERY );
css::uno::Reference< css::uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
m_xMenuController.set( xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext ), css::uno::UNO_QUERY );
if ( !m_xMenuController.is() || !xPopupMenu.is() )
return pContextMenu;
if ( !m_xMenuController.is() )
return nullptr;
m_xMenuController->setPopupMenu( xPopupMenu );
pContextMenu.reset( static_cast< PopupMenu* >( VCLXMenu::GetImplementation( xPopupMenu )->GetMenu() ) );
pContextMenu->AddEventListener( LINK( this, DBTreeListBox, MenuEventListener ) );
aMenuIdentifier = "private:resource/popupmenu/" + aResourceName;
}
rtl::Reference<VCLXPopupMenu> xPopupMenu( new VCLXPopupMenu );
m_xMenuController->setPopupMenu( xPopupMenu.get() );
VclPtr<PopupMenu> pContextMenu( static_cast< PopupMenu* >( xPopupMenu->GetMenu() ) );
pContextMenu->AddEventListener( LINK( this, DBTreeListBox, MenuEventListener ) );
// allow context menu interception
::comphelper::OInterfaceContainerHelper2* pInterceptors = m_pContextMenuProvider->getContextMenuInterceptors();
if ( !pInterceptors || !pInterceptors->getLength() )
return pContextMenu;
OUString aMenuIdentifier( "private:resource/popupmenu/" + aResourceName );
ContextMenuExecuteEvent aEvent;
aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
aEvent.ExecutePosition.X = -1;
@@ -654,20 +547,13 @@ VclPtr<PopupMenu> DBTreeListBox::CreateContextMenu()
::framework::ActionTriggerHelper::CreateMenuFromActionTriggerContainer(
pContextMenu, aEvent.ActionTriggerContainer );
aEvent.ActionTriggerContainer.clear();
// the interceptors only know command URLs, but our menus primarily work
// with IDs -> we need to translate the commands to IDs
if ( aResourceName.isEmpty() )
lcl_adjustMenuItemIDs( *pContextMenu, m_pContextMenuProvider->getCommandController() );
}
return pContextMenu;
}
void DBTreeListBox::ExecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry )
void DBTreeListBox::ExecuteContextMenuAction( sal_uInt16 )
{
if ( !m_xMenuController.is() && m_pContextMenuProvider && _nSelectedPopupEntry )
m_pContextMenuProvider->getCommandController().executeChecked( _nSelectedPopupEntry, Sequence< PropertyValue >() );
}
IMPL_LINK( DBTreeListBox, MenuEventListener, VclMenuEvent&, rMenuEvent, void )
-11
View File
@@ -71,20 +71,9 @@ namespace dbaui
/** returns the context menu resource name for the control
Supposed to be a valid name from uiconfig/<module>/popupmenu folder.
Nevertheless, the getContextMenu method will not be evaluated, as long
as this method returns non-empty string.
*/
virtual OUString getContextMenuResourceName( Control& _rControl ) const = 0;
/** returns the context menu for the control
Note that the menu does not need to care for the controls selection, or its
state in general.
The control itself will, using the controller provided by getCommandController,
disable menu entries as needed.
*/
virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const = 0;
/** returns the controller which is responsible for providing states of certain features,
and executing them.
*/
-1
View File
@@ -129,7 +129,6 @@
#define RID_QUERYFUNCTION_POPUPMENU RID_MENU_START + 6
#define RID_TABLEDESIGNROWPOPUPMENU RID_MENU_START + 7
#define RID_SBA_RTF_PKEYPOPUP RID_MENU_START + 9
#define MENU_BROWSER_DEFAULTCONTEXT RID_MENU_START + 14
#define RID_MENU_JOINVIEW_CONNECTION RID_MENU_START + 16
#define RID_MENU_JOINVIEW_TABLE RID_MENU_START + 17
-1
View File
@@ -233,7 +233,6 @@ namespace dbaui
// IContextMenuProvider
virtual OUString getContextMenuResourceName( Control& _rControl ) const override;
virtual VclPtr<PopupMenu> getContextMenu( Control& _rControl ) const override;
virtual IController& getCommandController() override;
virtual ::comphelper::OInterfaceContainerHelper2*
getContextMenuInterceptors() override;
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
-->
<menu:menupopup xmlns:menu="http://openoffice.org/2001/menu">
<menu:menuitem menu:id=".uno:DSBEditDB"/>
<menu:menuitem menu:id=".uno:DSBCloseConnection"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:Copy"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:DSBAdministrate"/>
</menu:menupopup>
@@ -3,6 +3,11 @@
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:install="http://openoffice.org/2004/installation" oor:name="DbBrowserWindowState" oor:package="org.openoffice.Office.UI">
<node oor:name="UIElements">
<node oor:name="States">
<node oor:name="private:resource/popupmenu/explorer" oor:op="replace">
<prop oor:name="UIName" oor:type="xs:string">
<value xml:lang="en-US">Explorer</value>
</prop>
</node>
<node oor:name="private:resource/toolbar/toolbar" oor:op="replace">
<prop oor:name="DockPos" oor:type="xs:string">
<value>0,1</value>
@@ -536,6 +536,21 @@
<value>1</value>
</prop>
</node>
<node oor:name=".uno:DSBEditDB" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Edit ~Database File...</value>
</prop>
</node>
<node oor:name=".uno:DSBCloseConnection" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Disco~nnect</value>
</prop>
</node>
<node oor:name=".uno:DSBAdministrate" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Registered databases ...</value>
</prop>
</node>
</node>
<node oor:name="Popups">
<node oor:name=".uno:DBDatabasePropertiesMenu" oor:op="replace">