public static bool Rename(ISymbol symbol, string newName) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (newName == null) { throw new ArgumentNullException("newName"); } try { var result = new RenameRefactoring().PerformChanges(symbol, new RenameProperties() { NewName = newName }); using (var monitor = new ProgressMonitor()) { if (result.Count > 0) { RefactoringService.AcceptChanges(monitor, result); } } return(true); } catch (AggregateException ae) { foreach (var inner in ae.Flatten().InnerExceptions) { LoggingService.LogError("Exception while rename.", inner); } return(false); } catch (Exception e) { LoggingService.LogError("Exception while rename.", e); return(false); } }
//FIXME: why is this invalid on the parseddocuments loaded when the doc is first loaded? //maybe the item's type's SourceProject is null? public IEnumerable<IAnalysisFixAction> GetFixes (MonoDevelop.Ide.Gui.Document doc, object fix) { var renameFix = (RenameMemberFix) fix; var refactoring = new RenameRefactoring (); var options = new RefactoringOptions () { Document = doc, Dom = doc.Dom, SelectedItem = renameFix.Item, }; if (!refactoring.IsValid (options)) yield break; var prop = new RenameRefactoring.RenameProperties () { NewName = renameFix.NewName, }; yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}'", renameFix.Item.Name, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = false, }; yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}' with preview", renameFix.Item.Name, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = true, }; }
protected override void Run(RefactoringOptions options) { RenameRefactoring renameRefactoring = new RenameRefactoring(); if (renameRefactoring.IsValid(options)) { renameRefactoring.Run(options); } }
protected override void Update(RefactoringOptions options, CommandInfo info) { var renameRefactoring = new RenameRefactoring(); if (!renameRefactoring.IsValid(options)) { info.Bypass = true; } }
//FIXME: why is this invalid on the parseddocuments loaded when the doc is first loaded? //maybe the item's type's SourceProject is null? public IEnumerable<IAnalysisFixAction> GetFixes (MonoDevelop.Ide.Gui.Document doc, object fix) { var renameFix = (RenameMemberFix)fix; var refactoring = new RenameRefactoring (); var options = new RefactoringOptions () { Document = doc, Dom = doc.Dom, SelectedItem = renameFix.Item, }; if (renameFix.Item == null) { INode item; ResolveResult resolveResult; var editor = options.Document.GetContent<MonoDevelop.Ide.Gui.Content.ITextBuffer> (); CurrentRefactoryOperationsHandler.GetItem (options.Dom, options.Document, editor, out resolveResult, out item); options.SelectedItem = item; } if (!refactoring.IsValid (options)) yield break; var prop = new RenameRefactoring.RenameProperties () { NewName = renameFix.NewName, }; if (string.IsNullOrEmpty (renameFix.NewName)) { yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}'...", renameFix.OldName), Refactoring = refactoring, Options = options, Properties = prop, Preview = false, }; yield break; } yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}'", renameFix.OldName, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = false, }; yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}' with preview", renameFix.OldName, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = true, }; }
//FIXME: why is this invalid on the parseddocuments loaded when the doc is first loaded? //maybe the item's type's SourceProject is null? public IEnumerable<IAnalysisFixAction> GetFixes (TextEditor editor, DocumentContext doc, object fix) { var renameFix = (RenameMemberFix)fix; var refactoring = new RenameRefactoring (); var options = new RefactoringOptions (editor, doc) { // SelectedItem = renameFix.Item, }; // if (renameFix.Item == null) { // ResolveResult resolveResult; // options.SelectedItem = CurrentRefactoryOperationsHandler.GetItem (options.Editor, options.DocumentContext, out resolveResult); // } // // if (!refactoring.IsValid (options)) // yield break; // var prop = new RenameRefactoring.RenameProperties () { NewName = renameFix.NewName, }; if (string.IsNullOrEmpty (renameFix.NewName)) { yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}'...", renameFix.OldName), Refactoring = refactoring, Options = options, Properties = prop, Preview = false, }; yield break; } yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}'", renameFix.OldName, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = false, }; yield return new RenameFixAction () { Label = GettextCatalog.GetString ("Rename '{0}' to '{1}' with preview", renameFix.OldName, renameFix.NewName), Refactoring = refactoring, Options = options, Properties = prop, Preview = true, }; }
public RenameNamespaceItemDialog(RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; Initialize(); this.Title = GettextCatalog.GetString ("Rename Namespace"); entry.SelectRegion (0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName (); }; ValidateName (); }
public static bool Rename (ISymbol symbol, string newName) { if (symbol == null) throw new ArgumentNullException ("symbol"); if (newName == null) throw new ArgumentNullException ("newName"); try { var result = new RenameRefactoring ().PerformChanges (symbol, new RenameProperties () { NewName = newName }); using (var monitor = new ProgressMonitor ()) { if (result.Count > 0) { RefactoringService.AcceptChanges (monitor, result); } } return true; } catch (AggregateException ae) { foreach (var inner in ae.Flatten ().InnerExceptions) LoggingService.LogError ("Exception while rename.", inner); return false; } catch (Exception e) { LoggingService.LogError ("Exception while rename.", e); return false; } }
public RenameItemDialog(ISymbol symbol, RenameRefactoring rename) { this.Build(); this.symbol = symbol; string title; if (symbol is ITypeSymbol) { var t = (ITypeSymbol)symbol; if (t.TypeKind == TypeKind.TypeParameter) { title = GettextCatalog.GetString("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = t; if (typeDefinition.ContainingType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = t.Locations.First().SourceTree.FilePath.Contains(typeDefinition.Name); } else { this.renameFileFlag.Active = false; } if (typeDefinition.TypeKind == TypeKind.Interface) { title = GettextCatalog.GetString("Rename Interface"); } else if (typeDefinition.TypeKind == TypeKind.Delegate) { title = GettextCatalog.GetString("Rename Delegate"); } else if (typeDefinition.TypeKind == TypeKind.Enum) { title = GettextCatalog.GetString("Rename Enum"); } else if (typeDefinition.TypeKind == TypeKind.Struct) { title = GettextCatalog.GetString("Rename Struct"); } else { title = GettextCatalog.GetString("Rename Class"); } } // this.fileName = type.GetDefinition ().Region.FileName; } else if (symbol.Kind == SymbolKind.Field) { title = GettextCatalog.GetString("Rename Field"); } else if (symbol.Kind == SymbolKind.Property) { title = GettextCatalog.GetString("Rename Property"); } else if (symbol.Kind == SymbolKind.Event) { title = GettextCatalog.GetString("Rename Event"); } else if (symbol.Kind == SymbolKind.Method) { var m = (IMethodSymbol)symbol; if (m.MethodKind == MethodKind.Constructor || m.MethodKind == MethodKind.StaticConstructor || m.MethodKind == MethodKind.Destructor) { title = GettextCatalog.GetString("Rename Class"); } else { title = GettextCatalog.GetString("Rename Method"); includeOverloadsCheckbox.Visible = m.ContainingType.GetMembers(m.Name).Length > 1; } } else if (symbol.Kind == SymbolKind.Parameter) { title = GettextCatalog.GetString("Rename Parameter"); } else if (symbol.Kind == SymbolKind.Local) { title = GettextCatalog.GetString("Rename Variable"); } else if (symbol.Kind == SymbolKind.TypeParameter) { title = GettextCatalog.GetString("Rename Type Parameter"); } else if (symbol.Kind == SymbolKind.Namespace) { title = GettextCatalog.GetString("Rename Namespace"); } else if (symbol.Kind == SymbolKind.Label) { title = GettextCatalog.GetString("Rename Label"); } else { title = GettextCatalog.GetString("Rename Item"); } Init(title, symbol.Name, async prop => { return(await rename.PerformChangesAsync(symbol, prop)); }); renameFileFlag.Visible = false; foreach (var loc in symbol.Locations) { if (loc.IsInSource) { if (loc.SourceTree == null || !System.IO.File.Exists(loc.SourceTree.FilePath) || IsFileNameForGeneratedCode(loc.SourceTree.FilePath)) { continue; } var oldName = System.IO.Path.GetFileNameWithoutExtension(loc.SourceTree.FilePath); if (RenameRefactoring.IsCompatibleForRenaming(oldName, symbol.Name)) { renameFileFlag.Visible = true; break; } } } }
public RenameItemDialog (RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build (); if (options.SelectedItem is IType) { var t = (IType)options.SelectedItem; if (t.Kind == TypeKind.TypeParameter) { this.Title = GettextCatalog.GetString ("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = (t).GetDefinition (); if (typeDefinition.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = true; // if more than one type is in the file, only rename the file as defilt if the file name contains the type name // see Bug 603938 - Renaming a Class in a file with multiple classes renames the file if (options.Document != null && options.Document.ParsedDocument.TopLevelTypeDefinitions.Count > 1) this.renameFileFlag.Active = options.Document.FileName.FileNameWithoutExtension.Contains (typeDefinition.Name); } else { this.renameFileFlag.Active = false; } if (typeDefinition.Kind == TypeKind.Interface) this.Title = GettextCatalog.GetString ("Rename Interface"); else this.Title = GettextCatalog.GetString ("Rename Class"); } // this.fileName = type.GetDefinition ().Region.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString ("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString ("Rename Indexer"); } else { this.Title = GettextCatalog.GetString ("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString ("Rename Event"); } else if (options.SelectedItem is IMethod) { var m = (IMethod)options.SelectedItem; if (m.IsConstructor || m.IsDestructor) { this.Title = GettextCatalog.GetString ("Rename Class"); } else { this.Title = GettextCatalog.GetString ("Rename Method"); } } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString ("Rename Parameter"); } else if (options.SelectedItem is IVariable) { this.Title = GettextCatalog.GetString ("Rename Variable"); } else if (options.SelectedItem is ITypeParameter) { this.Title = GettextCatalog.GetString ("Rename Type Parameter"); } else { this.Title = GettextCatalog.GetString ("Rename Item"); } if (options.SelectedItem is IEntity) { var member = (IEntity)options.SelectedItem; if (member.EntityType == EntityType.Constructor || member.EntityType == EntityType.Destructor) { entry.Text = member.DeclaringType.Name; } else { entry.Text = member.Name; } // fileName = member.Region.FileName; } else if (options.SelectedItem is ITypeParameter) { var lvar = (ITypeParameter)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is IVariable) { var lvar = (IVariable)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } entry.SelectRegion (0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName (); }; ValidateName (); }
public RenameItemDialog (RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build (); includeOverloadsCheckbox.Active = true; includeOverloadsCheckbox.Visible = false; if (options.SelectedItem is IType) { var t = (IType)options.SelectedItem; if (t.Kind == TypeKind.TypeParameter) { this.Title = GettextCatalog.GetString ("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = (t).GetDefinition (); if (typeDefinition.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = options.Document != null ? options.Document.FileName.FileNameWithoutExtension.Contains (typeDefinition.Name) : false; } else { this.renameFileFlag.Active = false; } if (typeDefinition.Kind == TypeKind.Interface) this.Title = GettextCatalog.GetString ("Rename Interface"); else this.Title = GettextCatalog.GetString ("Rename Class"); } // this.fileName = type.GetDefinition ().Region.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString ("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString ("Rename Indexer"); } else { this.Title = GettextCatalog.GetString ("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString ("Rename Event"); } else if (options.SelectedItem is IMethod) { var m = (IMethod)options.SelectedItem; if (m.IsConstructor || m.IsDestructor) { this.Title = GettextCatalog.GetString ("Rename Class"); } else { this.Title = GettextCatalog.GetString ("Rename Method"); includeOverloadsCheckbox.Visible = m.DeclaringType.GetMethods (x => x.Name == m.Name).Count () > 1; } } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString ("Rename Parameter"); } else if (options.SelectedItem is IVariable) { this.Title = GettextCatalog.GetString ("Rename Variable"); } else if (options.SelectedItem is ITypeParameter) { this.Title = GettextCatalog.GetString ("Rename Type Parameter"); } else if (options.SelectedItem is INamespace) { this.Title = GettextCatalog.GetString ("Rename namespace"); } else { this.Title = GettextCatalog.GetString ("Rename Item"); } if (options.SelectedItem is IEntity) { var member = (IEntity)options.SelectedItem; if (member.SymbolKind == SymbolKind.Constructor || member.SymbolKind == SymbolKind.Destructor) { entry.Text = member.DeclaringType.Name; } else { entry.Text = member.Name; } // fileName = member.Region.FileName; } else if (options.SelectedItem is ITypeParameter) { var lvar = (ITypeParameter)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is IVariable) { var lvar = (IVariable)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is INamespace) { var lvar = (INamespace)options.SelectedItem; entry.Text = lvar.FullName; // this.fileName = lvar.Region.FileName; } entry.SelectRegion (0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName (); }; ValidateName (); }
public RenameItemDialog (RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build (); if (options.SelectedItem is IType) { IType type = (IType)options.SelectedItem; if (type.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = true; // if more than one type is in the file, only rename the file as defilt if the file name contains the type name // see Bug 603938 - Renaming a Class in a file with multiple classes renames the file if (options.Document.CompilationUnit != null && options.Document.CompilationUnit.Types.Count > 1) this.renameFileFlag.Active = options.Document.FileName.FileNameWithoutExtension.Contains (type.Name); } else { this.renameFileFlag.Active = false; } if (type.ClassType == ClassType.Interface) this.Title = GettextCatalog.GetString ("Rename Interface"); else this.Title = GettextCatalog.GetString ("Rename Class"); this.fileName = type.CompilationUnit.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString ("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString ("Rename Indexer"); } else { this.Title = GettextCatalog.GetString ("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString ("Rename Event"); } else if (options.SelectedItem is IMethod) { this.Title = GettextCatalog.GetString ("Rename Method"); } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString ("Rename Parameter"); } else if (options.SelectedItem is LocalVariable) { this.Title = GettextCatalog.GetString ("Rename Variable"); } else { this.Title = GettextCatalog.GetString ("Rename Item"); } if (options.SelectedItem is IMember) { IMember member = (IMember)options.SelectedItem; entry.Text = member.Name; if (!(member is IType) && member.DeclaringType != null) this.fileName = member.DeclaringType.CompilationUnit.FileName; } else if (options.SelectedItem is LocalVariable) { LocalVariable lvar = (LocalVariable)options.SelectedItem; entry.Text = lvar.Name; this.fileName = lvar.FileName; } else { IParameter par = options.SelectedItem as IParameter; if (par != null) { entry.Text = par.Name; this.fileName = par.DeclaringMember.DeclaringType.CompilationUnit.FileName; } } entry.SelectRegion (0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName (); }; ValidateName (); }
public RenameItemDialog (ISymbol symbol, RenameRefactoring rename) { this.Build (); string title; if (symbol is ITypeSymbol) { var t = (ITypeSymbol)symbol; if (t.TypeKind == TypeKind.TypeParameter) { title = GettextCatalog.GetString ("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = t; if (typeDefinition.ContainingType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = t.Locations.First ().SourceTree.FilePath.Contains (typeDefinition.Name); } else { this.renameFileFlag.Active = false; } if (typeDefinition.TypeKind == TypeKind.Interface) title = GettextCatalog.GetString ("Rename Interface"); else if (typeDefinition.TypeKind == TypeKind.Delegate) title = GettextCatalog.GetString ("Rename Delegate"); else if (typeDefinition.TypeKind == TypeKind.Enum) title = GettextCatalog.GetString ("Rename Enum"); else if (typeDefinition.TypeKind == TypeKind.Struct) title = GettextCatalog.GetString ("Rename Struct"); else title = GettextCatalog.GetString ("Rename Class"); } // this.fileName = type.GetDefinition ().Region.FileName; } else if (symbol.Kind == SymbolKind.Field) { title = GettextCatalog.GetString ("Rename Field"); } else if (symbol.Kind == SymbolKind.Property) { title = GettextCatalog.GetString ("Rename Property"); } else if (symbol.Kind == SymbolKind.Event) { title = GettextCatalog.GetString ("Rename Event"); } else if (symbol.Kind == SymbolKind.Method) { var m = (IMethodSymbol)symbol; if (m.MethodKind == MethodKind.Constructor || m.MethodKind == MethodKind.StaticConstructor || m.MethodKind == MethodKind.Destructor) { title = GettextCatalog.GetString ("Rename Class"); } else { title = GettextCatalog.GetString ("Rename Method"); includeOverloadsCheckbox.Visible = m.ContainingType.GetMembers (m.Name).Length > 1; } } else if (symbol.Kind == SymbolKind.Parameter) { title = GettextCatalog.GetString ("Rename Parameter"); } else if (symbol.Kind == SymbolKind.Local) { title = GettextCatalog.GetString ("Rename Variable"); } else if (symbol.Kind == SymbolKind.TypeParameter) { title = GettextCatalog.GetString ("Rename Type Parameter"); } else if (symbol.Kind == SymbolKind.Namespace) { title = GettextCatalog.GetString ("Rename Namespace"); } else if (symbol.Kind == SymbolKind.Label) { title = GettextCatalog.GetString ("Rename Label"); } else { title = GettextCatalog.GetString ("Rename Item"); } Init (title, symbol.Name, async prop => { await rename.PerformChangesAsync (symbol, prop); return new List<Change> (); }); }
public RenameItemDialog(RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build(); if (options.SelectedItem is IType) { var t = (IType)options.SelectedItem; if (t.Kind == TypeKind.TypeParameter) { this.Title = GettextCatalog.GetString("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = (t).GetDefinition(); if (typeDefinition.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = true; // if more than one type is in the file, only rename the file as defilt if the file name contains the type name // see Bug 603938 - Renaming a Class in a file with multiple classes renames the file if (options.Document != null && options.Document.ParsedDocument.TopLevelTypeDefinitions.Count > 1) { this.renameFileFlag.Active = options.Document.FileName.FileNameWithoutExtension.Contains(typeDefinition.Name); } } else { this.renameFileFlag.Active = false; } if (typeDefinition.Kind == TypeKind.Interface) { this.Title = GettextCatalog.GetString("Rename Interface"); } else { this.Title = GettextCatalog.GetString("Rename Class"); } } // this.fileName = type.GetDefinition ().Region.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString("Rename Indexer"); } else { this.Title = GettextCatalog.GetString("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString("Rename Event"); } else if (options.SelectedItem is IMethod) { var m = (IMethod)options.SelectedItem; if (m.IsConstructor || m.IsDestructor) { this.Title = GettextCatalog.GetString("Rename Class"); } else { this.Title = GettextCatalog.GetString("Rename Method"); } } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString("Rename Parameter"); } else if (options.SelectedItem is IVariable) { this.Title = GettextCatalog.GetString("Rename Variable"); } else if (options.SelectedItem is ITypeParameter) { this.Title = GettextCatalog.GetString("Rename Type Parameter"); } else { this.Title = GettextCatalog.GetString("Rename Item"); } if (options.SelectedItem is IEntity) { var member = (IEntity)options.SelectedItem; if (member.EntityType == EntityType.Constructor || member.EntityType == EntityType.Destructor) { entry.Text = member.DeclaringType.Name; } else { entry.Text = member.Name; } // fileName = member.Region.FileName; } else if (options.SelectedItem is ITypeParameter) { var lvar = (ITypeParameter)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is IVariable) { var lvar = (IVariable)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } entry.SelectRegion(0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName(); }; ValidateName(); }
public RenameItemDialog(RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build(); if (options.SelectedItem is IType) { IType type = (IType)options.SelectedItem; if (type.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = true; // if more than one type is in the file, only rename the file as defilt if the file name contains the type name // see Bug 603938 - Renaming a Class in a file with multiple classes renames the file if (options.Document.CompilationUnit != null && options.Document.CompilationUnit.Types.Count > 1) { this.renameFileFlag.Active = options.Document.FileName.FileNameWithoutExtension.Contains(type.Name); } } else { this.renameFileFlag.Active = false; } if (type.ClassType == ClassType.Interface) { this.Title = GettextCatalog.GetString("Rename Interface"); } else { this.Title = GettextCatalog.GetString("Rename Class"); } this.fileName = type.CompilationUnit.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString("Rename Indexer"); } else { this.Title = GettextCatalog.GetString("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString("Rename Event"); } else if (options.SelectedItem is IMethod) { this.Title = GettextCatalog.GetString("Rename Method"); } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString("Rename Parameter"); } else if (options.SelectedItem is LocalVariable) { this.Title = GettextCatalog.GetString("Rename Variable"); } else { this.Title = GettextCatalog.GetString("Rename Item"); } if (options.SelectedItem is IMember) { IMember member = (IMember)options.SelectedItem; entry.Text = member.Name; if (!(member is IType) && member.DeclaringType != null) { this.fileName = member.DeclaringType.CompilationUnit.FileName; } } else if (options.SelectedItem is LocalVariable) { LocalVariable lvar = (LocalVariable)options.SelectedItem; entry.Text = lvar.Name; this.fileName = lvar.FileName; } else { IParameter par = options.SelectedItem as IParameter; if (par != null) { entry.Text = par.Name; this.fileName = par.DeclaringMember.DeclaringType.CompilationUnit.FileName; } } entry.SelectRegion(0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName(); }; ValidateName(); }
protected override void Run (RefactoringOptions options) { RenameRefactoring renameRefactoring = new RenameRefactoring (); if (renameRefactoring.IsValid (options)) renameRefactoring.Run (options); }
public RenameItemDialog(ISymbol symbol, RenameRefactoring rename) { this.Build(); string title; if (symbol is ITypeSymbol) { var t = (ITypeSymbol)symbol; if (t.TypeKind == TypeKind.TypeParameter) { title = GettextCatalog.GetString("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = t; if (typeDefinition.ContainingType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = t.Locations.First().SourceTree.FilePath.Contains(typeDefinition.Name); } else { this.renameFileFlag.Active = false; } if (typeDefinition.TypeKind == TypeKind.Interface) { title = GettextCatalog.GetString("Rename Interface"); } else if (typeDefinition.TypeKind == TypeKind.Delegate) { title = GettextCatalog.GetString("Rename Delegate"); } else if (typeDefinition.TypeKind == TypeKind.Enum) { title = GettextCatalog.GetString("Rename Enum"); } else if (typeDefinition.TypeKind == TypeKind.Struct) { title = GettextCatalog.GetString("Rename Struct"); } else { title = GettextCatalog.GetString("Rename Class"); } } // this.fileName = type.GetDefinition ().Region.FileName; } else if (symbol.Kind == SymbolKind.Field) { title = GettextCatalog.GetString("Rename Field"); } else if (symbol.Kind == SymbolKind.Property) { title = GettextCatalog.GetString("Rename Property"); } else if (symbol.Kind == SymbolKind.Event) { title = GettextCatalog.GetString("Rename Event"); } else if (symbol.Kind == SymbolKind.Method) { var m = (IMethodSymbol)symbol; if (m.MethodKind == MethodKind.Constructor || m.MethodKind == MethodKind.StaticConstructor || m.MethodKind == MethodKind.Destructor) { title = GettextCatalog.GetString("Rename Class"); } else { title = GettextCatalog.GetString("Rename Method"); includeOverloadsCheckbox.Visible = m.ContainingType.GetMembers(m.Name).Length > 1; } } else if (symbol.Kind == SymbolKind.Parameter) { title = GettextCatalog.GetString("Rename Parameter"); } else if (symbol.Kind == SymbolKind.Local) { title = GettextCatalog.GetString("Rename Variable"); } else if (symbol.Kind == SymbolKind.TypeParameter) { title = GettextCatalog.GetString("Rename Type Parameter"); } else if (symbol.Kind == SymbolKind.Namespace) { title = GettextCatalog.GetString("Rename Namespace"); } else if (symbol.Kind == SymbolKind.Label) { title = GettextCatalog.GetString("Rename Label"); } else { title = GettextCatalog.GetString("Rename Item"); } Init(title, symbol.Name, prop => { rename.PerformChanges(symbol, prop); return(new List <Change> ()); }); }
public RenameItemDialog(RefactoringOptions options, RenameRefactoring rename) { this.options = options; this.rename = rename; if (options.SelectedItem is IMethod && ((IMethod)options.SelectedItem).IsConstructor) { options.SelectedItem = ((IMethod)options.SelectedItem).DeclaringType; } this.Build(); includeOverloadsCheckbox.Active = true; includeOverloadsCheckbox.Visible = false; if (options.SelectedItem is IType) { var t = (IType)options.SelectedItem; if (t.Kind == TypeKind.TypeParameter) { this.Title = GettextCatalog.GetString("Rename Type Parameter"); entry.Text = t.Name; } else { var typeDefinition = (t).GetDefinition(); if (typeDefinition.DeclaringType == null) { // not supported for inner types this.renameFileFlag.Visible = true; this.renameFileFlag.Active = options.Document != null?options.Document.FileName.FileNameWithoutExtension.Contains(typeDefinition.Name) : false; } else { this.renameFileFlag.Active = false; } if (typeDefinition.Kind == TypeKind.Interface) { this.Title = GettextCatalog.GetString("Rename Interface"); } else { this.Title = GettextCatalog.GetString("Rename Class"); } } // this.fileName = type.GetDefinition ().Region.FileName; } else if (options.SelectedItem is IField) { this.Title = GettextCatalog.GetString("Rename Field"); } else if (options.SelectedItem is IProperty) { if (((IProperty)options.SelectedItem).IsIndexer) { this.Title = GettextCatalog.GetString("Rename Indexer"); } else { this.Title = GettextCatalog.GetString("Rename Property"); } } else if (options.SelectedItem is IEvent) { this.Title = GettextCatalog.GetString("Rename Event"); } else if (options.SelectedItem is IMethod) { var m = (IMethod)options.SelectedItem; if (m.IsConstructor || m.IsDestructor) { this.Title = GettextCatalog.GetString("Rename Class"); } else { this.Title = GettextCatalog.GetString("Rename Method"); includeOverloadsCheckbox.Visible = m.DeclaringType.GetMethods(x => x.Name == m.Name).Count() > 1; } } else if (options.SelectedItem is IParameter) { this.Title = GettextCatalog.GetString("Rename Parameter"); } else if (options.SelectedItem is IVariable) { this.Title = GettextCatalog.GetString("Rename Variable"); } else if (options.SelectedItem is ITypeParameter) { this.Title = GettextCatalog.GetString("Rename Type Parameter"); } else if (options.SelectedItem is INamespace) { this.Title = GettextCatalog.GetString("Rename namespace"); } else { this.Title = GettextCatalog.GetString("Rename Item"); } if (options.SelectedItem is IEntity) { var member = (IEntity)options.SelectedItem; if (member.SymbolKind == SymbolKind.Constructor || member.SymbolKind == SymbolKind.Destructor) { entry.Text = member.DeclaringType.Name; } else { entry.Text = member.Name; } // fileName = member.Region.FileName; } else if (options.SelectedItem is IType) { var lvar = (IType)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is ITypeParameter) { var lvar = (ITypeParameter)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is IVariable) { var lvar = (IVariable)options.SelectedItem; entry.Text = lvar.Name; // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is INamespace) { var lvar = (INamespace)options.SelectedItem; entry.Text = lvar.FullName; // this.fileName = lvar.Region.FileName; } entry.SelectRegion(0, -1); buttonPreview.Sensitive = buttonOk.Sensitive = false; entry.Changed += OnEntryChanged; entry.Activated += OnEntryActivated; buttonOk.Clicked += OnOKClicked; buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName(); }; ValidateName(); this.hbox1.HideAll(); }
protected override void Update (RefactoringOptions options, CommandInfo info) { var renameRefactoring = new RenameRefactoring (); if (!renameRefactoring.IsValid (options)) info.Bypass = true; }