Author: alink
Date: Sat Jun 7 02:36:09 2008
New Revision: 27018
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27018&view=rev
Log:
- Save alias between sessions
- use "alias something" to display its value
- use "alias something=" to free it
Modified:
trunk/src/menu_events.cpp
trunk/src/preferences.cpp
trunk/src/preferences.hpp
Modified: trunk/src/menu_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=27018&r1=27017&r2=27018&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sat Jun 7 02:36:09 2008
@@ -2417,7 +2417,7 @@
register_command("custom",
&console_handler::do_custom,
_("Set the command used by the custom
command hotkey"), "<command>");
register_command("alias",
&console_handler::do_set_alias,
- _("Set a alias to a command"),
"<name>=<command>");
+ _("Set or show alias to a command"),
"<name>[=<command>]");
register_command("set_var",
&console_handler::do_set_var,
_("Set a scenario variable."),
"<var>=<value>", "D");
register_command("show_var",
&console_handler::do_show_var,
@@ -2439,6 +2439,14 @@
register_command("throw",
&console_handler::do_event,
_("Fire a game event."), "", "D");
register_alias("throw", "fire");
+
+ config* alias_list = preferences::get_alias();
+ if (alias_list != NULL) {
+ string_map::const_iterator a =
alias_list->values.begin();
+ for (; a != alias_list->values.end();
++a) {
+ register_alias(a->second,
a->first);
+ }
+ }
}
private:
menu_handler& menu_handler_;
@@ -2840,10 +2848,24 @@
void console_handler::do_set_alias() {
const std::string data = get_data();
const std::string::const_iterator j =
std::find(data.begin(),data.end(),'=');
+ const std::string alias(data.begin(),j);
if(j != data.end()) {
- const std::string alias(data.begin(),j);
const std::string command(j+1,data.end());
- register_alias(command, alias);
+ if (!command.empty()) {
+ register_alias(command, alias);
+ } else {
+ // "alias something=" deactivate this alias. We
just set it
+ // equal to itself here. Later preferences will
filter empty alias.
+ register_alias(alias, alias);
+ }
+ preferences::add_alias(alias, command);
+ // directly save it for the moment, but will slow
commands sequence
+ preferences::write_preferences();
+ } else {
+ // "alias something" display its value
+ // if no alias, will be "'something' = 'something'"
+ const std::string command =
chmap::get_actual_cmd(alias);
+ print(get_cmd(), "'"+alias+"'" + " = " +
"'"+command+"'");
}
}
void console_handler::do_set_var() {
Modified: trunk/src/preferences.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.cpp?rev=27018&r1=27017&r2=27018&view=diff
==============================================================================
--- trunk/src/preferences.cpp (original)
+++ trunk/src/preferences.cpp Sat Jun 7 02:36:09 2008
@@ -535,6 +535,19 @@
hotkey::save_hotkeys(prefs);
}
+void add_alias(const std::string& alias, const std::string& command) {
+ config* alias_list = prefs.child("alias");
+ if (alias_list == NULL) {
+ alias_list = &(prefs.add_child("alias"));
+ }
+ alias_list->values[alias] = command;
+}
+
+
+config* get_alias() {
+ return prefs.child("alias");
+}
+
unsigned int sample_rate()
{
return lexical_cast_default<unsigned
int>(preferences::get("sample_rate"), 44100);
Modified: trunk/src/preferences.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.hpp?rev=27018&r1=27017&r2=27018&view=diff
==============================================================================
--- trunk/src/preferences.hpp (original)
+++ trunk/src/preferences.hpp Sat Jun 7 02:36:09 2008
@@ -127,6 +127,9 @@
void load_hotkeys();
void save_hotkeys();
+ void add_alias(const std::string& alias, const std::string& command);
+ config* get_alias();
+
bool use_colour_cursors();
void _set_colour_cursors(bool value);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits