[Spice-devel] [PATCH spice 1/9] spicec: add menu id & find_sub()
Hans de Goede
hdegoede at redhat.com
Sun Oct 17 07:24:47 PDT 2010
Ack.
On 10/17/2010 04:13 PM, Arnon Gilboa wrote:
> ---
> client/menu.cpp | 18 +++++++++++++++++-
> client/menu.h | 5 ++++-
> 2 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/client/menu.cpp b/client/menu.cpp
> index 0f7a7e8..1743821 100644
> --- a/client/menu.cpp
> +++ b/client/menu.cpp
> @@ -20,10 +20,11 @@
> #include "utils.h"
> #include "debug.h"
>
> -Menu::Menu(CommandTarget& target, const std::string& name)
> +Menu::Menu(CommandTarget& target, const std::string& name, int id)
> : _refs (1)
> , _target (target)
> , _name (name)
> + , _id (id)
> {
> }
>
> @@ -115,6 +116,21 @@ Menu* Menu::sub_at(int pos)
> return ((Menu*)_items[pos].obj)->ref();
> }
>
> +Menu* Menu::find_sub(int id)
> +{
> + Menu* sub;
> +
> + if (_id == id) {
> + return ref();
> + }
> + for (unsigned int i = 0; i< _items.size(); i++) {
> + if (_items[i].type == MENU_ITEM_TYPE_MENU&& (sub = ((Menu*)_items[i].obj)->find_sub(id))) {
> + return sub;
> + }
> + }
> + return NULL;
> +}
> +
> void Menu::clear()
> {
> for (unsigned int i = 0; i< _items.size(); i++) {
> diff --git a/client/menu.h b/client/menu.h
> index 809e798..6e3d2f1 100644
> --- a/client/menu.h
> +++ b/client/menu.h
> @@ -26,7 +26,7 @@ public:
>
> class Menu {
> public:
> - Menu(CommandTarget& target, const std::string& name);
> + Menu(CommandTarget& target, const std::string& name, int id = 0);
>
> enum ItemType {
> MENU_ITEM_TYPE_INVALID,
> @@ -46,6 +46,7 @@ public:
> void set_name(const std::string& name) { _name = name;}
> const std::string& get_name() { return _name;}
> CommandTarget& get_target() { return _target;}
> + int get_id() { return _id;}
>
> void add_command(const std::string& name, int cmd_id, int state = 0);
> void add_separator();
> @@ -57,6 +58,7 @@ public:
> ItemType item_type_at(int pos);
> void command_at(int pos, std::string& name, int& cmd_id, int& state);
> Menu* sub_at(int pos);
> + Menu* find_sub(int id);
>
> void clear();
>
> @@ -94,6 +96,7 @@ private:
> CommandTarget& _target;
> std::string _name;
> std::vector<MenuItem> _items;
> + int _id;
> };
>
> #endif
More information about the Spice-devel
mailing list