Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5406 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
9 changed files with 415 additions and 4 deletions
@ -0,0 +1,40 @@ |
|||||||
|
<Window x:Class="ICSharpCode.SharpDevelop.Gui.IntroduceMethodDialog" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui" |
||||||
|
xmlns:addin="clr-namespace:ICSharpCode.SharpDevelop.Refactoring" |
||||||
|
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||||
|
WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ResizeMode="NoResize" |
||||||
|
Title="Introduce method" Height="400" Width="600"> |
||||||
|
<DockPanel> |
||||||
|
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Center"> |
||||||
|
<Button Content="{sd:Localize Global.OKButtonText}" Margin="3" Click="OKButtonClick" IsDefault="True" /> |
||||||
|
<Button Content="{sd:Localize Global.CancelButtonText}" Margin="3" Click="CancelButtonClick" IsCancel="True" /> |
||||||
|
</StackPanel> |
||||||
|
<TextBlock Text="{sd:Localize Dialog.Refactoring.IntroduceMethod.Description}" DockPanel.Dock="Top" Margin="3" /> |
||||||
|
<Grid> |
||||||
|
<Grid.RowDefinitions> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
<RowDefinition Height="*" /> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
<RowDefinition Height="Auto" /> |
||||||
|
</Grid.RowDefinitions> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition Width="*" /> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
<RadioButton Margin="3" Content="Use existing class:" Name="rbExisting" IsChecked="True" GroupName="group" Grid.Column="0" Grid.Row="0" /> |
||||||
|
<ListBox Margin="3" Grid.Column="0" Grid.Row="1" Name="classList" IsEnabled="{Binding IsChecked, ElementName=rbExisting}"> |
||||||
|
<ListBox.ItemTemplate> |
||||||
|
<DataTemplate> |
||||||
|
<TextBlock Text="{Binding FullyQualifiedName}" /> |
||||||
|
</DataTemplate> |
||||||
|
</ListBox.ItemTemplate> |
||||||
|
</ListBox> |
||||||
|
<RadioButton Margin="3" Content="Create new class:" Name="rbNew" GroupName="group" Grid.Column="0" Grid.Row="2" /> |
||||||
|
<DockPanel Grid.Column="0" Grid.Row="3" IsEnabled="{Binding IsChecked, ElementName=rbNew}"> |
||||||
|
<Label DockPanel.Dock="Left" Content="Name:" Margin="3" /> |
||||||
|
<TextBox Name="newClassName" Text="Extensions" Margin="3" /> |
||||||
|
</DockPanel> |
||||||
|
</Grid> |
||||||
|
</DockPanel> |
||||||
|
</Window> |
@ -0,0 +1,92 @@ |
|||||||
|
// <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.Linq; |
||||||
|
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; |
||||||
|
|
||||||
|
using ICSharpCode.NRefactory.Ast; |
||||||
|
using ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Gui |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for IntroduceMethodDialog.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class IntroduceMethodDialog : Window |
||||||
|
{ |
||||||
|
public IClass CallingClass { get; private set; } |
||||||
|
|
||||||
|
ITextEditor editor; |
||||||
|
MethodDeclaration method; |
||||||
|
|
||||||
|
public IntroduceMethodDialog(IClass callingClass, MethodDeclaration method, ITextEditor editor) |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
CallingClass = callingClass; |
||||||
|
this.editor = editor; |
||||||
|
this.method = method; |
||||||
|
|
||||||
|
var classes = GetAllStaticClasses(callingClass.ProjectContent.Project as IProject); |
||||||
|
|
||||||
|
if (!classes.Any()) |
||||||
|
rbNew.IsChecked = true; |
||||||
|
else { |
||||||
|
classList.ItemsSource = classes; |
||||||
|
classList.SelectedItem = classes.FirstOrDefault(c => c.Name.Contains("Extensions")) ?? classes.First(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<IClass> GetAllStaticClasses(IProject project) |
||||||
|
{ |
||||||
|
IProjectContent projectContent = ParserService.GetProjectContent(project); |
||||||
|
if (projectContent != null) { |
||||||
|
foreach (IClass c in projectContent.Classes) { |
||||||
|
if (c.IsStatic) |
||||||
|
yield return c; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void OKButtonClick(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
CodeGenerator gen = CallingClass.ProjectContent.Language.CodeGenerator; |
||||||
|
|
||||||
|
if (rbExisting.IsChecked == true) { |
||||||
|
IClass c = (IClass)classList.SelectedItem; |
||||||
|
gen.InsertCodeAtEnd(c.BodyRegion, new RefactoringDocumentAdapter(editor.Document), method); |
||||||
|
} |
||||||
|
if (rbNew.IsChecked == true) { |
||||||
|
TypeDeclaration type = new TypeDeclaration(Modifiers.Static, null); |
||||||
|
|
||||||
|
type.Name = newClassName.Text; |
||||||
|
|
||||||
|
type.AddChild(method); |
||||||
|
|
||||||
|
gen.InsertCodeAfter(CallingClass, new RefactoringDocumentAdapter(editor.Document), type); |
||||||
|
} |
||||||
|
Close(); |
||||||
|
} |
||||||
|
|
||||||
|
void CancelButtonClick(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
// do nothing
|
||||||
|
Close(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue