Fixed and closed #379: positional parameterized snippets are now inserted on a single line by default.

This commit is contained in:
Dario Solera 2009-10-13 12:41:04 +00:00
parent 9738b0470b
commit cd75e9df29
2 changed files with 23 additions and 6 deletions

View file

@ -16,5 +16,5 @@ using System.Reflection;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.0.350")] [assembly: AssemblyVersion("3.0.0.351")]
[assembly: AssemblyFileVersion("3.0.0.350")] [assembly: AssemblyFileVersion("3.0.0.351")]

View file

@ -203,26 +203,43 @@ namespace ScrewTurn.Wiki {
label, s.Name); label, s.Name);
} }
else { else {
bool isPositional = IsSnippetPositional(parameters);
label = string.Format("{0} ({1} {2})", s.Name, paramCount, Properties.Messages.Parameters); label = string.Format("{0} ({1} {2})", s.Name, paramCount, Properties.Messages.Parameters);
sb.AppendFormat(@"<a href=""#"" title=""{0}"" onclick=""javascript:return InsertMarkup('&#0123;s:{1}\n{2}&#0125;');"" class=""menulink"">{0}</a>", sb.AppendFormat(@"<a href=""#"" title=""{0}"" onclick=""javascript:return InsertMarkup('&#0123;s:{1}{2}{3}&#0125;');"" class=""menulink"">{0}</a>",
label, s.Name, GetParametersPlaceHolders(parameters)); label, s.Name, isPositional ? "" : "\\r\\n", GetParametersPlaceHolders(parameters, isPositional));
} }
} }
if(sb.Length == 0) sb.Append("<i>" + Properties.Messages.NoSnippets + "</i>"); if(sb.Length == 0) sb.Append("<i>" + Properties.Messages.NoSnippets + "</i>");
lblSnippets.Text = sb.ToString(); lblSnippets.Text = sb.ToString();
} }
/// <summary>
/// Determines whether the parameters of a snippet are positional or not.
/// </summary>
/// <param name="parameters">The parameters.</param>
/// <returns><c>true</c> if the parameters are positional, <c>false</c> otherwise.</returns>
private static bool IsSnippetPositional(string[] parameters) {
int dummy;
for(int i = 0; i < parameters.Length; i++) {
if(!int.TryParse(parameters[i], out dummy)) return false;
if(dummy != i + 1) return false;
}
return true;
}
/// <summary> /// <summary>
/// Gets the placeholder for snippet parameters. /// Gets the placeholder for snippet parameters.
/// </summary> /// </summary>
/// <param name="parameters">The parameters.</param> /// <param name="parameters">The parameters.</param>
/// <param name="isSnippetPositional">A value indicating whether the snippet parameters are positional.</param>
/// <returns>The snippet placeholder/template.</returns> /// <returns>The snippet placeholder/template.</returns>
private static string GetParametersPlaceHolders(string[] parameters) { private static string GetParametersPlaceHolders(string[] parameters, bool isSnippetPositional) {
if(parameters.Length == 0) return ""; if(parameters.Length == 0) return "";
else { else {
StringBuilder sb = new StringBuilder(20); StringBuilder sb = new StringBuilder(20);
foreach(string param in parameters) { foreach(string param in parameters) {
sb.AppendFormat("| {0} = PLACE YOUR VALUE HERE\\r\\n", param); if(isSnippetPositional) sb.AppendFormat("|PLACE YOUR VALUE HERE ({0})", param);
else sb.AppendFormat("| {0} = PLACE YOUR VALUE HERE\\r\\n", param);
} }
/*for(int i = 1; i <= paramCount; i++) { /*for(int i = 1; i <= paramCount; i++) {
sb.Append("|P"); sb.Append("|P");