Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@857 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
40 changed files with 0 additions and 6080 deletions
@ -1,390 +0,0 @@
@@ -1,390 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.Reflection; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public abstract class AbstractDesignerGenerator : IDesignerGenerator |
||||
{ |
||||
IClass c; |
||||
IMethod initializeComponents; |
||||
|
||||
FormsDesignerViewContent viewContent; |
||||
bool failedDesignerInitialize = false; |
||||
|
||||
CodeDomProvider provider; |
||||
|
||||
public CodeDomProvider CodeDomProvider { |
||||
get { |
||||
if (this.provider == null) { |
||||
this.provider = this.CreateCodeProvider(); |
||||
} |
||||
return this.provider; |
||||
} |
||||
} |
||||
|
||||
public void Attach(FormsDesignerViewContent viewContent) |
||||
{ |
||||
this.viewContent = viewContent; |
||||
} |
||||
|
||||
public void Detach() |
||||
{ |
||||
this.viewContent = null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the field declaration with the specified name from the source file.
|
||||
/// </summary>
|
||||
void RemoveField(string fieldName) |
||||
{ |
||||
try { |
||||
LoggingService.Info("Remove field declaration: "+fieldName); |
||||
Reparse(); |
||||
IField field = GetField(c, fieldName); |
||||
if (field != null) { |
||||
int startOffset = document.PositionToOffset(new Point(0, field.Region.BeginLine - 1)); |
||||
int endOffset = document.PositionToOffset(new Point(0, field.Region.EndLine)); |
||||
document.Remove(startOffset, endOffset - startOffset); |
||||
} |
||||
SaveDocument(); |
||||
} catch (Exception ex) { |
||||
MessageService.ShowError(ex); |
||||
} |
||||
} |
||||
|
||||
protected virtual string GenerateFieldDeclaration(CodeDOMGenerator domGenerator, CodeMemberField field) |
||||
{ |
||||
StringWriter writer = new StringWriter(); |
||||
domGenerator.ConvertContentDefinition(field, writer); |
||||
return writer.ToString().Trim(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Contains the tabs in front of the InitializeComponents declaration.
|
||||
/// Used to indent the fields and generated statements.
|
||||
/// </summary>
|
||||
protected string tabs; |
||||
|
||||
/// <summary>
|
||||
/// Adds the declaration for the specified field to the source file
|
||||
/// or replaces the already present declaration for a field with the same name.
|
||||
/// </summary>
|
||||
/// <param name="domGenerator">The CodeDOMGenerator used to generate the field declaration.</param>
|
||||
/// <param name="newField">The CodeDom field to be added or replaced.</param>
|
||||
void AddOrReplaceField(CodeDOMGenerator domGenerator, CodeMemberField newField) |
||||
{ |
||||
try { |
||||
Reparse(); |
||||
IField oldField = GetField(c, newField.Name); |
||||
if (oldField != null) { |
||||
int startOffset = document.PositionToOffset(new Point(0, oldField.Region.BeginLine - 1)); |
||||
int endOffset = document.PositionToOffset(new Point(0, oldField.Region.EndLine)); |
||||
document.Replace(startOffset, endOffset - startOffset, tabs + GenerateFieldDeclaration(domGenerator, newField) + Environment.NewLine); |
||||
} else { |
||||
int endOffset = document.PositionToOffset(new Point(0, initializeComponents.BodyRegion.EndLine)); |
||||
document.Insert(endOffset, tabs + GenerateFieldDeclaration(domGenerator, newField) + Environment.NewLine); |
||||
} |
||||
SaveDocument(); |
||||
} catch (Exception ex) { |
||||
MessageService.ShowError(ex); |
||||
} |
||||
} |
||||
|
||||
protected abstract System.CodeDom.Compiler.CodeDomProvider CreateCodeProvider(); |
||||
|
||||
protected abstract DomRegion GetReplaceRegion(ICSharpCode.TextEditor.Document.IDocument document, IMethod method); |
||||
|
||||
public void MergeFormChanges(CodeCompileUnit unit) |
||||
{ |
||||
Reparse(); |
||||
|
||||
// find InitializeComponent method and the class it is declared in
|
||||
CodeTypeDeclaration formClass = null; |
||||
CodeMemberMethod initializeComponent = null; |
||||
foreach (CodeNamespace n in unit.Namespaces) { |
||||
foreach (CodeTypeDeclaration typeDecl in n.Types) { |
||||
foreach (CodeTypeMember m in typeDecl.Members) { |
||||
if (m is CodeMemberMethod && m.Name == "InitializeComponent") { |
||||
formClass = typeDecl; |
||||
initializeComponent = (CodeMemberMethod)m; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (formClass == null || initializeComponent == null) { |
||||
throw new InvalidOperationException("InitializeComponent method not found in framework-generated CodeDom."); |
||||
} |
||||
|
||||
// generate file and get initialize components string
|
||||
StringWriter writer = new StringWriter(); |
||||
CodeDOMGenerator domGenerator = new CodeDOMGenerator(this.CodeDomProvider, tabs + '\t'); |
||||
domGenerator.ConvertContentDefinition(initializeComponent, writer); |
||||
|
||||
string statements = writer.ToString(); |
||||
|
||||
// initializeComponents.BodyRegion.BeginLine + 1
|
||||
DomRegion bodyRegion = GetReplaceRegion(document, initializeComponents); |
||||
if (bodyRegion.BeginColumn <= 0 || bodyRegion.EndColumn <= 0) |
||||
throw new InvalidOperationException("Column must be > 0"); |
||||
int startOffset = document.PositionToOffset(new Point(bodyRegion.BeginColumn - 1, bodyRegion.BeginLine - 1)); |
||||
int endOffset = document.PositionToOffset(new Point(bodyRegion.EndColumn - 1, bodyRegion.EndLine - 1)); |
||||
|
||||
document.Replace(startOffset, endOffset - startOffset, statements); |
||||
SaveDocument(); |
||||
|
||||
// apply changes the designer made to field declarations
|
||||
// first loop looks for added and changed fields
|
||||
foreach (CodeTypeMember m in formClass.Members) { |
||||
if (m is CodeMemberField) { |
||||
CodeMemberField newField = (CodeMemberField)m; |
||||
IField oldField = GetField(c, newField.Name); |
||||
if (oldField == null || FieldChanged(oldField, newField)) { |
||||
AddOrReplaceField(domGenerator, newField); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// second loop looks for removed fields
|
||||
List<string> removedFields = new List<string>(); |
||||
foreach (IField field in c.Fields) { |
||||
bool found = false; |
||||
foreach (CodeTypeMember m in formClass.Members) { |
||||
if (m is CodeMemberField && m.Name == field.Name) { |
||||
found = true; |
||||
break; |
||||
} |
||||
} |
||||
if (!found) { |
||||
removedFields.Add(field.Name); |
||||
} |
||||
} |
||||
// removing fields is done in two steps because
|
||||
// we must not modify the c.Fields collection while it is enumerated
|
||||
removedFields.ForEach(RemoveField); |
||||
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares the SharpDevelop.Dom field declaration oldField to
|
||||
/// the CodeDom field declaration newField.
|
||||
/// </summary>
|
||||
/// <returns>true, if the fields are different in type or modifiers, otherwise false.</returns>
|
||||
bool FieldChanged(IField oldField, CodeMemberField newField) |
||||
{ |
||||
// compare types
|
||||
if (oldField.ReturnType.FullyQualifiedName != newField.Type.BaseType) { |
||||
return true; |
||||
} |
||||
|
||||
// compare modifiers
|
||||
ModifierEnum oldModifiers = oldField.Modifiers & ModifierEnum.VisibilityMask; |
||||
MemberAttributes newModifiers = newField.Attributes & MemberAttributes.AccessMask; |
||||
|
||||
// SharpDevelop.Dom always adds Private modifier, even if not specified
|
||||
// CodeDom omits Private modifier if not present (although it is the default)
|
||||
if (oldModifiers == ModifierEnum.Private) { |
||||
if (newModifiers != 0 && newModifiers != MemberAttributes.Private) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
ModifierEnum[] sdModifiers = new ModifierEnum[] {ModifierEnum.Protected, ModifierEnum.ProtectedAndInternal, ModifierEnum.Internal, ModifierEnum.Public}; |
||||
MemberAttributes[] cdModifiers = new MemberAttributes[] {MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Public}; |
||||
for (int i = 0; i < sdModifiers.Length; i++) { |
||||
if ((oldModifiers == sdModifiers[i]) ^ (newModifiers == cdModifiers[i])) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
IDocument document; |
||||
string saveDocumentToFile; // only set when InitializeComponent was loaded from code-behind file that was not opened
|
||||
|
||||
void SaveDocument() |
||||
{ |
||||
if (saveDocumentToFile != null) { |
||||
NamedFileOperationDelegate method = delegate(string fileName) { |
||||
using (StreamWriter writer = new StreamWriter(fileName, false, System.Text.Encoding.UTF8)) { |
||||
writer.Write(document.TextContent); |
||||
} |
||||
}; |
||||
FileUtility.ObservedSave(method, saveDocumentToFile, FileErrorPolicy.Inform); |
||||
} |
||||
} |
||||
|
||||
protected void Reparse() |
||||
{ |
||||
saveDocumentToFile = null; |
||||
|
||||
// get new initialize components
|
||||
string content = viewContent.Document.TextContent; |
||||
ParseInformation info = ParserService.ParseFile(viewContent.TextEditorControl.FileName, content, false, true); |
||||
ICompilationUnit cu = (ICompilationUnit)info.BestCompilationUnit; |
||||
foreach (IClass c in cu.Classes) { |
||||
if (FormsDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(c)) { |
||||
initializeComponents = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(c); |
||||
if (initializeComponents != null) { |
||||
string designerFile = initializeComponents.DeclaringType.CompilationUnit.FileName; |
||||
string designerContent; |
||||
if (FileUtility.IsEqualFileName(viewContent.TextEditorControl.FileName, designerFile)) { |
||||
designerContent = content; |
||||
document = viewContent.Document; |
||||
} else { |
||||
IWorkbenchWindow window = FileService.GetOpenFile(designerFile); |
||||
if (window == null) { |
||||
document = new DocumentFactory().CreateDocument(); |
||||
designerContent = ParserService.GetParseableFileContent(designerFile); |
||||
document.TextContent = designerContent; |
||||
saveDocumentToFile = designerFile; |
||||
} else { |
||||
ITextEditorControlProvider tecp = window.ViewContent as ITextEditorControlProvider; |
||||
if (tecp == null) |
||||
throw new ApplicationException("designer file viewcontent must implement ITextEditorControlProvider"); |
||||
document = tecp.TextEditorControl.Document; |
||||
designerContent = document.TextContent; |
||||
} |
||||
ParserService.ParseFile(designerFile, designerContent, false, true); |
||||
} |
||||
using (StringReader r = new StringReader(designerContent)) { |
||||
int count = initializeComponents.Region.BeginLine; |
||||
for (int i = 1; i < count; i++) |
||||
r.ReadLine(); |
||||
string line = r.ReadLine(); |
||||
tabs = line.Substring(0, line.Length - line.TrimStart().Length); |
||||
} |
||||
this.c = c; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected abstract string CreateEventHandler(EventDescriptor edesc, string eventMethodName, string body, string indentation); |
||||
|
||||
/// <summary>
|
||||
/// If found return true and int as position
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
/// <param name="edesc"></param>
|
||||
/// <returns></returns>
|
||||
public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out int position) |
||||
{ |
||||
if (this.failedDesignerInitialize) { |
||||
position = 0; |
||||
return false; |
||||
} |
||||
|
||||
Reparse(); |
||||
|
||||
foreach (IMethod method in c.Methods) { |
||||
if (method.Name == eventMethodName) { |
||||
position = method.Region.BeginLine + 1; |
||||
return true; |
||||
} |
||||
} |
||||
viewContent.MergeFormChanges(); |
||||
Reparse(); |
||||
|
||||
position = c.Region.EndLine + 1; |
||||
|
||||
int offset = viewContent.Document.GetLineSegment(GetEventHandlerInsertionLine(c) - 1).Offset; |
||||
|
||||
viewContent.Document.Insert(offset, CreateEventHandler(edesc, eventMethodName, body, tabs)); |
||||
|
||||
return false; |
||||
} |
||||
|
||||
protected virtual int GetEventHandlerInsertionLine(IClass c) |
||||
{ |
||||
return c.Region.EndLine; |
||||
} |
||||
|
||||
public ICollection GetCompatibleMethods(EventDescriptor edesc) |
||||
{ |
||||
Reparse(); |
||||
ArrayList compatibleMethods = new ArrayList(); |
||||
MethodInfo methodInfo = edesc.EventType.GetMethod("Invoke"); |
||||
c = c.DefaultReturnType.GetUnderlyingClass(); |
||||
foreach (IMethod method in c.Methods) { |
||||
if (method.Parameters.Count == methodInfo.GetParameters().Length) { |
||||
bool found = true; |
||||
for (int i = 0; i < methodInfo.GetParameters().Length; ++i) { |
||||
ParameterInfo pInfo = methodInfo.GetParameters()[i]; |
||||
IParameter p = method.Parameters[i]; |
||||
if (p.ReturnType.FullyQualifiedName != pInfo.ParameterType.ToString()) { |
||||
found = false; |
||||
break; |
||||
} |
||||
} |
||||
if (found) { |
||||
compatibleMethods.Add(method.Name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return compatibleMethods; |
||||
} |
||||
|
||||
public ICollection GetCompatibleMethods(EventInfo edesc) |
||||
{ |
||||
Reparse(); |
||||
ArrayList compatibleMethods = new ArrayList(); |
||||
MethodInfo methodInfo = edesc.GetAddMethod(); |
||||
ParameterInfo pInfo = methodInfo.GetParameters()[0]; |
||||
string eventName = pInfo.ParameterType.ToString().Replace("EventHandler", "EventArgs"); |
||||
|
||||
c = c.DefaultReturnType.GetUnderlyingClass(); |
||||
foreach (IMethod method in c.Methods) { |
||||
if (method.Parameters.Count == 2) { |
||||
bool found = true; |
||||
|
||||
IParameter p = method.Parameters[1]; |
||||
if (p.ReturnType.FullyQualifiedName != eventName) { |
||||
found = false; |
||||
} |
||||
if (found) { |
||||
compatibleMethods.Add(method.Name); |
||||
} |
||||
} |
||||
} |
||||
return compatibleMethods; |
||||
} |
||||
|
||||
IField GetField(IClass c, string name) |
||||
{ |
||||
foreach (IField field in c.Fields) { |
||||
if (field.Name == name) { |
||||
return field; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,86 +0,0 @@
@@ -1,86 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.Reflection; |
||||
using System.Text; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class CSharpDesignerGenerator : AbstractDesignerGenerator |
||||
{ |
||||
protected override DomRegion GetReplaceRegion(ICSharpCode.TextEditor.Document.IDocument document, IMethod method) |
||||
{ |
||||
DomRegion r = method.BodyRegion; |
||||
int offset = document.PositionToOffset(new Point(r.BeginColumn - 1, r.BeginLine - 1)); |
||||
string tmp = document.GetText(offset, 10); |
||||
while (offset < document.TextLength) { |
||||
char c = document.GetCharAt(offset++); |
||||
if (c == '{') { |
||||
return new DomRegion(r.BeginLine + 1, 1, r.EndLine, 1); |
||||
} |
||||
if (c != ' ') { |
||||
break; |
||||
} |
||||
} |
||||
return new DomRegion(r.BeginLine + 2, 1, r.EndLine, 1); |
||||
} |
||||
|
||||
protected override System.CodeDom.Compiler.CodeDomProvider CreateCodeProvider() |
||||
{ |
||||
return new Microsoft.CSharp.CSharpCodeProvider(); |
||||
} |
||||
|
||||
protected override string CreateEventHandler(EventDescriptor edesc, string eventMethodName, string body, string indentation) |
||||
{ |
||||
string param = GenerateParams(edesc, true); |
||||
|
||||
StringBuilder b = new StringBuilder(); |
||||
b.AppendLine(indentation); |
||||
b.AppendLine(indentation + "void " + eventMethodName + "(" + param + ")"); |
||||
b.AppendLine(indentation + "{"); |
||||
b.AppendLine(indentation + "\t" + body); |
||||
b.AppendLine(indentation + "}"); |
||||
return b.ToString(); |
||||
} |
||||
|
||||
protected static string GenerateParams(EventDescriptor edesc, bool paramNames) |
||||
{ |
||||
System.Type type = edesc.EventType; |
||||
MethodInfo mInfo = type.GetMethod("Invoke"); |
||||
string param = ""; |
||||
IAmbience csa = null; |
||||
try { |
||||
csa = (IAmbience)AddInTree.BuildItem("/SharpDevelop/Workbench/Ambiences/C#", null); |
||||
} catch (TreePathNotFoundException) { |
||||
LoggingService.Warn("C# ambience not found"); |
||||
} |
||||
|
||||
for (int i = 0; i < mInfo.GetParameters().Length; ++i) { |
||||
ParameterInfo pInfo = mInfo.GetParameters()[i]; |
||||
|
||||
string typeStr = pInfo.ParameterType.ToString(); |
||||
if (csa != null) { |
||||
typeStr = csa.GetIntrinsicTypeName(typeStr); |
||||
} |
||||
param += typeStr; |
||||
if (paramNames == true) { |
||||
param += " "; |
||||
param += pInfo.Name; |
||||
} |
||||
if (i + 1 < mInfo.GetParameters().Length) { |
||||
param += ", "; |
||||
} |
||||
} |
||||
return param; |
||||
} |
||||
} |
||||
} |
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
|
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
/// <summary>
|
||||
/// This class is able to generate a CodeDOM definition out of a XML file.
|
||||
/// </summary>
|
||||
public class CodeDOMGenerator |
||||
{ |
||||
CodeDomProvider codeProvider; |
||||
|
||||
CodeDOMGeneratorUtility codeDOMGeneratorUtility = new CodeDOMGeneratorUtility(); |
||||
string indentation; |
||||
|
||||
public CodeDOMGenerator(CodeDomProvider codeProvider, string indentation) |
||||
{ |
||||
this.codeProvider = codeProvider; |
||||
this.indentation = indentation; |
||||
} |
||||
|
||||
public void ConvertContentDefinition(CodeMemberMethod method, TextWriter writer) |
||||
{ |
||||
LoggingService.Info("Generate code for: "+method.Name); |
||||
|
||||
CodeGeneratorOptions options = codeDOMGeneratorUtility.CreateCodeGeneratorOptions; |
||||
options.IndentString = indentation; |
||||
foreach (CodeStatement statement in method.Statements) { |
||||
// indentation isn't generated when calling GenerateCodeFromStatement
|
||||
writer.Write(options.IndentString); |
||||
try { |
||||
// outputGenerator.PublicGenerateCodeFromStatement(statement, Console.Out, options);
|
||||
codeProvider.GenerateCodeFromStatement(statement, writer, options); |
||||
} catch (Exception e) { |
||||
codeProvider.GenerateCodeFromStatement(new CodeCommentStatement("TODO: Error while generating statement : " + e.Message), |
||||
writer, |
||||
options); |
||||
LoggingService.Error(e); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
public void ConvertContentDefinition(CodeMemberField field, TextWriter writer) |
||||
{ |
||||
LoggingService.Info("Generate field declaration for: "+field.Name); |
||||
|
||||
CodeGeneratorOptions options = codeDOMGeneratorUtility.CreateCodeGeneratorOptions; |
||||
options.IndentString = indentation; |
||||
try { |
||||
codeProvider.GenerateCodeFromMember(field, writer, options); |
||||
} catch (Exception e) { |
||||
codeProvider.GenerateCodeFromStatement(new CodeCommentStatement("TODO: Error while generating statement : " + e.Message), |
||||
writer, |
||||
options); |
||||
LoggingService.Error(e); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Reflection; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public interface IDesignerGenerator |
||||
{ |
||||
CodeDomProvider CodeDomProvider { |
||||
get; |
||||
} |
||||
void Attach(FormsDesignerViewContent viewContent); |
||||
void Detach(); |
||||
void MergeFormChanges(CodeCompileUnit unit); |
||||
bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out int position); |
||||
ICollection GetCompatibleMethods(EventDescriptor edesc); |
||||
ICollection GetCompatibleMethods(EventInfo edesc); |
||||
} |
||||
} |
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class VBNetDesignerGenerator : AbstractDesignerGenerator |
||||
{ |
||||
protected override System.CodeDom.Compiler.CodeDomProvider CreateCodeProvider() |
||||
{ |
||||
return new Microsoft.VisualBasic.VBCodeProvider(); |
||||
} |
||||
|
||||
protected override DomRegion GetReplaceRegion(ICSharpCode.TextEditor.Document.IDocument document, IMethod method) |
||||
{ |
||||
DomRegion r = method.BodyRegion; |
||||
return new DomRegion(r.BeginLine + 1, 1, r.EndLine, 1); |
||||
} |
||||
|
||||
protected override string CreateEventHandler(EventDescriptor edesc, string eventMethodName, string body, string indentation) |
||||
{ |
||||
string param = GenerateParams(edesc); |
||||
|
||||
StringBuilder b = new StringBuilder(); |
||||
b.AppendLine(indentation); |
||||
b.AppendLine(indentation + "Sub " + eventMethodName + "(" + param + ")"); |
||||
b.AppendLine(indentation + "\t" + body); |
||||
b.AppendLine(indentation + "End Sub"); |
||||
return b.ToString(); |
||||
} |
||||
|
||||
protected static string GenerateParams(EventDescriptor edesc) |
||||
{ |
||||
System.Type type = edesc.EventType; |
||||
MethodInfo mInfo = type.GetMethod("Invoke"); |
||||
string param = ""; |
||||
IAmbience csa = null; |
||||
try { |
||||
csa = (IAmbience)AddInTree.BuildItem("/SharpDevelop/Workbench/Ambiences/VBNet", null); |
||||
} catch (TreePathNotFoundException) { |
||||
LoggingService.Warn("VB ambience not found"); |
||||
} |
||||
|
||||
for (int i = 0; i < mInfo.GetParameters().Length; ++i) { |
||||
ParameterInfo pInfo = mInfo.GetParameters()[i]; |
||||
|
||||
param += pInfo.Name; |
||||
param += " As "; |
||||
|
||||
string typeStr = pInfo.ParameterType.ToString(); |
||||
if (csa != null) { |
||||
typeStr = csa.GetIntrinsicTypeName(typeStr); |
||||
} |
||||
param += typeStr; |
||||
if (i + 1 < mInfo.GetParameters().Length) { |
||||
param += ", "; |
||||
} |
||||
} |
||||
return param; |
||||
} |
||||
} |
||||
} |
@ -1,206 +0,0 @@
@@ -1,206 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class XmlDesignerGenerator : IDesignerGenerator |
||||
{ |
||||
FormsDesignerViewContent viewContent; |
||||
|
||||
public CodeDomProvider CodeDomProvider { |
||||
get { |
||||
return new Microsoft.CSharp.CSharpCodeProvider(); |
||||
} |
||||
} |
||||
|
||||
public void Attach(FormsDesignerViewContent viewContent) |
||||
{ |
||||
this.viewContent = viewContent; |
||||
} |
||||
|
||||
public void Detach() |
||||
{ |
||||
this.viewContent = null; |
||||
} |
||||
|
||||
public void MergeFormChanges(CodeCompileUnit unit) |
||||
{ |
||||
StringWriter writer = new StringWriter(); |
||||
XmlTextWriter xml = new XmlTextWriter(writer); |
||||
xml.Formatting = Formatting.Indented; |
||||
|
||||
//xml.WriteStartDocument();
|
||||
XmlElement el = GetElementFor(new XmlDocument(), viewContent.Host); |
||||
xml.WriteStartElement(el.Name); |
||||
xml.WriteAttributeString("version", "1.0"); |
||||
|
||||
foreach (XmlNode node in el.ChildNodes) { |
||||
node.WriteTo(xml); |
||||
} |
||||
xml.WriteEndElement(); |
||||
//xml.WriteEndDocument();
|
||||
viewContent.Document.TextContent = writer.ToString(); |
||||
} |
||||
public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out int position) |
||||
{ |
||||
position = 0; |
||||
return false; |
||||
} |
||||
|
||||
public ICollection GetCompatibleMethods(EventDescriptor edesc) |
||||
{ |
||||
return new object[] {}; |
||||
} |
||||
public ICollection GetCompatibleMethods(EventInfo edesc) |
||||
{ |
||||
return new object[] {}; |
||||
} |
||||
|
||||
public XmlElement GetElementFor(XmlDocument doc, object o) |
||||
{ |
||||
if (doc == null) { |
||||
throw new ArgumentNullException("doc"); |
||||
} |
||||
|
||||
if (o == null) { |
||||
throw new ArgumentNullException("o"); |
||||
} |
||||
|
||||
try { |
||||
XmlElement el = doc.CreateElement(o.GetType().FullName); |
||||
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(o); |
||||
|
||||
Control ctrl = o as Control; |
||||
bool nameInserted = false; |
||||
if (ctrl != null) { |
||||
XmlElement childEl = doc.CreateElement("Name"); |
||||
XmlAttribute valueAttribute = doc.CreateAttribute("value"); |
||||
valueAttribute.InnerText = ctrl.Name; |
||||
childEl.Attributes.Append(valueAttribute); |
||||
el.AppendChild(childEl); |
||||
nameInserted = true; |
||||
} |
||||
|
||||
// add collections as last child elements in the xml (because it is better
|
||||
// to set the properties first and then add items to controls (looks nicer
|
||||
// in XML and CODE))
|
||||
ArrayList childNodes = new ArrayList(); |
||||
|
||||
// the Controls collection should be generated as the last
|
||||
// element because properties like 'anchor' in the child elements
|
||||
// must be applied after the size has set.
|
||||
foreach (PropertyDescriptor pd in properties) { |
||||
// if (!pd.ShouldSerializeValue(o)) {
|
||||
// continue;
|
||||
// }
|
||||
if (pd.Name == "Name" && nameInserted) { |
||||
continue; |
||||
} |
||||
if (pd.Name == "DataBindings" || |
||||
// TabControl duplicate TabPages Workaround (TabPages got inserted twice : In Controls and in TabPages)
|
||||
(o.GetType().FullName == "System.Windows.Forms.TabControl" && pd.Name == "Controls")) { |
||||
continue; |
||||
} |
||||
|
||||
XmlElement childEl = null; |
||||
if (pd.Name == "Size" && ctrl != null && (ctrl is UserControl || ctrl is Form)) { |
||||
childEl = doc.CreateElement("ClientSize"); |
||||
childEl.SetAttribute("value", ctrl.ClientSize.ToString()); |
||||
childNodes.Insert(0, childEl); |
||||
continue; |
||||
} |
||||
childEl = doc.CreateElement(pd.Name); |
||||
|
||||
object propertyValue = null; |
||||
try { |
||||
propertyValue = pd.GetValue(o); |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.LoggingService.Warn(e); |
||||
continue; |
||||
} |
||||
|
||||
// lists are other than normal properties
|
||||
if (propertyValue is IList && !(ctrl is PropertyGrid)) { |
||||
foreach (object listObject in (IList)propertyValue) { |
||||
XmlElement newEl = GetElementFor(doc, listObject); |
||||
if (newEl != null) { |
||||
childEl.AppendChild(newEl); |
||||
} |
||||
} |
||||
|
||||
// only insert lists that contain elements (no empty lists!)
|
||||
if (childEl.ChildNodes.Count > 0) { |
||||
childNodes.Add(childEl); |
||||
} |
||||
} else if (pd.ShouldSerializeValue(o) && pd.IsBrowsable) { |
||||
XmlAttribute valueAttribute = doc.CreateAttribute("value"); |
||||
if (propertyValue is Font) { |
||||
Font f = (Font)propertyValue; |
||||
propertyValue = new Font(f.FontFamily, (float)Math.Round(f.Size)); |
||||
} |
||||
|
||||
valueAttribute.InnerText = propertyValue == null ? null : propertyValue.ToString(); |
||||
childEl.Attributes.Append(valueAttribute); |
||||
childNodes.Insert(0, childEl); |
||||
} |
||||
} |
||||
|
||||
foreach (XmlElement childEl in childNodes) { |
||||
el.AppendChild(childEl); |
||||
} |
||||
|
||||
// fallback to ToString, if no members can be generated (for example
|
||||
// handling System.String)
|
||||
if (el.ChildNodes.Count == 0) { |
||||
XmlAttribute valueAttribute = doc.CreateAttribute("value"); |
||||
valueAttribute.InnerText = o.ToString(); |
||||
el.Attributes.Append(valueAttribute); |
||||
} |
||||
|
||||
return el; |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.MessageService.ShowError(e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public XmlElement GetElementFor(XmlDocument doc, IDesignerHost host) |
||||
{ |
||||
XmlElement componentsElement = doc.CreateElement("Components"); |
||||
|
||||
XmlAttribute versionAttribute = doc.CreateAttribute("version"); |
||||
versionAttribute.InnerText = "1.0"; |
||||
componentsElement.Attributes.Append(versionAttribute); |
||||
|
||||
// insert root element
|
||||
componentsElement.AppendChild(GetElementFor(doc, host.RootComponent)); |
||||
|
||||
// insert any non gui (=tray components)
|
||||
foreach (IComponent component in host.Container.Components) { |
||||
if (!(component is Control)) { |
||||
componentsElement.AppendChild(GetElementFor(doc, component)); |
||||
} |
||||
} |
||||
|
||||
return componentsElement; |
||||
} |
||||
} |
||||
} |
@ -1,51 +0,0 @@
@@ -1,51 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public interface IDesignerLoaderProvider |
||||
{ |
||||
DesignerLoader CreateLoader(IDesignerGenerator generator); |
||||
} |
||||
|
||||
public class NRefactoryDesignerLoaderProvider : IDesignerLoaderProvider |
||||
{ |
||||
SupportedLanguage language; |
||||
TextEditorControl textEditorControl; |
||||
|
||||
public NRefactoryDesignerLoaderProvider(SupportedLanguage language, TextEditorControl textEditorControl) |
||||
{ |
||||
this.language = language; |
||||
this.textEditorControl = textEditorControl; |
||||
} |
||||
|
||||
public DesignerLoader CreateLoader(IDesignerGenerator generator) |
||||
{ |
||||
return new NRefactoryDesignerLoader(language, textEditorControl, generator); |
||||
} |
||||
} |
||||
|
||||
public class XmlDesignerLoaderProvider : IDesignerLoaderProvider |
||||
{ |
||||
TextEditorControl textEditorControl; |
||||
|
||||
public XmlDesignerLoaderProvider(TextEditorControl textEditorControl) |
||||
{ |
||||
this.textEditorControl = textEditorControl; |
||||
} |
||||
|
||||
public DesignerLoader CreateLoader(IDesignerGenerator generator) |
||||
{ |
||||
return new XmlDesignerLoader(textEditorControl, generator); |
||||
} |
||||
} |
||||
} |
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Runtime.Serialization; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
[Serializable()] |
||||
public class FormsDesignerLoadException : ApplicationException |
||||
{ |
||||
public FormsDesignerLoadException() : base() |
||||
{ |
||||
} |
||||
|
||||
public FormsDesignerLoadException(string message) : base(message) |
||||
{ |
||||
} |
||||
|
||||
public FormsDesignerLoadException(string message, Exception innerException) : base(message, innerException) |
||||
{ |
||||
} |
||||
|
||||
protected FormsDesignerLoadException(SerializationInfo info, StreamingContext context) : base(info, context) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,347 +0,0 @@
@@ -1,347 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.ComponentModel.Design; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
using ICSharpCode.NRefactory.PrettyPrinter; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class DefaultMemberRelationshipService : MemberRelationshipService |
||||
{ |
||||
public override bool SupportsRelationship(MemberRelationship source, MemberRelationship relationship) |
||||
{ |
||||
return true; |
||||
} |
||||
protected override MemberRelationship GetRelationship(MemberRelationship source) |
||||
{ |
||||
return base.GetRelationship(source); |
||||
} |
||||
} |
||||
|
||||
public class NRefactoryDesignerLoader : CodeDomDesignerLoader |
||||
{ |
||||
bool loading = true; |
||||
IDesignerLoaderHost designerLoaderHost = null; |
||||
ITypeResolutionService typeResolutionService = null; |
||||
IDesignerGenerator generator; |
||||
SupportedLanguage language; |
||||
|
||||
TextEditorControl textEditorControl; |
||||
|
||||
public string TextContent { |
||||
get { |
||||
return textEditorControl.Document.TextContent; |
||||
} |
||||
} |
||||
|
||||
public override bool Loading { |
||||
get { |
||||
return loading; |
||||
} |
||||
} |
||||
|
||||
public IDesignerLoaderHost DesignerLoaderHost { |
||||
get { |
||||
return designerLoaderHost; |
||||
} |
||||
} |
||||
|
||||
protected override CodeDomProvider CodeDomProvider { |
||||
get { |
||||
return generator.CodeDomProvider; |
||||
} |
||||
} |
||||
|
||||
protected override ITypeResolutionService TypeResolutionService { |
||||
get { |
||||
return typeResolutionService; |
||||
} |
||||
} |
||||
|
||||
protected override bool IsReloadNeeded() |
||||
{ |
||||
return base.IsReloadNeeded() || TextContent != lastTextContent; |
||||
} |
||||
|
||||
public NRefactoryDesignerLoader(SupportedLanguage language, TextEditorControl textEditorControl, IDesignerGenerator generator) |
||||
{ |
||||
this.language = language; |
||||
this.textEditorControl = textEditorControl; |
||||
this.generator = generator; |
||||
} |
||||
|
||||
public override void BeginLoad(IDesignerLoaderHost host) |
||||
{ |
||||
this.loading = true; |
||||
typeResolutionService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); |
||||
this.designerLoaderHost = host; |
||||
base.BeginLoad(host); |
||||
} |
||||
|
||||
protected override void Initialize() |
||||
{ |
||||
CodeDomLocalizationProvider localizationProvider = new CodeDomLocalizationProvider(designerLoaderHost, CodeDomLocalizationModel.PropertyAssignment); |
||||
IDesignerSerializationManager manager = (IDesignerSerializationManager)designerLoaderHost.GetService(typeof(IDesignerSerializationManager)); |
||||
manager.AddSerializationProvider(localizationProvider); |
||||
base.Initialize(); |
||||
} |
||||
|
||||
protected override void OnEndLoad(bool successful, ICollection errors) |
||||
{ |
||||
this.loading = false; |
||||
//when control's Dispose() has a exception and on loading also raised exception
|
||||
//then this is only place where this error can be logged, because after errors is
|
||||
//catched internally in .net
|
||||
try { |
||||
base.OnEndLoad(successful, errors); |
||||
} catch(ExceptionCollection e) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + e.Message); |
||||
foreach(Exception ine in e.Exceptions) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + ine.Message); |
||||
} |
||||
throw; |
||||
} catch(Exception e) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + e.Message); |
||||
throw; |
||||
} |
||||
} |
||||
|
||||
string lastTextContent; |
||||
|
||||
protected override CodeCompileUnit Parse() |
||||
{ |
||||
LoggingService.Debug("NRefactoryDesignerLoader.Parse()"); |
||||
|
||||
#if DEBUG
|
||||
if ((Control.ModifierKeys & (Keys.Alt | Keys.Control)) == (Keys.Alt | Keys.Control)) { |
||||
System.Diagnostics.Debugger.Break(); |
||||
} |
||||
#endif
|
||||
|
||||
lastTextContent = TextContent; |
||||
|
||||
ParseInformation parseInfo = ParserService.GetParseInformation(textEditorControl.FileName); |
||||
|
||||
IClass formClass = null; |
||||
|
||||
foreach (IClass c in parseInfo.BestCompilationUnit.Classes) { |
||||
if (FormsDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(c)) { |
||||
formClass = c; |
||||
break; |
||||
} |
||||
} |
||||
if (formClass == null) |
||||
throw new FormsDesignerLoadException("No class derived from Form or Control was found."); |
||||
|
||||
// Initialize designer for formClass
|
||||
formClass = formClass.DefaultReturnType.GetUnderlyingClass(); |
||||
List<IClass> parts; |
||||
if (formClass is CompoundClass) { |
||||
parts = (formClass as CompoundClass).Parts; |
||||
} else { |
||||
parts = new List<IClass>(); |
||||
parts.Add(formClass); |
||||
} |
||||
List<KeyValuePair<string, CompilationUnit>> compilationUnits = new List<KeyValuePair<string, CompilationUnit>>(); |
||||
bool foundInitMethod = false; |
||||
foreach (IClass part in parts) { |
||||
string fileName = part.CompilationUnit.FileName; |
||||
if (fileName == null) continue; |
||||
bool found = false; |
||||
foreach (KeyValuePair<string, CompilationUnit> entry in compilationUnits) { |
||||
if (FileUtility.IsEqualFileName(fileName, entry.Key)) { |
||||
found = true; |
||||
break; |
||||
} |
||||
} |
||||
if (found) continue; |
||||
|
||||
string fileContent = ParserService.GetParseableFileContent(fileName); |
||||
|
||||
ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(language, new StringReader(fileContent)); |
||||
p.Parse(); |
||||
if (p.Errors.count > 0) { |
||||
throw new FormsDesignerLoadException("Syntax errors in " + fileName + ":\r\n" + p.Errors.ErrorOutput); |
||||
} |
||||
|
||||
// Try to fix the type names to fully qualified ones
|
||||
FixTypeNames(p.CompilationUnit, parseInfo.BestCompilationUnit, ref foundInitMethod); |
||||
compilationUnits.Add(new KeyValuePair<string, CompilationUnit>(fileName, p.CompilationUnit)); |
||||
} |
||||
|
||||
if (!foundInitMethod) |
||||
throw new FormsDesignerLoadException("The InitializeComponent method was not found. Designer cannot be loaded."); |
||||
|
||||
CompilationUnit combinedCu = new CompilationUnit(); |
||||
NamespaceDeclaration nsDecl = new NamespaceDeclaration(formClass.Namespace); |
||||
combinedCu.AddChild(nsDecl); |
||||
TypeDeclaration formDecl = new TypeDeclaration(Modifier.Public, null); |
||||
nsDecl.AddChild(formDecl); |
||||
formDecl.Name = formClass.Name; |
||||
foreach (KeyValuePair<string, CompilationUnit> entry in compilationUnits) { |
||||
foreach (object o in entry.Value.Children) { |
||||
TypeDeclaration td = o as TypeDeclaration; |
||||
if (td != null && td.Name == formDecl.Name) { |
||||
foreach (INode node in td.Children) |
||||
formDecl.AddChild(node); |
||||
formDecl.BaseTypes.AddRange(td.BaseTypes); |
||||
} |
||||
if (o is NamespaceDeclaration) { |
||||
foreach (object o2 in ((NamespaceDeclaration)o).Children) { |
||||
td = o2 as TypeDeclaration; |
||||
if (td != null && td.Name == formDecl.Name) { |
||||
foreach (INode node in td.Children) |
||||
formDecl.AddChild(node); |
||||
formDecl.BaseTypes.AddRange(td.BaseTypes); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
CodeDOMVisitor visitor = new CodeDOMVisitor(); |
||||
visitor.Visit(combinedCu, null); |
||||
|
||||
// output generated CodeDOM to the console :
|
||||
#if DEBUG
|
||||
if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { |
||||
CodeDOMVerboseOutputGenerator outputGenerator = new CodeDOMVerboseOutputGenerator(); |
||||
outputGenerator.GenerateCodeFromMember(visitor.codeCompileUnit.Namespaces[0].Types[0], Console.Out, null); |
||||
this.CodeDomProvider.GenerateCodeFromCompileUnit(visitor.codeCompileUnit, Console.Out, null); |
||||
} |
||||
#endif
|
||||
|
||||
LoggingService.Debug("NRefactoryDesignerLoader.Parse() finished"); |
||||
return visitor.codeCompileUnit; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Fix type names and remove unused methods.
|
||||
/// </summary>
|
||||
void FixTypeNames(object o, ICSharpCode.SharpDevelop.Dom.ICompilationUnit domCu, ref bool foundInitMethod) |
||||
{ |
||||
if (domCu == null) |
||||
return; |
||||
CompilationUnit cu = o as CompilationUnit; |
||||
if (cu != null) { |
||||
foreach (object c in cu.Children) { |
||||
FixTypeNames(c, domCu, ref foundInitMethod); |
||||
} |
||||
return; |
||||
} |
||||
NamespaceDeclaration namespaceDecl = o as NamespaceDeclaration; |
||||
if (namespaceDecl != null) { |
||||
foreach (object c in namespaceDecl.Children) { |
||||
FixTypeNames(c, domCu, ref foundInitMethod); |
||||
} |
||||
return; |
||||
} |
||||
TypeDeclaration typeDecl = o as TypeDeclaration; |
||||
if (typeDecl != null) { |
||||
foreach (TypeReference tref in typeDecl.BaseTypes) { |
||||
FixTypeReference(tref, typeDecl.StartLocation, domCu); |
||||
} |
||||
for (int i = 0; i < typeDecl.Children.Count; i++) { |
||||
object child = typeDecl.Children[i]; |
||||
MethodDeclaration method = child as MethodDeclaration; |
||||
if (method != null) { |
||||
// remove all methods except InitializeComponents
|
||||
if ((method.Name == "InitializeComponents" || method.Name == "InitializeComponent") && method.Parameters.Count == 0) { |
||||
method.Name = "InitializeComponent"; |
||||
foundInitMethod = true; |
||||
} else { |
||||
typeDecl.Children.RemoveAt(i--); |
||||
} |
||||
} else if (child is TypeDeclaration || child is FieldDeclaration) { |
||||
FixTypeNames(child, domCu, ref foundInitMethod); |
||||
} else { |
||||
// child is property, event etc.
|
||||
typeDecl.Children.RemoveAt(i--); |
||||
} |
||||
} |
||||
|
||||
return; |
||||
} |
||||
FieldDeclaration fieldDecl = o as FieldDeclaration; |
||||
if (fieldDecl != null) { |
||||
FixTypeReference(fieldDecl.TypeReference, fieldDecl.StartLocation, domCu); |
||||
foreach (VariableDeclaration var in fieldDecl.Fields) { |
||||
if (var != null) { |
||||
FixTypeReference(var.TypeReference, fieldDecl.StartLocation, domCu); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void FixTypeReference(TypeReference type, Point location, ICSharpCode.SharpDevelop.Dom.ICompilationUnit domCu) |
||||
{ |
||||
if (type == null) |
||||
return; |
||||
if (type.SystemType != type.Type) |
||||
return; |
||||
foreach (TypeReference tref in type.GenericTypes) { |
||||
FixTypeReference(tref, location, domCu); |
||||
} |
||||
ICSharpCode.SharpDevelop.Dom.IClass curType = domCu.GetInnermostClass(location.Y, location.X); |
||||
ICSharpCode.SharpDevelop.Dom.IReturnType rt = domCu.ProjectContent.SearchType(type.Type, type.GenericTypes.Count, curType, domCu, location.Y, location.X); |
||||
if (rt != null) { |
||||
type.Type = rt.FullyQualifiedName; |
||||
} |
||||
} |
||||
|
||||
protected override void Write(CodeCompileUnit unit) |
||||
{ |
||||
LoggingService.Info("DesignerLoader.Write called"); |
||||
// output generated CodeDOM to the console :
|
||||
#if DEBUG
|
||||
if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { |
||||
this.CodeDomProvider.GenerateCodeFromCompileUnit(unit, Console.Out, null); |
||||
} |
||||
#endif
|
||||
generator.MergeFormChanges(unit); |
||||
} |
||||
|
||||
// public void Reload()
|
||||
// {
|
||||
// base.Reload(BasicDesignerLoader.ReloadFlags.Default);
|
||||
// }
|
||||
// public override void Flush()
|
||||
// {
|
||||
// base.Flush();
|
||||
// }
|
||||
|
||||
// void InitializeExtendersForProject(IDesignerHost host)
|
||||
// {
|
||||
// IExtenderProviderService elsi = (IExtenderProviderService)host.GetService(typeof(IExtenderProviderService));
|
||||
// elsi.AddExtenderProvider(new ICSharpCode.FormDesigner.Util.NameExtender());
|
||||
// }
|
||||
|
||||
public override void Dispose() |
||||
{ |
||||
base.Dispose(); |
||||
} |
||||
} |
||||
} |
@ -1,157 +0,0 @@
@@ -1,157 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.Drawing.Printing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Xml; |
||||
|
||||
|
||||
|
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
using ICSharpCode.NRefactory.PrettyPrinter; |
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
|
||||
public class XmlDesignerLoader : BasicDesignerLoader, IObjectCreator |
||||
{ |
||||
TextEditorControl textEditorControl; |
||||
IDesignerGenerator generator; |
||||
|
||||
public string TextContent { |
||||
get { |
||||
return textEditorControl.Document.TextContent; |
||||
} |
||||
} |
||||
|
||||
public XmlDesignerLoader(TextEditorControl textEditorControl, IDesignerGenerator generator) |
||||
{ |
||||
this.textEditorControl = textEditorControl; |
||||
this.generator = generator; |
||||
} |
||||
|
||||
IDesignerLoaderHost host; |
||||
public override void BeginLoad(IDesignerLoaderHost host) |
||||
{ |
||||
Debug.Assert(host != null); |
||||
this.host = host; |
||||
host.AddService(typeof(INameCreationService), new NameCreationService(host)); |
||||
host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host)); |
||||
base.BeginLoad(host); |
||||
} |
||||
|
||||
protected override void PerformLoad(IDesignerSerializationManager serializationManager) |
||||
{ |
||||
XmlLoader loader = new XmlLoader(); |
||||
loader.ObjectCreator = this; |
||||
loader.CreateObjectFromXmlDefinition(TextContent); |
||||
} |
||||
|
||||
protected override void PerformFlush(IDesignerSerializationManager serializationManager) |
||||
{ |
||||
// the XML designer is not based on CodeDom, so we pass null for the CodeCompileUnit
|
||||
generator.MergeFormChanges(null); |
||||
} |
||||
|
||||
Type IObjectCreator.GetType(string name) |
||||
{ |
||||
return host.GetType(name); |
||||
} |
||||
|
||||
object IObjectCreator.CreateObject(string name, XmlElement el) |
||||
{ |
||||
string componentName = null; |
||||
|
||||
if (el != null) { |
||||
foreach (XmlNode childNode in el) { |
||||
if (childNode.Name == "Name") { |
||||
componentName = ((XmlElement)childNode).GetAttribute("value"); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
Debug.Assert(componentName != null); |
||||
|
||||
Type componentType = host.GetType(name); |
||||
Debug.Assert(componentType != null); |
||||
|
||||
object newObject = host.CreateComponent(componentType, componentName); |
||||
|
||||
if (newObject is Control) { |
||||
((Control)newObject).SuspendLayout(); |
||||
} |
||||
|
||||
return newObject; |
||||
} |
||||
|
||||
public class NameCreationService : INameCreationService |
||||
{ |
||||
IDesignerHost host; |
||||
|
||||
public NameCreationService(IDesignerHost host) |
||||
{ |
||||
this.host = host; |
||||
} |
||||
|
||||
public string CreateName(Type dataType) |
||||
{ |
||||
return CreateName(host.Container, dataType); |
||||
} |
||||
|
||||
public string CreateName(IContainer container, Type dataType) |
||||
{ |
||||
string name = Char.ToLower(dataType.Name[0]) + dataType.Name.Substring(1); |
||||
int number = 1; |
||||
while (container.Components[name + number.ToString()] != null) { |
||||
++number; |
||||
} |
||||
return name + number.ToString(); |
||||
} |
||||
|
||||
public bool IsValidName(string name) |
||||
{ |
||||
if (name == null || name.Length == 0 || !(Char.IsLetter(name[0]) || name[0] == '_')) { |
||||
return false; |
||||
} |
||||
|
||||
foreach (char ch in name) { |
||||
if (!Char.IsLetterOrDigit(ch) && ch != '_') { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public void ValidateName(string name) |
||||
{ |
||||
if (!IsValidName(name)) { |
||||
throw new System.Exception("Invalid name " + name); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,535 +0,0 @@
@@ -1,535 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using System.Drawing.Printing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Internal.Undo; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.FormsDesigner.UndoRedo; |
||||
using ICSharpCode.TextEditor; |
||||
using ICSharpCode.TextEditor.Document; |
||||
|
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.NRefactory.Parser.AST; |
||||
using ICSharpCode.NRefactory.PrettyPrinter; |
||||
|
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using Microsoft.CSharp; |
||||
using Microsoft.VisualBasic; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class FormsDesignerViewContent : AbstractSecondaryViewContent, IClipboardHandler, IUndoHandler, IHasPropertyContainer, IContextHelpProvider |
||||
{ |
||||
protected bool failedDesignerInitialize; |
||||
|
||||
protected IViewContent viewContent; |
||||
protected Dictionary<string, DesignerResourceService.ResourceStorage> resources = new Dictionary<string, DesignerResourceService.ResourceStorage>(); |
||||
protected ITextEditorControlProvider textAreaControlProvider; |
||||
|
||||
Panel p = new Panel(); |
||||
DesignSurface designSurface; |
||||
bool disposing; |
||||
|
||||
IDesignerLoaderProvider loaderProvider; |
||||
IDesignerGenerator generator; |
||||
DesignerResourceService designerResourceService; |
||||
FormsDesignerUndoEngine undoEngine; |
||||
|
||||
public override Control Control { |
||||
get { |
||||
return p; |
||||
} |
||||
} |
||||
|
||||
public override string TabPageText { |
||||
get { |
||||
return "${res:FormsDesigner.DesignTabPages.DesignTabPage}"; |
||||
} |
||||
} |
||||
|
||||
public DesignSurface DesignSurface { |
||||
get { |
||||
return designSurface; |
||||
} |
||||
} |
||||
|
||||
public TextEditorControl TextEditorControl { |
||||
get { |
||||
return textAreaControlProvider.TextEditorControl; |
||||
} |
||||
} |
||||
public IDocument Document { |
||||
get { |
||||
return TextEditorControl.Document; |
||||
} |
||||
} |
||||
|
||||
public IDesignerHost Host { |
||||
get { |
||||
if (designSurface == null) |
||||
return null; |
||||
return (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||
} |
||||
} |
||||
public FormsDesignerViewContent(IViewContent viewContent, IDesignerLoaderProvider loaderProvider, IDesignerGenerator generator) |
||||
{ |
||||
if (!FormKeyHandler.inserted) { |
||||
FormKeyHandler.Insert(); |
||||
} |
||||
|
||||
this.loaderProvider = loaderProvider; |
||||
this.generator = generator; |
||||
p.BackColor = Color.White; |
||||
|
||||
this.viewContent = viewContent; |
||||
this.textAreaControlProvider = viewContent as ITextEditorControlProvider; |
||||
|
||||
} |
||||
|
||||
public override void SwitchedTo() |
||||
{ |
||||
if (IsFormsDesignerVisible) { |
||||
AddSideBars(); |
||||
} |
||||
} |
||||
|
||||
void LoadDesigner() |
||||
{ |
||||
LoggingService.Info("Form Designer: BEGIN INITIALIZE"); |
||||
|
||||
DefaultServiceContainer serviceContainer = new DefaultServiceContainer(); |
||||
serviceContainer.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService()); |
||||
serviceContainer.AddService(typeof(System.Drawing.Design.IToolboxService), ToolboxProvider.ToolboxService); |
||||
|
||||
serviceContainer.AddService(typeof(IHelpService), new HelpService()); |
||||
serviceContainer.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService()); |
||||
|
||||
designerResourceService = new DesignerResourceService(viewContent.FileName, this.resources); |
||||
serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService); |
||||
AmbientProperties ambientProperties = new AmbientProperties(); |
||||
serviceContainer.AddService(typeof(AmbientProperties), ambientProperties); |
||||
serviceContainer.AddService(typeof(ITypeResolutionService), ToolboxProvider.TypeResolutionService); |
||||
serviceContainer.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService()); |
||||
serviceContainer.AddService(typeof(System.ComponentModel.Design.DesignerOptionService), new ICSharpCode.FormsDesigner.Services.DesignerOptionService()); |
||||
serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService()); |
||||
serviceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService()); |
||||
|
||||
designSurface = new DesignSurface(serviceContainer); |
||||
|
||||
serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormsDesigner.Services.MenuCommandService(p, designSurface, serviceContainer)); |
||||
ICSharpCode.FormsDesigner.Services.EventBindingService eventBindingService = new ICSharpCode.FormsDesigner.Services.EventBindingService(designSurface); |
||||
serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), eventBindingService); |
||||
|
||||
designerResourceService.Host = Host; |
||||
serviceContainer.AddService(typeof(IDesignerHost), Host); |
||||
|
||||
DesignerLoader designerLoader = loaderProvider.CreateLoader(generator); |
||||
designSurface.BeginLoad(designerLoader); |
||||
|
||||
generator.Attach(this); |
||||
|
||||
undoEngine = new FormsDesignerUndoEngine(Host); |
||||
|
||||
IComponentChangeService componentChangeService = (IComponentChangeService)designSurface.GetService(typeof(IComponentChangeService)); |
||||
componentChangeService.ComponentChanged += delegate { viewContent.IsDirty = true; }; |
||||
|
||||
LoggingService.Info("Form Designer: END INITIALIZE"); |
||||
} |
||||
|
||||
void UnloadDesigner() |
||||
{ |
||||
generator.Detach(); |
||||
p.Controls.Clear(); |
||||
// We cannot dispose the design surface now because of SD2-451:
|
||||
// When the switch to the source view was triggered by a double-click on an event
|
||||
// in the PropertyPad, "InvalidOperationException: The container cannot be disposed
|
||||
// at design time" is thrown.
|
||||
// This is solved by calling dispose after the double-click event has been processed.
|
||||
if (disposing) { |
||||
designSurface.Dispose(); |
||||
} else { |
||||
p.BeginInvoke(new MethodInvoker(designSurface.Dispose)); |
||||
} |
||||
designSurface = null; |
||||
} |
||||
|
||||
PropertyContainer propertyContainer = new PropertyContainer(); |
||||
|
||||
public PropertyContainer PropertyContainer { |
||||
get { |
||||
return propertyContainer; |
||||
} |
||||
} |
||||
|
||||
public void ShowHelp() |
||||
{ |
||||
ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService)); |
||||
if (selectionService != null) { |
||||
Control ctl = selectionService.PrimarySelection as Control; |
||||
if (ctl != null) { |
||||
ICSharpCode.SharpDevelop.Dom.HelpProvider.ShowHelp(ctl.GetType().FullName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void Reload() |
||||
{ |
||||
try { |
||||
failedDesignerInitialize = false; |
||||
LoadDesigner(); |
||||
|
||||
if (designSurface != null && p.Controls.Count == 0) { |
||||
Control designer = designSurface.View as Control; |
||||
designer.Dock = DockStyle.Fill; |
||||
p.Controls.Add(designer); |
||||
} |
||||
} catch (Exception e) { |
||||
failedDesignerInitialize = true; |
||||
TextBox errorText = new TextBox(); |
||||
errorText.Multiline = true; |
||||
if (e.InnerException is FormsDesignerLoadException) |
||||
errorText.Text = e.InnerException.Message; |
||||
else if (e is FormsDesignerLoadException) |
||||
errorText.Text = e.Message; |
||||
else |
||||
errorText.Text = e.ToString(); |
||||
//output loaderrors too
|
||||
if(!designSurface.IsLoaded) { |
||||
errorText.Text += "\r\nDesignSurface not loaded :"; |
||||
if(designSurface.LoadErrors != null) { |
||||
foreach(Exception le in designSurface.LoadErrors) { |
||||
errorText.Text += "\r\n"; |
||||
errorText.Text += le.ToString(); |
||||
errorText.Text += "\r\n"; |
||||
errorText.Text += le.StackTrace; |
||||
} |
||||
} |
||||
} |
||||
|
||||
errorText.Dock = DockStyle.Fill; |
||||
p.Controls.Add(errorText); |
||||
Control title = new Label(); |
||||
title.Text = "Failed to load designer. Check the source code for syntax errors."; |
||||
title.Dock = DockStyle.Top; |
||||
p.Controls.Add(title); |
||||
} |
||||
} |
||||
|
||||
public virtual void MergeFormChanges() |
||||
{ |
||||
if (this.failedDesignerInitialize) { |
||||
return; |
||||
} |
||||
bool isDirty = viewContent.IsDirty; |
||||
LoggingService.Info("Merging form changes..."); |
||||
designSurface.Flush(); |
||||
LoggingService.Info("Finished merging form changes"); |
||||
viewContent.IsDirty = isDirty; |
||||
} |
||||
|
||||
public void ShowSourceCode() |
||||
{ |
||||
WorkbenchWindow.SwitchView(0); |
||||
} |
||||
|
||||
public void ShowSourceCode(int lineNumber) |
||||
{ |
||||
ShowSourceCode(); |
||||
textAreaControlProvider.TextEditorControl.ActiveTextAreaControl.JumpTo(lineNumber, 255); |
||||
} |
||||
|
||||
public void ShowSourceCode(IComponent component, EventDescriptor edesc, string eventMethodName) |
||||
{ |
||||
int position; |
||||
generator.InsertComponentEvent(component, edesc, eventMethodName, "", out position); |
||||
ShowSourceCode(position); |
||||
} |
||||
|
||||
public ICollection GetCompatibleMethods(EventDescriptor edesc) |
||||
{ |
||||
return generator.GetCompatibleMethods(edesc); |
||||
} |
||||
|
||||
public ICollection GetCompatibleMethods(EventInfo edesc) |
||||
{ |
||||
return generator.GetCompatibleMethods(edesc); |
||||
} |
||||
|
||||
public override void Selected() |
||||
{ |
||||
PropertyPad.PropertyValueChanged += PropertyValueChanged; |
||||
Reload(); |
||||
IsFormsDesignerVisible = true; |
||||
AddSideBars(); |
||||
propertyContainer.Host = Host; |
||||
UpdateSelectableObjects(); |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
disposing = true; |
||||
if (IsFormsDesignerVisible) { |
||||
Deselected(); |
||||
} |
||||
base.Dispose(); |
||||
} |
||||
|
||||
public override void Deselected() |
||||
{ |
||||
LoggingService.Info("Deselected form designer, unloading..."); |
||||
PropertyPad.PropertyValueChanged -= PropertyValueChanged; |
||||
propertyContainer.Clear(); |
||||
IsFormsDesignerVisible = false; |
||||
foreach(AxSideTab tab in ToolboxProvider.SideTabs) { |
||||
if (!SharpDevelopSideBar.SideBar.Tabs.Contains(tab)) { |
||||
return; |
||||
} |
||||
SharpDevelopSideBar.SideBar.Tabs.Remove(tab); |
||||
} |
||||
SharpDevelopSideBar.SideBar.Refresh(); |
||||
if (!failedDesignerInitialize) { |
||||
MergeFormChanges(); |
||||
textAreaControlProvider.TextEditorControl.Refresh(); |
||||
} |
||||
UnloadDesigner(); |
||||
LoggingService.Info("Unloading form designer finished"); |
||||
} |
||||
|
||||
public override void NotifyBeforeSave() |
||||
{ |
||||
base.NotifyBeforeSave(); |
||||
if (IsFormsDesignerVisible) |
||||
MergeFormChanges(); |
||||
} |
||||
|
||||
public override void NotifyAfterSave(bool successful) |
||||
{ |
||||
if (successful) { |
||||
if (designerResourceService != null) { |
||||
designerResourceService.Save(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected void UpdateSelectableObjects() |
||||
{ |
||||
propertyContainer.SelectableObjects = Host.Container.Components; |
||||
ISelectionService selectionService = (ISelectionService)Host.GetService(typeof(ISelectionService)); |
||||
if (selectionService != null) { |
||||
propertyContainer.SelectedObject = selectionService.PrimarySelection; |
||||
} |
||||
} |
||||
|
||||
public bool IsFormsDesignerVisible = false; |
||||
|
||||
#region IUndoHandler implementation
|
||||
public bool EnableUndo { |
||||
get { |
||||
if (undoEngine != null) { |
||||
return undoEngine.EnableUndo; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
public bool EnableRedo { |
||||
get { |
||||
if (undoEngine != null) { |
||||
return undoEngine.EnableRedo; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
public virtual void Undo() |
||||
{ |
||||
if (undoEngine != null) { |
||||
undoEngine.Undo(); |
||||
} |
||||
} |
||||
|
||||
public virtual void Redo() |
||||
{ |
||||
if (undoEngine != null) { |
||||
undoEngine.Redo(); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region IClipboardHandler implementation
|
||||
public bool EnableCut { |
||||
get { |
||||
//ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService));
|
||||
//return selectionService.SelectionCount >= 0 && selectionService.PrimarySelection != host.RootComponent;
|
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Cut); |
||||
if (menuCommand == null) { |
||||
return false; |
||||
} |
||||
int status = menuCommand.OleStatus; |
||||
return menuCommand.Enabled; |
||||
} |
||||
} |
||||
|
||||
public bool EnableCopy { |
||||
get { |
||||
//ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService));
|
||||
//return selectionService.SelectionCount >= 0 && selectionService.PrimarySelection != host.RootComponent;
|
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Copy); |
||||
if (menuCommand == null) { |
||||
return false; |
||||
} |
||||
int status = menuCommand.OleStatus; |
||||
return menuCommand.Enabled; |
||||
} |
||||
} |
||||
|
||||
const string ComponentClipboardFormat = "CF_DESIGNERCOMPONENTS"; |
||||
public bool EnablePaste { |
||||
get { |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Paste); |
||||
if (menuCommand == null) { |
||||
return false; |
||||
} |
||||
int status = menuCommand.OleStatus; |
||||
return menuCommand.Enabled; |
||||
} |
||||
} |
||||
|
||||
public bool EnableDelete { |
||||
get { |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
System.ComponentModel.Design.MenuCommand menuCommand = menuCommandService.FindCommand(StandardCommands.Delete); |
||||
if (menuCommand == null) { |
||||
return false; |
||||
} |
||||
int status = menuCommand.OleStatus; |
||||
return menuCommand.Enabled; |
||||
} |
||||
} |
||||
|
||||
public bool EnableSelectAll { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public void Cut() |
||||
{ |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.Cut); |
||||
} |
||||
|
||||
public void Copy() |
||||
{ |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.Copy); |
||||
} |
||||
|
||||
public void Paste() |
||||
{ |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.Paste); |
||||
} |
||||
|
||||
public void Delete() |
||||
{ |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.Delete); |
||||
} |
||||
|
||||
public void SelectAll() |
||||
{ |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.SelectAll); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Tab Order Handling
|
||||
bool tabOrderMode = false; |
||||
public virtual bool IsTabOrderMode { |
||||
get { |
||||
return tabOrderMode; |
||||
} |
||||
} |
||||
|
||||
public virtual void ShowTabOrder() |
||||
{ |
||||
if (!IsTabOrderMode) { |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.TabOrder); |
||||
tabOrderMode = true; |
||||
} |
||||
} |
||||
|
||||
public virtual void HideTabOrder() |
||||
{ |
||||
if (IsTabOrderMode) { |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService)); |
||||
menuCommandService.GlobalInvoke(StandardCommands.TabOrder); |
||||
tabOrderMode = false; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the form designer if the language property has changed.
|
||||
/// </summary>
|
||||
void PropertyValueChanged(object source, PropertyValueChangedEventArgs e) |
||||
{ |
||||
if (e.ChangedItem.GridItemType == GridItemType.Property) { |
||||
if (e.ChangedItem.PropertyDescriptor.Name == "Language") { |
||||
if (!e.OldValue.Equals(e.ChangedItem.Value)) { |
||||
LoggingService.Debug("Reloading designer due to language change."); |
||||
propertyContainer.Clear(); |
||||
if (!failedDesignerInitialize) { |
||||
MergeFormChanges(); |
||||
} |
||||
UnloadDesigner(); |
||||
Reload(); |
||||
propertyContainer.Host = Host; |
||||
UpdateSelectableObjects(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void AddSideBars() |
||||
{ |
||||
foreach(AxSideTab tab in ToolboxProvider.SideTabs) { |
||||
if (!SharpDevelopSideBar.SideBar.Tabs.Contains(tab)) { |
||||
SharpDevelopSideBar.SideBar.Tabs.Add(tab); |
||||
} |
||||
} |
||||
SharpDevelopSideBar.SideBar.Refresh(); |
||||
} |
||||
} |
||||
} |
@ -1,180 +0,0 @@
@@ -1,180 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using System.Drawing.Printing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Internal.Undo; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
|
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using Microsoft.CSharp; |
||||
using Microsoft.VisualBasic; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class FormKeyHandler : IMessageFilter |
||||
{ |
||||
const int keyPressedMessage = 0x100; |
||||
const int leftMouseButtonDownMessage = 0x0202; |
||||
|
||||
Hashtable keyTable = new Hashtable(); |
||||
public static bool inserted = false; |
||||
public static void Insert() |
||||
{ |
||||
inserted = true; |
||||
Application.AddMessageFilter(new FormKeyHandler()); |
||||
} |
||||
|
||||
public FormKeyHandler() |
||||
{ |
||||
// normal keys
|
||||
keyTable[Keys.Left] = new CommandWrapper(MenuCommands.KeyMoveLeft); |
||||
keyTable[Keys.Right] = new CommandWrapper(MenuCommands.KeyMoveRight); |
||||
keyTable[Keys.Up] = new CommandWrapper(MenuCommands.KeyMoveUp); |
||||
keyTable[Keys.Down] = new CommandWrapper(MenuCommands.KeyMoveDown); |
||||
keyTable[Keys.Tab] = new CommandWrapper(MenuCommands.KeySelectNext); |
||||
keyTable[Keys.Delete] = new CommandWrapper(MenuCommands.Delete); |
||||
keyTable[Keys.Back] = new CommandWrapper(MenuCommands.Delete); |
||||
|
||||
// shift modified keys
|
||||
keyTable[Keys.Left | Keys.Shift] = new CommandWrapper(MenuCommands.KeySizeWidthDecrease); |
||||
keyTable[Keys.Right | Keys.Shift] = new CommandWrapper(MenuCommands.KeySizeWidthIncrease); |
||||
keyTable[Keys.Up | Keys.Shift] = new CommandWrapper(MenuCommands.KeySizeHeightDecrease); |
||||
keyTable[Keys.Down | Keys.Shift] = new CommandWrapper(MenuCommands.KeySizeHeightIncrease); |
||||
keyTable[Keys.Tab | Keys.Shift] = new CommandWrapper(MenuCommands.KeySelectPrevious); |
||||
keyTable[Keys.Delete| Keys.Shift] = new CommandWrapper(MenuCommands.Delete); |
||||
keyTable[Keys.Back| Keys.Shift] = new CommandWrapper(MenuCommands.Delete); |
||||
|
||||
// ctrl modified keys
|
||||
keyTable[Keys.Left | Keys.Control] = new CommandWrapper(MenuCommands.KeyNudgeLeft); |
||||
keyTable[Keys.Right | Keys.Control] = new CommandWrapper(MenuCommands.KeyNudgeRight); |
||||
keyTable[Keys.Up | Keys.Control] = new CommandWrapper(MenuCommands.KeyNudgeUp); |
||||
keyTable[Keys.Down | Keys.Control] = new CommandWrapper(MenuCommands.KeyNudgeDown); |
||||
|
||||
// ctrl + shift modified keys
|
||||
keyTable[Keys.Left | Keys.Control | Keys.Shift] = new CommandWrapper(MenuCommands.KeyNudgeWidthDecrease); |
||||
keyTable[Keys.Right | Keys.Control | Keys.Shift] = new CommandWrapper(MenuCommands.KeyNudgeWidthIncrease); |
||||
keyTable[Keys.Up | Keys.Control | Keys.Shift] = new CommandWrapper(MenuCommands.KeyNudgeHeightDecrease); |
||||
keyTable[Keys.Down | Keys.Control | Keys.Shift] = new CommandWrapper(MenuCommands.KeyNudgeHeightIncrease); |
||||
} |
||||
|
||||
public bool PreFilterMessage(ref Message m) |
||||
{ |
||||
if (m.Msg != keyPressedMessage /*&& m.Msg != leftMouseButtonDownMessage*/) { |
||||
return false; |
||||
} |
||||
|
||||
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == null || |
||||
!WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent.Control.ContainsFocus) { |
||||
return false; |
||||
} |
||||
|
||||
FormsDesignerViewContent formDesigner = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as FormsDesignerViewContent; |
||||
|
||||
if (formDesigner == null) { |
||||
return false; |
||||
} |
||||
|
||||
if (!formDesigner.IsFormsDesignerVisible) { |
||||
return false; |
||||
} |
||||
|
||||
// if (AbstractMenuEditorControl.MenuEditorFocused) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (m.Msg == leftMouseButtonDownMessage) {
|
||||
// if (formDesigner.IsTabOrderMode) {
|
||||
// Point p = new Point(m.LParam.ToInt32());
|
||||
// Control c = Control.FromHandle(m.HWnd);
|
||||
// try {
|
||||
// if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
|
||||
// formDesigner.SetPrevTabIndex(c.PointToScreen(p));
|
||||
// } else {
|
||||
// formDesigner.SetNextTabIndex(c.PointToScreen(p));
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// MessageService.ShowError(e);
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
Keys keyPressed = (Keys)m.WParam.ToInt32() | Control.ModifierKeys; |
||||
|
||||
if (keyPressed == Keys.Escape) { |
||||
if (formDesigner.IsTabOrderMode) { |
||||
formDesigner.HideTabOrder(); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
CommandWrapper commandWrapper = (CommandWrapper)keyTable[keyPressed]; |
||||
if (commandWrapper != null) { |
||||
IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService)); |
||||
ISelectionService selectionService = (ISelectionService)formDesigner.Host.GetService(typeof(ISelectionService)); |
||||
ICollection components = selectionService.GetSelectedComponents(); |
||||
|
||||
menuCommandService.GlobalInvoke(commandWrapper.CommandID); |
||||
|
||||
if (commandWrapper.RestoreSelection) { |
||||
selectionService.SetSelectedComponents(components); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
class CommandWrapper |
||||
{ |
||||
CommandID commandID; |
||||
bool restoreSelection; |
||||
|
||||
public CommandID CommandID { |
||||
get { |
||||
return commandID; |
||||
} |
||||
} |
||||
|
||||
public bool RestoreSelection { |
||||
get { |
||||
return restoreSelection; |
||||
} |
||||
} |
||||
|
||||
public CommandWrapper(CommandID commandID) : this(commandID, false) |
||||
{ |
||||
} |
||||
public CommandWrapper(CommandID commandID, bool restoreSelection) |
||||
{ |
||||
this.commandID = commandID; |
||||
this.restoreSelection = restoreSelection; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,218 +0,0 @@
@@ -1,218 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
// created on 07.08.2003 at 13:46
|
||||
using System; |
||||
using System.IO; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Collections; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using MSjogren.GacTool.FusionNative; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class AddComponentsDialog : BaseSharpDevelopForm |
||||
{ |
||||
ArrayList selectedComponents; |
||||
|
||||
public ArrayList SelectedComponents { |
||||
get { |
||||
return selectedComponents; |
||||
} |
||||
} |
||||
|
||||
public AddComponentsDialog() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.FormsDesigner.Resources.AddSidebarComponentsDialog.xfrm")); |
||||
|
||||
Icon = null; |
||||
PrintGACCache(); |
||||
|
||||
ControlDictionary["browseButton"].Click += new System.EventHandler(this.browseButtonClick); |
||||
((ListView)ControlDictionary["gacListView"]).SelectedIndexChanged += new System.EventHandler(this.gacListViewSelectedIndexChanged); |
||||
// ((TextBox)ControlDictionary["fileNameTextBox"]).TextChanged += new System.EventHandler(this.fileNameTextBoxTextChanged);
|
||||
ControlDictionary["okButton"].Click += new System.EventHandler(this.buttonClick); |
||||
ControlDictionary["loadButton"].Click += new System.EventHandler(this.loadButtonClick); |
||||
} |
||||
|
||||
void PrintGACCache() |
||||
{ |
||||
IApplicationContext applicationContext = null; |
||||
IAssemblyEnum assemblyEnum = null; |
||||
IAssemblyName assemblyName = null; |
||||
|
||||
Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0); |
||||
|
||||
while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { |
||||
uint nChars = 0; |
||||
assemblyName.GetDisplayName(null, ref nChars, 0); |
||||
|
||||
StringBuilder sb = new StringBuilder((int)nChars); |
||||
assemblyName.GetDisplayName(sb, ref nChars, 0); |
||||
|
||||
string[] info = sb.ToString().Split(','); |
||||
|
||||
string name = info[0]; |
||||
string version = info[1].Substring(info[1].LastIndexOf('=') + 1); |
||||
|
||||
ListViewItem item = new ListViewItem(new string[] {name, version}); |
||||
item.Tag = sb.ToString(); |
||||
((ListView)ControlDictionary["gacListView"]).Items.Add(item); |
||||
} |
||||
} |
||||
|
||||
void FillComponents(Assembly assembly, string loadPath) |
||||
{ |
||||
((ListView)ControlDictionary["componentListView"]).BeginUpdate(); |
||||
((ListView)ControlDictionary["componentListView"]).Items.Clear(); |
||||
|
||||
if (assembly != null) { |
||||
Hashtable images = new Hashtable(); |
||||
ImageList il = new ImageList(); |
||||
// try to load res icon
|
||||
string[] imgNames = assembly.GetManifestResourceNames(); |
||||
|
||||
foreach (string im in imgNames) { |
||||
try { |
||||
Bitmap b = new Bitmap(Image.FromStream(assembly.GetManifestResourceStream(im))); |
||||
b.MakeTransparent(); |
||||
images[im] = il.Images.Count; |
||||
il.Images.Add(b); |
||||
} catch {} |
||||
} |
||||
try { |
||||
Module[] ms = assembly.GetModules(false); |
||||
((ListView)ControlDictionary["componentListView"]).SmallImageList = il; |
||||
foreach (Module m in ms) { |
||||
Type[] ts = m.GetTypes(); |
||||
foreach (Type t in ts) { |
||||
if (t.IsPublic && !t.IsAbstract) { |
||||
if (t.IsDefined(typeof(ToolboxItemFilterAttribute), true) || t.IsDefined(typeof(ToolboxItemAttribute), true) || typeof(System.ComponentModel.IComponent).IsAssignableFrom(t)) { |
||||
object[] attributes = t.GetCustomAttributes(false); |
||||
object[] filterAttrs = t.GetCustomAttributes(typeof(DesignTimeVisibleAttribute), true); |
||||
foreach (DesignTimeVisibleAttribute visibleAttr in filterAttrs) { |
||||
if (!visibleAttr.Visible) { |
||||
goto skip; |
||||
} |
||||
} |
||||
|
||||
if (images[t.FullName + ".bmp"] == null) { |
||||
if (t.IsDefined(typeof(ToolboxBitmapAttribute), false)) { |
||||
foreach (object attr in attributes) { |
||||
if (attr is ToolboxBitmapAttribute) { |
||||
ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; |
||||
images[t.FullName + ".bmp"] = il.Images.Count; |
||||
Bitmap b = new Bitmap(toolboxBitmapAttribute.GetImage(t)); |
||||
b.MakeTransparent(); |
||||
il.Images.Add(b); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
ListViewItem newItem = new ListViewItem(t.Name); |
||||
newItem.SubItems.Add(t.Namespace); |
||||
newItem.SubItems.Add(assembly.ToString()); |
||||
newItem.SubItems.Add(assembly.Location); |
||||
newItem.SubItems.Add(t.Namespace); |
||||
if (images[t.FullName + ".bmp"] != null) { |
||||
newItem.ImageIndex = (int)images[t.FullName + ".bmp"]; |
||||
} |
||||
newItem.Checked = true; |
||||
ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath)); |
||||
toolComponent.IsEnabled = true; |
||||
newItem.Tag = toolComponent; |
||||
((ListView)ControlDictionary["componentListView"]).Items.Add(newItem); |
||||
ToolboxItem item = new ToolboxItem(t); |
||||
skip:; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e); |
||||
} |
||||
} |
||||
((ListView)ControlDictionary["componentListView"]).EndUpdate(); |
||||
} |
||||
|
||||
/* changed this unexpected behaviour -- added a load button, G.B. |
||||
void fileNameTextBoxTextChanged(object sender, System.EventArgs e) |
||||
{ |
||||
if (File.Exists(this.fileNameTextBox.Text)) { |
||||
try { |
||||
FillComponents(Assembly.LoadFrom(this.fileNameTextBox.Text)); |
||||
} catch (Exception ex) { |
||||
|
||||
MessageService.ShowError(ex); |
||||
} |
||||
} |
||||
} |
||||
*/ |
||||
|
||||
void gacListViewSelectedIndexChanged(object sender, System.EventArgs e) |
||||
{ |
||||
if (((ListView)ControlDictionary["gacListView"]).SelectedItems != null && ((ListView)ControlDictionary["gacListView"]).SelectedItems.Count == 1) { |
||||
string assemblyName = ((ListView)ControlDictionary["gacListView"]).SelectedItems[0].Tag.ToString(); |
||||
Assembly asm = Assembly.Load(assemblyName); |
||||
FillComponents(asm, null); |
||||
} else { |
||||
FillComponents(null, null); |
||||
} |
||||
} |
||||
|
||||
void loadButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
if (!System.IO.File.Exists(ControlDictionary["fileNameTextBox"].Text)) { |
||||
MessageBox.Show("Please enter a valid file name.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
string assemblyFileName = ControlDictionary["fileNameTextBox"].Text; |
||||
Assembly asm = Assembly.LoadFrom(assemblyFileName); |
||||
FillComponents(asm, Path.GetDirectoryName(assemblyFileName)); |
||||
} catch { |
||||
MessageBox.Show("Please enter the file name of a valid .NET assembly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||||
FillComponents(null, null); |
||||
} |
||||
} |
||||
|
||||
void buttonClick(object sender, System.EventArgs e) |
||||
{ |
||||
selectedComponents = new ArrayList(); |
||||
foreach (ListViewItem item in ((ListView)ControlDictionary["componentListView"]).Items) { |
||||
if (item.Checked) { |
||||
selectedComponents.Add((ToolComponent)item.Tag); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void browseButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
using (OpenFileDialog fdiag = new OpenFileDialog()) { |
||||
fdiag.AddExtension = true; |
||||
|
||||
fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AssemblyFiles}|*.dll;*.exe|${res:SharpDevelop.FileFilter.AllFiles}|*.*"); |
||||
fdiag.Multiselect = false; |
||||
fdiag.CheckFileExists = true; |
||||
|
||||
if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) { |
||||
ControlDictionary["fileNameTextBox"].Text = fdiag.FileName; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,379 +0,0 @@
@@ -1,379 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Denis ERCHOFF" email="d_erchoff@hotmail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Drawing; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class ToolComponent |
||||
{ |
||||
string fullName; |
||||
string assemblyName; |
||||
string hintPath; |
||||
bool isEnabled = true; |
||||
|
||||
public string HintPath { |
||||
get { |
||||
return hintPath; |
||||
} |
||||
set { |
||||
hintPath = value; |
||||
} |
||||
} |
||||
|
||||
public string FullName { |
||||
get { |
||||
return fullName; |
||||
} |
||||
set { |
||||
fullName = value; |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
int idx = fullName.LastIndexOf('.'); |
||||
if (idx > 0) { |
||||
return fullName.Substring(idx + 1); |
||||
} |
||||
return fullName; |
||||
} |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { |
||||
int idx = fullName.LastIndexOf('.'); |
||||
if (idx > 0) { |
||||
return fullName.Substring(0, idx); |
||||
} |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public bool IsEnabled { |
||||
get { |
||||
return isEnabled; |
||||
} |
||||
set { |
||||
isEnabled = value; |
||||
} |
||||
} |
||||
|
||||
string AssemblyFileNameWithoutPath { |
||||
get { |
||||
int idx = assemblyName.IndexOf(','); |
||||
|
||||
return assemblyName.Substring(0, idx) + ".dll"; |
||||
} |
||||
} |
||||
|
||||
public string AssemblyName { |
||||
get { |
||||
return assemblyName; |
||||
} |
||||
set { |
||||
assemblyName = value; |
||||
} |
||||
} |
||||
protected ToolComponent() |
||||
{ |
||||
} |
||||
public ToolComponent(string fullName, ComponentAssembly assembly) |
||||
{ |
||||
this.fullName = fullName; |
||||
this.assemblyName = assembly.Name; |
||||
this.hintPath = assembly.HintPath; |
||||
} |
||||
public string FileName { |
||||
get { |
||||
if (HintPath == null) { |
||||
return null; |
||||
} |
||||
return Path.Combine(HintPath, AssemblyFileNameWithoutPath); |
||||
} |
||||
} |
||||
|
||||
public Assembly LoadAssembly() |
||||
{ |
||||
if (HintPath != null) { |
||||
return Assembly.LoadFrom(FileName); |
||||
} |
||||
return Assembly.Load(AssemblyName); |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
ToolComponent toolComponent = new ToolComponent(); |
||||
toolComponent.FullName = fullName; |
||||
toolComponent.AssemblyName = assemblyName; |
||||
toolComponent.IsEnabled = isEnabled; |
||||
return toolComponent; |
||||
} |
||||
} |
||||
|
||||
public class Category |
||||
{ |
||||
string name; |
||||
bool isEnabled = true; |
||||
ArrayList components = new ArrayList(); |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value; |
||||
} |
||||
} |
||||
|
||||
public bool IsEnabled { |
||||
get { |
||||
return isEnabled; |
||||
} |
||||
set { |
||||
isEnabled = value; |
||||
} |
||||
} |
||||
|
||||
public ArrayList ToolComponents { |
||||
get { |
||||
return components; |
||||
} |
||||
} |
||||
|
||||
protected Category() |
||||
{ |
||||
} |
||||
|
||||
public Category(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
Category newCategory = new Category(); |
||||
newCategory.Name = name; |
||||
newCategory.IsEnabled = isEnabled; |
||||
foreach (ToolComponent toolComponent in components) { |
||||
newCategory.ToolComponents.Add(toolComponent.Clone()); |
||||
} |
||||
return newCategory; |
||||
} |
||||
} |
||||
|
||||
public class ComponentAssembly |
||||
{ |
||||
string name; |
||||
string hintPath; |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value; |
||||
} |
||||
} |
||||
public string HintPath { |
||||
get { |
||||
return hintPath; |
||||
} |
||||
set { |
||||
hintPath = value; |
||||
} |
||||
} |
||||
public ComponentAssembly(string name) |
||||
{ |
||||
this.name = name; |
||||
this.hintPath = null; |
||||
} |
||||
public ComponentAssembly(string name, string hintPath) |
||||
{ |
||||
this.name = name; |
||||
this.hintPath = hintPath; |
||||
} |
||||
public override string ToString() |
||||
{ |
||||
return name; |
||||
} |
||||
} |
||||
|
||||
public class ComponentLibraryLoader |
||||
{ |
||||
static readonly string VERSION = "1.1.0"; |
||||
|
||||
ArrayList assemblies = new ArrayList(); |
||||
ArrayList categories = new ArrayList(); |
||||
|
||||
public ArrayList Categories { |
||||
get { |
||||
return categories; |
||||
} |
||||
set { |
||||
categories = value; |
||||
} |
||||
} |
||||
|
||||
public ArrayList CopyCategories() |
||||
{ |
||||
ArrayList newCategories = new ArrayList(); |
||||
foreach (Category category in categories) { |
||||
newCategories.Add(category.Clone()); |
||||
} |
||||
return newCategories; |
||||
} |
||||
|
||||
|
||||
public bool LoadToolComponentLibrary(string fileName) |
||||
{ |
||||
if (!File.Exists(fileName)) { |
||||
return false; |
||||
} |
||||
|
||||
try { |
||||
XmlDocument doc = new XmlDocument(); |
||||
doc.Load(fileName); |
||||
|
||||
if (doc.DocumentElement.Name != "SharpDevelopControlLibrary" || |
||||
doc.DocumentElement.Attributes["version"] == null || |
||||
doc.DocumentElement.Attributes["version"].InnerText != VERSION) { |
||||
return false; |
||||
} |
||||
|
||||
foreach (XmlNode node in doc.DocumentElement["Assemblies"].ChildNodes) { |
||||
if (node.Name == "Assembly") { |
||||
string assemblyName = node.Attributes["assembly"].InnerText; |
||||
if (node.Attributes["path"] != null) { |
||||
assemblies.Add(new ComponentAssembly(assemblyName, node.Attributes["path"].InnerText)); |
||||
} else { |
||||
assemblies.Add(new ComponentAssembly(assemblyName)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
foreach (XmlNode node in doc.DocumentElement["Categories"].ChildNodes) { |
||||
if (node.Name == "Category") { |
||||
string name = node.Attributes["name"].InnerText; |
||||
Category newCategory = new Category(name); |
||||
foreach (XmlNode componentNode in node.ChildNodes) { |
||||
ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, |
||||
(ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)]); |
||||
newCategory.ToolComponents.Add(newToolComponent); |
||||
} |
||||
categories.Add(newCategory); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.LoadToolComponentLibrary: " + e.Message); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public Bitmap GetIcon(ToolComponent component) |
||||
{ |
||||
Assembly asm = component.LoadAssembly(); |
||||
Type type = asm.GetType(component.FullName); |
||||
Bitmap b = null; |
||||
if (type != null) { |
||||
object[] attributes = type.GetCustomAttributes(false); |
||||
foreach (object attr in attributes) { |
||||
if (attr is ToolboxBitmapAttribute) { |
||||
ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; |
||||
b = new Bitmap(toolboxBitmapAttribute.GetImage(type)); |
||||
b.MakeTransparent(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
if (b == null) { |
||||
try { |
||||
Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp"); |
||||
if (imageStream != null) { |
||||
b = new Bitmap(Image.FromStream(imageStream)); |
||||
b.MakeTransparent(); |
||||
} |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message); |
||||
} |
||||
} |
||||
|
||||
// TODO: Maybe default icon needed ??!?!
|
||||
return b; |
||||
} |
||||
|
||||
public ToolComponent GetToolComponent(string assemblyName) |
||||
{ |
||||
foreach (Category category in categories) { |
||||
foreach (ToolComponent component in category.ToolComponents) { |
||||
if (component.AssemblyName == assemblyName) { |
||||
return component; |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void SaveToolComponentLibrary(string fileName) |
||||
{ |
||||
XmlDocument doc = new XmlDocument(); |
||||
doc.LoadXml("<SharpDevelopControlLibrary version=\"" + VERSION + "\"/>"); |
||||
Hashtable assemblyHashTable = new Hashtable(); |
||||
|
||||
XmlElement assemblyNode = doc.CreateElement("Assemblies"); |
||||
doc.DocumentElement.AppendChild(assemblyNode); |
||||
for (int i = 0; i < assemblies.Count; ++i) { |
||||
ComponentAssembly componentAssembly = (ComponentAssembly)assemblies[i]; |
||||
assemblyHashTable[componentAssembly.Name] = i; |
||||
|
||||
XmlElement newAssembly = doc.CreateElement("Assembly"); |
||||
|
||||
newAssembly.SetAttribute("assembly", componentAssembly.Name); |
||||
if (componentAssembly.HintPath != null) { |
||||
newAssembly.SetAttribute("path", componentAssembly.HintPath); |
||||
} |
||||
assemblyNode.AppendChild(newAssembly); |
||||
} |
||||
|
||||
XmlElement categoryNode = doc.CreateElement("Categories"); |
||||
doc.DocumentElement.AppendChild(categoryNode); |
||||
foreach (Category category in categories) { |
||||
XmlElement newCategory = doc.CreateElement("Category"); |
||||
newCategory.SetAttribute("name", category.Name); |
||||
newCategory.SetAttribute("enabled", category.IsEnabled.ToString()); |
||||
categoryNode.AppendChild(newCategory); |
||||
|
||||
foreach (ToolComponent component in category.ToolComponents) { |
||||
XmlElement newToolComponent = doc.CreateElement("ToolComponent"); |
||||
newToolComponent.SetAttribute("class", component.FullName); |
||||
|
||||
if (assemblyHashTable[component.AssemblyName] == null) { |
||||
XmlElement newAssembly = doc.CreateElement("Assembly"); |
||||
newAssembly.SetAttribute("assembly", component.AssemblyName); |
||||
if (component.HintPath != null) { |
||||
newAssembly.SetAttribute("path", component.HintPath); |
||||
} |
||||
|
||||
assemblyNode.AppendChild(newAssembly); |
||||
assemblyHashTable[component.AssemblyName] = assemblyHashTable.Values.Count; |
||||
} |
||||
|
||||
newToolComponent.SetAttribute("assembly", assemblyHashTable[component.AssemblyName].ToString()); |
||||
newToolComponent.SetAttribute("enabled", component.IsEnabled.ToString()); |
||||
newCategory.AppendChild(newToolComponent); |
||||
} |
||||
} |
||||
doc.Save(fileName); |
||||
} |
||||
} |
||||
} |
@ -1,196 +0,0 @@
@@ -1,196 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
// created on 07.08.2003 at 13:36
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Collections; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class ConfigureSideBarDialog : BaseSharpDevelopForm |
||||
{ |
||||
ArrayList oldComponents; |
||||
|
||||
public ConfigureSideBarDialog() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.FormsDesigner.Resources.ConfigureSidebarDialog.xfrm")); |
||||
|
||||
oldComponents = ToolboxProvider.ComponentLibraryLoader.CopyCategories(); |
||||
|
||||
FillCategories(); |
||||
categoryListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
componentListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
ControlDictionary["okButton"].Click += new System.EventHandler(this.okButtonClick); |
||||
ControlDictionary["newCategoryButton"].Click += new System.EventHandler(this.newCategoryButtonClick); |
||||
ControlDictionary["renameCategoryButton"].Click += new System.EventHandler(this.renameCategoryButtonClick); |
||||
ControlDictionary["removeCategoryButton"].Click += new System.EventHandler(this.removeCategoryButtonClick); |
||||
ControlDictionary["addComponentsButton"].Click += new System.EventHandler(this.button3Click); |
||||
ControlDictionary["removeComponentsButton"].Click += new System.EventHandler(this.removeComponentsButtonClick); |
||||
|
||||
((ListView)ControlDictionary["categoryListView"]).SelectedIndexChanged += new System.EventHandler(this.categoryListViewSelectedIndexChanged); |
||||
((ListView)ControlDictionary["componentListView"]).SelectedIndexChanged += new System.EventHandler(this.componentListViewSelectedIndexChanged); |
||||
} |
||||
|
||||
void FillCategories() |
||||
{ |
||||
((ListView)ControlDictionary["categoryListView"]).BeginUpdate(); |
||||
((ListView)ControlDictionary["categoryListView"]).Items.Clear(); |
||||
foreach (Category category in ToolboxProvider.ComponentLibraryLoader.Categories) { |
||||
ListViewItem newItem = new ListViewItem(category.Name); |
||||
newItem.Checked = category.IsEnabled; |
||||
newItem.Tag = category; |
||||
((ListView)ControlDictionary["categoryListView"]).Items.Add(newItem); |
||||
} |
||||
((ListView)ControlDictionary["categoryListView"]).EndUpdate(); |
||||
} |
||||
|
||||
void FillComponents() |
||||
{ |
||||
((ListView)ControlDictionary["componentListView"]).ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.componentListViewItemCheck); |
||||
((ListView)ControlDictionary["componentListView"]).BeginUpdate(); |
||||
((ListView)ControlDictionary["componentListView"]).Items.Clear(); |
||||
((ListView)ControlDictionary["componentListView"]).SmallImageList = new ImageList(); |
||||
|
||||
if (((ListView)ControlDictionary["categoryListView"]).SelectedItems != null && ((ListView)ControlDictionary["categoryListView"]).SelectedItems.Count == 1) { |
||||
Category category = (Category)((ListView)ControlDictionary["categoryListView"]).SelectedItems[0].Tag; |
||||
foreach (ToolComponent component in category.ToolComponents) { |
||||
Bitmap icon = null; |
||||
string loadError = null; |
||||
try { |
||||
icon = ToolboxProvider.ComponentLibraryLoader.GetIcon(component); |
||||
} catch (Exception e) { |
||||
|
||||
icon = IconService.GetBitmap("Icons.16x16.Warning"); |
||||
loadError = e.Message; |
||||
} |
||||
if (icon != null) { |
||||
((ListView)ControlDictionary["componentListView"]).SmallImageList.Images.Add(icon); |
||||
} |
||||
|
||||
ListViewItem newItem = new ListViewItem(component.Name); |
||||
newItem.SubItems.Add(component.Namespace); |
||||
newItem.SubItems.Add(loadError != null ? loadError :component.AssemblyName); |
||||
|
||||
newItem.Checked = component.IsEnabled; |
||||
newItem.Tag = component; |
||||
newItem.ImageIndex = ((ListView)ControlDictionary["componentListView"]).SmallImageList.Images.Count - 1; |
||||
((ListView)ControlDictionary["componentListView"]).Items.Add(newItem); |
||||
} |
||||
} |
||||
((ListView)ControlDictionary["componentListView"]).EndUpdate(); |
||||
((ListView)ControlDictionary["componentListView"]).ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.componentListViewItemCheck); |
||||
} |
||||
|
||||
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
|
||||
// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
|
||||
void categoryListViewSelectedIndexChanged(object sender, System.EventArgs e) |
||||
{ |
||||
ControlDictionary["renameCategoryButton"].Enabled = ControlDictionary["addComponentsButton"].Enabled = CurrentCategory != null; |
||||
FillComponents(); |
||||
} |
||||
|
||||
Category CurrentCategory { |
||||
get { |
||||
if (((ListView)ControlDictionary["categoryListView"]).SelectedItems != null && ((ListView)ControlDictionary["categoryListView"]).SelectedItems.Count == 1) { |
||||
return (Category)((ListView)ControlDictionary["categoryListView"]).SelectedItems[0].Tag; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
void button3Click(object sender, System.EventArgs e) |
||||
{ |
||||
AddComponentsDialog addComponentsDialog = new AddComponentsDialog(); |
||||
if (addComponentsDialog.ShowDialog(this) == DialogResult.OK) { |
||||
foreach (ToolComponent component in addComponentsDialog.SelectedComponents) { |
||||
CurrentCategory.ToolComponents.Add(component); |
||||
} |
||||
FillComponents(); |
||||
categoryListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
componentListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void newCategoryButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
RenameCategoryDialog renameCategoryDialog = new RenameCategoryDialog(null, this); |
||||
if (renameCategoryDialog.ShowDialog(this) == DialogResult.OK) { |
||||
ToolboxProvider.ComponentLibraryLoader.Categories.Add(new Category(renameCategoryDialog.CategoryName)); |
||||
FillCategories(); |
||||
} |
||||
} |
||||
|
||||
void removeCategoryButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
|
||||
if (MessageService.AskQuestion("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.ConfigureSideBarDialog.RemoveCategoryQuestion}")) { |
||||
categoryListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
ToolboxProvider.ComponentLibraryLoader.Categories.Remove(CurrentCategory); |
||||
FillCategories(); |
||||
FillComponents(); |
||||
categoryListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
componentListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void componentListViewSelectedIndexChanged(object sender, System.EventArgs e) |
||||
{ |
||||
ControlDictionary["removeComponentsButton"].Enabled = ((ListView)ControlDictionary["componentListView"]).SelectedItems != null && ((ListView)ControlDictionary["componentListView"]).SelectedItems.Count > 0; |
||||
} |
||||
|
||||
void removeComponentsButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
|
||||
if (MessageService.AskQuestion("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.ConfigureSideBarDialog.RemoveComponentsQuestion}")) { |
||||
foreach (ListViewItem item in ((ListView)ControlDictionary["componentListView"]).SelectedItems) { |
||||
CurrentCategory.ToolComponents.Remove((ToolComponent)item.Tag); |
||||
} |
||||
FillComponents(); |
||||
componentListViewSelectedIndexChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
protected override void OnClosed(System.EventArgs e) |
||||
{ |
||||
base.OnClosed(e); |
||||
if (oldComponents != null) { |
||||
ToolboxProvider.ComponentLibraryLoader.Categories = oldComponents; |
||||
} |
||||
} |
||||
|
||||
void renameCategoryButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
RenameCategoryDialog renameCategoryDialog = new RenameCategoryDialog(this.CurrentCategory.Name, this); |
||||
if (renameCategoryDialog.ShowDialog(this) == DialogResult.OK) { |
||||
this.CurrentCategory.Name = renameCategoryDialog.CategoryName; |
||||
FillCategories(); |
||||
} |
||||
} |
||||
|
||||
void okButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
oldComponents = null; |
||||
|
||||
foreach (ListViewItem item in ((ListView)ControlDictionary["categoryListView"]).Items) { |
||||
Category category = (Category)item.Tag; |
||||
category.IsEnabled = item.Checked; |
||||
} |
||||
|
||||
ToolboxProvider.SaveToolbox(); |
||||
} |
||||
|
||||
void componentListViewItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) |
||||
{ |
||||
ToolComponent tc = (ToolComponent)((ListView)ControlDictionary["componentListView"]).Items[e.Index].Tag; |
||||
tc.IsEnabled = !tc.IsEnabled; |
||||
} |
||||
} |
||||
} |
@ -1,188 +0,0 @@
@@ -1,188 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
|
||||
using System.Security.Policy; |
||||
using System.Runtime.Remoting; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
using System.Threading; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class CustomComponentsSideTab : SideTabDesigner |
||||
{ |
||||
ArrayList projectAssemblies = new ArrayList(); |
||||
ArrayList referencedAssemblies = new ArrayList(); |
||||
Dictionary<string, Assembly> loadedFiles = new Dictionary<string, Assembly>(); |
||||
List<string> loadedProjects = new List<string>(); |
||||
|
||||
static bool loadReferencedAssemblies = true; |
||||
|
||||
///<summary>Load an assembly's controls</summary>
|
||||
public CustomComponentsSideTab(AxSideBar sideTab, string name, IToolboxService toolboxService) : base(sideTab,name, toolboxService) |
||||
{ |
||||
ScanProjectAssemblies(); |
||||
ProjectService.EndBuild += RescanProjectAssemblies; |
||||
ProjectService.SolutionLoaded += RescanProjectAssemblies; |
||||
} |
||||
|
||||
public static bool LoadReferencedAssemblies { |
||||
get { |
||||
return loadReferencedAssemblies; |
||||
} |
||||
set { |
||||
loadReferencedAssemblies = value; |
||||
} |
||||
} |
||||
|
||||
string loadingPath = String.Empty; |
||||
|
||||
byte[] GetBytes(string fileName) |
||||
{ |
||||
FileStream fs = File.OpenRead(fileName); |
||||
long size = fs.Length; |
||||
byte[] outArray = new byte[size]; |
||||
fs.Read(outArray, 0, (int)size); |
||||
fs.Close(); |
||||
return outArray; |
||||
} |
||||
|
||||
Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) |
||||
{ |
||||
LoggingService.Debug("Form Designer: MyResolve: " + args.Name); |
||||
string file = args.Name; |
||||
int idx = file.IndexOf(','); |
||||
if (idx >= 0) { |
||||
file = file.Substring(0, idx); |
||||
} |
||||
//search in other assemblies, this also help to avoid doubling of loaded assms
|
||||
if (ProjectService.OpenSolution != null) { |
||||
foreach (IProject project in ProjectService.OpenSolution.Projects) { |
||||
if (project.AssemblyName == file) |
||||
return LoadAssemblyFile(project.OutputAssemblyFullPath, true); |
||||
} |
||||
} |
||||
|
||||
//skip already loaded
|
||||
Assembly lastAssembly = null; |
||||
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { |
||||
//LoggingService.Info("Assembly..." + asm.FullName);
|
||||
if (asm.FullName == args.Name) { |
||||
lastAssembly = asm; |
||||
} |
||||
} |
||||
if (lastAssembly != null) { |
||||
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name); |
||||
return lastAssembly; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
Assembly LoadAssemblyFile(string assemblyName, bool nonLocking) |
||||
{ |
||||
assemblyName = assemblyName.ToLower(); |
||||
//skip already loaded over MyResolveEventHandler
|
||||
if(loadedFiles.ContainsKey(assemblyName)) |
||||
return loadedFiles[assemblyName]; |
||||
if ((assemblyName.EndsWith("exe") || assemblyName.EndsWith("dll")) && File.Exists(assemblyName)) { |
||||
string fileAsmName = AssemblyName.GetAssemblyName(assemblyName).ToString(); |
||||
Assembly asm; |
||||
|
||||
//skip already loaded
|
||||
Assembly lastAssembly = null; |
||||
foreach (Assembly asmLoaded in AppDomain.CurrentDomain.GetAssemblies()) { |
||||
if (asmLoaded.FullName == fileAsmName) { |
||||
lastAssembly = asmLoaded; |
||||
} |
||||
} |
||||
if (lastAssembly != null) { |
||||
asm = lastAssembly; |
||||
} else { |
||||
asm = nonLocking ? Assembly.Load(GetBytes(assemblyName)) : Assembly.LoadFrom(assemblyName); //Assembly.LoadFrom(assemblyName);
|
||||
} |
||||
if (asm != null) { |
||||
loadedFiles[assemblyName] = asm; |
||||
BuildToolboxFromAssembly(asm); |
||||
} |
||||
return asm; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
void LoadProject(IProject project) |
||||
{ |
||||
string assemblyName = project.OutputAssemblyFullPath; |
||||
if(loadedProjects.Contains(assemblyName)) |
||||
return; |
||||
loadedProjects.Add(assemblyName); |
||||
|
||||
foreach (ProjectItem projectItem in project.Items) { |
||||
ProjectReferenceProjectItem projectReferenceProjectItem = projectItem as ProjectReferenceProjectItem; |
||||
if(projectReferenceProjectItem != null) |
||||
LoadProject(projectReferenceProjectItem.ReferencedProject); |
||||
} |
||||
|
||||
loadingPath = Path.GetDirectoryName(assemblyName) + Path.DirectorySeparatorChar; |
||||
LoadAssemblyFile(assemblyName, true); |
||||
} |
||||
|
||||
void ScanProjectAssemblies() |
||||
{ |
||||
projectAssemblies.Clear(); |
||||
referencedAssemblies.Clear(); |
||||
|
||||
loadedFiles.Clear(); |
||||
loadedProjects.Clear(); |
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); |
||||
try { |
||||
|
||||
// custom user controls don't need custom images
|
||||
loadImages = false; |
||||
ITypeResolutionService typeResolutionService = ToolboxProvider.TypeResolutionService; |
||||
if (ProjectService.OpenSolution != null) { |
||||
foreach (IProject project in ProjectService.OpenSolution.Projects) { |
||||
LoadProject(project); |
||||
projectAssemblies.Add(project.OutputAssemblyFullPath); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
LoggingService.Warn("Form Designer: ScanProjectAssemblies", e); |
||||
} finally { |
||||
AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(MyResolveEventHandler); |
||||
} |
||||
} |
||||
|
||||
void RescanProjectAssemblies(object sender, EventArgs e) |
||||
{ |
||||
projectAssemblies.Clear(); |
||||
referencedAssemblies.Clear(); |
||||
Items.Clear(); |
||||
AddDefaultItem(); |
||||
ScanProjectAssemblies(); |
||||
SharpDevelopSideBar.SideBar.Refresh(); |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
@ -1,62 +0,0 @@
@@ -1,62 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui.OptionPanels |
||||
{ |
||||
public class GridOptionsPanel : AbstractOptionPanel |
||||
{ |
||||
public override void LoadPanelContents() |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.FormsDesigner.Resources.WindowsFormsGridOptions.xfrm")); |
||||
|
||||
ControlDictionary["widthTextBox"].Text = PropertyService.Get("FormsDesigner.DesignerOptions.GridSizeWidth", 8).ToString(); |
||||
ControlDictionary["heightTextBox"].Text = PropertyService.Get("FormsDesigner.DesignerOptions.GridSizeHeight", 8).ToString(); |
||||
((CheckBox)ControlDictionary["showGridCheckBox"]).Checked = PropertyService.Get("FormsDesigner.DesignerOptions.ShowGrid", true); |
||||
((CheckBox)ControlDictionary["snapToGridCheckBox"]).Checked = PropertyService.Get("FormsDesigner.DesignerOptions.SnapToGrid", true); |
||||
((CheckBox)ControlDictionary["sortAlphabeticalCheckBox"]).Checked = PropertyService.Get("FormsDesigner.DesignerOptions.PropertyGridSortAlphabetical", false); |
||||
} |
||||
|
||||
public override bool StorePanelContents() |
||||
{ |
||||
int width = 0; |
||||
try { |
||||
width = Int32.Parse(ControlDictionary["widthTextBox"].Text); |
||||
} catch { |
||||
MessageService.ShowError("Forms Designer grid with is invalid"); |
||||
return false; |
||||
} |
||||
|
||||
int height = 0; |
||||
try { |
||||
height = Int32.Parse(ControlDictionary["heightTextBox"].Text); |
||||
} catch { |
||||
MessageService.ShowError("Forms Designer height with is invalid"); |
||||
return false; |
||||
} |
||||
|
||||
PropertyService.Set("FormsDesigner.DesignerOptions.GridSizeWidth", width); |
||||
PropertyService.Set("FormsDesigner.DesignerOptions.GridSizeHeight", height); |
||||
PropertyService.Set("FormsDesigner.DesignerOptions.ShowGrid", ((CheckBox)ControlDictionary["showGridCheckBox"]).Checked); |
||||
PropertyService.Set("FormsDesigner.DesignerOptions.SnapToGrid", ((CheckBox)ControlDictionary["snapToGridCheckBox"]).Checked); |
||||
PropertyService.Set("FormsDesigner.DesignerOptions.PropertyGridSortAlphabetical", ((CheckBox)ControlDictionary["sortAlphabeticalCheckBox"]).Checked); |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -1,84 +0,0 @@
@@ -1,84 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
// created on 08.08.2003 at 13:02
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui.XmlForms; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class RenameCategoryDialog : BaseSharpDevelopForm |
||||
{ |
||||
string categoryName = String.Empty; |
||||
|
||||
public string CategoryName { |
||||
get { |
||||
return categoryName; |
||||
} |
||||
} |
||||
|
||||
public RenameCategoryDialog(string categoryName, Form owner) |
||||
{ |
||||
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("ICSharpCode.FormsDesigner.Resources.RenameSidebarCategoryDialog.xfrm")); |
||||
|
||||
this.Owner = owner; |
||||
|
||||
|
||||
if (categoryName == null) { |
||||
ControlDictionary["categoryNameTextBox"].Text = "New Category"; |
||||
Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.RenameCategoryDialog.NewCategoryDialogName}"); |
||||
} else { |
||||
this.categoryName = categoryName; |
||||
ControlDictionary["categoryNameTextBox"].Text = categoryName; |
||||
Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.RenameCategoryDialog.RenameCategoryDialogName}"); |
||||
} |
||||
ControlDictionary["okButton"].Click += new EventHandler(okButtonClick); |
||||
} |
||||
|
||||
protected override void SetupXmlLoader() |
||||
{ |
||||
xmlLoader.StringValueFilter = new SharpDevelopStringValueFilter(); |
||||
xmlLoader.PropertyValueCreator = new SharpDevelopPropertyValueCreator(); |
||||
xmlLoader.ObjectCreator = new SharpDevelopObjectCreator(); |
||||
} |
||||
|
||||
void ShowDuplicateErrorMessage() |
||||
{ |
||||
|
||||
MessageService.ShowError("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.RenameCategoryDialog.DuplicateNameError}"); |
||||
} |
||||
|
||||
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
|
||||
// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
|
||||
void okButtonClick(object sender, System.EventArgs e) |
||||
{ |
||||
if (categoryName != ControlDictionary["categoryNameTextBox"].Text) { |
||||
foreach (Category cat in ToolboxProvider.ComponentLibraryLoader.Categories) { |
||||
if (cat.Name == ControlDictionary["categoryNameTextBox"].Text) { |
||||
ShowDuplicateErrorMessage(); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
foreach (AxSideTab tab in SharpDevelopSideBar.SideBar.Tabs) { |
||||
if (!(tab is SideTabDesigner) && !(tab is CustomComponentsSideTab)) { |
||||
if (tab.Name == ControlDictionary["categoryNameTextBox"].Text) { |
||||
ShowDuplicateErrorMessage(); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
|
||||
categoryName = ControlDictionary["categoryNameTextBox"].Text; |
||||
} |
||||
DialogResult = System.Windows.Forms.DialogResult.OK; |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
/// <summary>
|
||||
/// Interface defining the tab order mode.ning the tab order mode.
|
||||
/// </summary>
|
||||
public interface ITabOrder |
||||
{ |
||||
/// <summary>
|
||||
/// Checks if tab order mode is active
|
||||
/// </summary>
|
||||
bool IsTabOrderMode { get; } |
||||
|
||||
/// <summary>
|
||||
/// Sets the next tab index if over a control.
|
||||
/// </summary>
|
||||
void SetNextTabIndex(Point p); |
||||
|
||||
/// <summary>
|
||||
/// Sets the previous tab index if over a control.
|
||||
/// </summary>
|
||||
void SetPrevTabIndex(Point p); |
||||
|
||||
/// <summary>
|
||||
/// Show tab order.
|
||||
/// </summary>
|
||||
void ShowTabOrder(); |
||||
|
||||
/// <summary>
|
||||
/// Show tab order.
|
||||
/// </summary>
|
||||
void HideTabOrder(); |
||||
|
||||
} |
||||
} |
@ -1,102 +0,0 @@
@@ -1,102 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.Drawing.Drawing2D; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
/// <summary>
|
||||
/// This class represents a visual feedback for the current tab index of a
|
||||
/// form control.
|
||||
/// </summary>
|
||||
public class TabIndexControl : Control |
||||
{ |
||||
static Color BACKCOLOR2 = Color.DarkViolet; // background color when changed
|
||||
static Color BACKCOLOR = Color.DarkBlue; // normal background color
|
||||
static Color TEXTCOLOR = Color.White; // text color
|
||||
static Font TEXTFONT = new Font("Tahoma",8); // font for the tab index number text
|
||||
static Size DEFSIZE = new Size(20, 20); // default (also minimum) size of the control
|
||||
|
||||
protected Control associatedControl; // Associated form control
|
||||
protected bool hasChanged = false; // indicates if tab index has changed.
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets that the tab index contro has changed the index
|
||||
/// </summary>
|
||||
public bool HasChanged { |
||||
get { |
||||
return hasChanged; |
||||
} |
||||
set { |
||||
hasChanged = value; |
||||
} |
||||
} |
||||
|
||||
public Control AssociatedControl { |
||||
get { |
||||
return associatedControl; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a tab index control.
|
||||
/// </summary>
|
||||
public TabIndexControl(Control c) |
||||
{ |
||||
associatedControl = c; |
||||
this.Size = DEFSIZE; |
||||
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); |
||||
c.LocationChanged += new EventHandler(SetLocation); |
||||
c.TabIndexChanged += new EventHandler(RepaintOnTabIndexChange); |
||||
SetLocation(this, EventArgs.Empty); |
||||
} |
||||
|
||||
void RepaintOnTabIndexChange(object sender, EventArgs e) |
||||
{ |
||||
HasChanged = true; |
||||
Refresh(); |
||||
} |
||||
|
||||
void SetLocation(object sender, EventArgs e) |
||||
{ |
||||
this.Left = associatedControl.Left; |
||||
this.Top = associatedControl.Top; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Drawing code to draw the tab index number above the associated control.
|
||||
/// </summary>
|
||||
protected override void OnPaint(PaintEventArgs pe) |
||||
{ |
||||
Graphics g = pe.Graphics; |
||||
|
||||
string tabIndexAsString = associatedControl.TabIndex.ToString(); |
||||
Size sz = Size.Round(g.MeasureString( tabIndexAsString,TEXTFONT)); |
||||
|
||||
this.Width = (sz.Width < DEFSIZE.Width )? DEFSIZE.Width : sz.Width; |
||||
this.Height = DEFSIZE.Height; |
||||
Rectangle r = new Rectangle(0,0,this.Width,this.Height); |
||||
|
||||
Color bkColor = ( hasChanged )? BACKCOLOR2 : BACKCOLOR; |
||||
g.FillRectangle(new SolidBrush(bkColor),r); |
||||
|
||||
StringFormat sf = new StringFormat(); |
||||
sf.Alignment = StringAlignment.Center; |
||||
sf.LineAlignment = StringAlignment.Center; |
||||
g.DrawString(tabIndexAsString, TEXTFONT, new SolidBrush(TEXTCOLOR), r, sf); |
||||
} |
||||
} |
||||
} |
@ -1,186 +0,0 @@
@@ -1,186 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Denis ERCHOFF" email="d_erchoff@hotmail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class SideTabDesigner : AxSideTab |
||||
{ |
||||
protected bool loadImages = true; |
||||
IToolboxService toolboxService; |
||||
|
||||
public void CreatedUserControl() |
||||
{ |
||||
InitializeComponents(); |
||||
} |
||||
|
||||
void InitializeComponents() |
||||
{ |
||||
} |
||||
|
||||
protected SideTabDesigner(AxSideBar sideBar, string name, IToolboxService toolboxService) : base(sideBar, name) |
||||
{ |
||||
this.toolboxService = toolboxService; |
||||
this.CanSaved = false; |
||||
|
||||
AddDefaultItem(); |
||||
} |
||||
|
||||
protected void AddDefaultItem() |
||||
{ |
||||
this.Items.Add(new SideTabItemDesigner()); |
||||
//Event the user click on an another "control" itemin the current tab
|
||||
this.ChoosedItemChanged += new EventHandler(SelectedTabItemChanged); |
||||
} |
||||
|
||||
///<summary>Load an assembly's controls</summary>
|
||||
public SideTabDesigner(AxSideBar sideBar, Category category, IToolboxService toolboxService) : this(sideBar, category.Name, toolboxService) |
||||
{ |
||||
foreach (ToolComponent component in category.ToolComponents) { |
||||
if (component.IsEnabled) { |
||||
ToolboxItem toolboxItem = new ToolboxItem(); |
||||
toolboxItem.TypeName = component.FullName; |
||||
toolboxItem.Bitmap = ToolboxProvider.ComponentLibraryLoader.GetIcon(component); |
||||
toolboxItem.DisplayName = component.Name; |
||||
Assembly asm = component.LoadAssembly(); |
||||
toolboxItem.AssemblyName = asm.GetName(); |
||||
|
||||
this.Items.Add(new SideTabItemDesigner(toolboxItem)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected void LoadAssembly(string assemblyName) |
||||
{ |
||||
Assembly assembly = FindAssembly(assemblyName); |
||||
if (assembly == null) { |
||||
assembly = Assembly.Load(assemblyName); |
||||
} |
||||
|
||||
if (assembly != null) { |
||||
BuildToolboxFromAssembly(assembly); |
||||
} |
||||
} |
||||
|
||||
protected void BuildToolboxFromAssembly(Assembly assembly) |
||||
{ |
||||
ArrayList toolboxItems = GetToolboxItemsFromAssembly(assembly); |
||||
foreach (ToolboxItem toolboxItem in toolboxItems) { |
||||
//adding the toolboxitem into the tab with his bitmap and caption
|
||||
//loaded from the assembly
|
||||
this.Items.Add(new SideTabItemDesigner(toolboxItem)); |
||||
} |
||||
} |
||||
|
||||
|
||||
protected Assembly FindAssembly(string assemblyName) |
||||
{ |
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { |
||||
if (assembly.GetName().Name == assemblyName) { |
||||
return assembly; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected ArrayList GetToolboxItemsFromAssembly(Assembly assembly) |
||||
{ |
||||
ArrayList toolBoxItems = new ArrayList(); |
||||
|
||||
Hashtable images = new Hashtable(); |
||||
ImageList il = new ImageList(); |
||||
// try to load res icon
|
||||
string[] imgNames = assembly.GetManifestResourceNames(); |
||||
|
||||
foreach (string im in imgNames) { |
||||
if (!im.EndsWith(".resources")) //load resources only to avoid exception on debugging
|
||||
{ |
||||
try { |
||||
Stream stream = assembly.GetManifestResourceStream(im); |
||||
if (stream != null) { |
||||
Bitmap b = new Bitmap(Image.FromStream(stream, true, false)); |
||||
b.MakeTransparent(); |
||||
images[im] = il.Images.Count; |
||||
il.Images.Add(b); |
||||
stream.Close(); |
||||
} |
||||
} catch (Exception e) { |
||||
LoggingService.Warn("Form Designer: GetToolboxItemsFromAssembly", e); |
||||
} |
||||
} |
||||
} |
||||
Type[] ts = assembly.GetExportedTypes(); |
||||
foreach (Type t in ts) { |
||||
if (t.IsPublic && !t.IsAbstract) { |
||||
if (t.IsDefined(typeof(ToolboxItemFilterAttribute), true) || t.IsDefined(typeof(ToolboxItemAttribute), true) || t.IsDefined(typeof(DesignTimeVisibleAttribute), true) || typeof(System.ComponentModel.IComponent).IsAssignableFrom(t)) { |
||||
|
||||
object[] filterAttrs = t.GetCustomAttributes(typeof(DesignTimeVisibleAttribute), true); |
||||
foreach (DesignTimeVisibleAttribute visibleAttr in filterAttrs) { |
||||
if (!visibleAttr.Visible) { |
||||
goto skip; |
||||
} |
||||
} |
||||
string imageName = String.Concat(t.FullName, ".bmp"); |
||||
if (images[imageName] == null) { |
||||
object[] attributes = t.GetCustomAttributes(false); |
||||
if (t.IsDefined(typeof(ToolboxBitmapAttribute), false)) { |
||||
foreach (object attr in attributes) { |
||||
if (attr is ToolboxBitmapAttribute) { |
||||
ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; |
||||
Bitmap b = new Bitmap(toolboxBitmapAttribute.GetImage(t)); |
||||
b.MakeTransparent(); |
||||
il.Images.Add(b); |
||||
images[imageName] =b; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
ToolboxItem item = new ToolboxItem(t); |
||||
|
||||
if (images[imageName] != null) { |
||||
try { |
||||
if(images[imageName] is Bitmap) |
||||
item.Bitmap = (Bitmap)images[imageName]; |
||||
} catch (Exception ex) { |
||||
MessageService.ShowError(ex, "Exception converting bitmap : " + images[imageName] + " : "); |
||||
} |
||||
} |
||||
toolBoxItems.Add(item); |
||||
|
||||
skip:; |
||||
} |
||||
} |
||||
} |
||||
return toolBoxItems; |
||||
} |
||||
|
||||
void SelectedTabItemChanged(object sender, EventArgs e) |
||||
{ |
||||
AxSideTabItem item = (sender as AxSideTab).ChoosedItem; |
||||
if (item == null) { |
||||
toolboxService.SetSelectedToolboxItem(null); |
||||
} else { |
||||
toolboxService.SetSelectedToolboxItem(item.Tag as ToolboxItem); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,85 +0,0 @@
@@ -1,85 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Denis ERCHOFF" email="d_erchoff@hotmail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
/* |
||||
* Module : FormDesigner |
||||
* |
||||
* Project : FormDesigner Loading Library Control. |
||||
* |
||||
* Source code altering : A1 |
||||
* |
||||
* Description : création of the Tab item displayed into the AXSideTabDesigner control. |
||||
* the control's creator initialize the toolboxitem of the tab item |
||||
* |
||||
* Denis ERCHOFF 22/01/2003 |
||||
*/ |
||||
|
||||
|
||||
// Denis ERCHOFF 22/01/2003 BEGIN A1
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using System.Drawing.Design; |
||||
using System.Drawing; |
||||
using System.ComponentModel.Design; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui |
||||
{ |
||||
public class SideTabItemDesigner : SharpDevelopSideTabItem |
||||
{ |
||||
|
||||
public void CreatedUserControl() |
||||
{ |
||||
InitializeComponents(); |
||||
} |
||||
|
||||
void InitializeComponents() |
||||
{ |
||||
} |
||||
|
||||
///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary>
|
||||
public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag) |
||||
{ |
||||
this.Icon = tag.Bitmap; |
||||
ReloadToolBox(); |
||||
} |
||||
|
||||
///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary>
|
||||
public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag) |
||||
{ |
||||
this.Icon = tag.Bitmap; |
||||
ReloadToolBox(); |
||||
} |
||||
|
||||
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
|
||||
public SideTabItemDesigner() : base("Pointer") |
||||
{ |
||||
|
||||
|
||||
|
||||
Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16); |
||||
// ToolboxItem toolboxItemPointer = new ToolboxItem();
|
||||
// toolboxItemPointer.Bitmap = pointerBitmap;
|
||||
// toolboxItemPointer.DisplayName = "Pointer";
|
||||
this.Icon = pointerBitmap; |
||||
this.Tag = null; //toolboxItemPointer;
|
||||
ReloadToolBox(); |
||||
} |
||||
|
||||
///<summary>it force to reload toolboxitem into the ToolboxService when the hostchange</summary>
|
||||
public void ReloadToolBox() |
||||
{ |
||||
if (this.Name != "Pointer") { |
||||
ToolboxProvider.ToolboxService.AddToolboxItem(this.Tag as ToolboxItem); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,129 +0,0 @@
@@ -1,129 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.NRefactory.Parser; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using System.ComponentModel.Design; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class FormsDesignerSecondaryDisplayBinding : ISecondaryDisplayBinding |
||||
{ |
||||
public static IMethod GetInitializeComponents(IClass c) |
||||
{ |
||||
c = c.DefaultReturnType.GetUnderlyingClass(); |
||||
if (c == null) |
||||
return null; |
||||
foreach (IMethod method in c.Methods) { |
||||
if ((method.Name == "InitializeComponents" || method.Name == "InitializeComponent") && method.Parameters.Count == 0) { |
||||
return method; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static bool BaseClassIsFormOrControl(IClass c) |
||||
{ |
||||
// Simple test for fully qualified name
|
||||
foreach (IReturnType baseType in c.BaseTypes) { |
||||
if (baseType.FullyQualifiedName == "System.Windows.Forms.Form" |
||||
|| baseType.FullyQualifiedName == "System.Windows.Forms.UserControl" |
||||
// also accept Form and UserControl when they could not be resolved
|
||||
|| baseType.FullyQualifiedName == "Form" |
||||
|| baseType.FullyQualifiedName == "UserControl") |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
IClass form = ProjectContentRegistry.WinForms.GetClass("System.Windows.Forms.Form"); |
||||
IClass userControl = ProjectContentRegistry.WinForms.GetClass("System.Windows.Forms.UserControl"); |
||||
if (form != null && c.IsTypeInInheritanceTree(form)) |
||||
return true; |
||||
if (userControl != null && c.IsTypeInInheritanceTree(userControl)) |
||||
return true; |
||||
return false; |
||||
} |
||||
|
||||
public static bool IsDesignable(ParseInformation info) |
||||
{ |
||||
if (info != null) { |
||||
ICompilationUnit cu = (ICompilationUnit)info.BestCompilationUnit; |
||||
foreach (IClass c in cu.Classes) { |
||||
IMethod method = GetInitializeComponents(c); |
||||
if (method == null) { |
||||
return false; |
||||
} |
||||
return BaseClassIsFormOrControl(c); |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public bool CanAttachTo(IViewContent viewContent) |
||||
{ |
||||
if (viewContent is ITextEditorControlProvider) { |
||||
ITextEditorControlProvider textAreaControlProvider = (ITextEditorControlProvider)viewContent; |
||||
string fileExtension = String.Empty; |
||||
string fileName = viewContent.IsUntitled ? viewContent.UntitledName : viewContent.FileName; |
||||
if (fileName == null) |
||||
return false; |
||||
|
||||
fileExtension = Path.GetExtension(fileName).ToLowerInvariant(); |
||||
|
||||
switch (fileExtension) { |
||||
case ".cs": |
||||
case ".vb": |
||||
ParseInformation info = ParserService.ParseFile(fileName, textAreaControlProvider.TextEditorControl.Document.TextContent, false, true); |
||||
|
||||
if (IsDesignable(info)) |
||||
return true; |
||||
break; |
||||
case ".xfrm": |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public ISecondaryViewContent[] CreateSecondaryViewContent(IViewContent viewContent) |
||||
{ |
||||
string fileExtension = String.Empty; |
||||
string fileName = viewContent.IsUntitled ? viewContent.UntitledName : viewContent.FileName; |
||||
|
||||
fileExtension = Path.GetExtension(fileName).ToLowerInvariant(); |
||||
|
||||
IDesignerLoaderProvider loader; |
||||
IDesignerGenerator generator; |
||||
|
||||
switch (fileExtension) { |
||||
case ".cs": |
||||
loader = new NRefactoryDesignerLoaderProvider(SupportedLanguage.CSharp, ((ITextEditorControlProvider)viewContent).TextEditorControl); |
||||
generator = new CSharpDesignerGenerator(); |
||||
break; |
||||
case ".vb": |
||||
loader = new NRefactoryDesignerLoaderProvider(SupportedLanguage.VBNet, ((ITextEditorControlProvider)viewContent).TextEditorControl); |
||||
generator = new VBNetDesignerGenerator(); |
||||
break; |
||||
case ".xfrm": |
||||
loader = new XmlDesignerLoaderProvider(((ITextEditorControlProvider)viewContent).TextEditorControl); |
||||
generator = new XmlDesignerGenerator(); |
||||
break; |
||||
default: |
||||
throw new ApplicationException("Cannot create content for " + fileExtension); |
||||
} |
||||
return new ISecondaryViewContent[] { new FormsDesignerViewContent(viewContent, loader, generator) }; |
||||
} |
||||
} |
||||
} |
@ -1,116 +0,0 @@
@@ -1,116 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.Drawing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Windows.Forms.Design; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class DefaultServiceContainer : IServiceContainer, IDisposable |
||||
{ |
||||
IServiceContainer serviceContainer; |
||||
ArrayList services = new ArrayList(); |
||||
|
||||
public DefaultServiceContainer() |
||||
{ |
||||
serviceContainer = new ServiceContainer(); |
||||
} |
||||
|
||||
public DefaultServiceContainer(IServiceContainer parent) |
||||
{ |
||||
serviceContainer = new ServiceContainer(parent); |
||||
} |
||||
|
||||
#region System.IDisposable interface implementation
|
||||
public virtual void Dispose() |
||||
{ |
||||
foreach (object o in services) { |
||||
if (o == this) { |
||||
continue; |
||||
} |
||||
// || o.GetType().Assembly != Assembly.GetCallingAssembly()
|
||||
IDisposable disposeMe = o as IDisposable; |
||||
if (disposeMe != null) { |
||||
try { |
||||
disposeMe.Dispose(); |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.MessageService.ShowError(e, "Exception while disposing " + disposeMe); |
||||
} |
||||
} |
||||
} |
||||
services.Clear(); |
||||
services = null; |
||||
} |
||||
#endregion
|
||||
|
||||
#region System.ComponentModel.Design.IServiceContainer interface implementation
|
||||
public void RemoveService(System.Type serviceType, bool promote) |
||||
{ |
||||
serviceContainer.RemoveService(serviceType, promote); |
||||
} |
||||
|
||||
public void RemoveService(System.Type serviceType) |
||||
{ |
||||
serviceContainer.RemoveService(serviceType); |
||||
} |
||||
|
||||
public void AddService(System.Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback, bool promote) |
||||
{ |
||||
if (IsServiceMissing(serviceType)) { |
||||
serviceContainer.AddService(serviceType, callback, promote); |
||||
} |
||||
} |
||||
|
||||
public void AddService(System.Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback) |
||||
{ |
||||
if (IsServiceMissing(serviceType)) { |
||||
serviceContainer.AddService(serviceType, callback); |
||||
} |
||||
} |
||||
|
||||
public void AddService(System.Type serviceType, object serviceInstance, bool promote) |
||||
{ |
||||
if (IsServiceMissing(serviceType)) { |
||||
serviceContainer.AddService(serviceType, serviceInstance, promote); |
||||
services.Add(serviceInstance); |
||||
} |
||||
} |
||||
|
||||
public void AddService(System.Type serviceType, object serviceInstance) |
||||
{ |
||||
if (IsServiceMissing(serviceType)) { |
||||
serviceContainer.AddService(serviceType, serviceInstance); |
||||
services.Add(serviceInstance); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region System.IServiceProvider interface implementation
|
||||
public object GetService(System.Type serviceType) |
||||
{ |
||||
/* if (LoggingService.IsInfoEnabled && IsServiceMissing(serviceType)) { |
||||
LoggingService.InfoFormatted("request missing service : {0} from Assembly {1} is not aviable.", serviceType, serviceType.Assembly.FullName); |
||||
} else { |
||||
LoggingService.DebugFormatted("get service : {0} from Assembly {1}.", serviceType, serviceType.Assembly.FullName); |
||||
} */ |
||||
return serviceContainer.GetService(serviceType); |
||||
} |
||||
#endregion
|
||||
|
||||
bool IsServiceMissing(Type serviceType) |
||||
{ |
||||
return serviceContainer.GetService(serviceType) == null; |
||||
} |
||||
} |
||||
} |
@ -1,114 +0,0 @@
@@ -1,114 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class DesignerEventService : IDesignerEventService |
||||
{ |
||||
IDesignerHost activeDesigner = null; |
||||
ArrayList designers = new ArrayList(); |
||||
|
||||
public void Reset() |
||||
{ |
||||
this.activeDesigner = null; |
||||
this.designers.Clear(); |
||||
} |
||||
|
||||
public IDesignerHost ActiveDesigner { |
||||
get { |
||||
return activeDesigner; |
||||
} |
||||
} |
||||
|
||||
public DesignerCollection Designers { |
||||
get { |
||||
return new DesignerCollection(designers); |
||||
} |
||||
} |
||||
|
||||
public void AddDesigner(IDesignerHost host) |
||||
{ |
||||
this.designers.Add(host); |
||||
if (designers.Count == 1) { |
||||
SetActiveDesigner(host); |
||||
} |
||||
OnDesignerCreated(new DesignerEventArgs(host)); |
||||
} |
||||
|
||||
public void RemoveDesigner(IDesignerHost host) |
||||
{ |
||||
designers.Remove(host); |
||||
if (activeDesigner == host) { |
||||
if (designers.Count <= 0) { |
||||
SetActiveDesigner(null); |
||||
} else { |
||||
this.SetActiveDesigner((IDesignerHost)this.designers[designers.Count - 1]); |
||||
} |
||||
} |
||||
((IContainer)host).Dispose(); |
||||
OnDesignerDisposed(new DesignerEventArgs(host)); |
||||
} |
||||
|
||||
public void SetActiveDesigner(IDesignerHost host) |
||||
{ |
||||
if (activeDesigner != host) { |
||||
IDesignerHost oldDesigner = activeDesigner; |
||||
activeDesigner = host; |
||||
FileSelectionChanged(); |
||||
OnActiveDesignerChanged(new ActiveDesignerEventArgs(oldDesigner, host)); |
||||
} |
||||
} |
||||
|
||||
public void FileSelectionChanged() |
||||
{ |
||||
if (SelectionChanged != null) { |
||||
SelectionChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnDesignerCreated(DesignerEventArgs e) |
||||
{ |
||||
if (DesignerCreated != null) { |
||||
DesignerCreated(this, e); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnDesignerDisposed(DesignerEventArgs e) |
||||
{ |
||||
if (DesignerDisposed != null) { |
||||
DesignerDisposed(this, e); |
||||
} |
||||
} |
||||
|
||||
protected virtual void OnActiveDesignerChanged(ActiveDesignerEventArgs e) |
||||
{ |
||||
if (ActiveDesignerChanged != null) { |
||||
ActiveDesignerChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler SelectionChanged; |
||||
|
||||
public event DesignerEventHandler DesignerCreated; |
||||
public event DesignerEventHandler DesignerDisposed; |
||||
|
||||
public event ActiveDesignerEventHandler ActiveDesignerChanged; |
||||
|
||||
} |
||||
} |
@ -1,76 +0,0 @@
@@ -1,76 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.ComponentModel.Design; |
||||
using System.Windows.Forms.Design; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class SharpDevelopDesignerOptions : DesignerOptions |
||||
{ |
||||
public SharpDevelopDesignerOptions() |
||||
{ |
||||
UseSmartTags = true; |
||||
UseSnapLines = true; |
||||
} |
||||
|
||||
// public override Size GridSize {
|
||||
// get {
|
||||
// return new Size(PropertyService.Get("FormsDesigner.DesignerOptions.GridSizeWidth", 8),
|
||||
// PropertyService.Get("FormsDesigner.DesignerOptions.GridSizeHeight", 8));
|
||||
// }
|
||||
// set {
|
||||
// LoggingService.Debug("GridSize set");
|
||||
// PropertyService.Set("FormsDesigner.DesignerOptions.GridSizeWidth", value.Width);
|
||||
// PropertyService.Set("FormsDesigner.DesignerOptions.GridSizeHeight", value.Height);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public override bool ShowGrid {
|
||||
// get {
|
||||
// LoggingService.Debug("ShowGrid get");
|
||||
// return PropertyService.Get("FormsDesigner.DesignerOptions.ShowGrid", true);
|
||||
// }
|
||||
// set {
|
||||
// LoggingService.Debug("ShowGrid set");
|
||||
// PropertyService.Set("FormsDesigner.DesignerOptions.ShowGrid", value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public override bool SnapToGrid {
|
||||
// get {
|
||||
// LoggingService.Debug("SnapToGrid get");
|
||||
// return PropertyService.Get("FormsDesigner.DesignerOptions.SnapToGrid", true);
|
||||
// }
|
||||
// set {
|
||||
// LoggingService.Debug("SnapToGrid set");
|
||||
// }
|
||||
// }
|
||||
} |
||||
|
||||
public class DesignerOptionService : WindowsFormsDesignerOptionService |
||||
{ |
||||
DesignerOptions options; |
||||
|
||||
public DesignerOptionService() |
||||
{ |
||||
} |
||||
|
||||
public override DesignerOptions CompatibilityOptions { |
||||
get { |
||||
if (options == null) { |
||||
options = new SharpDevelopDesignerOptions(); |
||||
} |
||||
return options; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,319 +0,0 @@
@@ -1,319 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Globalization; |
||||
using System.Resources; |
||||
using System.Text; |
||||
using System.Collections.Specialized; |
||||
using System.Drawing.Design; |
||||
using System.ComponentModel.Design; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Project.Commands; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class DesignerResourceService : System.ComponentModel.Design.IResourceService , IDisposable |
||||
{ |
||||
IDesignerHost host; |
||||
|
||||
string FileName = String.Empty; |
||||
|
||||
#region ResourceStorage
|
||||
public class ResourceStorage |
||||
{ |
||||
MemoryStream stream; |
||||
IResourceWriter writer; |
||||
|
||||
public IProject project = null; |
||||
string fileName; |
||||
byte[] buffer; |
||||
|
||||
/// <summary>
|
||||
/// true, if the currently stored resource is not empty.
|
||||
/// Note that this property is only valid after at least one
|
||||
/// of GetReader, GetWriter or Save has been called.
|
||||
/// </summary>
|
||||
public bool ContainsData { |
||||
get { |
||||
return this.buffer != null; |
||||
} |
||||
} |
||||
|
||||
public ResourceStorage(string fileName, IProject project) |
||||
{ |
||||
this.project = project; |
||||
this.fileName = fileName; |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
if (this.stream != null) { |
||||
this.writer.Dispose(); |
||||
this.stream.Dispose(); |
||||
} |
||||
this.buffer = null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes the byte array containing the most recent version of the resource
|
||||
/// represented by this instance into the private field "buffer" and returns it.
|
||||
/// Returns null, if this resource has not been written to yet.
|
||||
/// </summary>
|
||||
byte[] GetBuffer() |
||||
{ |
||||
if (this.stream != null) { |
||||
byte[] buffer = this.stream.ToArray(); |
||||
if (buffer.Length > 0) { |
||||
this.writer.Close(); |
||||
this.writer.Dispose(); |
||||
this.buffer = this.stream.ToArray(); |
||||
this.writer = null; |
||||
this.stream.Dispose(); |
||||
this.stream = null; |
||||
} |
||||
} |
||||
return this.buffer; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a new resource reader for this resource based on the most recent
|
||||
/// version available (either in memory or on disk).
|
||||
/// </summary>
|
||||
public IResourceReader GetReader() |
||||
{ |
||||
if (this.GetBuffer() == null) { |
||||
if (File.Exists(this.fileName)) { |
||||
return CreateResourceReader(this.fileName, GetResourceType(this.fileName)); |
||||
} else { |
||||
return null; |
||||
} |
||||
} else { |
||||
return CreateResourceReader(new MemoryStream(this.buffer, false), GetResourceType(this.fileName)); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a new resource writer for this resource.
|
||||
/// According to the SDK documentation of IResourceService.GetResourceWriter,
|
||||
/// a new writer needs to be returned every time one is requested, discarding any
|
||||
/// data written by previously returned writers.
|
||||
/// </summary>
|
||||
public IResourceWriter GetWriter() |
||||
{ |
||||
this.stream = new MemoryStream(); |
||||
this.writer = CreateResourceWriter(this.stream, GetResourceType(this.fileName)); |
||||
return this.writer; |
||||
} |
||||
|
||||
public void Save(string fileName) |
||||
{ |
||||
if (this.GetBuffer() != null) { |
||||
File.WriteAllBytes(fileName, this.buffer); |
||||
} |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
enum ResourceType { |
||||
Resx = 0, |
||||
Resources = 1 |
||||
}; |
||||
|
||||
// In ResourceMemoryStreams are stored:
|
||||
// Key: "true" file names from the project
|
||||
// Value: ResourceStorage, where the resources are stored
|
||||
// If the file is read, after
|
||||
// calculating of the "true" file name, it looks for MemoryStream
|
||||
// uses it if it exists.
|
||||
// Memory streams are cleared, when WriteSerialization will start
|
||||
// or File in the editor will be reloaded from the disc and of
|
||||
// course in Dispose of the service
|
||||
protected Dictionary<string, ResourceStorage> resources = null; |
||||
public Dictionary<string, ResourceStorage> Resources |
||||
{ |
||||
get { |
||||
return resources; |
||||
} |
||||
set { |
||||
resources = value; |
||||
} |
||||
} |
||||
public IDesignerHost Host { |
||||
get { |
||||
return host; |
||||
} |
||||
set { |
||||
host = value; |
||||
} |
||||
} |
||||
|
||||
public DesignerResourceService(string fileName, Dictionary<string, ResourceStorage> resources) |
||||
{ |
||||
this.FileName = fileName; |
||||
this.resources = resources; |
||||
} |
||||
|
||||
IProject _project; |
||||
|
||||
IProject GetProject() |
||||
{ |
||||
if (_project == null && ProjectService.OpenSolution != null) |
||||
_project = ProjectService.OpenSolution.FindProjectContainingFile(FileName); |
||||
return _project; |
||||
} |
||||
|
||||
#region System.ComponentModel.Design.IResourceService interface implementation
|
||||
public System.Resources.IResourceWriter GetResourceWriter(System.Globalization.CultureInfo info) |
||||
{ |
||||
try { |
||||
LoggingService.Debug("ResourceWriter requested for culture: "+info.ToString()); |
||||
string fileName = CalcResourceFileName(info); |
||||
ResourceStorage resourceStorage; |
||||
if (resources.ContainsKey(fileName)) { |
||||
resourceStorage = resources[fileName]; |
||||
} else { |
||||
resourceStorage = new ResourceStorage(fileName, GetProject()); |
||||
resources[fileName] = resourceStorage; |
||||
} |
||||
return resourceStorage.GetWriter(); |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public System.Resources.IResourceReader GetResourceReader(System.Globalization.CultureInfo info) |
||||
{ |
||||
try { |
||||
LoggingService.Debug("ResourceReader requested for culture: "+info.ToString()); |
||||
string fileName = CalcResourceFileName(info); |
||||
ResourceStorage resourceStorage; |
||||
if (resources != null && resources.ContainsKey(fileName)) { |
||||
resourceStorage = resources[fileName]; |
||||
} else { |
||||
resourceStorage = new ResourceStorage(fileName, GetProject()); |
||||
resources[fileName] = resourceStorage; |
||||
} |
||||
return resourceStorage.GetReader(); |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e); |
||||
return null; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public void Save() |
||||
{ |
||||
if (resources != null) { |
||||
foreach (KeyValuePair<string, ResourceStorage> entry in resources) { |
||||
string resourceFileName = entry.Key; |
||||
FileUtility.ObservedSave(new NamedFileOperationDelegate(entry.Value.Save), resourceFileName, FileErrorPolicy.Inform); |
||||
|
||||
IProject project = GetProject(); |
||||
|
||||
// Add this resource file to the project
|
||||
if (entry.Value.ContainsData && project != null && !project.IsFileInProject(resourceFileName)) { |
||||
FileProjectItem newFileProjectItem = new FileProjectItem(project, ItemType.EmbeddedResource); |
||||
newFileProjectItem.DependentUpon = Path.GetFileName(FileName); |
||||
newFileProjectItem.Include = FileUtility.GetRelativePath(project.Directory, resourceFileName); |
||||
ProjectService.AddProjectItem(project, newFileProjectItem); |
||||
|
||||
PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(ProjectBrowserPad)); |
||||
FileNode formFileNode = ((ProjectBrowserPad)pd.PadContent).ProjectBrowserControl.FindFileNode(FileName); |
||||
if (formFileNode != null) { |
||||
LoggingService.Info("FormFileNode found, adding subitem"); |
||||
FileNode fileNode = new FileNode(resourceFileName, FileNodeStatus.BehindFile); |
||||
fileNode.AddTo(formFileNode); |
||||
fileNode.ProjectItem = newFileProjectItem; |
||||
} |
||||
project.Save(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected string CalcResourceFileName(System.Globalization.CultureInfo info) |
||||
{ |
||||
StringBuilder resourceFileName = null; |
||||
IProject project = GetProject(); |
||||
|
||||
if (FileName != null && FileName != String.Empty) { |
||||
resourceFileName = new StringBuilder(Path.GetDirectoryName(FileName)); |
||||
} else if (project != null) { |
||||
resourceFileName = new StringBuilder(project.Directory); |
||||
} else { |
||||
// required for untitled files. Untitled files should NOT save their resources.
|
||||
resourceFileName = new StringBuilder(Path.GetTempPath()); |
||||
} |
||||
resourceFileName.Append(Path.DirectorySeparatorChar); |
||||
resourceFileName.Append(host.RootComponent.Site.Name); |
||||
|
||||
if (info != null && info.Name.Length > 0) { |
||||
resourceFileName.Append('.'); |
||||
resourceFileName.Append(info.Name); |
||||
} |
||||
|
||||
// Use .resources filename if file exists.
|
||||
if (File.Exists(String.Concat(resourceFileName.ToString(), ".resources"))) { |
||||
resourceFileName.Append(".resources"); |
||||
} else { |
||||
resourceFileName.Append(".resx"); |
||||
} |
||||
|
||||
return resourceFileName.ToString(); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
if (resources != null) { |
||||
foreach (ResourceStorage storage in resources.Values) { |
||||
storage.Dispose(); |
||||
} |
||||
resources.Clear(); |
||||
} |
||||
} |
||||
|
||||
static ResourceType GetResourceType(string fileName) |
||||
{ |
||||
if (Path.GetExtension(fileName).ToLowerInvariant() == ".resx") { |
||||
return ResourceType.Resx; |
||||
} |
||||
return ResourceType.Resources; |
||||
} |
||||
|
||||
static IResourceReader CreateResourceReader(string fileName, ResourceType type) |
||||
{ |
||||
if (type == ResourceType.Resources) { |
||||
return new ResourceReader(fileName); |
||||
} |
||||
return new ResXResourceReader(fileName); |
||||
} |
||||
|
||||
static IResourceReader CreateResourceReader(Stream stream, ResourceType type) |
||||
{ |
||||
if (type == ResourceType.Resources) { |
||||
return new ResourceReader(stream); |
||||
} |
||||
return new ResXResourceReader(stream); |
||||
} |
||||
|
||||
static IResourceWriter CreateResourceWriter(Stream stream, ResourceType type) |
||||
{ |
||||
if (type == ResourceType.Resources) { |
||||
return new ResourceWriter(stream); |
||||
} |
||||
return new ResXResourceWriter(stream); |
||||
} |
||||
} |
||||
} |
@ -1,94 +0,0 @@
@@ -1,94 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Globalization; |
||||
|
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class EventBindingService : System.ComponentModel.Design.EventBindingService |
||||
{ |
||||
|
||||
public EventBindingService(IServiceProvider provider) : base(provider) |
||||
{ |
||||
} |
||||
|
||||
protected override string CreateUniqueMethodName(IComponent component, EventDescriptor e) |
||||
{ |
||||
return String.Format("{0}{1}", Char.ToUpper(component.Site.Name[0]) + component.Site.Name.Substring(1), e.DisplayName); |
||||
} |
||||
|
||||
// sohuld look around in form class for compatiable methodes
|
||||
protected override ICollection GetCompatibleMethods(EventDescriptor e) |
||||
{ |
||||
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||
if (window != null) { |
||||
FormsDesignerViewContent formDesigner = window.ActiveViewContent as FormsDesignerViewContent; |
||||
|
||||
if (formDesigner != null) { |
||||
return formDesigner.GetCompatibleMethods(e); |
||||
} |
||||
} |
||||
return new string[]{}; |
||||
} |
||||
|
||||
protected override bool ShowCode() |
||||
{ |
||||
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||
if (window == null) { |
||||
return false; |
||||
} |
||||
|
||||
FormsDesignerViewContent formDesigner = window.ActiveViewContent as FormsDesignerViewContent; |
||||
|
||||
if (formDesigner != null) { |
||||
formDesigner.ShowSourceCode(); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
protected override bool ShowCode(int lineNumber) |
||||
{ |
||||
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||
if (window == null) { |
||||
return false; |
||||
} |
||||
|
||||
FormsDesignerViewContent formDesigner = window.ActiveViewContent as FormsDesignerViewContent; |
||||
|
||||
if (formDesigner != null) { |
||||
formDesigner.ShowSourceCode(lineNumber); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
protected override bool ShowCode(IComponent component, EventDescriptor edesc, string methodName) |
||||
{ |
||||
IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||
if (window == null || edesc == null || edesc.Name == null || edesc.Name.Length == 0) { |
||||
return false; |
||||
} |
||||
FormsDesignerViewContent formDesigner = window.ActiveViewContent as FormsDesignerViewContent; |
||||
|
||||
if (formDesigner != null) { |
||||
formDesigner.ShowSourceCode(component, edesc, methodName); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
} |
@ -1,91 +0,0 @@
@@ -1,91 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
// created on 10/10/2002 at 16:13
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Windows.Forms; |
||||
using System.Threading; |
||||
using Microsoft.Win32; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
/// <summary>
|
||||
/// BaseImlementation of IHelpService
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// created by - Niv
|
||||
/// created on - 10/10/2002 11:44:46
|
||||
/// </remarks>
|
||||
public class HelpService : IHelpService |
||||
{ |
||||
string f1Keyword = null; |
||||
string generalKeyword = null; |
||||
|
||||
|
||||
public HelpService() |
||||
{ |
||||
} |
||||
|
||||
public void AddContextAttribute(string name, string value, HelpKeywordType keywordType) |
||||
{ |
||||
switch (keywordType) { |
||||
case HelpKeywordType.F1Keyword: |
||||
f1Keyword = value; |
||||
return; |
||||
case HelpKeywordType.GeneralKeyword: |
||||
generalKeyword = value; |
||||
return; |
||||
} |
||||
} |
||||
|
||||
public void ClearContextAttributes() |
||||
{ |
||||
} |
||||
|
||||
public IHelpService CreateLocalContext(HelpContextType contextType) |
||||
{ |
||||
return this; |
||||
} |
||||
|
||||
public void RemoveContextAttribute(string name, string value) |
||||
{ |
||||
// System.Console.WriteLine("child removeing {0} : {1}",name,value);
|
||||
// object att = helpGUI.RemoveContextAttributeFromView(name,value);
|
||||
// ContextAttributes.Remove(att);;
|
||||
} |
||||
|
||||
public void RemoveLocalContext(IHelpService localContext) |
||||
{ |
||||
} |
||||
|
||||
public void ShowHelpFromKeyword(string helpKeyword) |
||||
{ |
||||
ICSharpCode.SharpDevelop.Dom.HelpProvider.ShowHelpByKeyword(helpKeyword); |
||||
} |
||||
public void ShowGeneralHelp() |
||||
{ |
||||
ShowHelpFromKeyword(generalKeyword); |
||||
} |
||||
public void ShowHelp() |
||||
{ |
||||
ICSharpCode.SharpDevelop.Dom.HelpProvider.ShowHelp(f1Keyword); |
||||
} |
||||
|
||||
public void ShowHelpFromUrl(string helpURL) |
||||
{ |
||||
ICSharpCode.Core.FileService.OpenFile("browser://" + helpURL); |
||||
} |
||||
} |
||||
} |
@ -1,153 +0,0 @@
@@ -1,153 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Drawing; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
class MenuCommandService : IMenuCommandService |
||||
{ |
||||
IServiceContainer serviceContainer; |
||||
|
||||
ArrayList commands = new ArrayList(); |
||||
ArrayList verbs = new ArrayList(); |
||||
|
||||
Control panel; |
||||
DesignSurface designSurface; |
||||
|
||||
public DesignerVerbCollection Verbs { |
||||
get { |
||||
DesignerVerbCollection verbCollection = CreateDesignerVerbCollection(); |
||||
verbCollection.AddRange((DesignerVerb[])verbs.ToArray(typeof(DesignerVerb))); |
||||
return verbCollection; |
||||
} |
||||
} |
||||
|
||||
public MenuCommandService(Control panel, DesignSurface designSurface, IServiceContainer serviceContainer) |
||||
{ |
||||
this.panel = panel; |
||||
this.designSurface = designSurface; |
||||
this.serviceContainer = serviceContainer; |
||||
} |
||||
|
||||
public void AddCommand(System.ComponentModel.Design.MenuCommand command) |
||||
{ |
||||
if (command != null && command.CommandID != null) { |
||||
if (!commands.Contains(command)) { |
||||
this.commands.Add(command); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void AddVerb(DesignerVerb verb) |
||||
{ |
||||
if (verb != null) { |
||||
this.verbs.Add(verb); |
||||
} |
||||
} |
||||
|
||||
public void RemoveCommand(System.ComponentModel.Design.MenuCommand command) |
||||
{ |
||||
if (command != null) { |
||||
commands.Remove(command.CommandID); |
||||
} |
||||
} |
||||
|
||||
public void RemoveVerb(DesignerVerb verb) |
||||
{ |
||||
if (verb != null) { |
||||
verbs.Remove(verb); |
||||
} |
||||
} |
||||
|
||||
public bool GlobalInvoke(CommandID commandID) |
||||
{ |
||||
System.ComponentModel.Design.MenuCommand menuCommand = FindCommand(commandID); |
||||
if (menuCommand == null) { |
||||
return false; |
||||
} |
||||
|
||||
menuCommand.Invoke(); |
||||
return true; |
||||
} |
||||
|
||||
public System.ComponentModel.Design.MenuCommand FindCommand(CommandID commandID) |
||||
{ |
||||
// if (StringType.StrCmp(MenuUtilities.GetCommandNameFromCommandID(commandID), "", false) == 0 && StringType.StrCmp(commandID.ToString(), "74d21313-2aee-11d1-8bfb-00a0c90f26f7 : 12288", false) == 0) {
|
||||
// return MenuUtilities.gPropertyGridResetCommand;
|
||||
// }
|
||||
|
||||
foreach (System.ComponentModel.Design.MenuCommand menuCommand in commands) { |
||||
if (menuCommand.CommandID == commandID) { |
||||
return menuCommand; |
||||
} |
||||
} |
||||
|
||||
foreach (DesignerVerb verb in Verbs) { |
||||
if (verb.CommandID == commandID) { |
||||
return verb; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void ShowContextMenu(CommandID menuID, int x, int y) |
||||
{ |
||||
string contextMenuPath = "/SharpDevelop/FormsDesigner/ContextMenus/"; |
||||
|
||||
if (menuID == MenuCommands.ComponentTrayMenu) { |
||||
contextMenuPath += "ComponentTrayMenu"; |
||||
} else if (menuID == MenuCommands.ContainerMenu) { |
||||
contextMenuPath += "ContainerMenu"; |
||||
} else if (menuID == MenuCommands.SelectionMenu) { |
||||
contextMenuPath += "SelectionMenu"; |
||||
} else if (menuID == MenuCommands.TraySelectionMenu) { |
||||
contextMenuPath += "TraySelectionMenu"; |
||||
} else { |
||||
throw new Exception(); |
||||
} |
||||
Point p = panel.PointToClient(new Point(x, y)); |
||||
|
||||
|
||||
MenuService.ShowContextMenu(this, contextMenuPath, panel, p.X, p.Y); |
||||
} |
||||
|
||||
public DesignerVerbCollection CreateDesignerVerbCollection() |
||||
{ |
||||
DesignerVerbCollection designerVerbCollection = new DesignerVerbCollection(); |
||||
|
||||
ISelectionService selectionService = (ISelectionService)designSurface.GetService(typeof(ISelectionService)); |
||||
IDesignerHost host = (IDesignerHost)serviceContainer.GetService(typeof(IDesignerHost)); |
||||
if (host != null && selectionService != null && selectionService.SelectionCount == 1) { |
||||
IComponent selectedComponent = selectionService.PrimarySelection as Component; |
||||
if (selectedComponent != null) { |
||||
IDesigner designer = host.GetDesigner((IComponent)selectedComponent); |
||||
if (designer != null) { |
||||
designerVerbCollection.AddRange(designer.Verbs); |
||||
} |
||||
} |
||||
|
||||
if (selectedComponent == host.RootComponent) { |
||||
designerVerbCollection.AddRange((DesignerVerb[])this.verbs.ToArray(typeof(DesignerVerb))); |
||||
} |
||||
} |
||||
return designerVerbCollection; |
||||
} |
||||
} |
||||
} |
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version value="$version"/>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Drawing.Design; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class PropertyValueUIService : IPropertyValueUIService |
||||
{ |
||||
PropertyValueUIHandler propertyValueUIHandler; |
||||
|
||||
public void AddPropertyValueUIHandler(PropertyValueUIHandler newHandler) |
||||
{ |
||||
propertyValueUIHandler += newHandler; |
||||
} |
||||
|
||||
public PropertyValueUIItem[] GetPropertyUIValueItems(ITypeDescriptorContext context, PropertyDescriptor propDesc) |
||||
{ |
||||
// Let registered handlers have a chance to add their UIItems
|
||||
ArrayList propUIValues = new ArrayList(); |
||||
if (propertyValueUIHandler != null) { |
||||
propertyValueUIHandler(context,propDesc,propUIValues); |
||||
} |
||||
PropertyValueUIItem[] values = new PropertyValueUIItem[propUIValues.Count]; |
||||
if (propUIValues.Count > 0) { |
||||
propUIValues.CopyTo(values); |
||||
} |
||||
return values; |
||||
} |
||||
|
||||
public void NotifyPropertyValueUIItemsChanged() |
||||
{ |
||||
OnPropertyUIValueItemsChanged(EventArgs.Empty); |
||||
} |
||||
|
||||
public void RemovePropertyValueUIHandler(PropertyValueUIHandler newHandler) |
||||
{ |
||||
propertyValueUIHandler -= newHandler; |
||||
} |
||||
|
||||
protected virtual void OnPropertyUIValueItemsChanged(EventArgs e) |
||||
{ |
||||
if (PropertyUIValueItemsChanged != null) { |
||||
PropertyUIValueItemsChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler PropertyUIValueItemsChanged; |
||||
} |
||||
} |
@ -1,528 +0,0 @@
@@ -1,528 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.Drawing.Design; |
||||
using System.ComponentModel.Design; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public delegate void ToolboxEventHandler(object sender, ToolboxEventArgs tea); |
||||
|
||||
public class ToolboxEventArgs : EventArgs |
||||
{ |
||||
ToolboxItem item = null; |
||||
string category = null; |
||||
IDesignerHost host = null; |
||||
|
||||
public ToolboxEventArgs(ToolboxItem item, string category, IDesignerHost host) |
||||
{ |
||||
this.item = item; |
||||
this.category = category; |
||||
this.host = host; |
||||
} |
||||
|
||||
public ToolboxItem Item { |
||||
get { |
||||
return item; |
||||
} |
||||
} |
||||
|
||||
public string Category { |
||||
get { |
||||
return category; |
||||
} |
||||
} |
||||
|
||||
public IDesignerHost Host { |
||||
get { |
||||
return host; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Provides access to the toolbox in the development environment.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provides designers with the ability to configure what tools
|
||||
/// are available on the toolbox.
|
||||
/// </remarks>
|
||||
public class ToolboxService : IToolboxService |
||||
{ |
||||
static readonly string ALL_HOSTS = "_all_hosts_"; |
||||
static readonly string ALL_CATEGORIES = "_all_categories_"; |
||||
|
||||
IDictionary toolboxByCategory = new ListDictionary(); |
||||
IDictionary toolboxByHost = new ListDictionary(); |
||||
ArrayList toolboxItems = new ArrayList(); |
||||
|
||||
IDictionary creators = new HybridDictionary(); |
||||
IDictionary creatorsByHost = new ListDictionary(); |
||||
|
||||
string selectedCategory = null; |
||||
ToolboxItem selectedItem = null; |
||||
|
||||
// Constructor
|
||||
public ToolboxService() |
||||
{ |
||||
IList list = new ArrayList(); |
||||
toolboxByCategory.Add(ALL_CATEGORIES, list); |
||||
|
||||
list = new ArrayList(); |
||||
toolboxByHost.Add(ALL_HOSTS, list); |
||||
} |
||||
|
||||
// Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the names of all the tool categories currently on the toolbox.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Drawing.Design.CategoryNameCollection">
|
||||
/// containing the tool categories.
|
||||
/// </value>
|
||||
public CategoryNameCollection CategoryNames { |
||||
get { |
||||
string[] names = new string[toolboxByCategory.Count]; |
||||
toolboxByCategory.Keys.CopyTo(names, 0); |
||||
return new CategoryNameCollection(names); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the currently selected tool category
|
||||
/// from the toolbox.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The name of the currently selected category.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// The implementation of this property's "set" accessor fires the
|
||||
/// events <see cref="SelectedCategoryChanging"> and
|
||||
/// <see cref="SelectedCategoryChanged">.
|
||||
/// </remarks>
|
||||
public string SelectedCategory { |
||||
get { |
||||
return selectedCategory; |
||||
} |
||||
set { |
||||
if (value != selectedCategory) { |
||||
FireSelectedCategoryChanging(); |
||||
selectedCategory = value; |
||||
FireSelectedCategoryChanged(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Methods
|
||||
/// <summary>
|
||||
/// Adds a new toolbox item creator.
|
||||
/// </summary>
|
||||
/// <param name="creator">
|
||||
/// A <see cref="System.Drawing.Design.ToolboxItemCreatorCallback">
|
||||
/// that can create a component when the toolbox item
|
||||
/// is invoked. </param>
|
||||
/// <param name="format">
|
||||
/// The data format this creator responds to. If a creator responds
|
||||
/// to more than one format, call AddCreator more than once. It is
|
||||
/// an error to add more than one creator for the same format.
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// A toolbox item creator is used to handle data formats other than
|
||||
/// the standard native format of the toolbox service. Typically, the
|
||||
/// standard toolbox service format should be used, because it provides
|
||||
/// ample opportunity for customization in an object-oriented way.
|
||||
/// However, there are times when a legacy data format may need to be
|
||||
/// supported. A toolbox item creator is the mechanism by which these
|
||||
/// legacy data formats may be converted into toolbox items.
|
||||
/// </remarks>
|
||||
public void AddCreator(ToolboxItemCreatorCallback creator, string format) |
||||
{ |
||||
AddCreator(creator, format, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new toolbox item creator.
|
||||
/// </summary>
|
||||
/// <param name="creator">
|
||||
/// A <see cref="System.Drawing.Design.ToolboxItemCreatorCallback">
|
||||
/// that can create a component when the toolbox item
|
||||
/// is invoked. </param>
|
||||
/// <param name="format">
|
||||
/// The data format this creator responds to. If a creator responds
|
||||
/// to more than one format, call AddCreator more than once. It is
|
||||
/// an error to add more than one creator for the same format.
|
||||
/// </param>
|
||||
/// <param name="host">
|
||||
/// The designer host to associate with the creator. If this parameter
|
||||
/// is set to a null reference (Nothing in Visual Basic), this creator
|
||||
/// will be available to all designers. If a designer host is supplied,
|
||||
/// the creator will only be available to designers using the specified
|
||||
/// host.
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// A toolbox item creator is used to handle data formats other than
|
||||
/// the standard native format of the toolbox service. Typically, the
|
||||
/// standard toolbox service format should be used, because it provides
|
||||
/// ample opportunity for customization in an object-oriented way.
|
||||
/// However, there are times when a legacy data format may need to be
|
||||
/// supported. A toolbox item creator is the mechanism by which these
|
||||
/// legacy data formats may be converted into toolbox items.
|
||||
/// <para>
|
||||
/// This implemetation does add the specified creator to a collection,
|
||||
/// but at this time I have no idea what to do with it!
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public void AddCreator(ToolboxItemCreatorCallback creator, string format, IDesignerHost host) |
||||
{ |
||||
LoggingService.DebugFormatted("\tDefaultToolboxService:AddCreator({0}, {1}, {2})", creator, format, host); |
||||
if (host == null) { |
||||
creators.Add(format, creator); |
||||
} else { |
||||
IDictionary creatorsDict = (IDictionary)creatorsByHost[host]; |
||||
if (creatorsDict == null) { |
||||
creatorsDict = new HybridDictionary(); |
||||
creatorsByHost.Add(host, creatorsDict); |
||||
} |
||||
creatorsDict[format] =creator; |
||||
} |
||||
} |
||||
|
||||
void AddItemToToolbox(ToolboxItem toolboxItem, string category, IDesignerHost host) |
||||
{ |
||||
toolboxItems.Add(toolboxItem); |
||||
|
||||
if (host != null) { |
||||
IList list = (IList)toolboxByHost[host]; |
||||
if (list == null) { |
||||
list = new ArrayList(); |
||||
toolboxByHost.Add(host, list); |
||||
} |
||||
list.Add(toolboxItem); |
||||
} else { |
||||
IList list = (IList)toolboxByHost[ALL_HOSTS]; |
||||
list.Add(toolboxItem); |
||||
} |
||||
|
||||
if (category != null) { |
||||
IList list = (IList)toolboxByCategory[category]; |
||||
if (list == null) { |
||||
list = new ArrayList(); |
||||
toolboxByCategory.Add(category, list); |
||||
} |
||||
list.Add(toolboxItem); |
||||
} else { |
||||
IList list = (IList)toolboxByCategory[ALL_CATEGORIES]; |
||||
list.Add(toolboxItem); |
||||
} |
||||
|
||||
FireToolboxItemAdded(toolboxItem, category, host); |
||||
} |
||||
|
||||
public void AddLinkedToolboxItem(ToolboxItem toolboxItem, string category, IDesignerHost host) |
||||
{ |
||||
AddItemToToolbox(toolboxItem, category, host); |
||||
} |
||||
|
||||
public void AddLinkedToolboxItem(ToolboxItem toolboxItem, IDesignerHost host) |
||||
{ |
||||
this.AddLinkedToolboxItem(toolboxItem, null, host); |
||||
} |
||||
|
||||
public void AddToolboxItem(ToolboxItem toolboxItem) |
||||
{ |
||||
this.AddItemToToolbox(toolboxItem, null, null); |
||||
} |
||||
|
||||
public void AddToolboxItem(ToolboxItem toolboxItem, string category) |
||||
{ |
||||
this.AddItemToToolbox(toolboxItem, category, null); |
||||
} |
||||
|
||||
public ToolboxItem DeserializeToolboxItem(object serializedObject) |
||||
{ |
||||
return DeserializeToolboxItem(serializedObject, null); |
||||
} |
||||
|
||||
public ToolboxItem DeserializeToolboxItem(object serializedObject, IDesignerHost host) |
||||
{ |
||||
LoggingService.DebugFormatted("DeserializeToolboxItem {0} host {1}", serializedObject, host); |
||||
if (serializedObject is System.Windows.Forms.IDataObject) { |
||||
if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem))) { |
||||
ToolboxItem item = (ToolboxItem) ((System.Windows.Forms.IDataObject)serializedObject).GetData(typeof(ToolboxItem)); |
||||
|
||||
ArrayList list; |
||||
if (host != null) { |
||||
list = (ArrayList)toolboxByHost[host]; |
||||
if (list != null && list.Contains(item)) { |
||||
LoggingService.Warn(item.TypeName); |
||||
return item; |
||||
} |
||||
} |
||||
list = (ArrayList)toolboxByHost[ALL_HOSTS]; |
||||
if (list != null && list.Contains(item)) { |
||||
return item; |
||||
} |
||||
} |
||||
} |
||||
LoggingService.WarnFormatted("DeserializeToolboxItem {0} host {1} return null", serializedObject, host); |
||||
return null; |
||||
} |
||||
|
||||
public ToolboxItem GetSelectedToolboxItem() |
||||
{ |
||||
return selectedItem; |
||||
} |
||||
|
||||
public ToolboxItem GetSelectedToolboxItem(IDesignerHost host) |
||||
{ |
||||
IList list = (IList)toolboxByHost[host]; |
||||
if (list != null && list.Contains(selectedItem)) { |
||||
return selectedItem; |
||||
} |
||||
|
||||
list = (IList)toolboxByHost[ALL_HOSTS]; |
||||
if (list.Contains(selectedItem)) { |
||||
return selectedItem; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public ToolboxItemCollection GetToolboxItems() |
||||
{ |
||||
LoggingService.Debug("ToolboxService: GetToolboxItems"); |
||||
ToolboxItem[] items = new ToolboxItem[toolboxItems.Count]; |
||||
toolboxItems.CopyTo(items); |
||||
return new ToolboxItemCollection(items); |
||||
} |
||||
|
||||
public ToolboxItemCollection GetToolboxItems(string category) |
||||
{ |
||||
LoggingService.Debug("ToolboxService: GetToolboxItems category " + category); |
||||
if (category == null) { |
||||
category = ALL_CATEGORIES; |
||||
} |
||||
|
||||
ArrayList list = (ArrayList)toolboxByCategory[category]; |
||||
list.Add((ArrayList)toolboxByCategory[ALL_CATEGORIES]); |
||||
ToolboxItem[] items = new ToolboxItem[list.Count]; |
||||
toolboxItems.CopyTo(items); |
||||
return new ToolboxItemCollection(items); |
||||
} |
||||
|
||||
public ToolboxItemCollection GetToolboxItems(string category, IDesignerHost host) |
||||
{ |
||||
LoggingService.DebugFormatted("ToolboxService: GetToolboxItems category {0} host {1}", category, host); |
||||
if (category == null) { |
||||
category = ALL_CATEGORIES; |
||||
} |
||||
|
||||
ArrayList hList = null; |
||||
|
||||
if (host == null) { |
||||
hList = (ArrayList)toolboxByHost[ALL_HOSTS]; |
||||
} else { |
||||
hList = (ArrayList)toolboxByHost[host]; |
||||
} |
||||
|
||||
ArrayList cList = (ArrayList)toolboxByCategory[category]; |
||||
ArrayList list = new ArrayList(); |
||||
|
||||
foreach (ToolboxItem item in hList) { |
||||
if (cList.Contains(item)) { |
||||
list.Add(item); |
||||
} |
||||
} |
||||
|
||||
ToolboxItem[] items = new ToolboxItem[list.Count]; |
||||
toolboxItems.CopyTo(items); |
||||
return new ToolboxItemCollection(items); |
||||
} |
||||
|
||||
public ToolboxItemCollection GetToolboxItems(IDesignerHost host) |
||||
{ |
||||
ArrayList hList = null; |
||||
|
||||
if(host == null) { |
||||
hList = (ArrayList)toolboxByHost[ALL_HOSTS]; |
||||
} else { |
||||
hList = (ArrayList)toolboxByHost[host]; |
||||
} |
||||
ArrayList list = (ArrayList)toolboxByHost[host]; |
||||
list.Add((ArrayList)toolboxByHost[ALL_HOSTS]); |
||||
ToolboxItem[] items = new ToolboxItem[list.Count]; |
||||
toolboxItems.CopyTo(items); |
||||
return new ToolboxItemCollection(items); |
||||
} |
||||
|
||||
public bool IsSupported(object serializedObject, ICollection filterAttributes) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public bool IsSupported(object serializedObject, IDesignerHost host) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public bool IsToolboxItem(object serializedObject) |
||||
{ |
||||
if (serializedObject is System.Windows.Forms.IDataObject) { |
||||
if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem))) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public bool IsToolboxItem(object serializedObject, IDesignerHost host) |
||||
{ |
||||
// needed for Toolbox drag & drop
|
||||
if (serializedObject is System.Windows.Forms.IDataObject) { |
||||
if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem))) { |
||||
ToolboxItem item = (ToolboxItem) ((System.Windows.Forms.IDataObject)serializedObject).GetData(typeof(ToolboxItem)); |
||||
if (host != null) { |
||||
ArrayList list = (ArrayList)toolboxByHost[host]; |
||||
if (list != null && list.Contains(item)) { |
||||
return true; |
||||
} |
||||
list = (ArrayList)toolboxByHost[ALL_HOSTS]; |
||||
if (list != null && list.Contains(item)) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public void Refresh() |
||||
{ |
||||
//System.Console.WriteLine("\tDefaultToolboxService:Refresh()");
|
||||
} |
||||
|
||||
public void RemoveCreator(string format) |
||||
{ |
||||
} |
||||
|
||||
public void RemoveCreator(string format, IDesignerHost host) |
||||
{ |
||||
} |
||||
|
||||
public void RemoveToolboxItem(ToolboxItem toolboxItem) |
||||
{ |
||||
toolboxItems.Remove(toolboxItem); |
||||
ArrayList list = (ArrayList)toolboxByCategory[ALL_CATEGORIES]; |
||||
list.Remove(toolboxItem); |
||||
list = (ArrayList)toolboxByHost[ALL_HOSTS]; |
||||
list.Remove(toolboxItem); |
||||
FireToolboxItemRemoved(toolboxItem, null, null); |
||||
} |
||||
|
||||
public void RemoveToolboxItem(ToolboxItem toolboxItem, string category) |
||||
{ |
||||
toolboxItems.Remove(toolboxItem); |
||||
ArrayList list = (ArrayList)toolboxByCategory[category]; |
||||
list.Remove(toolboxItem); |
||||
FireToolboxItemRemoved(toolboxItem, category, null); |
||||
} |
||||
|
||||
public void SelectedToolboxItemUsed() |
||||
{ |
||||
FireSelectedItemUsed(); |
||||
} |
||||
|
||||
public object SerializeToolboxItem(ToolboxItem toolboxItem) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public bool SetCursor() |
||||
{ |
||||
if (selectedItem == null) { |
||||
return false; |
||||
} |
||||
if (selectedItem.DisplayName == "Pointer") { |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public void SetSelectedToolboxItem(ToolboxItem toolboxItem) |
||||
{ |
||||
if (toolboxItem != selectedItem) { |
||||
FireSelectedItemChanging(); |
||||
selectedItem = toolboxItem; |
||||
FireSelectedItemChanged(); |
||||
} |
||||
} |
||||
|
||||
// Event helpers
|
||||
void FireSelectedCategoryChanging() |
||||
{ |
||||
if (SelectedCategoryChanging != null) { |
||||
SelectedCategoryChanging(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void FireSelectedItemChanged() |
||||
{ |
||||
if (SelectedItemChanged != null) { |
||||
SelectedItemChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void FireSelectedItemChanging() |
||||
{ |
||||
if (SelectedItemChanging != null) { |
||||
SelectedItemChanging(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void FireSelectedCategoryChanged() |
||||
{ |
||||
if (SelectedCategoryChanged != null) { |
||||
SelectedCategoryChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void FireSelectedItemUsed() |
||||
{ |
||||
if (SelectedItemUsed != null) { |
||||
SelectedItemUsed(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
void FireToolboxItemAdded(ToolboxItem item, string category, IDesignerHost host) |
||||
{ |
||||
if (ToolboxItemAdded != null) { |
||||
ToolboxItemAdded(this, new ToolboxEventArgs(item, category, host)); |
||||
} |
||||
} |
||||
|
||||
void FireToolboxItemRemoved(ToolboxItem item, string category, IDesignerHost host) |
||||
{ |
||||
if (ToolboxItemAdded != null) { |
||||
ToolboxItemRemoved(this, new ToolboxEventArgs(item, category, host)); |
||||
} |
||||
} |
||||
|
||||
// Events
|
||||
public event EventHandler SelectedCategoryChanging; |
||||
public event EventHandler SelectedCategoryChanged; |
||||
public event EventHandler SelectedItemChanging; |
||||
public event EventHandler SelectedItemChanged; |
||||
public event EventHandler SelectedItemUsed; |
||||
public event ToolboxEventHandler ToolboxItemAdded; |
||||
public event ToolboxEventHandler ToolboxItemRemoved; |
||||
} |
||||
} |
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class TypeDescriptorFilterService : ITypeDescriptorFilterService |
||||
{ |
||||
IDesignerFilter GetDesignerFilter(IComponent component) |
||||
{ |
||||
ISite site = component.Site; |
||||
|
||||
if (site == null) { |
||||
return null; |
||||
} |
||||
|
||||
IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost)); |
||||
if (host == null) |
||||
return null; |
||||
return host.GetDesigner(component) as IDesignerFilter; |
||||
} |
||||
|
||||
|
||||
#region System.ComponentModel.Design.ITypeDescriptorFilterService interface implementation
|
||||
public bool FilterProperties(System.ComponentModel.IComponent component, System.Collections.IDictionary properties) |
||||
{ |
||||
IDesignerFilter designerFilter = GetDesignerFilter(component); |
||||
if (designerFilter != null) { |
||||
designerFilter.PreFilterProperties(properties); |
||||
designerFilter.PostFilterProperties(properties); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public bool FilterEvents(System.ComponentModel.IComponent component, System.Collections.IDictionary events) |
||||
{ |
||||
IDesignerFilter designerFilter = GetDesignerFilter(component); |
||||
if (designerFilter != null) { |
||||
designerFilter.PreFilterEvents(events); |
||||
designerFilter.PostFilterEvents(events); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public bool FilterAttributes(System.ComponentModel.IComponent component, System.Collections.IDictionary attributes) |
||||
{ |
||||
IDesignerFilter designerFilter = GetDesignerFilter(component); |
||||
if (designerFilter != null) { |
||||
designerFilter.PreFilterAttributes(attributes); |
||||
designerFilter.PostFilterAttributes(attributes); |
||||
} |
||||
return false; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -1,67 +0,0 @@
@@ -1,67 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class TypeDiscoveryService : ITypeDiscoveryService |
||||
{ |
||||
public TypeDiscoveryService() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the list of available types.
|
||||
/// </summary>
|
||||
/// <param name="baseType">The base type to match. Can be null.</param>
|
||||
/// <param name="excludeGlobalTypes">Determines whether types
|
||||
/// from all referenced assemblies should be checked.</param>
|
||||
public ICollection GetTypes(Type baseType, bool excludeGlobalTypes) |
||||
{ |
||||
List<Type> types = new List<Type>(); |
||||
if (baseType != null) { |
||||
LoggingService.Debug("TypeDiscoveryService.GetTypes baseType=" + baseType.FullName); |
||||
LoggingService.Debug("TypeDiscoveryService.GetTypes excludeGlobalTypes=" + excludeGlobalTypes.ToString()); |
||||
//seek in all assemblies
|
||||
//allow to work designers like columns editor in datagridview
|
||||
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { |
||||
AddDerivedTypes(baseType, asm, types); |
||||
} |
||||
|
||||
// TODO - Don't look in all assemblies.
|
||||
// Should use the current project and its referenced assemblies
|
||||
// as well as System.Windows.Forms.
|
||||
} |
||||
|
||||
return types; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the types derived from baseType from the assembly and adds them to the list.
|
||||
/// </summary>
|
||||
void AddDerivedTypes(Type baseType, Assembly assembly, IList<Type> list) |
||||
{ |
||||
foreach (Type t in assembly.GetExportedTypes()) { |
||||
if (t.IsSubclassOf(baseType)) { |
||||
LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName); |
||||
list.Add(t); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,123 +0,0 @@
@@ -1,123 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.Drawing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class TypeResolutionService : ITypeResolutionService |
||||
{ |
||||
public Assembly GetAssembly(AssemblyName name) |
||||
{ |
||||
return GetAssembly(name, false); |
||||
} |
||||
|
||||
public Assembly GetAssembly(AssemblyName name, bool throwOnError) |
||||
{ |
||||
return Assembly.Load(name); |
||||
} |
||||
|
||||
public string GetPathOfAssembly(AssemblyName name) |
||||
{ |
||||
Assembly assembly = GetAssembly(name); |
||||
if (assembly != null) { |
||||
return assembly.Location; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Type GetType(string name) |
||||
{ |
||||
return GetType(name, false); |
||||
} |
||||
|
||||
public Type GetType(string name, bool throwOnError) |
||||
{ |
||||
return GetType(name, throwOnError, false); |
||||
} |
||||
|
||||
public Type GetType(string name, bool throwOnError, bool ignoreCase) |
||||
{ |
||||
if (name == null || name.Length == 0) { |
||||
return null; |
||||
} |
||||
if (IgnoreType(name)) { |
||||
return null; |
||||
} |
||||
try { |
||||
Assembly lastAssembly = null; |
||||
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { |
||||
Type t = asm.GetType(name, throwOnError); |
||||
if (t != null) { |
||||
lastAssembly = asm; |
||||
} |
||||
} |
||||
if (lastAssembly != null) { |
||||
return lastAssembly.GetType(name, throwOnError, ignoreCase); |
||||
} |
||||
|
||||
Type type = Type.GetType(name, throwOnError, ignoreCase); |
||||
|
||||
// type lookup for typename, assembly, xyz style lookups
|
||||
if (type == null) { |
||||
int idx = name.IndexOf(","); |
||||
if (idx > 0) { |
||||
string[] splitName = name.Split(','); |
||||
string typeName = splitName[0]; |
||||
string assemblyName = splitName[1].Substring(1); |
||||
Assembly assembly = null; |
||||
try { |
||||
assembly = Assembly.Load(assemblyName); |
||||
} catch (Exception e) { |
||||
Console.WriteLine(e); |
||||
} |
||||
if (assembly != null) { |
||||
type = assembly.GetType(typeName, throwOnError, ignoreCase); |
||||
} else { |
||||
type = Type.GetType(typeName, throwOnError, ignoreCase); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return type; |
||||
} catch (Exception e) { |
||||
Console.WriteLine(e); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void ReferenceAssembly(AssemblyName name) |
||||
{ |
||||
ICSharpCode.Core.LoggingService.Warn("TODO: Add Assembly reference : " + name); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// HACK - Ignore any requests for types from the Microsoft.VSDesigner
|
||||
/// assembly. There are smart tag problems if data adapter
|
||||
/// designers are used from this assembly.
|
||||
/// </summary>
|
||||
bool IgnoreType(string name) |
||||
{ |
||||
int idx = name.IndexOf(","); |
||||
if (idx > 0) { |
||||
string[] splitName = name.Split(','); |
||||
string assemblyName = splitName[1].Substring(1); |
||||
if (assemblyName == "Microsoft.VSDesigner") { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -1,103 +0,0 @@
@@ -1,103 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using System.Collections; |
||||
using System.Collections.Specialized; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Services |
||||
{ |
||||
public class UIService : IUIService |
||||
{ |
||||
IDictionary styles = new Hashtable(); |
||||
|
||||
public IDictionary Styles { |
||||
get { |
||||
return styles; |
||||
} |
||||
} |
||||
|
||||
public UIService() |
||||
{ |
||||
styles["DialogFont"] = Control.DefaultFont; |
||||
styles["HighlightColor"] = Color.LightYellow; |
||||
} |
||||
|
||||
public void SetUIDirty() |
||||
{ |
||||
// TODO: Fixme!
|
||||
} |
||||
|
||||
#region ComponentEditor functions
|
||||
public bool CanShowComponentEditor(object component) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
public bool ShowComponentEditor(object component, IWin32Window parent) |
||||
{ |
||||
throw new System.NotImplementedException("Cannot display component editor for " + component); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Dialog functions
|
||||
public IWin32Window GetDialogOwnerWindow() |
||||
{ |
||||
return WorkbenchSingleton.MainForm; |
||||
} |
||||
|
||||
public DialogResult ShowDialog(Form form) |
||||
{ |
||||
return form.ShowDialog(GetDialogOwnerWindow()); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Show error functions
|
||||
public void ShowError(Exception ex) |
||||
{ |
||||
MessageService.ShowError(ex); |
||||
} |
||||
|
||||
public void ShowError(string message) |
||||
{ |
||||
MessageService.ShowError(message); |
||||
} |
||||
|
||||
public void ShowError(Exception ex, string message) |
||||
{ |
||||
MessageService.ShowError(ex, message); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Show Message functions
|
||||
public void ShowMessage(string message) |
||||
{ |
||||
ShowMessage(message, "", MessageBoxButtons.OK); |
||||
} |
||||
|
||||
public void ShowMessage(string message, string caption) |
||||
{ |
||||
ShowMessage(message, caption, MessageBoxButtons.OK); |
||||
} |
||||
|
||||
public DialogResult ShowMessage(string message, string caption, MessageBoxButtons buttons) |
||||
{ |
||||
return MessageBox.Show(GetDialogOwnerWindow(), message, caption, buttons); |
||||
} |
||||
#endregion
|
||||
|
||||
public bool ShowToolWindow(Guid toolWindow) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -1,260 +0,0 @@
@@ -1,260 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Collections; |
||||
using System.Drawing; |
||||
using System.Drawing.Design; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
using System.Drawing.Printing; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Internal.Undo; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.FormsDesigner.Gui; |
||||
|
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
|
||||
using Microsoft.CSharp; |
||||
using Microsoft.VisualBasic; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
public class ToolboxProvider |
||||
{ |
||||
static ICSharpCode.FormsDesigner.Services.ToolboxService toolboxService = null; |
||||
static ITypeResolutionService typeResolutionService = new TypeResolutionService(); |
||||
public static ArrayList SideTabs = new ArrayList(); |
||||
|
||||
static ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader(); |
||||
|
||||
public static ITypeResolutionService TypeResolutionService { |
||||
get { |
||||
return typeResolutionService; |
||||
} |
||||
} |
||||
|
||||
public static ComponentLibraryLoader ComponentLibraryLoader { |
||||
get { |
||||
return componentLibraryLoader; |
||||
} |
||||
} |
||||
public static ICSharpCode.FormsDesigner.Services.ToolboxService ToolboxService { |
||||
get { |
||||
if (toolboxService == null) { |
||||
toolboxService = new ICSharpCode.FormsDesigner.Services.ToolboxService(); |
||||
ReloadSideTabs(false); |
||||
toolboxService.SelectedItemUsed += new EventHandler(SelectedToolUsedHandler); |
||||
} |
||||
return toolboxService; |
||||
} |
||||
} |
||||
|
||||
static ToolboxProvider() |
||||
{ |
||||
PadDescriptor pad = WorkbenchSingleton.Workbench.GetPad(typeof(SideBarView)); |
||||
pad.CreatePad(); |
||||
LoadToolbox(); |
||||
} |
||||
static string componentLibraryFile = "SharpDevelopControlLibrary.sdcl"; |
||||
|
||||
static string GlobalConfigFile { |
||||
get { |
||||
return PropertyService.DataDirectory + Path.DirectorySeparatorChar + |
||||
"options" + Path.DirectorySeparatorChar + |
||||
componentLibraryFile; |
||||
} |
||||
} |
||||
|
||||
static string UserConfigFile { |
||||
get { |
||||
return Path.Combine(PropertyService.ConfigDirectory, componentLibraryFile); |
||||
} |
||||
} |
||||
|
||||
public static void SaveToolbox() |
||||
{ |
||||
componentLibraryLoader.SaveToolComponentLibrary(UserConfigFile); |
||||
} |
||||
|
||||
public static void LoadToolbox() |
||||
{ |
||||
if (!componentLibraryLoader.LoadToolComponentLibrary(UserConfigFile)) { |
||||
if (!componentLibraryLoader.LoadToolComponentLibrary(GlobalConfigFile)) { |
||||
|
||||
MessageService.ShowWarning("${res:ICSharpCode.SharpDevelop.FormDesigner.ToolboxProvider.CantLoadSidbarComponentLibraryWarning}"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void ReloadSideTabs(bool doInsert) |
||||
{ |
||||
bool reInsertTabs = false; |
||||
foreach(AxSideTab tab in SideTabs) { |
||||
if (SharpDevelopSideBar.SideBar.Tabs.Contains(tab)) { |
||||
SharpDevelopSideBar.SideBar.Tabs.Remove(tab); |
||||
reInsertTabs = true;; |
||||
} |
||||
} |
||||
reInsertTabs &= doInsert; |
||||
|
||||
SideTabs.Clear(); |
||||
foreach (Category category in componentLibraryLoader.Categories) { |
||||
if (category.IsEnabled) { |
||||
try { |
||||
SideTabDesigner newTab = new SideTabDesigner(SharpDevelopSideBar.SideBar, category, toolboxService); |
||||
SideTabs.Add(newTab); |
||||
} catch (Exception e) { |
||||
ICSharpCode.Core.LoggingService.Warn("Can't add tab : " + e); |
||||
} |
||||
} |
||||
} |
||||
SideTabDesigner customTab = new CustomComponentsSideTab(SharpDevelopSideBar.SideBar, "Custom Components", toolboxService); |
||||
SideTabs.Add(customTab); |
||||
if (reInsertTabs) { |
||||
foreach(AxSideTab tab in SideTabs) { |
||||
SharpDevelopSideBar.SideBar.Tabs.Add(tab); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void SelectedToolUsedHandler(object sender, EventArgs e) |
||||
{ |
||||
LoggingService.Debug("SelectedToolUsedHandler"); |
||||
AxSideTab tab = SharpDevelopSideBar.SideBar.ActiveTab; |
||||
|
||||
// try to add project reference
|
||||
if (sender != null && sender is ICSharpCode.FormsDesigner.Services.ToolboxService) { |
||||
ToolboxItem selectedItem = (sender as IToolboxService).GetSelectedToolboxItem(); |
||||
if (tab is CustomComponentsSideTab) { |
||||
if (selectedItem != null && selectedItem.TypeName != null) { |
||||
LoggingService.Debug("Checking for reference to CustomComponent: " + selectedItem.TypeName); |
||||
// Check current project has the custom component first.
|
||||
IProjectContent currentProjectContent = ParserService.CurrentProjectContent; |
||||
if (currentProjectContent != null) { |
||||
if (currentProjectContent.GetClass(selectedItem.TypeName) == null) { |
||||
// Check other projects in the solution.
|
||||
LoggingService.Debug("Checking other projects in the solution."); |
||||
IProject projectContainingType = FindProjectContainingType(selectedItem.TypeName); |
||||
if (projectContainingType != null) { |
||||
AddProjectReferenceToProject(ProjectService.CurrentProject, projectContainingType); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
if (selectedItem != null && selectedItem.AssemblyName != null) { |
||||
IProject currentProject = ProjectService.CurrentProject; |
||||
if (currentProject != null) { |
||||
if (!ProjectContainsReference(currentProject, selectedItem.AssemblyName)) { |
||||
AddReferenceToProject(currentProject, selectedItem.AssemblyName); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (tab.Items.Count > 0) { |
||||
tab.ChoosedItem = tab.Items[0]; |
||||
} |
||||
SharpDevelopSideBar.SideBar.Refresh(); |
||||
} |
||||
|
||||
static bool ProjectContainsReference(IProject project, AssemblyName referenceName) |
||||
{ |
||||
LoggingService.Debug("Checking project has reference: " + referenceName.FullName); |
||||
bool isAlreadyInRefFolder = false; |
||||
|
||||
foreach (ProjectItem projectItem in project.Items) { |
||||
ReferenceProjectItem referenceItem = projectItem as ReferenceProjectItem; |
||||
if (referenceItem != null) { |
||||
if (referenceItem.ItemType == ItemType.Reference) { |
||||
LoggingService.Debug("Checking project reference: " + referenceItem.Include); |
||||
if (referenceItem.HintPath.Length > 0) { |
||||
LoggingService.Debug("Checking assembly reference"); |
||||
AssemblyName assemblyName = AssemblyName.GetAssemblyName(referenceItem.FileName); |
||||
if (assemblyName != null && assemblyName.FullName == referenceName.FullName) { |
||||
isAlreadyInRefFolder = true; |
||||
break; |
||||
} |
||||
} else { // GAC reference.
|
||||
LoggingService.Debug("Checking GAC reference"); |
||||
if (referenceItem.Include == referenceName.FullName || referenceItem.Include == referenceName.Name) { |
||||
LoggingService.Debug("Found existing GAC reference"); |
||||
isAlreadyInRefFolder = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return isAlreadyInRefFolder; |
||||
} |
||||
|
||||
static void AddReferenceToProject(IProject project, AssemblyName referenceName) |
||||
{ |
||||
LoggingService.Debug("Adding reference to project: " + referenceName.FullName); |
||||
ReferenceProjectItem reference = new ReferenceProjectItem(project, "Reference"); |
||||
ToolComponent toolComponent = ToolboxProvider.ComponentLibraryLoader.GetToolComponent(referenceName.FullName); |
||||
if (toolComponent == null || toolComponent.HintPath == null) { |
||||
reference.Include = referenceName.FullName; |
||||
LoggingService.Debug("Added GAC reference to project: " + reference.Include); |
||||
} else { |
||||
reference.Include = referenceName.FullName; |
||||
reference.HintPath = FileUtility.GetRelativePath(project.Directory, toolComponent.FileName); |
||||
reference.SpecificVersion = false; |
||||
LoggingService.Debug("Added assembly reference to project: " + reference.Include); |
||||
} |
||||
ProjectService.AddProjectItem(project, reference); |
||||
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); |
||||
project.Save(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Looks for the specified type in all the projects in the open solution
|
||||
/// excluding the current project.
|
||||
/// </summary>
|
||||
static IProject FindProjectContainingType(string type) |
||||
{ |
||||
IProject currentProject = ProjectService.CurrentProject; |
||||
foreach (IProject project in ProjectService.OpenSolution.Projects) { |
||||
if (project != currentProject) { |
||||
IProjectContent projectContent = ParserService.GetProjectContent(project); |
||||
if (projectContent != null) { |
||||
if (projectContent.GetClass(type) != null) { |
||||
LoggingService.Debug("Found project containing type: " + project.FileName); |
||||
return project; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static void AddProjectReferenceToProject(IProject project, IProject referenceTo) |
||||
{ |
||||
LoggingService.Debug("Adding project reference to project."); |
||||
ProjectReferenceProjectItem reference = new ProjectReferenceProjectItem(project, referenceTo); |
||||
ProjectService.AddProjectItem(project, reference); |
||||
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); |
||||
project.Save(); |
||||
} |
||||
} |
||||
} |
@ -1,62 +0,0 @@
@@ -1,62 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.Design; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.UndoRedo |
||||
{ |
||||
public class FormsDesignerUndoEngine : UndoEngine, IUndoHandler |
||||
{ |
||||
Stack<UndoEngine.UndoUnit> undoStack = new Stack<UndoEngine.UndoUnit>(); |
||||
Stack<UndoEngine.UndoUnit> redoStack = new Stack<UndoEngine.UndoUnit>(); |
||||
|
||||
public FormsDesignerUndoEngine(IServiceProvider provider) : base(provider) |
||||
{ |
||||
} |
||||
|
||||
#region IUndoHandler
|
||||
public bool EnableUndo { |
||||
get { |
||||
return undoStack.Count > 0; |
||||
} |
||||
} |
||||
|
||||
public bool EnableRedo { |
||||
get { |
||||
return redoStack.Count > 0; |
||||
} |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
if (undoStack.Count > 0) { |
||||
UndoEngine.UndoUnit unit = undoStack.Pop(); |
||||
unit.Undo(); |
||||
redoStack.Push(unit); |
||||
} |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
if (redoStack.Count > 0) { |
||||
UndoEngine.UndoUnit unit = redoStack.Pop(); |
||||
unit.Undo(); |
||||
undoStack.Push(unit); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
protected override void AddUndoUnit(UndoEngine.UndoUnit unit) |
||||
{ |
||||
undoStack.Push(unit); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue