Browse Source

finish CreateProperties code generator

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
3da54df351
  1. 22
      data/resources/StringResources.es-mx.resx
  2. 22
      data/resources/StringResources.es.resx
  3. 14
      data/resources/StringResources.fr.resx
  4. 22
      data/resources/StringResources.it.resx
  5. 14
      data/resources/StringResources.nl.resx
  6. 12
      data/resources/StringResources.resx
  7. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs
  8. 2
      src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs
  9. 1
      src/AddIns/Misc/SearchAndReplace/Project/Gui/ObserverSearchResult.cs
  10. 11
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs
  11. 3
      src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin
  12. 2
      src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj
  13. 82
      src/AddIns/Misc/SharpRefactoring/Project/Src/CreateProperties.cs
  14. 25
      src/AddIns/Misc/SharpRefactoring/Project/Src/CreatePropertiesCommand.cs
  15. 92
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/CreatePropertiesDialog.xaml
  16. 6
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/FieldWrapper.cs
  17. 63
      src/AddIns/Misc/SharpRefactoring/Project/Src/InsertCtorSnippetRefactoring.cs

22
data/resources/StringResources.es-mx.resx

@ -229,6 +229,18 @@ Descargue un complemento de Internet, luego haga clic en "Instalar AddIn" y sele @@ -229,6 +229,18 @@ Descargue un complemento de Internet, luego haga clic en "Instalar AddIn" y sele
<data name="AddInManager.UnknownFileFormat" xml:space="preserve">
<value>Formato de archivo desconocido:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.ErrorText" xml:space="preserve">
<value>Error:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindNextText" xml:space="preserve">
<value>Buscar siguiente</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindPreviousText" xml:space="preserve">
<value>Buscar anterior</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.UseRegexText" xml:space="preserve">
<value>Usar expresiones regulares</value>
</data>
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Mostrar Diagrama de Clase</value>
</data>
@ -655,7 +667,7 @@ Opcionalmente puede especificar un directorio de trabajo y argumentos de línea @@ -655,7 +667,7 @@ Opcionalmente puede especificar un directorio de trabajo y argumentos de línea
<value>Ejecutar con el analizador</value>
</data>
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Buscar...</value>
<value>Buscando ...</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Extraer método</value>
@ -4932,7 +4944,7 @@ Vaya a 'Opciones-&gt;Estilo Visual' y cambie el lenguaje del ambiente.</value> @@ -4932,7 +4944,7 @@ Vaya a 'Opciones-&gt;Estilo Visual' y cambie el lenguaje del ambiente.</value>
<value>No se encontró el proceso ASP.NET/IIS (Express) ({0}).</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction" xml:space="preserve">
<value>No hay ningún url de proyecto ni programa externo especificado. Verifique el servidor web en Propiedades del Proyecto -&amp;gt; Depurar.</value>
<value>No hay ninguna url de proyecto ni programa externo especificado. Verifique el servidor web en la pestaña Propiedades del Proyecto - Depurar.</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.Port" xml:space="preserve">
<value>Puerto de servidor:</value>
@ -6201,6 +6213,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6201,6 +6213,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.NewSolutionFolder" xml:space="preserve">
<value>Nueva &amp;Carpeta de Solución</value>
</data>
<data name="ProjectComponent.ContextMenu.NotAWebProject" xml:space="preserve">
<value>Este proyecto no es un proyecto web.</value>
</data>
<data name="ProjectComponent.ContextMenu.Open" xml:space="preserve">
<value>A&amp;brir</value>
</data>
@ -6222,6 +6237,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6222,6 +6237,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.SetAsStartupProject" xml:space="preserve">
<value>Establecer como Proyecto &amp;Inicial</value>
</data>
<data name="ProjectComponent.ContextMenu.ViewInBrowser" xml:space="preserve">
<value>Ver en el navegador</value>
</data>
<data name="ProjectComponent.NewFolderString" xml:space="preserve">
<value>Nueva Carpeta</value>
</data>

22
data/resources/StringResources.es.resx

@ -229,6 +229,18 @@ Descargue un complemento de Internet, luego haga clic en 'Instalar Complemento' @@ -229,6 +229,18 @@ Descargue un complemento de Internet, luego haga clic en 'Instalar Complemento'
<data name="AddInManager.UnknownFileFormat" xml:space="preserve">
<value>Formato de archivo desconocido:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.ErrorText" xml:space="preserve">
<value>Error:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindNextText" xml:space="preserve">
<value>Buscar siguiente</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindPreviousText" xml:space="preserve">
<value>Buscar anterior</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.UseRegexText" xml:space="preserve">
<value>Usar expresiones regulares</value>
</data>
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Mostrar Diagrama de Clase</value>
</data>
@ -655,7 +667,7 @@ Opcionalmente puede especificar un directorio de trabajo y argumentos de línea @@ -655,7 +667,7 @@ Opcionalmente puede especificar un directorio de trabajo y argumentos de línea
<value>Ejecutar con el analizador</value>
</data>
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Buscar...</value>
<value>Buscando ...</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Extraer método</value>
@ -4936,7 +4948,7 @@ Vaya a 'Opciones-&gt;Estilo Visual' y cambie el lenguaje del ambiente.</value> @@ -4936,7 +4948,7 @@ Vaya a 'Opciones-&gt;Estilo Visual' y cambie el lenguaje del ambiente.</value>
<value>No se encontró el proceso ASP.NET/IIS (Express) ({0}).</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction" xml:space="preserve">
<value>No hay ningún url de proyecto ni programa externo especificado. Verifique el servidor web en Propiedades del Proyecto -&amp;gt; Depurar.</value>
<value>No hay ninguna url de proyecto ni programa externo especificado. Verifique el servidor web en la pestaña Propiedades del Proyecto - Depurar.</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.Port" xml:space="preserve">
<value>Puerto de servidor:</value>
@ -6205,6 +6217,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6205,6 +6217,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.NewSolutionFolder" xml:space="preserve">
<value>Nueva &amp;Carpeta de Solución</value>
</data>
<data name="ProjectComponent.ContextMenu.NotAWebProject" xml:space="preserve">
<value>Este proyecto no es un proyecto web.</value>
</data>
<data name="ProjectComponent.ContextMenu.Open" xml:space="preserve">
<value>A&amp;brir</value>
</data>
@ -6226,6 +6241,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6226,6 +6241,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.SetAsStartupProject" xml:space="preserve">
<value>Est&amp;ablecer como Proyecto de Inicio</value>
</data>
<data name="ProjectComponent.ContextMenu.ViewInBrowser" xml:space="preserve">
<value>Ver en el navegador</value>
</data>
<data name="ProjectComponent.NewFolderString" xml:space="preserve">
<value>Directorio Nuevo</value>
</data>

14
data/resources/StringResources.fr.resx

@ -229,6 +229,18 @@ Téléchargez un AddIn depuis l'Internet, cliquez ensuite sur 'Installer un AddI @@ -229,6 +229,18 @@ Téléchargez un AddIn depuis l'Internet, cliquez ensuite sur 'Installer un AddI
<data name="AddInManager.UnknownFileFormat" xml:space="preserve">
<value>Format de fichier inconnu:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.ErrorText" xml:space="preserve">
<value>Erreur:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindNextText" xml:space="preserve">
<value>Trouver Suivant</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindPreviousText" xml:space="preserve">
<value>Trouver Précédent</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.UseRegexText" xml:space="preserve">
<value>Utiliser des expressions rationnelles</value>
</data>
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Afficher le diagramme des classes</value>
</data>
@ -654,7 +666,7 @@ En option, vous pouvez spécifer un répertoire de travail et des arguments en l @@ -654,7 +666,7 @@ En option, vous pouvez spécifer un répertoire de travail et des arguments en l
<value>Exécuter avec le profileur</value>
</data>
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Rechercher...</value>
<value>Recherche...</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Extraire la méthode</value>

22
data/resources/StringResources.it.resx

