Skip to content

Commit

Permalink
Merge pull request #11 from jknphy/add_menu_bar_widget
Browse files Browse the repository at this point in the history
Add item selection in YMenuBar
  • Loading branch information
lslezak committed Sep 29, 2020
2 parents 53d9c0a + f70f650 commit 21e1058
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
10 changes: 6 additions & 4 deletions API_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ curl -X POST 'http://localhost:9999/v1/widgets?label=Description&action=enter_te
curl -X POST 'http://localhost:9999/v1/widgets?id=names&action=select&row=1'
# select row with "test" cell value in the 2-nd column (counting from zero) in table with id "names"
curl -X POST 'http://localhost:9999/v1/widgets?id=names&action=select&value=test&column=2'
# select tree item with in tree with id "files"
curl -X POST 'http://localhost:9999/v1/widgets?id=files&action=select&value=root|subnode|subnode'
# select tree item with in tree with id "files" and path 'root|subnode|subnode
curl -X POST 'http://localhost:9999/v1/widgets?id=files&action=select&value=root%7Csubnode%7Csubnode'
# press url (<a href=\"firewall\">(enable)</a>) in richtext
curl -X POST 'http://localhost:9999/v1/widgets?type=YRichText&action=select&value=firewall'
# select menu item with label "Image" in parent menu item with label Document in button menu
curl -X POST 'http://localhost:9999/v1/widgets?type=YMenuButton&action=select&value=Document|Image'
# select menu item with label "Image" in parent menu item with label "Document" in menu button
curl -X POST 'http://localhost:9999/v1/widgets?type=YMenuButton&action=select&value=Document%7CImage'
# select menu bar item with label "&Folder" in parent menu item with label "&Create" in menu bar
curl -X POST 'http://localhost:9999/v1/widgets?type=YMenuBar&action=select&value=%26Create%7C%26Folder'
```
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SET( VERSION_MAJOR "0")
SET( VERSION_MINOR "5" )
SET( VERSION_PATCH "4" )
SET( VERSION_PATCH "5" )
SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${GIT_SHA1_VERSION}" )

##### This is need for the libyui core, ONLY.
Expand Down
5 changes: 5 additions & 0 deletions package/libyui-rest-api.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Mon Sep 17 08:05:00 UTC 2020 - Joaquín Rivera <jeriveramoya@suse.com>

- Add item selection in YMenuBar (bsc#1175115)
- 0.5.5

-------------------------------------------------------------------
Wed Sep 16 10:14:16 UTC 2020 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/libyui-rest-api.spec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
%define libyui_devel_version libyui-devel >= 3.10.1

Name: libyui-rest-api
Version: 0.5.4
Version: 0.5.5
Release: 0
Summary: Libyui - REST API plugin, the shared part
License: LGPL-2.1-only OR LGPL-3.0-only
Expand Down
22 changes: 6 additions & 16 deletions src/YHttpWidgetsActionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "YDumbTab.h"
#include "YIntField.h"
#include "YItemSelector.h"
#include "YMenuBar.h"
#include "YMenuButton.h"
#include "YMultiLineEdit.h"
#include "YProperty.h"
Expand Down Expand Up @@ -473,22 +474,11 @@ int YHttpWidgetsActionHandler::do_action(YWidget *widget, const std::string &act
}
else if( dynamic_cast<YMenuButton*>(widget) )
{
return action_handler<YMenuButton>( widget, body, [&] (YMenuButton *mb) {
// 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 = mb->findItem( path );
if ( item )
{
yuiMilestone() << "Activating Item by path :" << value << " in \"" << mb->label() << "\" MenuButton" << std::endl;
mb->setKeyboardFocus();
activate_widget( mb, item );
}
else
{
throw YUIException("Item with path: '" + value + "' cannot be found in the MenuButton widget");
}
} );
return get_menu_selector_handler( dynamic_cast<YMenuButton*>(widget), value, body );
}
else if( dynamic_cast<YMenuBar*>(widget) )
{
return get_menu_selector_handler( dynamic_cast<YMenuBar*>(widget), value, body );
}

std::string error ( "Action 'select' is not supported for the selected widget: \"" );
Expand Down
25 changes: 25 additions & 0 deletions src/YHttpWidgetsActionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@
#include "YInputField.h"
#include "YItem.h"
#include "YMultiSelectionBox.h"
#include "YMenuItem.h"
#include "YSelectionBox.h"
#include "YTimeField.h"
#include "YWidgetFinder.h"
#include "YWidget.h"

#include <boost/algorithm/string.hpp>

#define YUILogComponent "rest-api"
#include "YUILog.h"

class YHttpWidgetsActionHandler : public YHttpHandler
{
Expand Down Expand Up @@ -158,6 +163,26 @@ class YHttpWidgetsActionHandler : public YHttpHandler
}
} );
}

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 )
{
yuiMilestone() << "Activating Item by path :" << value << " in \"" << menu_selector->label() << "\" menu selector" << std::endl;
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

0 comments on commit 21e1058

Please sign in to comment.