Browse Source

Initial check-in of the new Class Wizard.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2235 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Itar Bar-Haim 19 years ago
parent
commit
97c7083516
  1. 25
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/ClassWizard.addin
  2. 69
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/ClassWizard.csproj
  3. 20
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Configuration/AssemblyInfo.cs
  4. 215
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Resources/AddClassForm.xfrm
  5. 39
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Resources/ClassesList.xfrm
  6. 189
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddClassForm.cs
  7. 34
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddNewClassCommand.cs
  8. 13
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddNewInterfaceCommand.cs
  9. 185
      src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/ClassesList.cs
  10. 9
      src/SharpDevelop.sln

25
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/ClassWizard.addin

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<AddIn name = "ClassWizard"
author = "Itai Bar-Haim"
url = ""
description = "Visually add new classes to the project.">
<Manifest>
<Identity name="ClassWizard" version="@ClassWizard.dll"/>
<Dependency addin="SharpDevelop" version="2.1"/>
</Manifest>
<Runtime>
<Import assembly = "ClassWizard.dll"/>
</Runtime>
<Path name = "/SharpDevelop/Workbench/MainMenu/Project/ProjectAddMenu">
<Condition name = "ProjectActive" activeproject="*">
<MenuItem type = "Separator"/>
<MenuItem id = "NewClass"
label = "Class"
class = "ClassWizard.AddNewClassCommand"/>
</Condition>
</Path>
</AddIn>

69
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/ClassWizard.csproj

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ClassWizard</RootNamespace>
<AssemblyName>ClassWizard</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<None Include="ClassWizard.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<EmbeddedResource Include="Resources\ClassesList.xfrm" />
<EmbeddedResource Include="Resources\AddClassForm.xfrm" />
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AddClassForm.cs" />
<Compile Include="Src\AddNewClassCommand.cs" />
<Compile Include="Src\AddNewInterfaceCommand.cs" />
<Compile Include="Src\ClassesList.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project>
<Name>ICSharpCode.TextEditor</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
</ProjectReference>
</ItemGroup>
</Project>