@ -229,6 +229,18 @@ Scaricare un componente da internet, poi cliccare 'Install AddIn' e selezionare @@ -229,6 +229,18 @@ Scaricare un componente da internet, poi cliccare 'Install AddIn' e selezionare
<data name="AddInManager.UnknownFileFormat" xml:space="preserve">
<value>Formato file sconosciuto:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.ErrorText" xml:space="preserve">
<value>Errore:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindNextText" xml:space="preserve">
<value>Trova successivo</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindPreviousText" xml:space="preserve">
<value>Trova precedente</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.UseRegexText" xml:space="preserve">
<value>Usa espressioni regolari</value>
</data>
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Mostra Diagramma delle Classi</value>
</data>
@ -654,7 +666,7 @@ Installare il .NET Framework SDK per utilizzare il sistema di help.</value> @@ -654,7 +666,7 @@ Installare il .NET Framework SDK per utilizzare il sistema di help.</value>
<value>Esegui con profiler</value>
</data>
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Cerca...</value>
<value>Ricerca...</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Estrai metodo</value>
@ -4937,7 +4949,7 @@ Vai a 'Opzioni-&gt;Stile visuale' e cambia l'attuale ambiente di linguaggio.</va @@ -4937,7 +4949,7 @@ Vai a 'Opzioni-&gt;Stile visuale' e cambia l'attuale ambiente di linguaggio.</va
<value>ASP.NET/IIS (Express) worker process ({0}) non trovato.</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction" xml:space="preserve">
<value>Non è stato specificato nessun Url di Progetto o programma esterno. Controlla parametri web server su Proprietà Progetto -&amp;gt; linguetta Debug.</value>
<value>Non è stato specificato nessun Url di Progetto o programma esterno. Controlla il web server su Proprietà Progetto - Debug.</value>
</data>
<data name="ICSharpCode.WepProjectOptionsPanel.Port" xml:space="preserve">
<value>Porta server:</value>
@ -6206,6 +6218,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6206,6 +6218,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.NewSolutionFolder" xml:space="preserve">
<value>Nuova &amp;Cartella Soluzione</value>
</data>
<data name="ProjectComponent.ContextMenu.NotAWebProject" xml:space="preserve">
<value>Il progetto non è un progetto web.</value>
</data>
<data name="ProjectComponent.ContextMenu.Open" xml:space="preserve">
<value>A&amp;pri</value>
</data>
@ -6227,6 +6242,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension< @@ -6227,6 +6242,9 @@ Microsoft.Tools.WindowsInstallerXml.Extensions.NetFxCompiler, WixNetFxExtension<
<data name="ProjectComponent.ContextMenu.SetAsStartupProject" xml:space="preserve">
<value>Imposta come Progetto Inizi&amp;ale</value>
</data>
<data name="ProjectComponent.ContextMenu.ViewInBrowser" xml:space="preserve">
<value>Visualizza nel browser</value>
</data>
<data name="ProjectComponent.NewFolderString" xml:space="preserve">
<value>Cartella nuova</value>
</data>

14
data/resources/StringResources.nl.resx

@ -228,6 +228,18 @@ @@ -228,6 +228,18 @@
<data name="AddInManager.UnknownFileFormat" xml:space="preserve">
<value>Onbekend bestandsformaat:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.ErrorText" xml:space="preserve">
<value>Fout:</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindNextText" xml:space="preserve">
<value>Vind volgende</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.FindPreviousText" xml:space="preserve">
<value>Vorige vinden</value>
</data>
<data name="AddIns.AvalonEdit.SearchPanel.UseRegexText" xml:space="preserve">
<value>Reguliere Expressies gebruiken</value>
</data>
<data name="AddIns.ClassDiagram.ShowClassDiagram" xml:space="preserve">
<value>Klassendiagram weergeven</value>
</data>
@ -654,7 +666,7 @@ Optioneel kunnen een werkmap en commandoprompt argumenten gespecificeerd worden. @@ -654,7 +666,7 @@ Optioneel kunnen een werkmap en commandoprompt argumenten gespecificeerd worden.
<value>Voer uit met profiler</value>
</data>
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Zoeken...</value>
<value>Zoekende...</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Onttrekken</value>

12
data/resources/StringResources.resx

@ -677,6 +677,18 @@ Optionally you can specify a working directory and command line arguments. @@ -677,6 +677,18 @@ Optionally you can specify a working directory and command line arguments.
<data name="AddIns.SearchReplace.SearchProgressTitle" xml:space="preserve">
<value>Searching ...</value>
</data>
<data name="AddIns.SharpRefactoring.CreateProperties.AddSetterLabel" xml:space="preserve">
<value>Add setter</value>
</data>
<data name="AddIns.SharpRefactoring.CreateProperties.Description" xml:space="preserve">
<value>Select the fields you want to create properties for:</value>
</data>
<data name="AddIns.SharpRefactoring.CreateProperties.Description.ImplementINotifyPropertyChanged" xml:space="preserve">
<value>Implement INotifyPropertyChanged</value>
</data>
<data name="AddIns.SharpRefactoring.CreateProperties.Title" xml:space="preserve">
<value>Create properties</value>
</data>
<data name="AddIns.SharpRefactoring.ExtractMethod" xml:space="preserve">
<value>Extract method</value>
<comment>Text of the "Extract Method" refactoring menu command.</comment>

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Snippets/SnippetManager.cs

@ -76,6 +76,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets @@ -76,6 +76,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Snippets
Text = "${type} ${toFieldName(name)};\n\npublic ${type=int} ${name=Property} {\n\tget { return ${toFieldName(name)}; }\n\tset { ${toFieldName(name)} = value; }\n}${Caret}",
Keyword = "event"
},
new CodeSnippet {
Name = "propall",
Description = "Allows to implement properties for all fields in the class",
Text = "${refactoring:propall}${Caret}",
Keyword = "event"
},
new CodeSnippet {
Name = "propdp",
Description = "Dependency Property",

2
src/AddIns/Misc/SearchAndReplace/Project/Gui/DefaultSearchResult.cs

@ -38,7 +38,7 @@ namespace SearchAndReplace @@ -38,7 +38,7 @@ namespace SearchAndReplace
public string Text {
get {
return rootNode.Title + " (" + SearchRootNode.GetOccurrencesString(rootNode.Occurrences) + ")";
return rootNode.Title + " (" + SearchRootNode.GetOccurrencesString(rootNode.Occurrences) + SearchRootNode.GetWasCancelledString(rootNode.WasCancelled) + ")";
}
}

1
src/AddIns/Misc/SearchAndReplace/Project/Gui/ObserverSearchResult.cs

@ -56,6 +56,7 @@ namespace SearchAndReplace @@ -56,6 +56,7 @@ namespace SearchAndReplace
stopButton.Visibility = Visibility.Hidden;
if (Registration != null) Registration.Dispose();
} finally {
rootNode.WasCancelled = true;
finished = true;
}
}

11
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchRootNode.cs

@ -22,6 +22,7 @@ namespace SearchAndReplace @@ -22,6 +22,7 @@ namespace SearchAndReplace
ObservableCollection<SearchFileNode> fileNodes;
public string Title { get; private set; }
public bool WasCancelled { get; set; }
public SearchRootNode(string title, IList<SearchResultMatch> results)
{
@ -61,7 +62,7 @@ namespace SearchAndReplace @@ -61,7 +62,7 @@ namespace SearchAndReplace
new Bold(new Run(this.Title)),
new Run(" (" + GetOccurrencesString(resultNodes.Count)
+ StringParser.Parse(" ${res:MainWindow.Windows.SearchResultPanel.In} ")
+ GetFileCountString(fileNodes.Count) + ")")
+ GetFileCountString(fileNodes.Count) + GetWasCancelledString(WasCancelled) + ")")
}
};
}
@ -85,5 +86,13 @@ namespace SearchAndReplace @@ -85,5 +86,13 @@ namespace SearchAndReplace
new StringTagPair("Count", count.ToString()));
}
}
public static string GetWasCancelledString(bool wasCancelled)
{
if (wasCancelled)
return "; was cancelled";
return "";
}
}
}

3
src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.addin

@ -29,6 +29,9 @@ @@ -29,6 +29,9 @@
<MenuItem id = "ExtractMethod"
label = "${res:AddIns.SharpRefactoring.ExtractMethod}"
class = "SharpRefactoring.ExtractMethodCommand" />
<MenuItem id = "CreateProperties"
label = "${res:AddIns.SharpRefactoring.CreateProperties.Title}"
class = "SharpRefactoring.CreatePropertiesCommand" />
</Path>
<Path name="/SharpDevelop/ViewContent/AvalonEdit/SnippetElementProviders">

