Kaydet (Commit) cbf0812a authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile

Recent files menu in the StartModule should be the same as in the menubar

üst e1687ce1
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include "comphelper/sequenceashashmap.hxx" #include "comphelper/sequenceashashmap.hxx"
#include "comphelper/configurationhelper.hxx" #include "comphelper/configurationhelper.hxx"
#include <toolkit/awt/vclxmenu.hxx>
#include "cppuhelper/implbase1.hxx" #include "cppuhelper/implbase1.hxx"
#include "rtl/strbuf.hxx" #include "rtl/strbuf.hxx"
...@@ -58,7 +60,7 @@ ...@@ -58,7 +60,7 @@
#include "com/sun/star/system/SystemShellExecuteFlags.hpp" #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
#include "com/sun/star/task/XJobExecutor.hpp" #include "com/sun/star/task/XJobExecutor.hpp"
#include "com/sun/star/util/XStringWidth.hpp" #include "com/sun/star/util/XStringWidth.hpp"
#include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
using namespace ::com::sun::star::beans; using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame; using namespace ::com::sun::star::frame;
...@@ -66,6 +68,8 @@ using namespace ::com::sun::star::uno; ...@@ -66,6 +68,8 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace framework; using namespace framework;
#define RECENT_FILE_LIST ".uno:RecentFileList"
#define WRITER_URL "private:factory/swriter" #define WRITER_URL "private:factory/swriter"
#define CALC_URL "private:factory/scalc" #define CALC_URL "private:factory/scalc"
#define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686" #define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686"
...@@ -150,15 +154,18 @@ BackingWindow::BackingWindow( Window* i_pParent ) : ...@@ -150,15 +154,18 @@ BackingWindow::BackingWindow( Window* i_pParent ) :
mnLayoutStyle( 0 ), mnLayoutStyle( 0 ),
mpAccExec( NULL ), mpAccExec( NULL ),
mnBtnPos( 120 ), mnBtnPos( 120 ),
mnBtnTop( 150 ), mnBtnTop( 150 )
mpRecentMenu( NULL )
{ {
mnColumnWidth[0] = mnColumnWidth[1] = 0; mnColumnWidth[0] = mnColumnWidth[1] = 0;
mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0; mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0;
try try
{ {
Reference<lang::XMultiServiceFactory> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY); mxContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
Reference<lang::XMultiServiceFactory> xConfig(
mxContext->getServiceManager()->createInstanceWithContext(
SERVICENAME_CFGPROVIDER, mxContext), UNO_QUERY);
if( xConfig.is() ) if( xConfig.is() )
{ {
Sequence<Any> args(1); Sequence<Any> args(1);
...@@ -176,9 +183,22 @@ BackingWindow::BackingWindow( Window* i_pParent ) : ...@@ -176,9 +183,22 @@ BackingWindow::BackingWindow( Window* i_pParent ) :
mnLayoutStyle = value.get<sal_Int32>(); mnLayoutStyle = value.get<sal_Int32>();
} }
} }
mxPopupMenuFactory.set(
frame::PopupMenuControllerFactory::create( mxContext ) );
// TODO If there is no PopupMenuController, the button should be a nomral one not a MenuButton
if ( mxPopupMenuFactory->hasController(
DECLARE_ASCII( RECENT_FILE_LIST ) , SERVICENAME_STARTMODULE ) )
{
mxPopupMenu.set( mxContext->getServiceManager()->createInstanceWithContext(
DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), mxContext ), uno::UNO_QUERY_THROW );
}
} }
catch (Exception& ) catch (const Exception& e)
{ {
OSL_TRACE( "BackingWindow - caught an exception! %s",
rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
(void) e;
} }
String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) ); String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
...@@ -244,8 +264,24 @@ BackingWindow::BackingWindow( Window* i_pParent ) : ...@@ -244,8 +264,24 @@ BackingWindow::BackingWindow( Window* i_pParent ) :
BackingWindow::~BackingWindow() BackingWindow::~BackingWindow()
{ {
delete mpRecentMenu;
delete mpAccExec; delete mpAccExec;
if( mxPopupMenuController.is() )
{
Reference< lang::XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
if( xComponent.is() )
{
try
{
xComponent->dispose();
}
catch (...)
{}
}
mxPopupMenuController.clear();
}
mxPopupMenuFactory.clear();
mxPopupMenu.clear();
} }
void BackingWindow::GetFocus() void BackingWindow::GetFocus()
...@@ -275,117 +311,42 @@ void BackingWindow::DataChanged( const DataChangedEvent& rDCEvt ) ...@@ -275,117 +311,42 @@ void BackingWindow::DataChanged( const DataChangedEvent& rDCEvt )
void BackingWindow::prepareRecentFileMenu() void BackingWindow::prepareRecentFileMenu()
{ {
if( ! mpRecentMenu ) if( ! mxPopupMenu.is() )
mpRecentMenu = new PopupMenu(); return;
mpRecentMenu->Clear();
maRecentFiles.clear();
// get recent file list and dispatch arguments
Sequence< Sequence< PropertyValue > > aHistoryList( SvtHistoryOptions().GetList( ePICKLIST ) );
sal_Int32 nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
if( ( nPickListMenuItems > 0 ) ) if ( !mxPopupMenuController.is() )
{ {
maRecentFiles.reserve( nPickListMenuItems ); uno::Sequence< uno::Any > aArgs( 2 );
for ( sal_Int32 i = 0; i < nPickListMenuItems; i++ ) beans::PropertyValue aProp;
{
Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
rtl::OUString aURL, aFilter, aFilterOpt, aTitle;
for ( sal_Int32 j = 0; j < rPickListEntry.getLength(); j++ )
{
const Any& a = rPickListEntry[j].Value;
if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
a >>= aURL;
else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
{
a >>= aFilter;
sal_Int32 nPos = aFilter.indexOf( '|' );
if ( nPos >= 0 )
{
if ( nPos < ( aFilter.getLength() - 1 ) )
aFilterOpt = aFilter.copy( nPos+1 );
aFilter = aFilter.copy( 0, nPos-1 );
}
}
else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
a >>= aTitle;
}
maRecentFiles.push_back( LoadRecentFile() );
maRecentFiles.back().aTargetURL = aURL;
sal_Int32 nArgs = aFilterOpt.getLength() ? 4 : 3;
Sequence< PropertyValue >& rArgsList( maRecentFiles.back().aArgSeq );
rArgsList.realloc( nArgs );
nArgs--; aProp.Name = DECLARE_ASCII( "Frame" );
rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); aProp.Value <<= mxFrame;
rArgsList[nArgs].Value = makeAny( aFilter ); aArgs[0] <<= aProp;
if( aFilterOpt.getLength() ) aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
{ aProp.Value <<= SERVICENAME_STARTMODULE;
nArgs--; aArgs[1] <<= aProp;
rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" )); try
rArgsList[nArgs].Value = makeAny( aFilterOpt ); {
} mxPopupMenuController.set(
mxPopupMenuFactory->createInstanceWithArgumentsAndContext(
// documents in the picklist will never be opened as templates DECLARE_ASCII( RECENT_FILE_LIST ), aArgs, mxContext),
nArgs--; uno::UNO_QUERY_THROW );
rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" )); mxPopupMenuController->setPopupMenu( mxPopupMenu );
rArgsList[nArgs].Value = makeAny( (sal_Bool) sal_False );
nArgs--;
rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
rArgsList[nArgs].Value = makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:user" ) ) );
// and finally create an entry in the popupmenu
rtl::OUString aMenuTitle;
INetURLObject aURLObj( aURL );
if ( aURLObj.GetProtocol() == INET_PROT_FILE )
{
// Do handle file URL differently => convert it to a system
// path and abbreviate it with a special function:
String aFileSystemPath( aURLObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
rtl::OUString aSystemPath( aFileSystemPath );
rtl::OUString aCompactedSystemPath;
oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
if ( !nError )
aMenuTitle = String( aCompactedSystemPath );
else
aMenuTitle = aSystemPath;
}
else
{
// Use INetURLObject to abbreviate all other URLs
Reference< util::XStringWidth > xStringLength( new RecentFilesStringLength() );
aMenuTitle = aURLObj.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
}
rtl::OUStringBuffer aBuf( aMenuTitle.getLength() + 5 );
if( i < 9 )
{
aBuf.append( sal_Unicode( '~' ) );
aBuf.append( i+1 );
}
else if( i == 9 )
aBuf.appendAscii( "1~0" );
else
aBuf.append( i+1 );
aBuf.appendAscii( ": " );
aBuf.append( aMenuTitle );
mpRecentMenu->InsertItem( static_cast<sal_uInt16>(i+1), aBuf.makeStringAndClear() );
} }
catch ( const Exception &e )
{
OSL_TRACE( "BackingWindow - caught an exception! %s",
rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
(void) e;
}
PopupMenu *pRecentMenu = NULL;
VCLXMenu* pTKMenu = VCLXMenu::GetImplementation( mxPopupMenu );
if ( pTKMenu )
pRecentMenu = dynamic_cast< PopupMenu * >( pTKMenu->GetMenu() );
maOpenButton.SetPopupMenu( pRecentMenu );
} }
else
{
String aNoDoc( FwkResId( STR_NODOCUMENT ) );
mpRecentMenu->InsertItem( 0xffff, aNoDoc );
}
maOpenButton.SetPopupMenu( mpRecentMenu );
} }
void BackingWindow::initBackground() void BackingWindow::initBackground()
...@@ -455,7 +416,6 @@ void BackingWindow::initBackground() ...@@ -455,7 +416,6 @@ void BackingWindow::initBackground()
loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton ); loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED ); maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
maOpenButton.SetSelectHdl( LINK( this, BackingWindow, SelectHdl ) );
maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) ); maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) );
} }
...@@ -1026,19 +986,6 @@ IMPL_LINK( BackingWindow, ClickHdl, Button*, pButton ) ...@@ -1026,19 +986,6 @@ IMPL_LINK( BackingWindow, ClickHdl, Button*, pButton )
return 0; return 0;
} }
IMPL_LINK( BackingWindow, SelectHdl, Button*, pButton )
{
if( pButton == &maOpenButton )
{
sal_Int32 nItem = sal_Int32(maOpenButton.GetCurItemId())-1;
if( nItem >= 0 && nItem < sal_Int32(maRecentFiles.size()) )
{
Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
dispatchURL( maRecentFiles[nItem].aTargetURL, rtl::OUString(), xFrame, maRecentFiles[nItem].aArgSeq );
}
}
return 0;
}
IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton ) IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton )
{ {
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
#include "unotools/moduleoptions.hxx" #include "unotools/moduleoptions.hxx"
#include "svtools/acceleratorexecute.hxx" #include "svtools/acceleratorexecute.hxx"
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/frame/XUIControllerFactory.hpp>
#include <com/sun/star/frame/XPopupMenuController.hpp>
#include <com/sun/star/awt/XPopupMenu.hpp>
#include "com/sun/star/frame/XDispatchProvider.hpp" #include "com/sun/star/frame/XDispatchProvider.hpp"
#include "com/sun/star/frame/XDesktop.hpp" #include "com/sun/star/frame/XDesktop.hpp"
#include "com/sun/star/frame/XFrame.hpp" #include "com/sun/star/frame/XFrame.hpp"
...@@ -74,16 +78,14 @@ namespace framework ...@@ -74,16 +78,14 @@ namespace framework
class BackingWindow : public Window class BackingWindow : public Window
{ {
struct LoadRecentFile
{
rtl::OUString aTargetURL;
com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aArgSeq;
};
com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxContext;
com::sun::star::uno::Reference<com::sun::star::frame::XDesktop> mxDesktop; com::sun::star::uno::Reference<com::sun::star::frame::XDesktop> mxDesktop;
com::sun::star::uno::Reference<com::sun::star::frame::XDispatchProvider > mxDesktopDispatchProvider; com::sun::star::uno::Reference<com::sun::star::frame::XDispatchProvider > mxDesktopDispatchProvider;
com::sun::star::uno::Reference<com::sun::star::frame::XFrame> mxFrame; com::sun::star::uno::Reference<com::sun::star::frame::XFrame> mxFrame;
com::sun::star::uno::Reference<com::sun::star::document::XEventBroadcaster> mxBroadcaster; com::sun::star::uno::Reference< com::sun::star::frame::XUIControllerFactory > mxPopupMenuFactory;
com::sun::star::uno::Reference< com::sun::star::frame::XPopupMenuController > mxPopupMenuController;
com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu > mxPopupMenu;
FixedText maWelcome; FixedText maWelcome;
Size maWelcomeSize; Size maWelcomeSize;
...@@ -126,9 +128,6 @@ namespace framework ...@@ -126,9 +128,6 @@ namespace framework
long mnBtnPos; long mnBtnPos;
long mnBtnTop; long mnBtnTop;
PopupMenu* mpRecentMenu;
std::vector< LoadRecentFile > maRecentFiles;
static const int nItemId_Extensions = 1; static const int nItemId_Extensions = 1;
static const int nItemId_Reg = 2; static const int nItemId_Reg = 2;
static const int nItemId_Info = 3; static const int nItemId_Info = 3;
...@@ -154,7 +153,6 @@ namespace framework ...@@ -154,7 +153,6 @@ namespace framework
); );
DECL_LINK( ClickHdl, Button* ); DECL_LINK( ClickHdl, Button* );
DECL_LINK( SelectHdl, Button* );
DECL_LINK( ActivateHdl, Button* ); DECL_LINK( ActivateHdl, Button* );
DECL_LINK( ToolboxHdl, void* ); DECL_LINK( ToolboxHdl, void* );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment