Hello community,
here is the log from the commit of package libyui-rest-api for openSUSE:Factory checked in at 2020-12-01 14:21:25
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/libyui-rest-api (Old)
and /work/SRC/openSUSE:Factory/.libyui-rest-api.new.5913 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libyui-rest-api"
Tue Dec 1 14:21:25 2020 rev:13 rq:851305 version:0.5.11
Changes:
--------
--- /work/SRC/openSUSE:Factory/libyui-rest-api/libyui-rest-api.changes 2020-11-25 19:27:42.806366497 +0100
+++ /work/SRC/openSUSE:Factory/.libyui-rest-api.new.5913/libyui-rest-api.changes 2020-12-01 14:21:27.241506821 +0100
@@ -1,0 +2,7 @@
+Thu Nov 26 13:42:21 UTC 2020 - Rodion Iafarov <riafarov(a)suse.com>
+
+- Add activation for YTable (bsc#1139747)
+- Create structure to move handlers to separate classes
+- 0.5.11
+
+-------------------------------------------------------------------
Old:
----
libyui-rest-api-0.5.10.tar.bz2
New:
----
libyui-rest-api-0.5.11.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ libyui-rest-api.spec ++++++
--- /var/tmp/diff_new_pack.YKENA1/_old 2020-12-01 14:21:27.737507357 +0100
+++ /var/tmp/diff_new_pack.YKENA1/_new 2020-12-01 14:21:27.737507357 +0100
@@ -21,7 +21,7 @@
%define libyui_devel_version libyui-devel >= 3.10.1
Name: libyui-rest-api
-Version: 0.5.10
+Version: 0.5.11
Release: 0
Summary: Libyui - REST API plugin, the shared part
License: LGPL-2.1-only OR LGPL-3.0-only
++++++ libyui-rest-api-0.5.10.tar.bz2 -> libyui-rest-api-0.5.11.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/SOURCECONF.cmake new/libyui-rest-api-0.5.11/SOURCECONF.cmake
--- old/libyui-rest-api-0.5.10/SOURCECONF.cmake 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/SOURCECONF.cmake 2020-11-27 13:06:48.000000000 +0100
@@ -22,6 +22,7 @@
YHttpVersionHandler.h
YHttpAppHandler.h
YTableActionHandler.h
+ YWidgetActionHandler.h
YHttpWidgetsHandler.h
YHttpWidgetsActionHandler.h
YHttpMount.h
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/VERSION.cmake new/libyui-rest-api-0.5.11/VERSION.cmake
--- old/libyui-rest-api-0.5.10/VERSION.cmake 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/VERSION.cmake 2020-11-27 13:06:48.000000000 +0100
@@ -1,6 +1,6 @@
SET( VERSION_MAJOR "0")
SET( VERSION_MINOR "5" )
-SET( VERSION_PATCH "10" )
+SET( VERSION_PATCH "11" )
SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${GIT_SHA1_VERSION}" )
##### This is need for the libyui core, ONLY.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/package/libyui-rest-api.changes new/libyui-rest-api-0.5.11/package/libyui-rest-api.changes
--- old/libyui-rest-api-0.5.10/package/libyui-rest-api.changes 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/package/libyui-rest-api.changes 2020-11-27 13:06:48.000000000 +0100
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Thu Nov 26 13:42:21 UTC 2020 - Rodion Iafarov <riafarov(a)suse.com>
+
+- Add activation for YTable (bsc#1139747)
+- Create structure to move handlers to separate classes
+- 0.5.11
+
+-------------------------------------------------------------------
Tue Nov 24 11:21:45 UTC 2020 - Rodion Iafarov <riafarov(a)suse.com>
- Add activation for Radiobutton (bsc#1139747)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/package/libyui-rest-api.spec new/libyui-rest-api-0.5.11/package/libyui-rest-api.spec
--- old/libyui-rest-api-0.5.10/package/libyui-rest-api.spec 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/package/libyui-rest-api.spec 2020-11-27 13:06:48.000000000 +0100
@@ -21,7 +21,7 @@
%define libyui_devel_version libyui-devel >= 3.10.1
Name: libyui-rest-api
-Version: 0.5.10
+Version: 0.5.11
Release: 0
Summary: Libyui - REST API plugin, the shared part
License: LGPL-2.1-only OR LGPL-3.0-only
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/src/YHttpWidgetsActionHandler.cc new/libyui-rest-api-0.5.11/src/YHttpWidgetsActionHandler.cc
--- old/libyui-rest-api-0.5.10/src/YHttpWidgetsActionHandler.cc 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/src/YHttpWidgetsActionHandler.cc 2020-11-27 13:06:48.000000000 +0100
@@ -25,7 +25,6 @@
#include "YProperty.h"
#include "YPushButton.h"
#include "YRichText.h"
-#include "YTableActionHandler.h"
#include "YTree.h"
#include "YTreeItem.h"
#include "YWidgetID.h"
@@ -115,7 +114,7 @@
return action_handler<YPushButton>( widget, body, [&] (YPushButton *button) {
yuiMilestone() << "Pressing button \"" << button->label() << '"' << std::endl;
button->setKeyboardFocus();
- activate_widget( button );
+ get_widget_handler()->activate_widget( button );
} );
}
std::string error ( "Action 'press' is not supported for the selected widget: \"" );
@@ -142,7 +141,7 @@
yuiMilestone() << "Checking \"" << cbframe->label() << '"' << std::endl;
cbframe->setKeyboardFocus();
cbframe->setValue( true );
- activate_widget( cbframe );
+ get_widget_handler()->activate_widget( cbframe );
},
true );
}
@@ -154,12 +153,16 @@
if( YItemSelector* selector = dynamic_cast<YItemSelector*>(widget) )
{
- return get_item_selector_handler( selector, value, body, 1 );
+ return action_handler<YItemSelector>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 1 ) );
}
if( YMultiSelectionBox* selector = dynamic_cast<YMultiSelectionBox*>(widget) )
{
- return get_item_selector_handler( selector, value, body, 1 );
+ return action_handler<YMultiSelectionBox>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 1 ) );
}
}
@@ -185,7 +188,7 @@
yuiMilestone() << "Unchecking \"" << cbframe->label() << '"' << std::endl;
cbframe->setKeyboardFocus();
cbframe->setValue( false );
- activate_widget( cbframe );
+ get_widget_handler()->activate_widget( cbframe );
} );
}
else
@@ -196,12 +199,16 @@
if( YItemSelector* selector = dynamic_cast<YItemSelector*>(widget) )
{
- return get_item_selector_handler( selector, value, body, 0 );
+ return action_handler<YItemSelector>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 0 ) );
}
if( YMultiSelectionBox* selector = dynamic_cast<YMultiSelectionBox*>(widget) )
{
- return get_item_selector_handler( selector, value, body, 0 );
+ return action_handler<YMultiSelectionBox>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 0 ) );
}
}
@@ -226,9 +233,9 @@
[&] (YCheckBoxFrame *cbframe) {
yuiMilestone() << "Toggling \"" << cbframe->label() << '"' << std::endl;
cbframe->setKeyboardFocus();
- activate_widget( cbframe );
+ get_widget_handler()->activate_widget( cbframe );
cbframe->setValue( !cbframe->value() );
- activate_widget( cbframe );
+ get_widget_handler()->activate_widget( cbframe );
},
true ); //Allowing acting on disabled, as do not know state in advance
}
@@ -240,12 +247,16 @@
if( YItemSelector* selector = dynamic_cast<YItemSelector*>(widget) )
{
- return get_item_selector_handler( selector, value, body );
+ return action_handler<YItemSelector>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value ) );
}
if( YMultiSelectionBox* selector = dynamic_cast<YMultiSelectionBox*>(widget) )
{
- return get_item_selector_handler( selector, value, body );
+ return action_handler<YMultiSelectionBox>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value ) );
}
}
@@ -266,7 +277,7 @@
yuiMilestone() << "Setting value for InputField \"" << input->label() << '"' << std::endl;
input->setKeyboardFocus();
input->setValue(value);
- activate_widget( input );
+ get_widget_handler()->activate_widget( input );
} );
}
else if ( dynamic_cast<YIntField*>(widget) )
@@ -291,7 +302,7 @@
yuiMilestone() << "Setting value for YDateField \"" << input->label() << '"' << std::endl;
input->setKeyboardFocus();
input->setValue( value );
- activate_widget( input );
+ get_widget_handler()->activate_widget( input );
} );
}
else if ( dynamic_cast<YTimeField*>(widget) )
@@ -300,7 +311,7 @@
yuiMilestone() << "Setting value for YTimeField \"" << input->label() << '"' << std::endl;
input->setKeyboardFocus();
input->setValue( value );
- activate_widget( input );
+ get_widget_handler()->activate_widget( input );
} );
}
else if ( dynamic_cast<YComboBox*>(widget) )
@@ -316,7 +327,7 @@
yuiMilestone() << "Setting value for YComboBox \"" << cb->label() << '"' << std::endl;
cb->setKeyboardFocus();
cb->setValue( value );
- activate_widget( cb );
+ get_widget_handler()->activate_widget( cb );
} );
}
@@ -339,7 +350,7 @@
{
yuiMilestone() << "Activating Combobox \"" << cb->label() << '"' << std::endl;
cb->selectItem( item );
- activate_widget( cb );
+ get_widget_handler()->activate_widget( cb );
}
else
{
@@ -357,7 +368,7 @@
if ( const char* val = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "column") )
column_id = atoi(val);
- return action_handler<YTable>( widget, body, YTableActionHandler::get_handler(tbl, value, column_id, row_id) );
+ return action_handler<YTable>( widget, body, get_table_handler()->get_handler( tbl, value, column_id, row_id) );
}
else if( dynamic_cast<YTree*>(widget) )
{
@@ -371,7 +382,7 @@
yuiMilestone() << "Activating Tree Item \"" << item->label() << '"' << std::endl;
tree->setKeyboardFocus();
tree->selectItem( item );
- activate_widget( tree );
+ get_widget_handler()->activate_widget( tree );
}
else
{
@@ -388,7 +399,7 @@
yuiMilestone() << "Activating Tree Item \"" << item->label() << '"' << std::endl;
tab->setKeyboardFocus();
tab->selectItem( item );
- activate_widget( tab );
+ get_widget_handler()->activate_widget( tab );
}
else
{
@@ -402,7 +413,7 @@
yuiMilestone() << "Activating RadioButton \"" << rb->label() << '"' << std::endl;
rb->setKeyboardFocus();
rb->setValue(true);
- activate_widget( rb );
+ get_widget_handler()->activate_widget( rb );
} );
}
else if( dynamic_cast<YSelectionBox*>(widget) )
@@ -414,7 +425,7 @@
yuiMilestone() << "Activating selection box \"" << sb->label() << '"' << std::endl;
sb->setKeyboardFocus();
sb->selectItem( item );
- activate_widget( sb );
+ get_widget_handler()->activate_widget( sb );
}
else
{
@@ -422,13 +433,17 @@
}
} );
}
- else if( dynamic_cast<YMultiSelectionBox*>(widget) )
+ else if( YMultiSelectionBox* selector = dynamic_cast<YMultiSelectionBox*>(widget) )
{
- return get_item_selector_handler( dynamic_cast<YMultiSelectionBox*>(widget), value, body, 1 );
+ return action_handler<YMultiSelectionBox>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 1 ) );
}
- else if( dynamic_cast<YItemSelector*>(widget) )
+ else if( YItemSelector* selector = dynamic_cast<YItemSelector*>(widget) )
{
- return get_item_selector_handler( dynamic_cast<YItemSelector*>(widget), value, body, 1 );
+ return action_handler<YItemSelector>( widget,
+ body,
+ get_widget_handler()->get_item_selector_handler( selector, value, 1 ) );
}
else if ( dynamic_cast<YRichText*>(widget) )
{
@@ -438,13 +453,17 @@
rt->activateLink(value);
} );
}
- else if( dynamic_cast<YMenuButton*>(widget) )
+ else if( YMenuButton* menu = dynamic_cast<YMenuButton*>(widget) )
{
- return get_menu_selector_handler( dynamic_cast<YMenuButton*>(widget), value, body );
+ return action_handler<YMenuButton>( widget,
+ body,
+ get_widget_handler()->get_menu_selector_handler( menu, value ) );
}
- else if( dynamic_cast<YMenuBar*>(widget) )
+ else if( YMenuBar* menu = dynamic_cast<YMenuBar*>(widget) )
{
- return get_menu_selector_handler( dynamic_cast<YMenuBar*>(widget), value, body );
+ return action_handler<YMenuBar>( widget,
+ body,
+ get_widget_handler()->get_menu_selector_handler( menu, value ) );
}
std::string error ( "Action 'select' is not supported for the selected widget: \"" );
@@ -459,3 +478,15 @@
return MHD_HTTP_OK;
}
+
+YWidgetActionHandler* YHttpWidgetsActionHandler::get_widget_handler() {
+ if( !widget_action_handler )
+ widget_action_handler = new YWidgetActionHandler();
+ return widget_action_handler;
+}
+
+YTableActionHandler* YHttpWidgetsActionHandler::get_table_handler() {
+ if( !table_action_handler )
+ table_action_handler = new YTableActionHandler();
+ return table_action_handler;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/src/YHttpWidgetsActionHandler.h new/libyui-rest-api-0.5.11/src/YHttpWidgetsActionHandler.h
--- old/libyui-rest-api-0.5.10/src/YHttpWidgetsActionHandler.h 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/src/YHttpWidgetsActionHandler.h 2020-11-27 13:06:48.000000000 +0100
@@ -37,6 +37,8 @@
#include "YTimeField.h"
#include "YWidgetFinder.h"
#include "YWidget.h"
+#include "YWidgetActionHandler.h"
+#include "YTableActionHandler.h"
#include <boost/algorithm/string.hpp>
@@ -45,8 +47,8 @@
public:
- YHttpWidgetsActionHandler() {}
- virtual ~YHttpWidgetsActionHandler() {}
+ YHttpWidgetsActionHandler() {};
+ virtual ~YHttpWidgetsActionHandler() {};
protected:
@@ -57,7 +59,12 @@
int do_action( YWidget *widget, const std::string &action, struct MHD_Connection *connection, std::ostream& body );
- // TODO: move this somewhere else...
+ /**
+ * Define widgets handlers to override in case need to implement
+ * UI specific actions, like activation.
+ **/
+ virtual YWidgetActionHandler* get_widget_handler();
+ virtual YTableActionHandler* get_table_handler();
/**
* Processes action on the given widget.
@@ -100,87 +107,9 @@
return MHD_HTTP_OK;
}
+ YTableActionHandler * table_action_handler = nullptr;
+ YWidgetActionHandler * widget_action_handler = nullptr;
- /**
- * Define default widget activation and override only widgets which
- * either don't have method availaible in libyui or if they require
- * exceptional handling.
- **/
- template<typename T>
- void activate_widget( T * widget ) {
- widget->activate();
- }
-
- /**
- * Declare methods where we need to override widget activation for nc or qt
- * We keep empty methods here, that it still works in case of missing
- * override in the children classes.
- **/
- virtual void activate_widget( YCheckBoxFrame * widget ) {};
- virtual void activate_widget( YComboBox * widget ) {};
- virtual void activate_widget( YDateField * widget ) {};
- virtual void activate_widget( YInputField * widget ) {};
- virtual void activate_widget( YRadioButton * widget ) {};
- virtual void activate_widget( YTimeField * widget ) {};
- virtual void activate_widget( YSelectionBox * widget ) {};
-
- /**
- * Same as activate_widget, but for some widgets we also need to specify
- * item for the selection, so provide method to do exactly that.
- */
- template<typename T, typename I >
- void activate_widget( T * selector, I *item ) {
- selector->activateItem( item );
- }
-
- virtual void activate_widget ( YMultiSelectionBox * widget, YItem * item ) {};
-
- template<typename T>
- int get_item_selector_handler( T *widget, const std::string &value, std::ostream& body, const int state = -1 ) {
- return action_handler<T>( widget, body, [&] (T *selector) {
- YItem * item = selector->findItem( value );
- if ( item )
- {
- selector->setKeyboardFocus();
- // Toggle in case state selector undefined
- bool select = state < 0 ? !item->selected() : (state != 0);
- if( state < 0 )
- {
- select = !item->selected();
- }
- else
- {
- select = (state != 0);
- }
- item->setSelected( select );
- selector->selectItem( item, select );
- activate_widget( selector, item );
- }
- else
- {
- throw YUIException("Item: '" + value + "' cannot be found in the item selector widget");
- }
- } );
- }
-
- template<typename T>
- int get_menu_selector_handler( T *widget, const std::string &value, std::ostream& body ) {
- return action_handler<T>( widget, body, [&] (T *menu_selector) {
- // Vector of string to store path to the tree item
- std::vector<std::string> path;
- boost::split( path, value, boost::is_any_of( TreePathDelimiter ) );
- YMenuItem * item = menu_selector->findItem( path );
- if ( item )
- {
- menu_selector->setKeyboardFocus();
- activate_widget( menu_selector, item );
- }
- else
- {
- throw YUIException("Item with path: '" + value + "' cannot be found in the menu selector widget");
- }
- } );
- }
};
#endif // YHttpWidgetsActionHandler_h
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/src/YTableActionHandler.cc new/libyui-rest-api-0.5.11/src/YTableActionHandler.cc
--- old/libyui-rest-api-0.5.10/src/YTableActionHandler.cc 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/src/YTableActionHandler.cc 2020-11-27 13:06:48.000000000 +0100
@@ -22,6 +22,7 @@
#include "YTableActionHandler.h"
+
#define YUILogComponent "rest-api"
#include "YUILog.h"
@@ -42,6 +43,7 @@
yuiMilestone() << "Activating Table \"" << tb->label() << '"' << std::endl;
tb->setKeyboardFocus();
tb->selectItem( item );
+ activate_widget(tb, item);
}
else
{
@@ -64,6 +66,7 @@
yuiMilestone() << "Activating Table \"" << tb->label() << "\" Item: \"" << item->label( column_id ) << "\"" << std::endl;
tb->setKeyboardFocus();
tb->selectItem( item );
+ activate_widget(tb, item);
}
else
{
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/src/YTableActionHandler.h new/libyui-rest-api-0.5.11/src/YTableActionHandler.h
--- old/libyui-rest-api-0.5.10/src/YTableActionHandler.h 2020-11-24 14:16:45.000000000 +0100
+++ new/libyui-rest-api-0.5.11/src/YTableActionHandler.h 2020-11-27 13:06:48.000000000 +0100
@@ -22,19 +22,24 @@
#include "YTable.h"
#include "YTableItem.h"
+#include "YWidgetActionHandler.h"
+
#define TablePathDelimiter "|"
-class YTableActionHandler
+class YTableActionHandler : public YWidgetActionHandler
{
public:
- YTableActionHandler() {}
- virtual ~YTableActionHandler() {}
+ YTableActionHandler() {};
+ virtual ~YTableActionHandler() {};
+
+public:
+ std::function<void (YTable*)> get_handler( YTable * widget,
+ const std::string &value,
+ const int &column_id = 0, //Use first column by default
+ const int &row_id = -1 );
- static std::function<void (YTable*)> get_handler( YTable * widget,
- const std::string &value,
- const int &column_id = 0, //Use first column by default
- const int &row_id = -1 );
+ virtual void activate_widget( YTable * widget, YItem * item ) {};
protected:
static YTableItem * table_findItem( std::vector<std::string>::const_iterator path_begin,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libyui-rest-api-0.5.10/src/YWidgetActionHandler.h new/libyui-rest-api-0.5.11/src/YWidgetActionHandler.h
--- old/libyui-rest-api-0.5.10/src/YWidgetActionHandler.h 1970-01-01 01:00:00.000000000 +0100
+++ new/libyui-rest-api-0.5.11/src/YWidgetActionHandler.h 2020-11-27 13:06:48.000000000 +0100
@@ -0,0 +1,133 @@
+/*
+ Copyright (C) 2020 SUSE LLC
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) version 3.0 of the License. This library
+ is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details. You should have received a copy of the GNU
+ Lesser General Public License along with this library; if not, write
+ to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef YWidgetActionHandler_h
+#define YWidgetActionHandler_h
+
+#include <iostream>
+#include <functional>
+#include <microhttpd.h>
+#include <sstream>
+
+#define TreePathDelimiter "|"
+
+#include "YCheckBoxFrame.h"
+#include "YComboBox.h"
+#include "YDateField.h"
+#include "YHttpHandler.h"
+#include "YInputField.h"
+#include "YItem.h"
+#include "YMultiSelectionBox.h"
+#include "YMenuItem.h"
+#include "YRadioButton.h"
+#include "YSelectionBox.h"
+#include "YTimeField.h"
+#include "YWidgetFinder.h"
+#include "YWidget.h"
+
+#include <boost/algorithm/string.hpp>
+
+class YWidgetActionHandler
+{
+
+public:
+
+ YWidgetActionHandler() {}
+ virtual ~YWidgetActionHandler() {}
+
+ /**
+ * Define default widget activation and override only widgets which
+ * either don't have method availaible in libyui or if they require
+ * exceptional handling.
+ **/
+ template<typename T>
+ void activate_widget( T * widget ) {
+ widget->activate();
+ }
+
+ /**
+ * Declare methods where we need to override widget activation for nc or qt
+ * We keep empty methods here, that it still works in case of missing
+ * override in the children classes.
+ **/
+ virtual void activate_widget( YCheckBoxFrame * widget ) {};
+ virtual void activate_widget( YComboBox * widget ) {};
+ virtual void activate_widget( YDateField * widget ) {};
+ virtual void activate_widget( YInputField * widget ) {};
+ virtual void activate_widget( YRadioButton * widget ) {};
+ virtual void activate_widget( YTimeField * widget ) {};
+ virtual void activate_widget( YSelectionBox * widget ) {};
+
+ /**
+ * Same as activate_widget, but for some widgets we also need to specify
+ * item for the selection, so provide method to do exactly that.
+ */
+ template<typename T, typename I >
+ void activate_widget( T * selector, I *item ) {
+ selector->activateItem( item );
+ }
+
+ virtual void activate_widget( YMultiSelectionBox * widget, YItem * item ) {};
+
+ template<typename T>
+ std::function<void (T*)> get_item_selector_handler( T *widget, const std::string &value, const int state = -1 ) {
+ return [&] (T *selector) {
+ YItem * item = selector->findItem( value );
+ if ( item )
+ {
+ selector->setKeyboardFocus();
+ // Toggle in case state selector undefined
+ bool select = state < 0 ? !item->selected() : (state != 0);
+ if( state < 0 )
+ {
+ select = !item->selected();
+ }
+ else
+ {
+ select = (state != 0);
+ }
+ item->setSelected( select );
+ selector->selectItem( item, select );
+ activate_widget( selector, item );
+ }
+ else
+ {
+ throw YUIException("Item: '" + value + "' cannot be found in the item selector widget");
+ }
+ };
+ }
+
+ template<typename T>
+ std::function<void (T*)> get_menu_selector_handler( T *widget, const std::string &value ) {
+ return [&] (T *menu_selector) {
+ // Vector of string to store path to the tree item
+ std::vector<std::string> path;
+ boost::split( path, value, boost::is_any_of( TreePathDelimiter ) );
+ YMenuItem * item = menu_selector->findItem( path );
+ if ( item )
+ {
+ menu_selector->setKeyboardFocus();
+ activate_widget( menu_selector, item );
+ }
+ else
+ {
+ throw YUIException("Item with path: '" + value + "' cannot be found in the menu selector widget");
+ }
+ };
+ }
+};
+
+#endif //YWidgetActionHandler_h