コード例 #1
0
		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)));
		}
コード例 #2
0
		protected override bool IsValid (MDRefactoringContext context)
		{
			var type = GetTypeDeclaration (context);
			if (type == null)
				return false;
			return Path.GetFileNameWithoutExtension (context.Document.FileName) != type.Name;
		}
コード例 #3
0
		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);
		}
コード例 #4
0
        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);
        }
コード例 #5
0
		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);
		}
コード例 #6
0
        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));
        }
コード例 #7
0
        protected override bool IsValid(MDRefactoringContext context)
        {
            var type = GetTypeDeclaration(context);

            if (type == null)
            {
                return(false);
            }
            return(Path.GetFileNameWithoutExtension(context.Document.FileName) != type.Name);
        }
コード例 #8
0
        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))));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
		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);
			}
		}
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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));
        }
コード例 #16
0
		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);
		}
コード例 #17
0
 public MdLinkAction(MDRefactoringContext ctx, IEnumerable <AstNode> linkedNodes) : base(linkedNodes)
 {
     this.ctx = ctx;
 }
コード例 #18
0
 public MdFormatTextAction(MDRefactoringContext ctx, Func <RefactoringContext, AstNode> callback) : base(callback)
 {
     this.ctx = ctx;
 }
コード例 #19
0
			public MdScript (MDRefactoringContext ctx) : base(ctx)
			{
				this.ctx = ctx;
			}
コード例 #20
0
			public MdLinkAction (MDRefactoringContext ctx, IEnumerable<AstNode> linkedNodes) : base (linkedNodes)
			{
				this.ctx = ctx;
			}
コード例 #21
0
			public MdFormatTextAction (MDRefactoringContext ctx, Func<RefactoringContext, AstNode> callback) : base (callback)
			{
				this.ctx = ctx;
			}
コード例 #22
0
 protected abstract void Run(MDRefactoringContext context);
コード例 #23
0
 string GetCorrectFileName(MDRefactoringContext context, TypeDeclaration type)
 {
     return(Path.Combine(Path.GetDirectoryName(context.Document.FileName), type.Name + Path.GetExtension(context.Document.FileName)));
 }
コード例 #24
0
		protected abstract bool IsValid (MDRefactoringContext context);
コード例 #25
0
		protected abstract void Run (MDRefactoringContext context);
コード例 #26
0
		string GetCorrectFileName (MDRefactoringContext context, TypeDeclaration type)
		{
			return Path.Combine (Path.GetDirectoryName (context.Document.FileName), type.Name + Path.GetExtension (context.Document.FileName));
		}
コード例 #27
0
		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;
		}
コード例 #28
0
 protected virtual string GetMenuText(MDRefactoringContext context)
 {
     return(Node.Title);
 }
コード例 #29
0
 protected override void Run(MDRefactoringContext context)
 {
     action.Run(context);
 }
コード例 #30
0
 public MdScript(MDRefactoringContext ctx) : base(ctx)
 {
     this.ctx = ctx;
 }
コード例 #31
0
        protected override string GetMenuText(MDRefactoringContext context)
        {
            var identifier = ICSharpCode.NRefactory.CSharp.Refactoring.CreateField.GetIdentifier(context);

            return(string.Format(GettextCatalog.GetString("Create property '{0}'"), identifier));
        }
コード例 #32
0
		protected virtual string GetMenuText (MDRefactoringContext context)
		{
			return Node.Title;
		}
コード例 #33
0
 protected override bool IsValid(MDRefactoringContext context)
 {
     return(action.IsValid(context));
 }
コード例 #34
0
 protected abstract bool IsValid(MDRefactoringContext context);
コード例 #35
0
		bool IsSingleType (MDRefactoringContext context)
		{
			return context.Unit.GetTypes ().Count () == 1;
		}
コード例 #36
0
 bool IsSingleType(MDRefactoringContext context)
 {
     return(context.Unit.GetTypes().Count() == 1);
 }