added 'undo', 'redo', and 'cycle' to the context menu

made it so shortcut keys are displayed next to menu items
This commit is contained in:
Dave White 2004-03-23 15:23:36 +00:00
parent abc52ba0f5
commit 34aeef509d
5 changed files with 117 additions and 3 deletions

View file

@ -39,7 +39,7 @@ height=600
[menu]
is_context_menu=true
items=describeunit,speak,recruit,recall,createunit,endturn
items=undo,redo,cycle,describeunit,speak,recruit,recall,createunit,endturn
[/menu]
# top panel

View file

@ -376,7 +376,7 @@ action_zoomout="Zoom Out"
action_zoomdefault="Default Zoom"
action_fullscreen="Fullscreen"
action_accelerated="Accelerated"
action_cycle="Cycle units"
action_cycle="Next unit"
action_endturn="End Turn"
action_endunitturn="End Unit Turn"
action_leader="Leader"

View file

@ -1176,6 +1176,92 @@ config::all_children_iterator config::ordered_end() const
return all_children_iterator(ordered_children.end());
}
config config::get_diff(const config& c) const
{
config res;
config* inserts = NULL;
string_map::const_iterator i;
for(i = values.begin(); i != values.end(); ++i) {
const string_map::const_iterator j = c.values.find(i->first);
if(j == c.values.end() || i->second != j->second) {
if(inserts == NULL) {
inserts = &res.add_child("insert");
}
(*inserts)[i->first] = i->second;
}
}
config* deletes = NULL;
for(i = c.values.begin(); i != c.values.end(); ++i) {
if(values.count(i->first) == 0) {
if(deletes == NULL) {
deletes = &res.add_child("delete");
}
(*deletes)[i->first] = "x";
}
}
return res;
}
void config::apply_diff(const config& diff)
{
const config* const inserts = diff.child("insert");
if(inserts != NULL) {
for(string_map::const_iterator i = inserts->values.begin(); i != inserts->values.end(); ++i) {
values[i->first] = i->second;
}
}
const config* const deletes = diff.child("delete");
if(deletes != NULL) {
for(string_map::const_iterator i = deletes->values.begin(); i != deletes->values.end(); ++i) {
values.erase(i->first);
}
}
}
bool operator==(const config& a, const config& b)
{
if(a.values.size() != b.values.size()) {
return false;
}
for(string_map::const_iterator i = a.values.begin(); i != a.values.end(); ++i) {
const string_map::const_iterator j = b.values.find(i->first);
if(j == b.values.end() || i->second != j->second) {
return false;
}
}
config::all_children_iterator x = a.ordered_begin(), y = b.ordered_begin();
while(x != a.ordered_end() && y != b.ordered_end()) {
const std::pair<const std::string*,const config*> val1 = *x;
const std::pair<const std::string*,const config*> val2 = *y;
if(*val1.first != *val2.first || *val1.second != *val2.second) {
return false;
}
++x;
++y;
}
return x == a.ordered_end() && y == b.ordered_end();
}
bool operator!=(const config& a, const config& b)
{
return !operator==(a,b);
}
//#define TEST_CONFIG
#ifdef TEST_CONFIG

View file

@ -195,6 +195,13 @@ struct config
all_children_iterator ordered_begin() const;
all_children_iterator ordered_end() const;
//a function to get the differences between this object, and 'c', as another config
//object. i.e. calling cfg2.apply_diff(cfg1.get_diff(cfg2)) will make cfg1 identical
//to cfg2.
config get_diff(const config& c) const;
void apply_diff(const config& diff);
//all the attributes of this node.
string_map values;
@ -210,6 +217,9 @@ private:
std::vector<child_pos> ordered_children;
};
bool operator==(const config& a, const config& b);
bool operator!=(const config& a, const config& b);
struct config_has_value {
config_has_value(const std::string& name, const std::string& value)
: name_(name), value_(value)

View file

@ -851,7 +851,25 @@ void turn_info::show_menu(const std::vector<std::string>& items_arg, int xloc, i
std::vector<std::string> menu;
for(std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) {
menu.push_back(translate_string("action_" + *i));
std::stringstream str;
str << translate_string("action_" + *i);
//see if this menu item has an associated hotkey
const hotkey::HOTKEY_COMMAND cmd = hotkey::string_to_command(*i);
const std::vector<hotkey::hotkey_item>& hotkeys = hotkey::get_hotkeys();
std::vector<hotkey::hotkey_item>::const_iterator hk;
for(hk = hotkeys.begin(); hk != hotkeys.end(); ++hk) {
if(hk->action == cmd) {
break;
}
}
if(hk != hotkeys.end()) {
str << "," << hotkey::get_hotkey_name(*hk);
}
menu.push_back(str.str());
}
static const std::string style = "menu2";