protected IEnumerable<MonoDevelop.CodeActions.CodeAction> GetActions (MDRefactoringContext context)
		{
			if (context.IsInvalid)
				yield break;
			var type = GetTypeDeclaration (context);
			if (type == null)
				yield break;
			if (Path.GetFileNameWithoutExtension (context.Document.FileName) == type.Name)
				yield break;
			string title;
			if (IsSingleType (context)) {
				title = String.Format (GettextCatalog.GetString ("_Rename file to '{0}'"), Path.GetFileName (GetCorrectFileName (context, type)));
			} else {
				title = String.Format (GettextCatalog.GetString ("_Move type to file '{0}'"), Path.GetFileName (GetCorrectFileName (context, type)));
			}
			yield return new MonoDevelop.CodeActions.DefaultCodeAction (title, (d, l) => {
				var ctx = new MDRefactoringContext (d, l);
				string correctFileName = GetCorrectFileName (ctx, type);
				if (IsSingleType (ctx)) {
					FileService.RenameFile (ctx.Document.FileName, correctFileName);
					if (ctx.Document.Project != null)
						ctx.Document.Project.Save (new NullProgressMonitor ());
					return;
				}
				
				CreateNewFile (ctx, type, correctFileName);
				using (var script = ctx.StartScript ()) {
					script.Remove (type);
				}
			});
		}
Beispiel #2
0
        public override void Run(Document document, TextLocation loc)
        {
            var context = new MDRefactoringContext(document, loc);

            using (var script = context.StartScript())
                act.Run(script);
        }
		public override void BatchRun (Document document, TextLocation loc)
		{
			base.BatchRun (document, loc);
			var context = new MDRefactoringContext (document, loc);
			using (var script = context.StartScript ()) {
				foreach (var action in SiblingActions) {
					context.SetLocation (action.Start);
					action.Run (script);
				}
			}
		}
Beispiel #4
0
        public override void BatchRun(Document document, TextLocation loc)
        {
            base.BatchRun(document, loc);
            var context = new MDRefactoringContext(document, loc);

            using (var script = context.StartScript()) {
                foreach (var action in SiblingActions)
                {
                    context.SetLocation(action.Start);
                    action.Run(script);
                }
            }
        }
Beispiel #5
0
        protected IEnumerable <MonoDevelop.CodeActions.CodeAction> GetActions(MDRefactoringContext context)
        {
            if (context.IsInvalid)
            {
                yield break;
            }
            var type = GetTypeDeclaration(context);

            if (type == null)
            {
                yield break;
            }
            if (Path.GetFileNameWithoutExtension(context.Document.FileName) == type.Name)
            {
                yield break;
            }
            string title;

            if (IsSingleType(context))
            {
                title = String.Format(GettextCatalog.GetString("_Rename file to '{0}'"), Path.GetFileName(GetCorrectFileName(context, type)));
            }
            else
            {
                title = String.Format(GettextCatalog.GetString("_Move type to file '{0}'"), Path.GetFileName(GetCorrectFileName(context, type)));
            }
            yield return(new MonoDevelop.CodeActions.DefaultCodeAction(title, (d, l) =>
            {
                var ctx = new MDRefactoringContext(d, l);
                string correctFileName = GetCorrectFileName(ctx, type);
                if (IsSingleType(ctx))
                {
                    FileService.RenameFile(ctx.Document.FileName, correctFileName);
                    if (ctx.Document.Project != null)
                    {
                        ctx.Document.Project.Save(new NullProgressMonitor());
                    }
                    return;
                }

                CreateNewFile(ctx, type, correctFileName);
                using (var script = ctx.StartScript())
                {
                    script.Remove(type);
                }
            }));
        }
		public override void Run (Document document, TextLocation loc)
		{
			var context = new MDRefactoringContext (document, loc);
			using (var script = context.StartScript ())
				act.Run (script);
		}