Skip to content
Snippets Groups Projects
Commit e43fc910 authored by Flavien BRIDAULT's avatar Flavien BRIDAULT
Browse files

feat(SFolderSelector): add new service to select a folder with a dialog

parent af22bb5c
No related branches found
No related tags found
No related merge requests found
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2017.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#ifndef __UIIO_ACTION_SFOLDERSELECTOR_HPP__
#define __UIIO_ACTION_SFOLDERSELECTOR_HPP__
#include "uiIO/config.hpp"
#include <fwGui/IActionSrv.hpp>
#include <boost/filesystem/path.hpp>
namespace uiIO
{
namespace action
{
/**
* @brief Raise a pop-up dialog to select a directory, then send it via a signal.
*
* @section Signals Signals
* - \b folderSelector(::boost::filesystem::path) : Emitted when the directory is chosen.
*
* @section XML XML Configuration
*
* @code{.xml}
<service type="::uiIO::action::SFolderSelector" >
<dialogTitle>Select a folder</dialogTitle>
</service>
@endcode
* @subsection Configuration Configuration:
* - \b dialogTitle (optional): title of the dialog.
*/
class UIIO_CLASS_API SFolderSelector : public ::fwGui::IActionSrv
{
public:
fwCoreServiceClassDefinitionsMacro( (SFolderSelector)( ::fwGui::IActionSrv) )
/**
* @name Signals API
* @{
*/
typedef ::fwCom::Signal< void ( ::boost::filesystem::path ) > FolderSelectedSignalType;
static const ::fwCom::Signals::SignalKeyType s_FOLDER_SELECTED_SIG;
/// @}
UIIO_API SFolderSelector() noexcept;
UIIO_API virtual ~SFolderSelector() noexcept;
protected:
/// Do nothing
UIIO_API void configuring() override;
/// Do nothing.
UIIO_API void starting() override;
/// Show the dialog and send the signal with the chosen directory
UIIO_API void updating() override;
/// Do nothing.
UIIO_API void stopping() override;
private:
/// Optional title for the dialog
std::string m_dialogTitle;
};
} // namespace action
} // namespace uiIO
#endif // __UIIO_ACTION_SFOLDERSELECTOR_HPP__
/* ***** BEGIN LICENSE BLOCK *****
* FW4SPL - Copyright (C) IRCAD, 2009-2017.
* Distributed under the terms of the GNU Lesser General Public License (LGPL) as
* published by the Free Software Foundation.
* ****** END LICENSE BLOCK ****** */
#include "uiIO/action/SFolderSelector.hpp"
#include <fwCom/Signal.hxx>
#include <fwData/location/Folder.hpp>
#include <fwGui/dialog/LocationDialog.hpp>
#include <fwServices/macros.hpp>
namespace uiIO
{
namespace action
{
fwServicesRegisterMacro( ::fwGui::IActionSrv, ::uiIO::action::SFolderSelector, ::fwData::Object );
const ::fwCom::Signals::SignalKeyType SFolderSelector::s_FOLDER_SELECTED_SIG = "folderSelected";
//------------------------------------------------------------------------------
SFolderSelector::SFolderSelector( ) noexcept
{
newSignal< FolderSelectedSignalType >( s_FOLDER_SELECTED_SIG );
}
//------------------------------------------------------------------------------
SFolderSelector::~SFolderSelector() noexcept
{
}
//------------------------------------------------------------------------------
void SFolderSelector::configuring()
{
const auto& config = this->getConfigTree();
m_dialogTitle = config.get("dialogTitle", "Select a folder");
}
//------------------------------------------------------------------------------
void SFolderSelector::starting()
{
}
//------------------------------------------------------------------------------
void SFolderSelector::updating( )
{
static ::boost::filesystem::path _sDefaultPath("");
::fwGui::dialog::LocationDialog dialogFile;
dialogFile.setTitle(m_dialogTitle);
dialogFile.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
dialogFile.setOption(::fwGui::dialog::ILocationDialog::READ);
dialogFile.setType(::fwGui::dialog::ILocationDialog::FOLDER);
::fwData::location::Folder::sptr result;
result = ::fwData::location::Folder::dynamicCast( dialogFile.show() );
if (result)
{
auto sig = this->signal<FolderSelectedSignalType>(s_FOLDER_SELECTED_SIG);
sig->asyncEmit(result->getFolder());
}
}
//------------------------------------------------------------------------------
void SFolderSelector::stopping()
{
}
//------------------------------------------------------------------------------
//
} // namespace action
} // namespace uiIO
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment