My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef _XMLCommand_h_
#define _XMLCommand_h_

#include <CtrlCore/CtrlCore.h>

NAMESPACE_UPP

////////////////////////////////////////////////////////////////////////////////////
// a single command, i.e. available entry for menu and bars
class XMLCommand
{
friend class XMLCommands;
private:
// embedded control, if any
Ptr<Ctrl> control;
Size ctrlSize;

// associated callback, if any
Callback callback;

// enabled flag
bool enabled;

// custom command flag
bool custom;

// custom command string to be sent
// to custom command handler
String commandString;

public:
Ctrl *GetCtrl(void) const { return control; }
Size const &GetCtrlSize(void) const { return ctrlSize; }
Callback const &GetCallback(void) const { return callback; }
bool GetIsEnabled(void) const { return enabled; }
bool GetIsCustom(void) const { return custom; }

String const &GetCommandString(void) const { return commandString; }
XMLCommand &SetCommandString(String const &s) { commandString = s; return *this; }

bool operator==(XMLCommand &other) const;

// xml support
void Xmlize(XmlIO xml);
};

////////////////////////////////////////////////////////////////////////////////////
// an array of available commands
class XMLCommands : DeepCopyOption<XMLCommands>
{
private:
ArrayMap<String, XMLCommand> commands;

public:
// default constructor
XMLCommands() {}

// copy constructor
XMLCommands(XMLCommands const &cmds, int dummy) : commands(cmds.commands, 0) {}

// pick constructor
XMLCommands(XMLCommands pick_ &cmds) : commands(cmds.commands) {}

// adds a custom command
XMLCommands &Add(String const &id, String const &cmd);

// adds a built-in command with given callback
XMLCommands &Add(String const &id, Callback cb);

// adds a control
XMLCommands &Add(String const &id, Ctrl &ctrl);
XMLCommands &Add(String const &id, Ctrl &ctrl, Size const &size);

// adds a custom command, allows enable/disable item
XMLCommands &Add(bool enabled, String const &id, String const &cmd);

// adds a built-in command with given callback, allows enable/disable item
XMLCommands &Add(bool enabled, String const &id, Callback cb);

// adds a control, allows enable/disable item
XMLCommands &Add(bool enabled, String const &id, Ctrl &ctrl);
XMLCommands &Add(bool enabled, String const &id, Ctrl &ctrl, Size const &size);

// removes a command
XMLCommands &Remove(int idx) { commands.Remove(idx); return *this; }

// get all available command IDs
Vector<String> const &GetIds(void) const;

// get a command for a given id
XMLCommand const &Get(String const &id) const { return commands.Get(id); }

// find a command given its name
int Find(String const &id) const { return commands.Find(id); }

// sets the commands by a callback
void Set(Callback1<XMLCommands &> commands);

// checks wether a command is present given its id
bool Has(String const &id) const { return commands.Find(id) >= 0; }

// array access
XMLCommand const &operator[](int idx) const { return commands[idx]; }
XMLCommand &operator[](int idx) { return commands[idx]; }

// sort items - alphabetically, but first built-in commands, then custom ones
XMLCommands &Sort(void);

// xml support
void Xmlize(XmlIO xml);
};

END_UPP_NAMESPACE

#endif

Change log

r4247 by micio on Dec 5, 2011   Diff
Bazaar/XMLMenu : removed a couple of Add()
in commands because of overloading
mismatches
Go to: 
Project members, sign in to write a code review

Older revisions

r4242 by micio on Dec 4, 2011   Diff
Bazaar/XMLMenu : allow custom command
string on custom commands
Fixed a couple of bugs in editor
r4070 by micio on Oct 20, 2011   Diff
sandbox/XMLMenu moved to bazaar
r4055 by micio on Oct 18, 2011   Diff
sandbox/XMLMenu : XML streaming almost
complete - Missing toolbar positions
All revisions of this file

File info

Size: 3486 bytes, 115 lines
Powered by Google Project Hosting