20
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Configuration/AssemblyInfo.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Itai Bar-Haim" email=""/>
// </file>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Information about this assembly is defined by the following
// attributes.
//
// change them to the information which is associated with the assembly
// you compile.
[assembly: AssemblyTitle("ClassWizard")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

215
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Resources/AddClassForm.xfrm

@ -0,0 +1,215 @@ @@ -0,0 +1,215 @@
<Components version="1.0">
<System.Windows.Forms.Form>
<Name value="AddClassForm" />
<MinimumSize value="365, 342" />
<ControlBox value="False" />
<Text value="Add New Class" />
<ClientSize value="{Width=357, Height=308}" />
<Controls>
<System.Windows.Forms.CheckBox>
<Name value="isSealedCheckBox" />
<Location value="232, 194" />
<Text value="Sealed" />
<TabIndex value="15" />
<Size value="61, 20" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Bottom, Left" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox>
<Name value="isStaticCheckBox" />
<Location value="165, 193" />
<Text value="Static" />
<TabIndex value="8" />
<Size value="61, 20" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Bottom, Left" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox>
<Name value="isAbstractCheckBox" />
<Location value="84, 193" />
<Text value="Abstract" />
<TabIndex value="7" />
<Size value="75, 20" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Bottom, Left" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.ComboBox>
<Name value="namespaceComboBox" />
<Size value="261, 21" />
<TabIndex value="0" />
<Sorted value="True" />
<FormattingEnabled value="True" />
<Location value="84, 11" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.ComboBox>
<System.Windows.Forms.Label>
<Name value="label5" />
<Location value="12, 14" />
<Text value="Namespace:" />
<Size value="67, 13" />
<AutoSize value="True" />
<TabIndex value="14" />
</System.Windows.Forms.Label>
<System.Windows.Forms.CheckBox>
<Name value="isPartialCheckBox" />
<Location value="299, 193" />
<Text value="Partial" />
<TabIndex value="9" />
<Size value="61, 20" />
<UseVisualStyleBackColor value="True" />
<Anchor value="Bottom, Left" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.ComboBox>
<Name value="visibilityComboBox" />
<Size value="123, 21" />
<TabIndex value="6" />
<FormattingEnabled value="True" />
<DropDownStyle value="DropDownList" />
<Location value="84, 166" />
<Anchor value="Bottom, Left" />
</System.Windows.Forms.ComboBox>
<System.Windows.Forms.Label>
<Name value="label4" />
<Location value="8, 169" />
<Text value="Visibility:" />
<Anchor value="Bottom, Left" />
<Size value="46, 13" />
<AutoSize value="True" />
<TabIndex value="11" />
</System.Windows.Forms.Label>
<System.Windows.Forms.Button>
<Name value="selectInterfacesButton" />
<Location value="320, 141" />
<Text value="..." />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="25, 19" />
<TabIndex value="5" />
</System.Windows.Forms.Button>
<System.Windows.Forms.ListBox>
<Name value="implementedInterfacesListBox" />
<Size value="230, 69" />
<TabIndex value="4" />
<HorizontalScrollbar value="True" />
<FormattingEnabled value="True" />
<Location value="84, 90" />
<Anchor value="Top, Bottom, Left, Right" />
</System.Windows.Forms.ListBox>
<System.Windows.Forms.Button>
<Name value="selectClassButton" />
<Location value="319, 64" />
<Text value="..." />
<Anchor value="Top, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="25, 19" />
<TabIndex value="3" />
</System.Windows.Forms.Button>
<System.Windows.Forms.TextBox>
<Name value="inheritFromTextBox" />
<TabIndex value="2" />
<Size value="230, 20" />
<Location value="84, 64" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.TextBox>
<System.Windows.Forms.Button>
<Name value="browseButton" />
<Location value="320, 221" />
<Text value="..." />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="25, 19" />
<TabIndex value="11" />
</System.Windows.Forms.Button>
<System.Windows.Forms.ComboBox>
<Name value="existingFilesComboBox" />
<Size value="214, 21" />
<TabIndex value="12" />
<Sorted value="True" />
<FormattingEnabled value="True" />
<DropDownStyle value="DropDownList" />
<Location value="131, 246" />
<Anchor value="Bottom, Left, Right" />
</System.Windows.Forms.ComboBox>
<System.Windows.Forms.RadioButton>
<Name value="addToFileRadioButton" />
<Location value="8, 247" />
<Text value="Add to existing file:" />
<Anchor value="Bottom, Left" />
<UseVisualStyleBackColor value="True" />
<Size value="113, 17" />
<AutoSize value="True" />
<TabIndex value="10" />
</System.Windows.Forms.RadioButton>
<System.Windows.Forms.TextBox>
<Name value="newFileNameTextBox" />
<TabIndex value="10" />
<Size value="183, 20" />
<Location value="131, 220" />
<Anchor value="Bottom, Left, Right" />
</System.Windows.Forms.TextBox>
<System.Windows.Forms.RadioButton>
<Name value="createNewFileRadioButton" />
<TabStop value="True" />
<Location value="8, 221" />
<Checked value="True" />
<Text value="Create in new file:" />
<Anchor value="Bottom, Left" />
<UseVisualStyleBackColor value="True" />
<Size value="109, 17" />
<AutoSize value="True" />
<TabIndex value="8" />
</System.Windows.Forms.RadioButton>
<System.Windows.Forms.Button>
<Name value="cancelButton" />
<DialogResult value="Cancel" />
<Location value="270, 273" />
<Text value="Cancel" />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="75, 23" />
<TabIndex value="14" />
</System.Windows.Forms.Button>
<System.Windows.Forms.Button>
<Name value="okButton" />
<DialogResult value="OK" />
<Location value="189, 273" />
<Text value="OK" />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="75, 23" />
<TabIndex value="13" />
</System.Windows.Forms.Button>
<System.Windows.Forms.Label>
<Name value="label3" />
<Location value="12, 90" />
<Text value="Implements:" />
<Size value="63, 13" />
<AutoSize value="True" />
<TabIndex value="5" />
</System.Windows.Forms.Label>
<System.Windows.Forms.Label>
<Name value="label2" />
<Location value="12, 67" />
<Text value="Inherit from:" />
<Size value="62, 13" />
<AutoSize value="True" />
<TabIndex value="3" />
</System.Windows.Forms.Label>
<System.Windows.Forms.Label>
<Name value="label1" />
<Location value="12, 41" />
<Text value="Class Name:" />
<Size value="66, 13" />
<AutoSize value="True" />
<TabIndex value="1" />
</System.Windows.Forms.Label>
<System.Windows.Forms.TextBox>
<Name value="classNameTextBox" />
<TabIndex value="1" />
<Size value="261, 20" />
<Location value="84, 38" />
<Anchor value="Top, Left, Right" />
</System.Windows.Forms.TextBox>
</Controls>
</System.Windows.Forms.Form>
</Components>

39
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Resources/ClassesList.xfrm

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<Components version="1.0">
<System.Windows.Forms.Form>
<Name value="form1" />
<ControlBox value="False" />
<Text value="Select Class To Inherit" />
<ClientSize value="{Width=292, Height=266}" />
<Controls>
<System.Windows.Forms.Button>
<Name value="cancelButton" />
<DialogResult value="Cancel" />
<Location value="205, 231" />
<Text value="Cancel" />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="75, 23" />
<TabIndex value="15" />
</System.Windows.Forms.Button>
<System.Windows.Forms.Button>
<Name value="okButton" />
<Enabled value="False" />
<DialogResult value="OK" />
<Location value="124, 231" />
<Text value="OK" />
<Anchor value="Bottom, Right" />
<UseVisualStyleBackColor value="True" />
<Size value="75, 23" />
<TabIndex value="14" />
</System.Windows.Forms.Button>
<System.Windows.Forms.TreeView>
<Name value="classesTreeView" />
<Size value="268, 213" />
<TabIndex value="13" />
<PathSeparator value="." />
<Location value="12, 12" />
<Anchor value="Top, Bottom, Left, Right" />
</System.Windows.Forms.TreeView>
</Controls>
</System.Windows.Forms.Form>
</Components>

189
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddClassForm.cs

@ -0,0 +1,189 @@ @@ -0,0 +1,189 @@
/*
* Created by SharpDevelop.
* User: itai
* Date: 12/22/2006
* Time: 3:34 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Gui.XmlForms;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Refactoring;
namespace ClassWizard
{
public class AddClassForm : BaseSharpDevelopForm
{
public AddClassForm()
{
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ClassWizard.Resources.AddClassForm.xfrm"));
Get<Button>("ok").Click += OkButtonClick;
Get<RadioButton>("createNewFile").CheckedChanged += FileCreationModeChanged;
Get<RadioButton>("addToFile").CheckedChanged += FileCreationModeChanged;
Get<Button>("selectClass").Click += SelectClassButtonClick;
Get<Button>("selectInterfaces").Click += SelectInterfacesButtonClick;
ComboBox visibility = Get<ComboBox>("visibility");
visibility.Items.Add("Public");
visibility.Items.Add("Private");
visibility.Items.Add("Protected");
visibility.Items.Add("Internal");
visibility.SelectedIndex = 0;
classes.ClassType = ICSharpCode.SharpDevelop.Dom.ClassType.Class;
classes.SelectMultiple = false;
interfaces.ClassType = ICSharpCode.SharpDevelop.Dom.ClassType.Interface;
interfaces.SelectMultiple = true;
}
private ClassesListDialog classes = new ClassesListDialog();
private ClassesListDialog interfaces = new ClassesListDialog();
protected override void OnShown(EventArgs e)
{
IProject proj = ProjectService.CurrentProject;
IProjectContent projCont = proj.CreateProjectContent();
classes.Project = proj;
interfaces.Project = proj;
ComboBox existingFiles = Get<ComboBox>("existingFiles");
existingFiles.Items.Clear();
foreach (ProjectItem projectItem in ProjectService.CurrentProject.Items)
{
if (projectItem.ItemType == ItemType.Compile)
existingFiles.Items.Add(FileUtility.GetRelativePath(proj.Directory, projectItem.FileName));
}
ComboBox namespaces = Get<ComboBox>("namespace");
namespaces.Items.Clear();
foreach (string nsn in projCont.NamespaceNames)
namespaces.Items.Add(nsn);
base.OnShown(e);
}
void OkButtonClick(object sender, EventArgs e)
{
IProject proj = ProjectService.CurrentProject;
NamespaceDeclaration domNS = new NamespaceDeclaration(Get<ComboBox>("namespace").Text);
domNS.AddChild(new UsingDeclaration("System"));
domNS.AddChild(new UsingDeclaration("System.Collections.Generic"));
Modifiers mods = Modifiers.None;
if (Get<CheckBox>("isStatic").Checked)
mods |= Modifiers.Static;
if (Get<CheckBox>("isAbstract").Checked)
mods |= Modifiers.Abstract;
if (Get<CheckBox>("isSealed").Checked)
mods |= Modifiers.Sealed;
if (Get<CheckBox>("isPartial").Checked)
mods |= Modifiers.Partial;
ComboBox visibility = Get<ComboBox>("visibility");
switch (visibility.SelectedIndex)
{
case 0: mods |= Modifiers.Public; break;
case 1: mods |= Modifiers.Private; break;
case 2: mods |= Modifiers.Protected; break;
case 3: mods |= Modifiers.Internal; break;
}
TypeDeclaration domType = new TypeDeclaration(mods, null);
domType.Name = Get<TextBox>("className").Text;
domType.Type = ICSharpCode.NRefactory.Ast.ClassType.Class;
ListBox ifacesList = Get<ListBox>("implementedInterfaces");
foreach (string c in ifacesList.Items)
domType.BaseTypes.Add(new TypeReference(c));
domNS.AddChild(domType);
if (Get<RadioButton>("createNewFile").Checked)
{
StreamWriter sw;
string filename = Get<TextBox>("newFileName").Text;
if (!Path.HasExtension(filename))
filename += "." + proj.LanguageProperties.CodeDomProvider.FileExtension;
filename = Path.Combine(proj.Directory, filename);
sw = File.CreateText(filename);
sw.Write(proj.LanguageProperties.CodeGenerator.GenerateCode(domNS, String.Empty));
sw.Close();
FileProjectItem fpi = new FileProjectItem(proj, ItemType.Compile);
fpi.FileName = filename;
ProjectService.AddProjectItem(proj, fpi);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
proj.Save();
}
else
{
string filename = Path.Combine(proj.Directory, Get<ComboBox>("existingFiles").Text);
IWorkbenchWindow wbw = FileService.OpenFile(filename);
proj.LanguageProperties.CodeGenerator.InsertCodeAtEnd(DomRegion.Empty, GetDocument(wbw), new AbstractNode[] { domNS });
}
}
private static IDocument GetDocument(IWorkbenchWindow workbenchWindow)
{
ITextEditorControlProvider provider1 = workbenchWindow.ViewContent as ITextEditorControlProvider;
if (provider1 == null)
{
return null;
}
return new TextEditorDocument (provider1.TextEditorControl.Document);
}
void SelectClassButtonClick(object sender, EventArgs e)
{
if (classes.ShowDialog())
{
Get<TextBox>("inheritFrom").Text = classes.SelectedClasses[0].FullyQualifiedName;
}
}
void SelectInterfacesButtonClick(object sender, EventArgs e)
{
if (interfaces.ShowDialog())
{
ListBox ifacesList = Get<ListBox>("implementedInterfaces");
foreach (IClass c in interfaces.SelectedClasses)
{
ifacesList.Items.Add(c.FullyQualifiedName);
}
}
}
void FileCreationModeChanged(object sender, EventArgs e)
{
bool createNewState = Get<RadioButton>("createNewFile").Checked;
bool addToFileState = Get<RadioButton>("addToFile").Checked;
Get<TextBox>("newFileName").Enabled = createNewState;
Get<Button>("browse").Enabled = createNewState;
Get<ComboBox>("existingFiles").Enabled = addToFileState;
}
}
}

34
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddNewClassCommand.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
/*
* Created by SharpDevelop.
* User: itai
* Date: 12/22/2006
* Time: 5:34 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ClassWizard
{
/// <summary>
/// Description of AddNewClassCommand
/// </summary>
public class AddNewClassCommand : AbstractCommand
{
/// <summary>
/// Starts the command
/// </summary>
public override void Run()
{
using (AddClassForm form = new AddClassForm())
{
form.Owner = (Form) WorkbenchSingleton.Workbench;
form.ShowDialog(WorkbenchSingleton.MainForm);
}
}
}
}

13
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/AddNewInterfaceCommand.cs

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
namespace ClassWizard
{
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
public class AddNewInterfaceCommand : AbstractCommand
{
public override void Run()
{
}
}
}

185
src/AddIns/DisplayBindings/ClassDiagram/ClassWizard/Src/ClassesList.cs

@ -0,0 +1,185 @@ @@ -0,0 +1,185 @@
/*
* Created by SharpDevelop.
* User: itai
* Date: 12/23/2006
* Time: 8:27 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Gui.XmlForms;
using ICSharpCode.SharpDevelop.Dom;
namespace ClassWizard
{
public class ClassesListDialog
{
private class ClassesList : BaseSharpDevelopForm
{
IClass baseClass;
public ClassesList() : this (null) {}
public ClassesList(IClass baseClass)
{
this.baseClass = baseClass;
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ClassWizard.Resources.ClassesList.xfrm"));
treeView = Get<TreeView>("classes");
treeView.BeforeCheck += ClassesTreeViewBeforeCheck;
treeView.AfterCheck += ClassesTreeViewAfterCheck;
treeView.AfterSelect += ClassesTreeViewAfterCheck;
}
private TreeView treeView;
public void InitializeClasses(IProject project, ClassType ct)
{
IProjectContent pc = ParserService.GetProjectContent(project);
treeView.Nodes.Clear();
AddClasses (pc, ct, false);
foreach (IProjectContent rpc in pc.ReferencedContents)
AddClasses (rpc, ct, false);
}
void AddClasses (IProjectContent pc, ClassType ct, bool allowSealed)
{
if (pc.Classes == null) return;
foreach (IClass c in pc.Classes)
{
if (c.ClassType == ct && (!c.IsSealed || (c.IsSealed && allowSealed)))
{
if (baseClass == null || (baseClass != null && c.IsTypeInInheritanceTree(baseClass)))
{
TreeNode node = AddItemToTreeView(c.FullyQualifiedName);
if (node != null)
node.Tag = c;
}
}
}
}
TreeNode AddItemToTreeView (string item)
{
string[] path = item.Split(treeView.PathSeparator[0]);
TreeNodeCollection tnc = treeView.Nodes;
TreeNode ret = null;
foreach (string pathitem in path)
{
if (tnc != null)
{
TreeNode tn;
if (!tnc.ContainsKey(pathitem))
{
tn = tnc.Add(pathitem, pathitem);
ret = tn;
}
else
tn = tnc[pathitem];
if (tn == null)
{
MessageBox.Show("Treenode is null: " + pathitem + "\n" + item);
}
tnc = tn.Nodes;
}
}
return ret;
}
void ClassesTreeViewBeforeCheck (object sender, TreeViewCancelEventArgs e)
{
e.Cancel = (e.Node.Nodes != null && e.Node.Nodes.Count > 0);
}
void ClassesTreeViewAfterCheck (object sender, TreeViewEventArgs e)
{
IClass c = (IClass) e.Node.Tag;
if (SelectMultiple)
{
if (e.Node.Checked && !selectedItems.Contains(c))
selectedItems.Add(c);
else if (!e.Node.Checked && selectedItems.Contains(c))
selectedItems.Remove(c);
}
else
{
selectedItems.Clear();
if (treeView.SelectedNode.Nodes == null || treeView.SelectedNode.Nodes.Count == 0)
selectedItems.Add((IClass)treeView.SelectedNode.Tag);
}
Get<Button>("ok").Enabled = (selectedItems.Count > 0);
}
public bool SelectMultiple
{
get { return treeView.CheckBoxes; }
set { treeView.CheckBoxes = value; }
}
List<IClass> selectedItems = new List<IClass>();
public IList<IClass> SelectedClasses
{
get { return selectedItems; }
}
}
ClassesList classesList = new ClassesList();
ClassType classType;
IProject project;
bool initialized = false;
public ClassesListDialog() {}
public bool ShowDialog()
{
if (!initialized)
{
classesList.InitializeClasses(project, classType);
initialized = true;
}
classesList.ShowDialog();
return classesList.DialogResult == DialogResult.OK;
}
public ClassType ClassType
{
get { return classType; }
set
{
initialized &= classType == value;
classType = value;
}
}
public IProject Project
{
get { return project; }
set
{
initialized &= project == value;
project = value;
}
}
public bool SelectMultiple
{
get { return classesList.SelectMultiple; }
set { classesList.SelectMultiple = value; }
}
public IList<IClass> SelectedClasses
{
get { return classesList.SelectedClasses; }
}
}
}

9
src/SharpDevelop.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
# SharpDevelop 2.1.0.2192
# SharpDevelop 2.1.0.2226
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{14A277EE-7DF1-4529-B639-7D1EF334C1C5}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ClassDiagram", "ClassDiagra @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ClassDiagram", "ClassDiagra
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassWizard", "AddIns\DisplayBindings\ClassDiagram\ClassWizard\ClassWizard.csproj", "{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diagrams", "AddIns\DisplayBindings\ClassDiagram\DiagramRouter\Diagrams.csproj", "{0991423A-DBF6-4C89-B365-A1DF1EB32E42}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassDiagramAddin", "AddIns\DisplayBindings\ClassDiagram\ClassDiagramAddin\ClassDiagramAddin.csproj", "{5A1354DF-4989-4BB4-BC6B-D627C2E9FA13}"
@ -434,6 +436,10 @@ Global @@ -434,6 +436,10 @@ Global
{0991423A-DBF6-4C89-B365-A1DF1EB32E42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0991423A-DBF6-4C89-B365-A1DF1EB32E42}.Release|Any CPU.Build.0 = Release|Any CPU
{0991423A-DBF6-4C89-B365-A1DF1EB32E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}.Release|Any CPU.Build.0 = Release|Any CPU
{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CE5B42B7-6E8C-4385-9E97-F4023FC16BF2} = {14A277EE-7DF1-4529-B639-7D1EF334C1C5}
@ -449,6 +455,7 @@ Global @@ -449,6 +455,7 @@ Global
{F5E059BB-96C2-4398-BED0-8598CD434173} = {DB137F0B-9B62-4232-AE92-F7BE0280B8D3}
{5A1354DF-4989-4BB4-BC6B-D627C2E9FA13} = {DB137F0B-9B62-4232-AE92-F7BE0280B8D3}
{0991423A-DBF6-4C89-B365-A1DF1EB32E42} = {DB137F0B-9B62-4232-AE92-F7BE0280B8D3}
{8C59E80D-C4E4-4F36-9AD8-47C40F6E58B4} = {DB137F0B-9B62-4232-AE92-F7BE0280B8D3}
{DC1CCE11-CB91-40FA-9C47-4D9EB5D67BFD} = {0D37CE59-B0EF-4F3C-B9EB-8557E53A448B}
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92} = {0D37CE59-B0EF-4F3C-B9EB-8557E53A448B}
{1F1AC7CD-D154-45BB-8EAF-804CA8055F5A} = {FEB825FA-4AD8-425D-8E4A-B5A18EE1B81C}

Loading…
Cancel
Save