libyui-rest-api
Loading...
Searching...
No Matches
YMenuWidgetActionHandler.h
1/*
2 Copyright (C) 2021 SUSE LLC
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) version 3.0 of the License. This library
8 is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 License for more details. You should have received a copy of the GNU
12 Lesser General Public License along with this library; if not, write
13 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14 Floor, Boston, MA 02110-1301 USA
15*/
16
17#ifndef YMenuWidgetActionHandler_h
18#define YMenuWidgetActionHandler_h
19
20#include "YWidgetActionHandler.h"
21
22
24{
25public:
26
28 virtual ~YMenuWidgetActionHandler() {};
29
30 template<typename T>
31 std::function<void (T*)> get_handler( T *widget, const std::string &value ) {
32 return [&] ( T *menu_selector ) {
33 std::string value_sanitized = normalize_label( value );
34 // Vector of string to store path to the tree item
35 std::vector<std::string> path;
36 boost::split( path, value_sanitized, boost::is_any_of( TreePathDelimiter ) );
37 YMenuItem * item = findItem( path.begin(), path.end(), widget->itemsBegin(), widget->itemsEnd() );
38 if ( item )
39 {
40 menu_selector->setKeyboardFocus();
41 activate_widget( menu_selector, item );
42 }
43 else
44 {
45 throw YUIException( "Item with path: '" + value + "' cannot be found in the menu selector widget" );
46 }
47 };
48 }
49
50private:
51
52 YMenuItem * findItem( std::vector<std::string>::iterator path_begin,
53 std::vector<std::string>::iterator path_end,
54 YItemConstIterator begin,
55 YItemConstIterator end ) const;
56};
57
58#endif // YMenuWidgetActionHandler_h
Definition YMenuWidgetActionHandler.h:24
Definition YWidgetActionHandler.h:45
void activate_widget(T *widget)
Definition YWidgetActionHandler.h:58