static string Common(string sourceText, string newName, ScintillaControl sci) { SetSrc(sci, sourceText); CommandFactoryProvider.GetFactory(sci) .CreateExtractLocalVariableCommand(false, newName) .Execute(); return(sci.Text); }
static string Common(string sourceText, MemberModel currentMember, string newName, ScintillaControl sci) { sci.Text = sourceText; SnippetHelper.PostProcessSnippets(sci, 0); ASContext.Context.CurrentMember.Returns(currentMember); CommandFactoryProvider.GetFactory(sci) .CreateExtractLocalVariableCommand(false, newName) .Execute(); return(sci.Text); }
internal static string Common(ScintillaControl sci, string sourceText, string fileName) { ASContext.Context.CurrentModel.FileName = fileName; SetSrc(sci, sourceText); sci.Colourise(0, -1); // Needed for preprocessor directives... CommandFactoryProvider.GetFactory(sci) .CreateOrganizeImportsCommand() .Execute(); return(sci.Text); }
public string Haxe(string sourceText, string newName, int contextualGeneratorItem) { SetHaxeFeatures(sci); SetSrc(sci, sourceText); var command = (ExtractLocalVariableCommand)CommandFactoryProvider.GetFactory(sci).CreateExtractLocalVariableCommand(false, newName); command.Execute(); ((CompletionListItem)command.CompletionList[contextualGeneratorItem]).PerformClick(); return(sci.Text); }
static string Common(string sourceText, string newName, ScintillaControl sci) { sci.Text = sourceText; SnippetHelper.PostProcessSnippets(sci, 0); var model = ASContext.Context.GetCodeModel(sourceText); ASContext.Context.CurrentMember.Returns(model.Classes.First().Members.Items.First()); CommandFactoryProvider.GetFactory(sci) .CreateExtractMethodCommand(newName) .Execute(); return(sci.Text); }
internal static string Common(ScintillaControl sci, string sourceText, string fileName) { sci.Text = sourceText; sci.Colourise(0, -1); // Needed for preprocessor directives... SnippetHelper.PostProcessSnippets(sci, 0); var currentModel = ASContext.Context.CurrentModel; new ASFileParser().ParseSrc(currentModel, sci.Text); CommandFactoryProvider.GetFactory(sci) .CreateOrganizeImportsCommand() .Execute(); return(sci.Text); }
public void Process(IEnumerable <string> files) { foreach (var file in files) { var document = PluginBase.MainForm.OpenEditableDocument(file) as ITabbedDocument; var command = (OrganizeImports)CommandFactoryProvider.GetFactory(document)?.CreateOrganizeImportsCommand(); if (command == null) { continue; } command.SciControl = document.SciControl; command.Execute(); } }
public string Haxe(string sourceText, MemberModel currentMember, string newName, int contextualGeneratorItem) { ASContext.Context.SetHaxeFeatures(); ASContext.Context.CurrentModel.Returns(new FileModel { haXe = true, Context = ASContext.Context }); ASContext.Context.CurrentMember.Returns(currentMember); Sci.Text = sourceText; Sci.ConfigurationLanguage = "haxe"; SnippetHelper.PostProcessSnippets(Sci, 0); var command = (ExtractLocalVariableCommand)CommandFactoryProvider.GetFactory(Sci).CreateExtractLocalVariableCommand(false, newName); command.Execute(); ((CompletionListItem)command.CompletionList[contextualGeneratorItem]).PerformClick(); return(Sci.Text); }
static string Common(ScintillaControl sci, string sourceText, string newName) { SetSrc(sci, sourceText); var waitHandle = new AutoResetEvent(false); CommandFactoryProvider.GetFactory(sci) .CreateRenameCommandAndExecute(RefactoringHelper.GetDefaultRefactorTarget(), false, newName) .OnRefactorComplete += (sender, args) => waitHandle.Set(); var end = DateTime.Now.AddSeconds(2); var result = false; while ((!result) && (DateTime.Now < end)) { context.Send(state => {}, new {}); result = waitHandle.WaitOne(0); } return(sci.Text); }
/// <summary> /// Initializes a new instance of <see cref="Rename"/> class. /// </summary> /// <param name="target">The target declaration to find references to.</param> /// <param name="outputResults">If true, will send the found results to the trace log and results panel</param> /// <param name="newName">If provided, will not query the user for a new name.</param> /// <param name="ignoreDeclarationSource">If true, will not rename the original declaration source. Useful for Encapsulation refactoring.</param> /// <param name="inline">Whether to use inline renaming.</param> public Rename(ASResult target, bool outputResults, string newName, bool ignoreDeclarationSource, bool inline = false) { if (target == null) { TraceManager.Add("Refactor target is null."); return; } Target = target; OutputResults = outputResults; if (target.IsPackage) { isRenamePackage = true; string package = target.Path.Replace('.', Path.DirectorySeparatorChar); foreach (var aPath in ASContext.Context.Classpath) { if (aPath.IsValid && !aPath.Updating) { string path = Path.Combine(aPath.Path, package); if (Directory.Exists(path)) { TargetName = Path.GetFileName(path); renamePackagePath = path; StartRename(inline, TargetName, newName); return; } } } return; } isRenamePackage = false; TargetName = RefactoringHelper.GetRefactorTargetName(target); // create a FindAllReferences refactor to get all the changes we need to make // we'll also let it output the results, at least until we implement a way of outputting the renamed results later findAllReferencesCommand = CommandFactoryProvider.GetFactory(target).CreateFindAllReferencesCommand(target, false, ignoreDeclarationSource, true); // register a completion listener to the FindAllReferences so we can rename the entries findAllReferencesCommand.OnRefactorComplete += OnFindAllReferencesCompleted; StartRename(inline, TargetName, newName); }
public string Haxe(string sourceText, string fileName) { Sci.ConfigurationLanguage = "haxe"; ASContext.Context.SetHaxeFeatures(); ASContext.Context.CurrentModel.Returns(new FileModel { haXe = true, Context = ASContext.Context, FileName = fileName }); Sci.Text = sourceText; SnippetHelper.PostProcessSnippets(Sci, 0); var currentModel = ASContext.Context.CurrentModel; new ASFileParser().ParseSrc(currentModel, Sci.Text); CommandFactoryProvider.GetFactory(Sci) .CreateOrganizeImportsCommand() .Execute(); return(Sci.Text); }
protected override void ExecutionImplementation() { String oldFileName = Path.GetFileNameWithoutExtension(oldPath); String newFileName = Path.GetFileNameWithoutExtension(newPath); String msg = TextHelper.GetString("Info.RenamingFile"); String title = String.Format(TextHelper.GetString("Title.RenameDialog"), oldFileName); if (MessageBox.Show(msg, title, MessageBoxButtons.YesNo) == DialogResult.Yes) { var target = RefactoringHelper.GetRefactorTargetFromFile(oldPath, AssociatedDocumentHelper); if (target != null) { var command = CommandFactoryProvider.GetFactory(target).CreateRenameCommandAndExecute(target, true, newFileName); command.RegisterDocumentHelper(AssociatedDocumentHelper); return; } } // refactor failed or was refused if (Path.GetFileName(oldPath).Equals(newPath, StringComparison.OrdinalIgnoreCase)) { // name casing changed string tmpPath = oldPath + "$renaming$"; File.Move(oldPath, tmpPath); oldPath = tmpPath; } if (!Path.IsPathRooted(newPath)) { newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath); } if (FileHelper.ConfirmOverwrite(newPath)) { FileHelper.ForceMove(oldPath, newPath); DocumentManager.MoveDocuments(oldPath, newPath); RefactoringHelper.RaiseMoveEvent(oldPath, newPath); } }
private void UpdateMenuItems(ResolvedContext resolved) { try { var document = PluginBase.MainForm.CurrentDocument; var curFileName = document != null ? document.FileName : string.Empty; this.refactorMainMenu.DelegateMenuItem.Enabled = false; this.refactorContextMenu.DelegateMenuItem.Enabled = false; bool langIsValid = RefactoringHelper.GetLanguageIsValid(); bool isValid = langIsValid && resolved != null && resolved.Position >= 0; ASResult result = isValid ? resolved.Result : null; if (result != null && !result.IsNull()) { var validator = CommandFactoryProvider.GetFactory(result)?.GetValidator(typeof(Rename)) ?? CommandFactoryProvider.DefaultFactory.GetValidator(typeof(Rename)); var isRenameable = validator(result); this.refactorContextMenu.RenameMenuItem.Enabled = isRenameable; this.refactorMainMenu.RenameMenuItem.Enabled = isRenameable; var enabled = !result.IsPackage && (File.Exists(curFileName) || curFileName.Contains("[model]")); this.editorReferencesItem.Enabled = enabled; this.viewReferencesItem.Enabled = enabled; if (result.InFile != null && result.InClass != null && (result.InClass.Flags & FlagType.Interface) == 0 && result.Member != null && result.Type != null) { FlagType flags = result.Member.Flags; if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0) { this.refactorContextMenu.DelegateMenuItem.Enabled = true; this.refactorMainMenu.DelegateMenuItem.Enabled = true; } } } else { this.refactorMainMenu.RenameMenuItem.Enabled = false; this.refactorContextMenu.RenameMenuItem.Enabled = false; this.editorReferencesItem.Enabled = false; this.viewReferencesItem.Enabled = false; } IASContext context = ASContext.Context; if (context != null && context.CurrentModel != null) { bool enabled = langIsValid && context.CurrentModel.Imports.Count > 0; this.refactorContextMenu.OrganizeMenuItem.Enabled = enabled; this.refactorContextMenu.TruncateMenuItem.Enabled = enabled; this.refactorMainMenu.OrganizeMenuItem.Enabled = enabled; this.refactorMainMenu.TruncateMenuItem.Enabled = enabled; } refactorMainMenu.MoveMenuItem.Enabled = false; refactorContextMenu.MoveMenuItem.Enabled = false; this.surroundContextMenu.Enabled = false; this.refactorMainMenu.SurroundMenu.Enabled = false; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = false; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = false; this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = false; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false; if (document != null && document.IsEditable && langIsValid) { bool isValidFile = IsValidFile(curFileName); refactorMainMenu.MoveMenuItem.Enabled = isValidFile; refactorContextMenu.MoveMenuItem.Enabled = isValidFile; var sci = document.SciControl; if (sci.SelTextSize > 0) { if (!sci.PositionIsOnComment(sci.SelectionStart) || !sci.PositionIsOnComment(sci.SelectionEnd)) { this.surroundContextMenu.Enabled = true; this.refactorMainMenu.SurroundMenu.Enabled = true; this.refactorMainMenu.ExtractMethodMenuItem.Enabled = true; this.refactorContextMenu.ExtractMethodMenuItem.Enabled = true; } if (context != null) { var declAtSelStart = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionStart)); var declAtSelEnd = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionEnd)); if (declAtSelStart != null && declAtSelStart.Member != null && (declAtSelStart.Member.Flags & FlagType.Function) > 0 && declAtSelEnd != null && declAtSelStart.Member.Equals(declAtSelEnd.Member)) { this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled = true; this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true; } } } } this.refactorMainMenu.CodeGeneratorMenuItem.Enabled = isValid; this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid; } catch { } }