← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2135: Extend %[line:] to create combo boxes

 

------------------------------------------------------------
revno: 2135
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Sat 2010-05-08 21:13:52 +0200
message:
  Extend %[line:] to create combo boxes
modified:
  changelog.txt
  help/dialog_user_command.html
  win32/WinUtil.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2010-05-08 16:17:17 +0000
+++ changelog.txt	2010-05-08 19:13:52 +0000
@@ -13,6 +13,7 @@
 * [L#556011] Respect the font style in chat windows
 * [L#551319] Add %[fileMN] to user command params (thanks darkklor)
 * Magnet links are now produced with a size (xl) param
+* [L#505450] Extend %[line:] to create combo boxes (thanks sulan)
 
 -- 0.761 2010-03-14 --
 * [L#533840] Fix crashes with themed menus (poy)

=== modified file 'help/dialog_user_command.html'
--- help/dialog_user_command.html	2010-05-08 16:17:17 +0000
+++ help/dialog_user_command.html	2010-05-08 19:13:52 +0000
@@ -68,7 +68,14 @@
 	<a href="http://en.wikipedia.org/wiki/Magnet_link"; target="_blank" class="external">magnet link</a>
 	to the file (search, file list contexts only)</li>
 	<li>%[type]: "File" or "Directory" (directory context only)</li>
-	<li>%[line:<i>reason</i>]: Opens up a window asking for "<i>reason</i>"</li>
+	<li>
+	%[line:<i>caption</i>]: Opens up a dialog asking for "<i>caption</i>".<br/>
+	By default, the input interface is a text-box control, unless "<i>caption</i>" corresponds to
+	the following syntax: caption/default_sel/value0/value1/.../valueN where <i>caption</i> is the
+	new caption, <i>default_sel</i> is a number corresponding to the default value to select, and
+	the following params are values of a drop-down list control created instead of the text-box.
+	Params are separated using forward slashes ('/'); one can use '//' to actually write a slash.
+	</li>
 </ul>
 <p>
 In addition to these variables, all of the ADC INF flags are available, with the following prefixes: <b>my</b>, <b>user</b>, and <b>hub</b>. Some may <u>not</u> be available on NMDC hubs. Many useful ones are enumerated below:

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2010-05-08 16:17:17 +0000
+++ win32/WinUtil.cpp	2010-05-08 19:13:52 +0000
@@ -679,15 +679,45 @@
 		if(j == string::npos)
 			break;
 
-		string name = uc.getCommand().substr(i, j - i);
+		const string name = uc.getCommand().substr(i, j - i);
 		if(find(names.begin(), names.end(), name) == names.end()) {
-			string caption = name;
+			tstring caption = Text::toT(name);
 			if(uc.adc()) {
-				Util::replace("\\\\", "\\", caption);
-				Util::replace("\\s", " ", caption);
-			}
-
-			dlg.addTextBox(Text::toT(caption), Text::toT(sm["line:" + name]));
+				Util::replace(_T("\\\\"), _T("\\"), caption);
+				Util::replace(_T("\\s"), _T(" "), caption);
+			}
+
+			// let's break between slashes (while ignoring double-slashes) to see if it's a combo
+			int combo_sel = -1;
+			tstring name_ = caption;
+			Util::replace(_T("//"), _T("\t"), name_);
+			TStringList combo_values = StringTokenizer<tstring>(name_, _T('/')).getTokens();
+			if(combo_values.size() > 2) { // must contain at least: caption, default sel, 1 value
+
+				TStringIter first = combo_values.begin();
+				caption = *first;
+				combo_values.erase(first);
+
+				first = combo_values.begin();
+				combo_sel = Util::toUInt(Text::fromT(*first));
+				combo_values.erase(first);
+				if(static_cast<size_t>(combo_sel) >= combo_values.size())
+					combo_sel = 0; // default selection value too high
+
+				for(TStringIter i = combo_values.begin(), iend = combo_values.end(); i != iend; ++i)
+					Util::replace(_T("\t"), _T("/"), *i);
+
+				// if the combo has already been displayed before, retrieve the prev value and bypass combo_sel
+				TStringIterC prev = find(combo_values.begin(), combo_values.end(), Text::toT(sm["line:" + name]));
+				if(prev != combo_values.end())
+					combo_sel = prev - combo_values.begin();
+			}
+
+			if(combo_sel >= 0) {
+				dlg.addComboBox(caption, combo_values, combo_sel);
+			} else {
+				dlg.addTextBox(caption, Text::toT(sm["line:" + name]));
+			}
 			names.push_back(name);
 		}
 		i = j + 1;