summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriel Constenla-Haile <arielch@apache.org>2012-05-23 01:14:58 +0000
committerMichael Meeks <michael.meeks@suse.com>2013-03-26 17:35:23 +0000
commit0e6a5bf1d9f4106af44996548ab0924ce7e5648c (patch)
treef7acc425cfefd70b74e449821c3a730def27d65c
parent700b6c1cbf4fee4044aa2b7179d3f1886ae928c6 (diff)
framework::RecentFilesMenuController clean-up, add clear item.
Conflicts: framework/inc/uielement/recentfilesmenucontroller.hxx framework/source/uielement/recentfilesmenucontroller.cxx Change-Id: Ia8b861b42bd77a90dce3bebdfa6aefd5e5cd91dd
-rw-r--r--framework/inc/classes/resource.hrc2
-rw-r--r--framework/inc/uielement/recentfilesmenucontroller.hxx22
-rw-r--r--framework/source/classes/resource.src10
-rw-r--r--framework/source/uielement/recentfilesmenucontroller.cxx184
4 files changed, 77 insertions, 141 deletions
diff --git a/framework/inc/classes/resource.hrc b/framework/inc/classes/resource.hrc
index f9e3bf61f7cd..8d1d23632349 100644
--- a/framework/inc/classes/resource.hrc
+++ b/framework/inc/classes/resource.hrc
@@ -48,6 +48,8 @@
#define STR_SET_LANGUAGE_FOR_ALL_TEXT (RID_STR_START+20)
#define STR_UNTITLED_DOCUMENT (RID_STR_START+21)
#define STR_RESET_TO_DEFAULT_LANGUAGE (RID_STR_START+22)
+#define STR_CLEAR_RECENT_FILES (RID_STR_START+23)
+#define STR_CLEAR_RECENT_FILES_HELP (RID_STR_START+24)
#define POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION (RID_MENU_START+0)
diff --git a/framework/inc/uielement/recentfilesmenucontroller.hxx b/framework/inc/uielement/recentfilesmenucontroller.hxx
index 0df0fd397514..2b07c41a1b21 100644
--- a/framework/inc/uielement/recentfilesmenucontroller.hxx
+++ b/framework/inc/uielement/recentfilesmenucontroller.hxx
@@ -21,23 +21,8 @@
#define __FRAMEWORK_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX_
#include <macros/xserviceinfo.hxx>
-#include <stdtypes.h>
-
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/lang/XTypeProvider.hpp>
-#include <com/sun/star/lang/XInitialization.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/frame/XFrame.hpp>
-#include <com/sun/star/frame/XDispatchProvider.hpp>
-#include <com/sun/star/frame/XDispatch.hpp>
-#include <com/sun/star/frame/XStatusListener.hpp>
-#include <com/sun/star/frame/XPopupMenuController.hpp>
-#include <com/sun/star/beans/XPropertySet.hpp>
-
#include <svtools/popupmenucontrollerbase.hxx>
-#include <toolkit/awt/vclxmenu.hxx>
-#include <cppuhelper/weak.hxx>
-#include <rtl/ustring.hxx>
+#include <macros/xserviceinfo.hxx>
namespace framework
{
@@ -59,9 +44,6 @@ namespace framework
// XServiceInfo
DECLARE_XSERVICEINFO
- // XPopupMenuController
- virtual void SAL_CALL updatePopupMenu() throw (::com::sun::star::uno::RuntimeException);
-
// XStatusListener
virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
@@ -74,8 +56,6 @@ namespace framework
// XDispatch
virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& seqProperties ) throw( ::com::sun::star::uno::RuntimeException );
- virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw( ::com::sun::star::uno::RuntimeException );
- virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw( ::com::sun::star::uno::RuntimeException );
// XEventListener
virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
diff --git a/framework/source/classes/resource.src b/framework/source/classes/resource.src
index 567777ba73b8..24874e53fd3e 100644
--- a/framework/source/classes/resource.src
+++ b/framework/source/classes/resource.src
@@ -104,6 +104,16 @@ String STR_NODOCUMENT
Text [ en-US ] = "No Documents";
};
+String STR_CLEAR_RECENT_FILES
+{
+ Text [ en-US ] = "Clear List";
+};
+
+String STR_CLEAR_RECENT_FILES_HELP
+{
+ Text [ en-US ] = "Clears the list with the most recently opened files. This action can not be undone.";
+};
+
String STR_TOOLBAR_TITLE_ADDON
{
Text [ en-US ] = "Add-On %num%";
diff --git a/framework/source/uielement/recentfilesmenucontroller.cxx b/framework/source/uielement/recentfilesmenucontroller.cxx
index f12fbe1d7a80..59d6fe5c16d0 100644
--- a/framework/source/uielement/recentfilesmenucontroller.cxx
+++ b/framework/source/uielement/recentfilesmenucontroller.cxx
@@ -18,45 +18,35 @@
*/
#include <uielement/recentfilesmenucontroller.hxx>
-
#include <threadhelp/resetableguard.hxx>
#include "services.h"
#include <classes/resource.hrc>
#include <classes/fwkresid.hxx>
-#include <com/sun/star/awt/XDevice.hpp>
-#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/awt/MenuItemStyle.hpp>
#include <com/sun/star/util/XStringWidth.hpp>
-#include <vcl/menu.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/i18nhelp.hxx>
-#include <tools/urlobj.hxx>
-#include <rtl/ustrbuf.hxx>
-#include <unotools/historyoptions.hxx>
#include <cppuhelper/implbase1.hxx>
#include <osl/file.hxx>
-#ifdef WNT
-#define GradientStyle_RECT BLA_GradientStyle_RECT
-#include <windows.h>
-#undef GradientStyle_RECT
-#endif
+#include <tools/urlobj.hxx>
+#include <unotools/historyoptions.hxx>
+#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
#include <osl/mutex.hxx>
-//_________________________________________________________________________________________________________________
-// Defines
-//_________________________________________________________________________________________________________________
-
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::frame;
using namespace com::sun::star::beans;
using namespace com::sun::star::util;
-using namespace com::sun::star::container;
+
+#define MAX_STR_WIDTH 46
+#define MAX_MENU_ITEMS 99
static const char SFX_REFERER_USER[] = "private:user";
+static const char CMD_CLEAR_LIST[] = ".uno:ClearRecentFileList";
+static const char CMD_PREFIX[] = "vnd.sun.star.popup:RecentFileList?entry=";
+static const char MENU_SHOTCUT[] = "~N: ";
namespace framework
{
@@ -96,8 +86,8 @@ RecentFilesMenuController::~RecentFilesMenuController()
// private function
void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
{
- VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
- PopupMenu* pVCLPopupMenu = 0;
+ VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
+ PopupMenu* pVCLPopupMenu = 0;
SolarMutexGuard aSolarMutexGuard;
@@ -110,11 +100,7 @@ void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >
Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
Reference< XStringWidth > xStringLength( new RecentFilesStringLength );
- int nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
-
- // New vnd.sun.star.popup: command URL to support direct dispatches
- const OUString aCmdPrefix( "vnd.sun.star.popup:RecentFileList?entry=" );
-
+ int nPickListMenuItems = ( aHistoryList.getLength() > MAX_MENU_ITEMS ) ? MAX_MENU_ITEMS : aHistoryList.getLength();
m_aRecentFilesItems.clear();
if (( nPickListMenuItems > 0 ) && !m_bDisabled )
{
@@ -141,73 +127,77 @@ void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >
if ( !m_aRecentFilesItems.empty() )
{
- URL aTargetURL;
-
const sal_uInt32 nCount = m_aRecentFilesItems.size();
for ( sal_uInt32 i = 0; i < nCount; i++ )
{
- OUString aMenuShortCut;
+ OUStringBuffer aMenuShortCut;
if ( i <= 9 )
{
if ( i == 9 )
- aMenuShortCut = OUString( "1~0: " );
+ aMenuShortCut.append( "1~0: " );
else
{
- char menuShortCut[5] = "~n: ";
- menuShortCut[1] = (char)( '1' + i );
- aMenuShortCut = OUString::createFromAscii( menuShortCut );
+ aMenuShortCut.append( MENU_SHOTCUT );
+ aMenuShortCut[ 1 ] = sal_Unicode( i + '1' );
}
}
else
{
- aMenuShortCut = OUString::valueOf((sal_Int32)( i + 1 ));
- aMenuShortCut += ": ";
+ aMenuShortCut.append( sal_Int32( i + 1 ) );
+ aMenuShortCut.append( ": " );
}
+ rtl::OUStringBuffer aStrBuffer;
+ aStrBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( CMD_PREFIX ) );
+ aStrBuffer.append( sal_Int32( i ) );
+ rtl::OUString aURLString( aStrBuffer.makeStringAndClear() );
+
// Abbreviate URL
- OUString aURLString( aCmdPrefix + OUString::valueOf( sal_Int32( i )));
- OUString aTipHelpText;
- OUString aMenuTitle;
+ rtl::OUString aTipHelpText;
+ rtl::OUString aMenuTitle;
INetURLObject aURL( m_aRecentFilesItems[i].aURL );
if ( aURL.GetProtocol() == INET_PROT_FILE )
{
// Do handle file URL differently => convert it to a system
// path and abbreviate it with a special function:
- String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
-
- OUString aSystemPath( aFileSystemPath );
- OUString aCompactedSystemPath;
-
+ rtl::OUString aSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
aTipHelpText = aSystemPath;
- oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
- if ( !nError )
- aMenuTitle = String( aCompactedSystemPath );
+
+ ::rtl::OUString aCompactedSystemPath;
+ if ( osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, MAX_STR_WIDTH, NULL ) == osl_File_E_None )
+ aMenuTitle = aCompactedSystemPath;
else
aMenuTitle = aSystemPath;
}
else
{
// Use INetURLObject to abbreviate all other URLs
- String aShortURL;
- aShortURL = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
- aMenuTitle += aShortURL;
+ aMenuTitle = aURL.getAbbreviated( xStringLength, MAX_STR_WIDTH, INetURLObject::DECODE_UNAMBIGUOUS );
aTipHelpText = aURLString;
}
- OUString aTitle( aMenuShortCut + aMenuTitle );
+ aMenuShortCut.append( aMenuTitle );
- pVCLPopupMenu->InsertItem( sal_uInt16( i+1 ), aTitle );
+ pVCLPopupMenu->InsertItem( sal_uInt16( i+1 ), aMenuShortCut.makeStringAndClear() );
pVCLPopupMenu->SetTipHelpText( sal_uInt16( i+1 ), aTipHelpText );
pVCLPopupMenu->SetItemCommand( sal_uInt16( i+1 ), aURLString );
}
+
+ pVCLPopupMenu->InsertSeparator();
+ // Clear List menu entry
+ pVCLPopupMenu->InsertItem( sal_uInt16( nCount + 1 ),
+ String( FwkResId( STR_CLEAR_RECENT_FILES ) ) );
+ pVCLPopupMenu->SetItemCommand( sal_uInt16( nCount + 1 ),
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_CLEAR_LIST ) ) );
+ pVCLPopupMenu->SetHelpText( sal_uInt16( nCount + 1 ),
+ String( FwkResId( STR_CLEAR_RECENT_FILES_HELP ) ) );
}
else
{
// No recent documents => insert "no document" string
- String aNoDocumentStr = String( FwkResId( STR_NODOCUMENT ));
- pVCLPopupMenu->InsertItem( 1, aNoDocumentStr );
+ pVCLPopupMenu->InsertItem( 1, String( FwkResId( STR_NODOCUMENT ) ) );
pVCLPopupMenu->EnableItem( 1, sal_False );
}
}
@@ -215,20 +205,15 @@ void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >
void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
{
- Reference< css::awt::XPopupMenu > xPopupMenu;
Reference< XDispatch > xDispatch;
Reference< XDispatchProvider > xDispatchProvider;
- Reference< XMultiServiceFactory > xServiceManager;
+ css::util::URL aTargetURL;
+ Sequence< PropertyValue > aArgsList;
osl::ClearableMutexGuard aLock( m_aMutex );
- xPopupMenu = m_xPopupMenu;
- xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
- xServiceManager = m_xServiceManager;
+ xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
aLock.clear();
- css::util::URL aTargetURL;
- Sequence< PropertyValue > aArgsList;
-
if (( nIndex >= 0 ) &&
( nIndex < sal::static_int_cast<sal_Int32>( m_aRecentFilesItems.size() )))
{
@@ -238,12 +223,12 @@ void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
m_xURLTransformer->parseStrict( aTargetURL );
sal_Int32 nSize = 2;
- aArgsList.realloc(nSize);
- aArgsList[0].Name = OUString( "Referer" );
- aArgsList[0].Value = makeAny( OUString(SFX_REFERER_USER ));
+ aArgsList.realloc( nSize );
+ aArgsList[0].Name = "Referer";
+ aArgsList[0].Value = makeAny( OUString( SFX_REFERER_USER ) );
// documents in the picklist will never be opened as templates
- aArgsList[1].Name = OUString( "AsTemplate" );
+ aArgsList[1].Name = "AsTemplate";
aArgsList[1].Value = makeAny( (sal_Bool) sal_False );
if (!m_aModuleName.isEmpty())
@@ -254,7 +239,7 @@ void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
aArgsList[nSize-1].Value <<= m_aModuleName;
}
- xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString("_default"), 0 );
+ xDispatch = xDispatchProvider->queryDispatch( aTargetURL, "_default", 0 );
}
if ( xDispatch.is() )
@@ -266,6 +251,7 @@ void RecentFilesMenuController::executeEntry( sal_Int32 nIndex )
pLoadRecentFile->xDispatch = xDispatch;
pLoadRecentFile->aTargetURL = aTargetURL;
pLoadRecentFile->aArgSeq = aArgsList;
+
Application::PostUserEvent( STATIC_LINK(0, RecentFilesMenuController, ExecuteHdl_Impl), pLoadRecentFile );
}
}
@@ -294,24 +280,23 @@ void SAL_CALL RecentFilesMenuController::statusChanged( const FeatureStateEvent&
void SAL_CALL RecentFilesMenuController::select( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
{
- Reference< css::awt::XPopupMenu > xPopupMenu;
- Reference< XDispatch > xDispatch;
- Reference< XDispatchProvider > xDispatchProvider;
- Reference< XMultiServiceFactory > xServiceManager;
+ Reference< css::awt::XPopupMenu > xPopupMenu;
+ Reference< css::awt::XMenuExtended > xMenuExt;
osl::ClearableMutexGuard aLock( m_aMutex );
xPopupMenu = m_xPopupMenu;
- xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
- xServiceManager = m_xServiceManager;
+ xMenuExt = Reference< css::awt::XMenuExtended >( m_xPopupMenu, UNO_QUERY );
aLock.clear();
- css::util::URL aTargetURL;
- Sequence< PropertyValue > aArgsList;
-
- if ( xPopupMenu.is() && xDispatchProvider.is() )
+ if ( xMenuExt.is() )
{
- VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu );
- if ( pPopupMenu )
+ const rtl::OUString aCommand( xMenuExt->getCommand( rEvent.MenuId ) );
+ OSL_TRACE( "RecentFilesMenuController::select() - Command : %s",
+ rtl::OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
+
+ if ( aCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( CMD_CLEAR_LIST ) ) )
+ SvtHistoryOptions().Clear( ePICKLIST );
+ else
executeEntry( rEvent.MenuId-1 );
}
}
@@ -329,27 +314,6 @@ void RecentFilesMenuController::impl_setPopupMenu()
fillPopupMenu( m_xPopupMenu );
}
-void SAL_CALL RecentFilesMenuController::updatePopupMenu() throw (RuntimeException)
-{
- osl::ClearableMutexGuard aLock( m_aMutex );
-
- throwIfDisposed();
-
- Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
- Reference< XDispatch > xDispatch( m_xDispatch );
- com::sun::star::util::URL aTargetURL;
- aTargetURL.Complete = m_aCommandURL;
- m_xURLTransformer->parseStrict( aTargetURL );
- aLock.clear();
-
- // Add/remove status listener to get a status update once
- if ( xDispatch.is() )
- {
- xDispatch->addStatusListener( xStatusListener, aTargetURL );
- xDispatch->removeStatusListener( xStatusListener, aTargetURL );
- }
-}
-
// XDispatchProvider
Reference< XDispatch > SAL_CALL RecentFilesMenuController::queryDispatch(
const URL& aURL,
@@ -403,26 +367,6 @@ throw( RuntimeException )
}
}
-void SAL_CALL RecentFilesMenuController::addStatusListener(
- const Reference< XStatusListener >& xControl,
- const URL& aURL )
-throw( RuntimeException )
-{
- osl::MutexGuard aLock( m_aMutex );
-
- throwIfDisposed();
-
- svt::PopupMenuControllerBase::addStatusListener( xControl, aURL );
-}
-
-void SAL_CALL RecentFilesMenuController::removeStatusListener(
- const Reference< XStatusListener >& xControl,
- const URL& aURL )
-throw( RuntimeException )
-{
- svt::PopupMenuControllerBase::removeStatusListener( xControl, aURL );
-}
-
IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile*, pLoadRecentFile )
{
try