Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add item selection in YMenuBar #11

Merged
merged 1 commit into from Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions API_v1.md
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
@@ -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
@@ -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
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
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
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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that one, it breaks compilation of ncurses library, because we cannot redefine log component. I will fix that.

#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 );
jknphy marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
throw YUIException("Item with path: '" + value + "' cannot be found in the menu selector widget");
}
} );
}
};

#endif // YHttpWidgetsActionHandler_h