[Wesnoth-commits] r10191 - in /trunk: changelog src/multiplayer_ui.cpp src/playturn.cpp (February 19, 2006 - 08:48)

Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Headers

 

Author: boucman
Date: Sun Feb 19 08:47:56 2006
New Revision: 10191

URL: http://svn.gna.org/viewcvs/wesnoth?rev=10191&view=rev
Log:
tab completion now completes to the shortest substring, ans show the list of possible completions

Modified:
    trunk/changelog
    trunk/src/multiplayer_ui.cpp
    trunk/src/playturn.cpp

Modified: trunk/changelog
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=10191&r1=10190&r2=10191&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Feb 19 08:47:56 2006
@@ -41,6 +41,8 @@
    * WML-generated units with "random_traits" now show the traits description
    * flags on village don't "flicker" at the end of their animations
    * really fix bug 3388, now really centering on image when clicking it
+   * tab completion now completes to smallest substring, and show possoble
+   completions
    
 Version 1.1.1:
  * campaigns

Modified: trunk/src/multiplayer_ui.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_ui.cpp?rev=10191&r1=10190&r2=10191&view=diff
==============================================================================
--- trunk/src/multiplayer_ui.cpp (original)
+++ trunk/src/multiplayer_ui.cpp Sun Feb 19 08:47:56 2006
@@ -310,21 +310,40 @@
 			semiword.assign(text,last_space+1,text.size());
 		}
 
-		std::string guess;
 
 		std::vector<std::string>& users = user_list_;
+		std::vector<std::string> matches;
 		std::sort<std::vector<std::string>::iterator>(users.begin(), users.end());
-		for(std::vector<std::string>::const_iterator i = users.begin(); i != users.end(); ++i) {
+		std::string best_match = semiword;
+		for(std::vector<std::string>::iterator i = users.begin(); i != users.end(); ++i) {
 			if( i->size() >= semiword.size() && 
 					std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
-				guess = *i;
-				break;
+				if(matches.empty()) {
+					best_match = *i;
+				} else {
+					int j=0;
+					while(best_match[j] == (*i)[j]) j++;
+					best_match.erase(best_match.begin()+j,best_match.end());
+				}
+				matches.push_back(*i);
 			}
 		}
 
-		if(guess.empty() == false) {
+		if(!matches.empty()) {
 			std::string add = beginning ? ": " : " ";
-			text.replace(last_space+1, semiword.size(), guess + add);
+			text.replace(last_space+1, semiword.size(), best_match);
+			if(matches.size() == 1) {
+				text.append(add);
+			} else {
+				std::string completion_list;
+				std::vector<std::string>::iterator it;
+				for(it =matches.begin();it!=matches.end();it++) {
+					completion_list += " ";
+					completion_list += *it;
+				}
+				chat_.add_message("",completion_list);
+				chat_.update_textbox(chat_textbox_);
+			}
 			entry_textbox_.set_text(text);
 		}
 	}

Modified: trunk/src/playturn.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/playturn.cpp?rev=10191&r1=10190&r2=10191&view=diff
==============================================================================
--- trunk/src/playturn.cpp (original)
+++ trunk/src/playturn.cpp Sun Feb 19 08:47:56 2006
@@ -3027,14 +3027,6 @@
 	close_textbox();
 }
 
-namespace {
-
-bool tab_complete(const std::string& partword, const std::string& name)
-{
-	return name.size() >= partword.size() && std::equal(partword.begin(),partword.end(),name.begin(),chars_equal_insensitive);
-}
-
-}
 
 void turn_info::tab_textbox()
 {
@@ -3064,7 +3056,8 @@
 			semiword.assign(text,last_space+1,text.size());
 		}
 
-		std::string guess;
+		std::vector<std::string> matches;
+		std::string best_match = semiword;
 
 		for(size_t n = 0; n != teams_.size(); ++n) {
 			if(teams_[n].is_empty()) {
@@ -3073,25 +3066,51 @@
 			const unit_map::const_iterator leader = team_leader(n+1,units_);
 			if(leader != units_.end()) {
 				const std::string& name = leader->second.description();
-				if(tab_complete(semiword,name)) {
-					guess = name;
+				if( name.size() >= semiword.size() && 
+						std::equal(semiword.begin(),semiword.end(),name.begin(),chars_equal_insensitive)) {
+					if(matches.empty()) {
+						best_match = name;
+					} else {
+						int j= 0;;
+						while(best_match[j] == name[j]) j++;
+						best_match.erase(best_match.begin()+j,best_match.end());
+					}
+					matches.push_back(name);
 				}
 			}
 		}
 
-		if(guess.empty()) {
+		if(matches.empty()) {
 			const std::set<std::string>& observers = gui_.observers();
 			for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) {
-				if(tab_complete(semiword,*i)) {
-					guess = *i;
-					break;
+				if( i->size() >= semiword.size() && 
+						std::equal(semiword.begin(),semiword.end(),i->begin(),chars_equal_insensitive)) {
+					if(matches.empty()) {
+						best_match = *i;
+					} else {
+						int j;
+						while(best_match[j] == (*i)[j]) j++;
+						best_match.erase(best_match.begin()+j,best_match.end());
+					}
+					matches.push_back(*i);
 				}
 			}
 		}
 
-		if(guess.empty() == false) {
+		if(!matches.empty()) {
 			std::string add = beginning ? ": " : " ";
-			text.replace(last_space+1, semiword.size(), guess + add);
+			text.replace(last_space+1, semiword.size(), best_match);
+			if(matches.size() == 1) {
+				text.append(add);
+			} else {
+				std::string completion_list;
+				std::vector<std::string>::iterator it;
+				for(it =matches.begin();it!=matches.end();it++) {
+					completion_list += " ";
+					completion_list += *it;
+				}
+				gui_.add_chat_message("",0,completion_list,display::MESSAGE_PRIVATE);
+			}
 			textbox_.box->set_text(text);
 		}
 		break;



Related Mails




Powered by MHonArc, Updated Sun Feb 19 10:00:24 2006