예제 #1
0
        void OnPropertyGridPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (propertyGridView.PropertyGrid.ReloadActive)
            {
                return;
            }
            if (e.PropertyName == "Name")
            {
                if (!propertyGridView.PropertyGrid.IsNameCorrect)
                {
                    return;
                }

                // get the XAML file
                OpenedFile file = this.Files.FirstOrDefault(f => f.FileName.ToString().EndsWith(".xaml", StringComparison.OrdinalIgnoreCase));
                if (file == null)
                {
                    return;
                }

                // parse the XAML file
                ParseInformation info = SD.ParserService.Parse(file.FileName);
                if (info == null)
                {
                    return;
                }
                ICompilation compilation   = SD.ParserService.GetCompilationForFile(file.FileName);
                var          designerClass = info.UnresolvedFile.TopLevelTypeDefinitions[0]
                                             .Resolve(new SimpleTypeResolveContext(compilation.MainAssembly))
                                             .GetDefinition();
                if (designerClass == null)
                {
                    return;
                }
                var reparseFileNameList = designerClass.Parts.Select(p => new ICSharpCode.Core.FileName(p.UnresolvedFile.FileName)).ToArray();

                // rename the member
                ISymbol controlSymbol = designerClass.GetFields(f => f.Name == propertyGridView.PropertyGrid.OldName, GetMemberOptions.IgnoreInheritedMembers)
                                        .SingleOrDefault();
                if (controlSymbol != null)
                {
                    AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
                        "${res:SharpDevelop.Refactoring.Rename}",
                        progressMonitor =>
                        FindReferenceService.RenameSymbol(controlSymbol, propertyGridView.PropertyGrid.Name, progressMonitor)
                        .ObserveOnUIThread()
                        .Subscribe(error => SD.MessageService.ShowError(error.Message), // onNext
                                   ex => SD.MessageService.ShowException(ex),           // onError
                                                                                        // onCompleted
                                   () => {
                        foreach (var fileName in reparseFileNameList)
                        {
                            SD.ParserService.ParseAsync(fileName).FireAndForget();
                        }
                    }
                                   )
                        );
                }
            }
        }
예제 #2
0
        public override void Run(ResolveResult symbol)
        {
            var entity = GetSymbol(symbol);

            if (entity != null)
            {
                var project = GetProjectFromSymbol(entity);
                if (project != null)
                {
                    var languageBinding = project.LanguageBinding;

                    RenameSymbolDialog renameDialog = new RenameSymbolDialog(name => CheckName(name, languageBinding))
                    {
                        Owner         = SD.Workbench.MainWindow,
                        OldSymbolName = entity.Name,
                        NewSymbolName = entity.Name
                    };
                    if ((bool)renameDialog.ShowDialog())
                    {
                        AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
                            "${res:SharpDevelop.Refactoring.Rename}",
                            progressMonitor =>
                            FindReferenceService.RenameSymbol(entity, renameDialog.NewSymbolName, progressMonitor)
                            .ObserveOnUIThread()
                            .Subscribe(error => SD.MessageService.ShowError(error.Message), ex => SD.MessageService.ShowException(ex), () => {}));
                    }
                }
            }
        }
예제 #3
0
 public static void RunRename(ISymbol symbol, string newName = null)
 {
     if ((symbol is IMember) && ((symbol.SymbolKind == SymbolKind.Constructor) || (symbol.SymbolKind == SymbolKind.Destructor)))
     {
         // Don't rename constructors/destructors, rename their declaring type instead
         symbol = ((IMember)symbol).DeclaringType.GetDefinition();
     }
     if (symbol != null)
     {
         var project = GetProjectFromSymbol(symbol);
         if (project != null)
         {
             var languageBinding = project.LanguageBinding;
             if (newName == null)
             {
                 RenameSymbolDialog renameDialog = new RenameSymbolDialog(name => CheckName(name, languageBinding))
                 {
                     Owner         = SD.Workbench.MainWindow,
                     OldSymbolName = symbol.Name,
                     NewSymbolName = symbol.Name
                 };
                 if (renameDialog.ShowDialog() == true)
                 {
                     newName = renameDialog.NewSymbolName;
                 }
                 else
                 {
                     return;
                 }
             }
             AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
                 "${res:SharpDevelop.Refactoring.Rename}",
                 progressMonitor =>
                 FindReferenceService.RenameSymbol(symbol, newName, progressMonitor)
                 .ObserveOnUIThread()
                 .Subscribe(error => SD.MessageService.ShowError(error.Message), ex => SD.MessageService.ShowException(ex), () => {}));
         }
     }
 }
예제 #4
0
        protected override void OnComponentRename(object component, string oldName, string newName)
        {
            base.OnComponentRename(component, oldName, newName);
            if (oldName != newName)
            {
                var primaryParseInfo = context.GetPrimaryFileParseInformation();
                var compilation      = context.GetCompilation();

                // Find designer class
                ITypeDefinition designerClass = FormsDesignerSecondaryDisplayBinding.GetDesignableClass(primaryParseInfo.UnresolvedFile, compilation, out primaryPart);

                ISymbol controlSymbol;
                if (DesignerLoaderHost != null && DesignerLoaderHost.RootComponent == component)
                {
                    controlSymbol = designerClass;
                }
                else
                {
                    controlSymbol = designerClass.GetFields(f => f.Name == oldName, GetMemberOptions.IgnoreInheritedMembers)
                                    .SingleOrDefault();
                }
                if (controlSymbol != null)
                {
                    AsynchronousWaitDialog.ShowWaitDialogForAsyncOperation(
                        "${res:SharpDevelop.Refactoring.Rename}",
                        progressMonitor =>
                        FindReferenceService.RenameSymbol(controlSymbol, newName, progressMonitor)
                        .ObserveOnUIThread()
                        .Subscribe(error => SD.MessageService.ShowError(error.Message), // onNext
                                   ex => SD.MessageService.ShowException(ex),           // onError
                                                                                        // onCompleted - force refresh of the DesignerCodeFile's parse info, because the code generator
                                                                                        // seems to work with an outdated version, when the document is saved.
                                   () => SD.ParserService.Parse(new FileName(context.DesignerCodeFileDocument.FileName), context.DesignerCodeFileDocument)
                                   )
                        );
                }
            }
        }