1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // this file contains code from filectrl.cxx which needs to be compiled with enabled exception hanling
22 #include <svtools/filectrl.hxx>
23 #include <com/sun/star/ui/dialogs/FilePicker.hpp>
24 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <tools/urlobj.hxx>
28 #include <vcl/stdtext.hxx>
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::ui
;
34 void FileControl::ImplBrowseFile( )
38 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
39 Reference
< dialogs::XFilePicker3
> xFilePicker
= dialogs::FilePicker::createWithMode( xContext
, dialogs::TemplateDescription::FILEOPEN_SIMPLE
);
40 // transform the system notation text into a file URL
41 OUString sSystemNotation
= GetText(), sFileURL
;
42 oslFileError nError
= osl_getFileURLFromSystemPath( sSystemNotation
.pData
, &sFileURL
.pData
);
43 if ( nError
== osl_File_E_INVAL
)
44 sFileURL
= GetText(); // #97709# Maybe URL is already a file URL...
46 //#90430# Check if URL is really a file URL
48 if ( osl_getSystemPathFromFileURL( sFileURL
.pData
, &aTmp
.pData
) == osl_File_E_None
)
50 // initially set this directory
51 xFilePicker
->setDisplayDirectory( sFileURL
);
54 if ( xFilePicker
->execute() )
56 Sequence
< OUString
> aPathSeq
= xFilePicker
->getFiles();
58 if ( aPathSeq
.getLength() )
60 OUString aNewText
= aPathSeq
[0];
61 INetURLObject
aObj( aNewText
);
62 if ( aObj
.GetProtocol() == INET_PROT_FILE
)
63 aNewText
= aObj
.PathToFileName();
65 maEdit
.GetModifyHdl().Call( &maEdit
);
69 catch( const Exception
& )
71 OSL_FAIL( "FileControl::ImplBrowseFile: caught an exception while executing the file picker!" );
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */