Example #1
0
        string PromptForNewNameForRename()
        {
            WordAtPosition word = Editor.GetWordAtCaret();

            if (word.IsEmpty || word.IsInvalid)
            {
                return(null);
            }

            return(RenameItemDialog.PromptForNewName(word.Text));
        }
Example #2
0
        public static string PromptForNewName(string text)
        {
            using (var dialog = new RenameItemDialog(text)) {
                var result = dialog.ShowWithParent();
                if ((result == Xwt.Command.Ok) && (dialog.NewName != text))
                {
                    return(dialog.NewName);
                }
            }

            return(null);
        }
        public async Task RenameOccurrences(FilePath fileName, DocumentLocation location)
        {
            try {
                using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitorForRename()) {
                    Location[] locations = await session.GetReferences(
                        fileName,
                        location.CreatePosition(),
                        monitor.CancellationToken);

                    if (locations == null)
                    {
                        monitor.ReportNoReferencesFound();
                        return;
                    }

                    List <SearchResult> references = ToSearchResults(locations).ToList();
                    if (!references.Any())
                    {
                        monitor.ReportNoReferencesFound();
                    }
                    else if (AllSearchResultsExistInCurrentEditor(references))
                    {
                        editor.StartTextEditorRename(references);
                    }
                    else
                    {
                        // Multiple files - cannot use text editor edit links.
                        string oldName = GetSearchResultItemText(references [0]);
                        string newName = RenameItemDialog.PromptForNewName(oldName);
                        WorkspaceEditHandler.ApplyChanges(locations, newName);
                    }
                }
            } catch (OperationCanceledException) {
                LanguageClientLoggingService.Log("Rename was canceled.");
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("RenameOccurrences error.", ex);
            }
        }