summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2015-11-07 22:01:20 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2015-11-11 15:43:36 +0200
commitc65e00d908a2dcf47d3ff925d09e336d9b0939f7 (patch)
tree1d015ff5e376c0298825b44d6443187671be4166
parent899453aa8407fca8a93d51f12ad4e335d1beeb62 (diff)
tdf#93837 Make customization actually work
Change-Id: I004c9ad3a7d389228b9bb532a1b2c5d6294f7e42
-rw-r--r--cui/source/customize/cfg.cxx215
-rw-r--r--cui/source/inc/cfg.hxx45
2 files changed, 240 insertions, 20 deletions
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index ba0829fa0bf1..94912286a906 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -775,6 +775,25 @@ bool showKeyConfigTabPage( const css::uno::Reference< css::frame::XFrame >& xFra
&& sModuleId != "com.sun.star.frame.StartModule";
}
+bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
+{
+ return a->GetName().compareTo( b->GetName() ) < 0;
+}
+
+bool SvxConfigEntryModified( SvxConfigEntry* pEntry )
+{
+ SvxEntries* pEntries = pEntry->GetEntries();
+ if ( !pEntries )
+ return false;
+
+ for ( const auto& entry : *pEntries )
+ {
+ if ( entry->IsModified() || SvxConfigEntryModified( entry ) )
+ return true;
+ }
+ return false;
+}
+
}
/******************************************************************************
@@ -1071,7 +1090,7 @@ MenuSaveInData::SetEntries( SvxEntries* pNewEntries )
pRootEntry->SetEntries( pNewEntries );
}
-bool MenuSaveInData::LoadSubMenus(
+bool SaveInData::LoadSubMenus(
const uno::Reference< container::XIndexAccess >& xMenuSettings,
const OUString& rBaseTitle,
SvxConfigEntry* pParentData )
@@ -1111,7 +1130,7 @@ bool MenuSaveInData::LoadSubMenus(
// If custom label not set retrieve it from the command
// to info service
- if ( aLabel.equals( OUString() ) )
+ if ( aLabel.isEmpty() )
{
uno::Sequence< beans::PropertyValue > aPropSeq;
if ( a >>= aPropSeq )
@@ -1257,7 +1276,7 @@ void MenuSaveInData::Apply(
}
}
-void MenuSaveInData::ApplyMenu(
+void SaveInData::ApplyMenu(
uno::Reference< container::XIndexContainer >& rMenuBar,
uno::Reference< lang::XSingleComponentFactory >& rFactory,
SvxConfigEntry* pMenuData )
@@ -1282,13 +1301,14 @@ void MenuSaveInData::ApplyMenu(
sal_Int32 nIndex = aPropValueSeq.getLength();
aPropValueSeq.realloc( nIndex + 1 );
- aPropValueSeq[nIndex].Name = m_aDescriptorContainer;
+ aPropValueSeq[nIndex].Name = ITEM_DESCRIPTOR_CONTAINER;
aPropValueSeq[nIndex].Value <<= xSubMenuBar;
rMenuBar->insertByIndex(
rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
ApplyMenu( xSubMenuBar, rFactory, pEntry );
+ pEntry->SetModified( false );
}
else if ( pEntry->IsSeparator() )
{
@@ -1303,6 +1323,7 @@ void MenuSaveInData::ApplyMenu(
rMenuBar->getCount(), uno::makeAny( aPropValueSeq ));
}
}
+ pMenuData->SetModified( false );
}
void
@@ -1324,6 +1345,177 @@ MenuSaveInData::Reset()
}
}
+ContextMenuSaveInData::ContextMenuSaveInData(
+ const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
+ const css::uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
+ const OUString& aModuleId, bool bIsDocConfig )
+ : SaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bIsDocConfig )
+{
+}
+
+ContextMenuSaveInData::~ContextMenuSaveInData()
+{
+}
+
+SvxEntries* ContextMenuSaveInData::GetEntries()
+{
+ if ( !m_pRootEntry )
+ {
+ typedef std::unordered_map< OUString, bool, OUStringHash, std::equal_to< OUString > > MenuInfo;
+ MenuInfo aMenuInfo;
+
+ m_pRootEntry.reset( new SvxConfigEntry( "ContextMenus", OUString(), true ) );
+ css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aElementsInfo;
+ try
+ {
+ aElementsInfo = GetConfigManager()->getUIElementsInfo( css::ui::UIElementType::POPUPMENU );
+ }
+ catch ( const css::lang::IllegalArgumentException& )
+ {}
+
+ for ( const auto& aElement : aElementsInfo )
+ {
+ OUString aUrl;
+ for ( const auto& aElementProp : aElement )
+ {
+ if ( aElementProp.Name == ITEM_DESCRIPTOR_RESOURCEURL )
+ aElementProp.Value >>= aUrl;
+ }
+
+ css::uno::Reference< css::container::XIndexAccess > xPopupMenu;
+ try
+ {
+ xPopupMenu = GetConfigManager()->getSettings( aUrl, sal_False );
+ }
+ catch ( const css::uno::Exception& )
+ {}
+
+ if ( xPopupMenu.is() )
+ {
+ OUString aMenuName = aUrl.copy( aUrl.lastIndexOf( '/' ) + 1 );
+
+ // insert into std::unordered_map to filter duplicates from the parent
+ aMenuInfo.insert( MenuInfo::value_type( aMenuName, true ) );
+
+ SvxConfigEntry* pEntry = new SvxConfigEntry( aMenuName, aUrl, true );
+ pEntry->SetMain();
+ m_pRootEntry->GetEntries()->push_back( pEntry );
+ LoadSubMenus( xPopupMenu, aMenuName, pEntry );
+ }
+ }
+
+ // Retrieve also the parent menus, to make it possible to configure module menus and save them into the document.
+ css::uno::Reference< css::ui::XUIConfigurationManager > xParentCfgMgr = GetParentConfigManager();
+ css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aParentElementsInfo;
+ try
+ {
+ if ( xParentCfgMgr.is() )
+ aParentElementsInfo = xParentCfgMgr->getUIElementsInfo( css::ui::UIElementType::POPUPMENU );
+ }
+ catch ( const css::lang::IllegalArgumentException& )
+ {}
+
+ for ( const auto& aElement : aParentElementsInfo )
+ {
+ OUString aUrl, aMenuName;
+ for ( const auto& aElementProp : aElement )
+ {
+ if ( aElementProp.Name == ITEM_DESCRIPTOR_RESOURCEURL )
+ {
+ aElementProp.Value >>= aUrl;
+ aMenuName = aUrl.copy( aUrl.lastIndexOf( '/' ) + 1 );
+ }
+ }
+
+ css::uno::Reference< css::container::XIndexAccess > xPopupMenu;
+ try
+ {
+ if ( aMenuInfo.find( aMenuName ) == aMenuInfo.end() )
+ xPopupMenu = xParentCfgMgr->getSettings( aUrl, sal_False );
+ }
+ catch ( const css::uno::Exception& )
+ {}
+
+ if ( xPopupMenu.is() )
+ {
+ SvxConfigEntry* pEntry = new SvxConfigEntry( aMenuName, aUrl, true, true );
+ pEntry->SetMain();
+ m_pRootEntry->GetEntries()->push_back( pEntry );
+ LoadSubMenus( xPopupMenu, aMenuName, pEntry );
+ }
+ }
+ std::sort( m_pRootEntry->GetEntries()->begin(), m_pRootEntry->GetEntries()->end(), EntrySort );
+ }
+ return m_pRootEntry->GetEntries();
+}
+
+void ContextMenuSaveInData::SetEntries( SvxEntries* pNewEntries )
+{
+ delete m_pRootEntry->GetEntries();
+ m_pRootEntry->SetEntries( pNewEntries );
+}
+
+bool ContextMenuSaveInData::HasURL( const OUString& rURL )
+{
+ SvxEntries* pEntries = GetEntries();
+ for ( const auto& pEntry : *pEntries )
+ if ( pEntry->GetCommand() == rURL )
+ return true;
+
+ return false;
+}
+
+bool ContextMenuSaveInData::HasSettings()
+{
+ return m_pRootEntry && m_pRootEntry->GetEntries()->size();
+}
+
+bool ContextMenuSaveInData::Apply()
+{
+ if ( !IsModified() )
+ return false;
+
+ SvxEntries* pEntries = GetEntries();
+ for ( const auto& pEntry : *pEntries )
+ {
+ if ( pEntry->IsModified() || SvxConfigEntryModified( pEntry ) )
+ {
+ css::uno::Reference< css::container::XIndexContainer > xIndexContainer( GetConfigManager()->createSettings(), css::uno::UNO_QUERY );
+ css::uno::Reference< css::lang::XSingleComponentFactory > xFactory( xIndexContainer, css::uno::UNO_QUERY );
+ ApplyMenu( xIndexContainer, xFactory, pEntry );
+
+ OUString aUrl = pEntry->GetCommand();
+ try
+ {
+ if ( GetConfigManager()->hasSettings( aUrl ) )
+ GetConfigManager()->replaceSettings( aUrl, xIndexContainer );
+ else
+ GetConfigManager()->insertSettings( aUrl, xIndexContainer );
+ }
+ catch ( const css::uno::Exception& )
+ {}
+ }
+ }
+ SetModified( false );
+ return PersistChanges( GetConfigManager() );
+}
+
+void ContextMenuSaveInData::Reset()
+{
+ SvxEntries* pEntries = GetEntries();
+ for ( const auto& pEntry : *pEntries )
+ {
+ try
+ {
+ GetConfigManager()->removeSettings( pEntry->GetCommand() );
+ }
+ catch ( const css::uno::Exception& )
+ {}
+ }
+ PersistChanges( GetConfigManager() );
+ m_pRootEntry.reset();
+}
+
class PopupPainter : public SvLBoxString
{
public:
@@ -2069,6 +2261,7 @@ SvTreeListEntry* SvxConfigPage::InsertEntry(
m_pContentsListBox->MakeVisible( pNewEntry );
GetSaveInData()->SetModified();
+ GetTopLevelSelection()->SetModified();
}
return pNewEntry;
@@ -2196,6 +2389,7 @@ bool SvxConfigPage::MoveEntryData(
pEntries->insert( ++iter, pSourceData );
GetSaveInData()->SetModified();
+ GetTopLevelSelection()->SetModified();
return true;
}
@@ -2381,6 +2575,7 @@ bool SvxMenuConfigPage::DeleteSelectedContent()
delete pMenuEntry;
GetSaveInData()->SetModified();
+ pMenu->SetModified();
return true;
}
@@ -2589,8 +2784,10 @@ SaveInData* SvxMenuConfigPage::CreateSaveInData(
const OUString& aModuleId,
bool bDocConfig )
{
- return static_cast< SaveInData* >(
- new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
+ if ( !m_bIsMenuBar )
+ return static_cast< SaveInData* >( new ContextMenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ) );
+
+ return static_cast< SaveInData* >( new MenuSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ) );
}
SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog(
@@ -2804,6 +3001,7 @@ SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName,
, bIsUserDefined( false )
, bIsMain( false )
, bIsParentData( bParentData )
+ , bIsModified( false )
, bIsVisible( true )
, nStyle( 0 )
, mpEntries( nullptr )
@@ -3668,11 +3866,6 @@ OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
return result;
}
-bool EntrySort( SvxConfigEntry* a, SvxConfigEntry* b )
-{
- return a->GetName().compareTo( b->GetName() ) < 0;
-}
-
SvxEntries* ToolbarSaveInData::GetEntries()
{
typedef std::unordered_map<OUString, bool,
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index b4cbaa0ff54f..9066bad31a56 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -95,6 +95,17 @@ private:
static css::uno::Reference
< css::ui::XImageManager >* xDefaultImgMgr;
+protected:
+
+ void ApplyMenu(
+ css::uno::Reference< css::container::XIndexContainer >& rMenuBar,
+ css::uno::Reference< css::lang::XSingleComponentFactory >& rFactory,
+ SvxConfigEntry *pMenuData = nullptr );
+
+ bool LoadSubMenus(
+ const css::uno::Reference< css::container::XIndexAccess >& xMenuSettings,
+ const OUString& rBaseTitle, SvxConfigEntry* pParentData );
+
public:
SaveInData(
@@ -170,15 +181,6 @@ private:
css::uno::Reference< css::lang::XSingleComponentFactory >& rFactory,
SvTreeListEntry *pParent = nullptr );
- void ApplyMenu(
- css::uno::Reference< css::container::XIndexContainer >& rNewMenuBar,
- css::uno::Reference< css::lang::XSingleComponentFactory >& rFactory,
- SvxConfigEntry *pMenuData = nullptr );
-
- bool LoadSubMenus(
- const css::uno::Reference< css::container::XIndexAccess >& xMenuBarSettings,
- const OUString& rBaseTitle, SvxConfigEntry* pParentData );
-
public:
MenuSaveInData(
@@ -198,6 +200,26 @@ public:
bool Apply() override;
};
+class ContextMenuSaveInData : public SaveInData
+{
+private:
+ std::unique_ptr< SvxConfigEntry > m_pRootEntry;
+
+public:
+ ContextMenuSaveInData(
+ const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
+ const css::uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
+ const OUString& aModuleId, bool bIsDocConfig );
+ virtual ~ContextMenuSaveInData();
+
+ SvxEntries* GetEntries() override;
+ void SetEntries( SvxEntries* pNewEntries ) override;
+ bool HasSettings() override;
+ bool HasURL( const OUString& rURL ) override;
+ void Reset() override;
+ bool Apply() override;
+};
+
class SvxConfigEntry
{
private:
@@ -213,6 +235,7 @@ private:
bool bIsUserDefined;
bool bIsMain;
bool bIsParentData;
+ bool bIsModified;
/// toolbar specific properties
bool bIsVisible;
@@ -238,6 +261,7 @@ public:
bIsUserDefined( false ),
bIsMain( false ),
bIsParentData( false ),
+ bIsModified( false ),
bIsVisible( true ),
nStyle( 0 ),
mpEntries( nullptr )
@@ -270,6 +294,9 @@ public:
void SetParentData( bool bValue = true ) { bIsParentData = bValue; }
bool IsParentData() { return bIsParentData; }
+ void SetModified( bool bValue = true ) { bIsModified = bValue; }
+ bool IsModified() { return bIsModified; }
+
bool IsMovable();
bool IsDeletable();
bool IsRenamable();