Browse Source

Fixed SD2-1251: Code generation in partial classes picks the wrong part

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2261 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
14d8cd8f50
  1. 40
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

40
src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

@ -31,6 +31,43 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -31,6 +31,43 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
/// </summary>
public class ClassBookmarkMenuBuilder : ISubmenuBuilder
{
/// <summary>
/// Gets a specific part of the compound class.
/// </summary>
static IClass GetPart(IClass possibleCompound, string fileName)
{
CompoundClass compound = possibleCompound as CompoundClass;
if (compound == null)
return possibleCompound;
IList<IClass> parts = compound.GetParts();
if (!string.IsNullOrEmpty(fileName)) {
// get the part with the requested file name
foreach (IClass part in parts) {
if (FileUtility.IsEqualFileName(fileName, part.CompilationUnit.FileName))
return part;
}
}
// Fallback: get the part with the shortest file name.
// This should prefer non-designer files over designer files.
IClass preferredClass = parts[0];
for (int i = 1; i < parts.Count; i++) {
if (parts[i].CompilationUnit.FileName.Length < preferredClass.CompilationUnit.FileName.Length)
preferredClass = parts[i];
}
return preferredClass;
}
static IClass GetCurrentPart(IClass possibleCompound)
{
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
if (window != null)
return GetPart(possibleCompound, window.ViewContent.FileName);
else
return GetPart(possibleCompound, null);
}
public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
{
MenuCommand cmd;
@ -45,10 +82,13 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -45,10 +82,13 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
ParserService.ParseCurrentViewContent();
c = c.ProjectContent.GetClass(c.FullyQualifiedName, c.TypeParameters.Count);
c = GetCurrentPart(c);
if (c == null) {
return new ToolStripMenuItem[0];
}
LanguageProperties language = c.ProjectContent.Language;
List<ToolStripItem> list = new List<ToolStripItem>();

Loading…
Cancel
Save