Browse Source
- fixed ClassCodeGeneratorMenuBuilder - allow OptionBinding to be used from Code git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5272 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
14 changed files with 273 additions and 29 deletions
@ -0,0 +1,78 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.Core.Presentation; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
|
||||||
|
namespace SharpRefactoring.Gui |
||||||
|
{ |
||||||
|
public class OverrideEqualsGetHashCodeMethodsDialog : AbstractInlineRefactorDialog |
||||||
|
{ |
||||||
|
CheckBox addIEquatableCheckBox; |
||||||
|
CheckBox addOperatorOverrides; |
||||||
|
CheckBox implementAllIEquatables; |
||||||
|
|
||||||
|
IClass selectedClass; |
||||||
|
|
||||||
|
public OverrideEqualsGetHashCodeMethodsDialog(ITextEditor editor, ITextAnchor anchor, IClass selectedClass) |
||||||
|
: base(editor, anchor) |
||||||
|
{ |
||||||
|
if (selectedClass == null) |
||||||
|
throw new ArgumentNullException("selectedClass"); |
||||||
|
|
||||||
|
this.selectedClass = selectedClass; |
||||||
|
|
||||||
|
addIEquatableCheckBox.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); |
||||||
|
addIEquatableCheckBox.IsEnabled = !selectedClass.BaseTypes.Any(type => { |
||||||
|
if (!type.IsGenericReturnType) |
||||||
|
return false; |
||||||
|
var genericType = type.CastToGenericReturnType(); |
||||||
|
var boundTo = genericType.TypeParameter.BoundTo; |
||||||
|
if (boundTo == null) |
||||||
|
return false; |
||||||
|
return boundTo.Name == selectedClass.Name; |
||||||
|
} |
||||||
|
); |
||||||
|
|
||||||
|
addIEquatableCheckBox.SetValueToExtension(CheckBox.IsCheckedProperty, |
||||||
|
new OptionBinding(typeof(Options), "AddInterface") |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
protected override UIElement CreateContentElement() |
||||||
|
{ |
||||||
|
addIEquatableCheckBox = new CheckBox(); |
||||||
|
|
||||||
|
StackPanel panel = new StackPanel() { |
||||||
|
Orientation = Orientation.Vertical, |
||||||
|
Children = { |
||||||
|
addIEquatableCheckBox |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
return panel; |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GenerateCode(CodeGenerator generator, IClass currentClass) |
||||||
|
{ |
||||||
|
throw new NotImplementedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public interface IInlineRefactoring |
||||||
|
{ |
||||||
|
void GenerateCode(ITextEditor editor); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
<UserControl x:Class="SharpRefactoring.Gui.OverrideToStringMethodDialog" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||||
|
<Grid> |
||||||
|
|
||||||
|
</Grid> |
||||||
|
</UserControl> |
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Text; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Data; |
||||||
|
using System.Windows.Documents; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
namespace SharpRefactoring.Gui |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for OverrideToStringMethodDialog.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class OverrideToStringMethodDialog : UserControl |
||||||
|
{ |
||||||
|
public OverrideToStringMethodDialog() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Diagnostics; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace SharpRefactoring |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of Options.
|
||||||
|
/// </summary>
|
||||||
|
public static class Options |
||||||
|
{ |
||||||
|
static Properties properties; |
||||||
|
|
||||||
|
public static Properties Properties { |
||||||
|
get { |
||||||
|
Debug.Assert(properties != null); |
||||||
|
return properties; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static Options() |
||||||
|
{ |
||||||
|
properties = PropertyService.Get("SharpRefactoringOptions", new Properties()); |
||||||
|
} |
||||||
|
|
||||||
|
public static bool AddInterface { |
||||||
|
get { return properties.Get("AddInterface", false); } |
||||||
|
set { properties.Set("AddInterface", value); } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Refactoring; |
||||||
|
using SharpRefactoring.Gui; |
||||||
|
|
||||||
|
namespace SharpRefactoring |
||||||
|
{ |
||||||
|
public class OverrideEqualsGetHashCodeMethodsCommand : AbstractRefactoringCommand |
||||||
|
{ |
||||||
|
protected override void Run(ITextEditor textEditor, RefactoringProvider provider) |
||||||
|
{ |
||||||
|
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; |
||||||
|
|
||||||
|
if (uiService == null) |
||||||
|
return; |
||||||
|
|
||||||
|
ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName); |
||||||
|
|
||||||
|
if (parseInfo == null) |
||||||
|
return; |
||||||
|
|
||||||
|
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; |
||||||
|
IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column); |
||||||
|
|
||||||
|
if (current == null) |
||||||
|
return; |
||||||
|
|
||||||
|
ITextAnchor anchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
||||||
|
anchor.MovementType = AnchorMovementType.AfterInsertion; |
||||||
|
|
||||||
|
var line = textEditor.Document.GetLineForOffset(textEditor.Caret.Offset); |
||||||
|
|
||||||
|
string indent = DocumentUtilitites.GetWhitespaceAfter(textEditor.Document, line.Offset); |
||||||
|
|
||||||
|
// textEditor.Document.Insert(anchor.Offset, "#region Equals and GetHashCode implementation\n" + indent);
|
||||||
|
// textEditor.Document.Insert(anchor.Offset + 1, indent + "#endregion\n");
|
||||||
|
//
|
||||||
|
// AbstractInlineRefactorDialog dialog = new OverrideEqualsGetHashCodeMethodsDialog(textEditor, anchor, current);
|
||||||
|
//
|
||||||
|
// dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue