protected override string GetMenuText (MDRefactoringContext context) { var type = GetTypeDeclaration (context); if (IsSingleType (context)) return String.Format (GettextCatalog.GetString ("_Rename file to '{0}'"), Path.GetFileName (GetCorrectFileName (context, type))); return String.Format (GettextCatalog.GetString ("_Move type to file '{0}'"), Path.GetFileName (GetCorrectFileName (context, type))); }
protected override bool IsValid (MDRefactoringContext context) { var type = GetTypeDeclaration (context); if (type == null) return false; return Path.GetFileNameWithoutExtension (context.Document.FileName) != type.Name; }
public sealed override bool IsValid (MonoDevelop.Ide.Gui.Document document, MonoDevelop.Projects.Dom.DomLocation loc) { var context = new MDRefactoringContext (document, loc); if (context.Unit == null) return false; return IsValid (context); }
void CreateNewFile(MDRefactoringContext context, TypeDeclaration type, string correctFileName) { var content = context.Document.Editor.Text; var types = new List <TypeDeclaration> (context.Unit.GetTypes().Where(t => t != type)); types.Sort((x, y) => y.StartLocation.CompareTo(x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset(removeType.StartLocation); var end = context.GetOffset(removeType.EndLocation); content = content.Remove(start, end - start); } if (context.Document.Project is MonoDevelop.Projects.DotNetProject) { string header = StandardHeaderService.GetHeader(context.Document.Project, correctFileName, true); if (!string.IsNullOrEmpty(header)) { content = header + context.Document.Editor.EolMarker + StripHeader(content); } } content = StripDoubleBlankLines(content); File.WriteAllText(correctFileName, content); context.Document.Project.AddFile(correctFileName); MonoDevelop.Ide.IdeApp.ProjectOperations.Save(context.Document.Project); }
public sealed override string GetMenuText (MonoDevelop.Ide.Gui.Document document, MonoDevelop.Projects.Dom.DomLocation loc) { var context = new MDRefactoringContext (document, loc); if (context.Unit == null) return "invalid"; return GetMenuText (context); }
public sealed override string GetMenuText(MonoDevelop.Ide.Gui.Document document, MonoDevelop.Projects.Dom.DomLocation loc) { var context = new MDRefactoringContext(document, loc); if (context.Unit == null) { return("invalid"); } return(GetMenuText(context)); }
protected override bool IsValid(MDRefactoringContext context) { var type = GetTypeDeclaration(context); if (type == null) { return(false); } return(Path.GetFileNameWithoutExtension(context.Document.FileName) != type.Name); }
protected override string GetMenuText(MDRefactoringContext context) { var type = GetTypeDeclaration(context); if (IsSingleType(context)) { return(String.Format(GettextCatalog.GetString("_Rename file to '{0}'"), Path.GetFileName(GetCorrectFileName(context, type)))); } return(String.Format(GettextCatalog.GetString("_Move type to file '{0}'"), Path.GetFileName(GetCorrectFileName(context, type)))); }
public sealed override bool IsValid(MonoDevelop.Ide.Gui.Document document, MonoDevelop.Projects.Dom.DomLocation loc) { var context = new MDRefactoringContext(document, loc); if (context.Unit == null) { return(false); } return(IsValid(context)); }
protected override string GetMenuText(MDRefactoringContext context) { if (action.GetUnresolvedArguments(context).Count > 0) { return(GettextCatalog.GetString("Create local variable declarations for arguments")); } var identifier = ICSharpCode.NRefactory.CSharp.Refactoring.CreateField.GetIdentifier(context); return(string.Format(GettextCatalog.GetString("Create local variable '{0}'"), identifier)); }
TypeDeclaration GetTypeDeclaration(MDRefactoringContext context) { var result = context.GetNode <TypeDeclaration> (); if (result == null || result.Parent is TypeDeclaration) { return(null); } if (result != null && result.NameToken.Contains(context.Location.Line, context.Location.Column)) { return(result); } return(null); }
protected override void Run (MDRefactoringContext context) { var type = GetTypeDeclaration (context); string correctFileName = GetCorrectFileName (context, type); if (IsSingleType (context)) { FileService.RenameFile (context.Document.FileName, correctFileName); // context.Do (new RenameFileChange ()); return; } CreateNewFile (context, type, correctFileName); using (var script = context.StartScript ()) { script.Remove (type); } }
public sealed override void Run(MonoDevelop.Ide.Gui.Document document, MonoDevelop.Projects.Dom.DomLocation loc) { var context = new MDRefactoringContext(document, loc); if (context.Unit == null) { return; } if (!IsValid(context)) { return; } Run(context); }
protected override void Run(MDRefactoringContext context) { var type = GetTypeDeclaration(context); string correctFileName = GetCorrectFileName(context, type); if (IsSingleType(context)) { FileService.RenameFile(context.Document.FileName, correctFileName); // context.Do (new RenameFileChange ()); return; } CreateNewFile(context, type, correctFileName); using (var script = context.StartScript()) { script.Remove(type); } }
protected override string GetMenuText(MDRefactoringContext context) { var binop = ICSharpCode.NRefactory.CSharp.Refactoring.FlipOperatorArguments.GetBinaryOperatorExpression(context); string op; switch (binop.Operator) { case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.Equality: op = "=="; break; case ICSharpCode.NRefactory.CSharp.BinaryOperatorType.InEquality: op = "!="; break; default: throw new InvalidOperationException(); } return(string.Format(GettextCatalog.GetString("Flip '{0}' operator arguments"), op)); }
void CreateNewFile (MDRefactoringContext context, TypeDeclaration type, string correctFileName) { var content = context.Document.Editor.Text; var types = new List<TypeDeclaration> (context.Unit.GetTypes ().Where (t => t != type)); types.Sort ((x, y) => y.StartLocation.CompareTo (x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset (removeType.StartLocation); var end = context.GetOffset (removeType.EndLocation); content = content.Remove (start, end - start); } if (context.Document.Project is MonoDevelop.Projects.DotNetProject) { string header = StandardHeaderService.GetHeader (context.Document.Project, correctFileName, true); if (!string.IsNullOrEmpty (header)) content = header + context.Document.Editor.EolMarker + StripHeader (content); } content = StripDoubleBlankLines (content); File.WriteAllText (correctFileName, content); context.Document.Project.AddFile (correctFileName); MonoDevelop.Ide.IdeApp.ProjectOperations.Save (context.Document.Project); }
public MdLinkAction(MDRefactoringContext ctx, IEnumerable <AstNode> linkedNodes) : base(linkedNodes) { this.ctx = ctx; }
public MdFormatTextAction(MDRefactoringContext ctx, Func <RefactoringContext, AstNode> callback) : base(callback) { this.ctx = ctx; }
public MdScript (MDRefactoringContext ctx) : base(ctx) { this.ctx = ctx; }
public MdLinkAction (MDRefactoringContext ctx, IEnumerable<AstNode> linkedNodes) : base (linkedNodes) { this.ctx = ctx; }
public MdFormatTextAction (MDRefactoringContext ctx, Func<RefactoringContext, AstNode> callback) : base (callback) { this.ctx = ctx; }
protected abstract void Run(MDRefactoringContext context);
string GetCorrectFileName(MDRefactoringContext context, TypeDeclaration type) { return(Path.Combine(Path.GetDirectoryName(context.Document.FileName), type.Name + Path.GetExtension(context.Document.FileName))); }
protected abstract bool IsValid (MDRefactoringContext context);
protected abstract void Run (MDRefactoringContext context);
string GetCorrectFileName (MDRefactoringContext context, TypeDeclaration type) { return Path.Combine (Path.GetDirectoryName (context.Document.FileName), type.Name + Path.GetExtension (context.Document.FileName)); }
TypeDeclaration GetTypeDeclaration (MDRefactoringContext context) { var result = context.GetNode<TypeDeclaration> (); if (result == null || result.Parent is TypeDeclaration) return null; if (result != null && result.NameToken.Contains (context.Location.Line, context.Location.Column)) return result; return null; }
protected virtual string GetMenuText(MDRefactoringContext context) { return(Node.Title); }
protected override void Run(MDRefactoringContext context) { action.Run(context); }
public MdScript(MDRefactoringContext ctx) : base(ctx) { this.ctx = ctx; }
protected override string GetMenuText(MDRefactoringContext context) { var identifier = ICSharpCode.NRefactory.CSharp.Refactoring.CreateField.GetIdentifier(context); return(string.Format(GettextCatalog.GetString("Create property '{0}'"), identifier)); }
protected virtual string GetMenuText (MDRefactoringContext context) { return Node.Title; }
protected override bool IsValid(MDRefactoringContext context) { return(action.IsValid(context)); }
protected abstract bool IsValid(MDRefactoringContext context);
bool IsSingleType (MDRefactoringContext context) { return context.Unit.GetTypes ().Count () == 1; }
bool IsSingleType(MDRefactoringContext context) { return(context.Unit.GetTypes().Count() == 1); }