2
src/AddIns/Misc/SharpRefactoring/Project/SharpRefactoring.csproj

@ -89,6 +89,8 @@ @@ -89,6 +89,8 @@
<Compile Include="Src\ContextActions\ParamCheckForNull.cs" />
<Compile Include="Src\ContextActions\ParamRangeCheck.cs" />
<Compile Include="Src\ContextActions\RenameFileToMatchClassName.cs" />
<Compile Include="Src\CreateProperties.cs" />
<Compile Include="Src\CreatePropertiesCommand.cs" />
<Compile Include="Src\CSharpMethodExtractor.cs" />
<Compile Include="Src\Extensions.cs" />
<Compile Include="Src\ExtractMethodCommand.cs" />

82
src/AddIns/Misc/SharpRefactoring/Project/Src/CreateProperties.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using SharpRefactoring.Gui;
namespace SharpRefactoring
{
public class CreateProperties : ISnippetElementProvider
{
public SnippetElement GetElement(SnippetInfo snippetInfo)
{
if ("refactoring:propall".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase))
return new InlineRefactorSnippetElement(context => CreateDialog(context), "{" + snippetInfo.Tag + "}");
return null;
}
CreatePropertiesDialog CreateDialog(InsertionContext context)
{
ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;
if (textEditor == null)
return null;
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (uiService == null)
return null;
ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName);
if (parseInfo == null)
return null;
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator;
// cannot use insertion position at this point, because it might not be
// valid, because we are still generating the elements.
// DOM is not updated
ICSharpCode.AvalonEdit.Document.TextLocation loc = context.Document.GetLocation(context.StartPosition);
IClass current = parseInfo.CompilationUnit.GetInnermostClass(loc.Line, loc.Column);
if (current == null)
return null;
List<FieldWrapper> parameters = FindFields(current).ToList();
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;
CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor, current, parameters);
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);
return dialog;
}
IEnumerable<FieldWrapper> FindFields(IClass sourceClass)
{
int i = 0;
foreach (var f in sourceClass.Fields.Where(field => !field.IsConst
&& field.ReturnType != null)) {
yield return new FieldWrapper(f) { Index = i };
i++;
}
}
}
}

25
src/AddIns/Misc/SharpRefactoring/Project/Src/CreatePropertiesCommand.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Snippets;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Refactoring;
namespace SharpRefactoring
{
public class CreatePropertiesCommand : AbstractRefactoringCommand
{
protected override void Run(ITextEditor textEditor, RefactoringProvider provider)
{
new Snippet {
Elements = {
new CreateProperties().GetElement(new SnippetInfo("refactoring:propall", "${refactoring:propall}", 0))
}
}.Insert((TextArea)textEditor.GetService(typeof(TextArea)));
}
}
}

