Browse Source

dynamic help: new method/type detection (by Robert_G, Delphi-PRAXiS) used for Forms designer support

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@477 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mathias Simmack 21 years ago
parent
commit
4d7308244b
  1. 111
      src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/DynamicHelpPad.cs

111
src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/DynamicHelpPad.cs

@ -9,6 +9,7 @@ namespace HtmlHelp2
{ {
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Drawing; using System.Drawing;
using System.Drawing.Design; using System.Drawing.Design;
@ -43,7 +44,7 @@ namespace HtmlHelp2
private int internalIndex = 0; private int internalIndex = 0;
private StringCollection dynamicHelpTerms = new StringCollection(); private StringCollection dynamicHelpTerms = new StringCollection();
private string debugPreElement = String.Empty; private string debugPreElement = String.Empty;
private bool enableDebugInfo = false; private bool enableDebugInfo = true;
public override Control Control public override Control Control
{ {
@ -71,7 +72,6 @@ namespace HtmlHelp2
PropertyPad.SelectedObjectChanged += new EventHandler(this.FormsDesignerSelectedObjectChanged); PropertyPad.SelectedObjectChanged += new EventHandler(this.FormsDesignerSelectedObjectChanged);
PropertyPad.SelectedGridItemChanged += new SelectedGridItemChangedEventHandler(this.FormsDesignerSelectedGridItemChanged); PropertyPad.SelectedGridItemChanged += new SelectedGridItemChangedEventHandler(this.FormsDesignerSelectedGridItemChanged);
ProjectService.SolutionClosed += new EventHandler(this.SolutionClosed); ProjectService.SolutionClosed += new EventHandler(this.SolutionClosed);
this.enableDebugInfo = this.EnableDebugInfo();
} }
#region WebBrowser Scripting #region WebBrowser Scripting
@ -123,7 +123,8 @@ namespace HtmlHelp2
{ {
result = true; result = true;
IHxTopic[] newTopics = this.SortTopics(topics); List<IHxTopic> newTopics = this.SortTopics(topics);
// IHxTopic[] newTopics = this.SortTopics(topics);
foreach(IHxTopic topic in newTopics) foreach(IHxTopic topic in newTopics)
{ {
this.BuildNewChild(topic.Location, this.BuildNewChild(topic.Location,
@ -410,20 +411,13 @@ namespace HtmlHelp2
Type myObject = selectedObject.GetType(); Type myObject = selectedObject.GetType();
if(selectedItem != null) if(selectedItem != null)
{ {
this.AddToStringCollection(String.Format("!{0}.{1}", foreach(Type type in TypeHandling.FindDeclaringType(myObject, selectedItem.Label))
myObject.FullName,
selectedItem.Label));
while(myObject.BaseType != null)
{ {
myObject = myObject.BaseType; this.AddToStringCollection(String.Format("{0}.{1}",
this.AddToStringCollection(String.Format("!{0}.{1}", type.FullName,
myObject.FullName,
selectedItem.Label)); selectedItem.Label));
} }
} }
myObject = selectedObject.GetType();
this.AddToStringCollection(myObject.FullName); this.AddToStringCollection(myObject.FullName);
WorkbenchSingleton.SafeThreadAsyncCall(this, WorkbenchSingleton.SafeThreadAsyncCall(this,
@ -451,21 +445,6 @@ namespace HtmlHelp2
} }
catch {} catch {}
} }
private bool EnableDebugInfo()
{
try
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(PropertyService.ConfigDirectory + "help2environment.xml");
XmlNode node = xmldoc.SelectSingleNode("/help2environment/dynamic_help/@enabledebuginfo");
return (node != null && node.InnerText == "yes");
}
catch {}
return false;
}
#endregion #endregion
private void SolutionClosed(object sender, EventArgs e) private void SolutionClosed(object sender, EventArgs e)
@ -488,61 +467,47 @@ namespace HtmlHelp2
} }
} }
private IHxTopic[] SortTopics(IHxTopicList topics) private List<IHxTopic> SortTopics(IHxTopicList topics)
{ {
IHxTopic[] result = null; List<IHxTopic> result = new List<IHxTopic>();
try try
{ {
result = new IHxTopic[topics.Count]; if(topics != null && topics.Count > 0)
int counter = 0;
foreach(IHxTopic topic in topics)
{ {
result[counter] = topic; foreach(IHxTopic topic in topics)
counter++; {
if(!result.Contains(topic)) result.Add(topic);
}
TopicComparer topicComparer = new TopicComparer();
result.Sort(topicComparer);
} }
TopicComparer topicComparer = new TopicComparer();
Array.Sort(result, topicComparer);
} }
catch {} catch {}
return result; return result;
} }
class TopicComparer : IComparer class TopicComparer : IComparer<IHxTopic>
{ {
private IHxTopic topicA = null; public int Compare(IHxTopic x, IHxTopic y)
private IHxTopic topicB = null;
public int Compare(object x, object y)
{ {
topicA = (IHxTopic)x; int result = CompareType("kbSyntax", x, y);
topicB = (IHxTopic)y; if(result == 0) result = CompareType("kbHowTo", x, y);
int result = 0; if(result == 0) result = CompareType("kbArticle", x, y);
result = CompareType("kbSyntax");
if(result == 0) result = CompareType("kbHowTo");
if(result == 0) result = CompareType("kbArticle");
return result; return result;
} }
private int CompareType(string topicType) private int CompareType(string topicType, IHxTopic x, IHxTopic y)
{ {
if(topicA.HasAttribute("TopicType", topicType) && !topicB.HasAttribute("TopicType", topicType)) if(x.HasAttribute("TopicType", topicType) && !y.HasAttribute("TopicType", topicType))
{
return -1; return -1;
} else if(y.HasAttribute("TopicType", topicType) && !x.HasAttribute("TopicType", topicType))
else if(topicB.HasAttribute("TopicType", topicType) && !topicA.HasAttribute("TopicType", topicType))
{
return 1; return 1;
}
else else
{
return 0; return 0;
}
} }
} }
#endregion #endregion
@ -686,4 +651,30 @@ namespace HtmlHelp2
} }
#endregion #endregion
} }
#region TypeHandling by Robert_G
public static class TypeHandling
{
public static IEnumerable<Type> FindDeclaringType(Type type, string memberName)
{
MemberInfo[] memberInfos = type.GetMember(memberName);
List<Type> declaringTypes = new List<Type>();
foreach(MemberInfo memberInfo in memberInfos)
{
if(!declaringTypes.Contains(memberInfo.DeclaringType))
declaringTypes.Add(memberInfo.DeclaringType);
}
foreach(Type declaringType in declaringTypes)
{
yield return declaringType;
}
// QUOTE:
// "Aber das ist wohl eher ein no-Brainer... ;-)"
// (Robert)
}
}
#endregion
} }

Loading…
Cancel
Save