92
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/CreatePropertiesDialog.xaml

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<gui:AbstractInlineRefactorDialog x:Class="SharpRefactoring.Gui.CreatePropertiesDialog"
Header="Create Properties"
Header="{sd:Localize AddIns.SharpRefactoring.CreateProperties.Title}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:gui="clr-namespace:SharpRefactoring.Gui"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
@ -7,35 +7,33 @@ @@ -7,35 +7,33 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Cursor="Arrow" KeyboardNavigation.TabNavigation="Cycle">
<Grid.Resources>
<Style x:Key="ListBoxItemFocusHighlight" TargetType="{x:Type ListBoxItem}">
<!-- This style replaces the default ListBoxItem template with one that highlights the focused item instead of the selected item -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocusWithin"
Value="true">
<Setter TargetName="Bd"
Property="Background"
Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ListViewItemFocusHighlight" TargetType="{x:Type ListViewItem}">
<!-- This style replaces the default ListViewItem template with one that highlights the focused item instead of the selected items -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocusWithin"
Value="true">
<Setter TargetName="Bd"
Property="Background"
Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -44,19 +42,29 @@ @@ -44,19 +42,29 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="3"
Text="{sd:Localize AddIns.SharpRefactoring.OverrideToStringMethod.Description}"
Text="{sd:Localize AddIns.SharpRefactoring.CreateProperties.Description}"
TextWrapping="Wrap" />
<CheckBox x:Name="implementInterface" Margin="3" Grid.Row="1" Content="Implement INotifyPropertyChanged" />
<ListBox Margin="4" Grid.Row="2" SelectionMode="Multiple" ItemContainerStyle="{StaticResource ListBoxItemFocusHighlight}" x:Name="listBox">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- The checkbox is toggling the actual IsSelected property on the container (ListBoxItem), so it'll update ListBox.SelectedItems -->
<!-- Focusable=false because the ListViewItem is already focusable -->
<CheckBox Content="{Binding Text}"
IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<CheckBox x:Name="implementInterface" Margin="3" Grid.Row="1" Content="{sd:Localize AddIns.SharpRefactoring.CreateProperties.Description.ImplementINotifyPropertyChanged}" />
<ListView x:Name="listBox" Grid.Row="2" SelectionMode="Multiple" KeyboardNavigation.TabNavigation="Cycle" ItemContainerStyle="{StaticResource ListViewItemFocusHighlight}" MaxHeight="300">
<ListView.View>
<GridView>
<GridViewColumn Header="{sd:Localize AddIns.SharpRefactoring.InsertCtor.VariableLabel}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding Text}" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{sd:Localize AddIns.SharpRefactoring.CreateProperties.AddSetterLabel}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding AddSetter, Mode=TwoWay}" IsEnabled="{Binding IsSetable}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<widgets:UniformGridWithSpacing Columns="3" Margin="3" Grid.Row="3" HorizontalAlignment="Center">
<Button Content="{sd:Localize Global.OKButtonText}" Click="OKButtonClick" Style="{x:Static sd:GlobalStyles.ButtonStyle}" />
<Button Content="{sd:Localize Global.CancelButtonText}" Click="CancelButtonClick" Style="{x:Static sd:GlobalStyles.ButtonStyle}" />

6
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/FieldWrapper.cs

@ -68,6 +68,12 @@ namespace SharpRefactoring @@ -68,6 +68,12 @@ namespace SharpRefactoring
}
}
public bool IsSetable {
get {
return !field.IsReadonly && !field.IsConst;
}
}
static string ToPropertyName(string memberName)
{
if (string.IsNullOrEmpty(memberName))

63
src/AddIns/Misc/SharpRefactoring/Project/Src/InsertCtorSnippetRefactoring.cs

@ -89,67 +89,6 @@ namespace SharpRefactoring @@ -89,67 +89,6 @@ namespace SharpRefactoring
}
}
public class CreateProperties : ISnippetElementProvider
{
public SnippetElement GetElement(SnippetInfo snippetInfo)
{
if ("refactoring:propall".Equals(snippetInfo.Tag, StringComparison.OrdinalIgnoreCase))
return new InlineRefactorSnippetElement(context => CreateDialog(context), "{" + snippetInfo.Tag + "}");
return null;
}
CreatePropertiesDialog CreateDialog(InsertionContext context)
{
ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor;
if (textEditor == null)
return null;
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;
if (uiService == null)
return null;
ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName);
if (parseInfo == null)
return null;
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator;
// cannot use insertion position at this point, because it might not be
// valid, because we are still generating the elements.
// DOM is not updated
ICSharpCode.AvalonEdit.Document.TextLocation loc = context.Document.GetLocation(context.StartPosition);
IClass current = parseInfo.CompilationUnit.GetInnermostClass(loc.Line, loc.Column);
if (current == null)
return null;
List<FieldWrapper> parameters = FindFields(current).ToList();
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;
CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor, current, parameters);
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog);
return dialog;
}
IEnumerable<FieldWrapper> FindFields(IClass sourceClass)
{
int i = 0;
foreach (var f in sourceClass.Fields.Where(field => !field.IsConst
&& field.ReturnType != null)) {
yield return new FieldWrapper(f) { Index = i };
i++;
}
}
}
}

Loading…
Cancel
Save