Пример #1
0
        public override void CreateNewType(AstNode newType, NewTypeContext ntctx = NewTypeContext.CurrentNamespace)
        {
            if (newType == null)
            {
                throw new ArgumentNullException("newType");
            }
            var correctFileName = MoveTypeToFile.GetCorrectFileName(context, (EntityDeclaration)newType);

            var content = context.TextEditor.Text;

            var types = new List <EntityDeclaration> (context.Unit.GetTypes());

            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);
            }

            var insertLocation = types.Count > 0 ? context.GetOffset(types.Last().StartLocation) : -1;

            if (insertLocation < 0 || insertLocation > content.Length)
            {
                insertLocation = content.Length;
            }
            content = content.Substring(0, insertLocation) + newType.ToString(FormattingOptions) + content.Substring(insertLocation);

            var project = context.FileContainerProject;

            if (project != null)
            {
                var policy     = project.Policies.Get <CSharpFormattingPolicy> ();
                var textPolicy = project.Policies.Get <TextStylePolicy> ();
                content = MonoDevelop.CSharp.Formatting.CSharpFormatter.FormatText(policy, textPolicy, MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType, content, 0, content.Length);
            }

            File.WriteAllText(correctFileName, content);

            if (project != null)
            {
                project.AddFile(correctFileName);
                IdeApp.ProjectOperations.Save(project);
            }
            IdeApp.Workbench.OpenDocument(correctFileName, project);
        }
Пример #2
0
        public override void CreateNewType(AstNode newType, NewTypeContext ntctx)
        {
            if (newType == null)
            {
                throw new System.ArgumentNullException("newType");
            }
            var correctFileName = MoveTypeToFile.GetCorrectFileName(context, (EntityDeclaration)newType);

            var content = context.Document.Editor.Text;

            var types = new List <EntityDeclaration> (context.Unit.GetTypes());

            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);
            }

            var insertLocation   = types.Count > 0 ? context.GetOffset(types.Last().StartLocation) : -1;
            var formattingPolicy = this.document.GetFormattingPolicy();

            if (insertLocation < 0 || insertLocation > content.Length)
            {
                insertLocation = content.Length;
            }
            content = content.Substring(0, insertLocation) + newType.GetText(formattingPolicy.CreateOptions()) + content.Substring(insertLocation);

            var formatter = new CSharpFormatter();

            content = formatter.FormatText(formattingPolicy, null, CSharpFormatter.MimeType, content, 0, content.Length);

            File.WriteAllText(correctFileName, content);
            document.Project.AddFile(correctFileName);
            MonoDevelop.Ide.IdeApp.ProjectOperations.Save(document.Project);
            MonoDevelop.Ide.IdeApp.Workbench.OpenDocument(correctFileName);
        }
Пример #3
0
		/// <summary>
		/// Creates a new file containing the type, namespace and correct usings.
		/// (Note: Should take care of IDE specific things, file headers, add to project, correct name).
		/// </summary>
		/// <param name='newType'>
		/// New type to be created.
		/// </param>
		/// <param name='context'>
		/// The Context in which the new type should be created.
		/// </param>
		public virtual void CreateNewType(AstNode newType, NewTypeContext context = NewTypeContext.CurrentNamespace)
		{
		}
Пример #4
0
 /// <summary>
 /// Creates a new file containing the type, namespace and correct usings.
 /// (Note: Should take care of IDE specific things, file headers, add to project, correct name).
 /// </summary>
 /// <param name='newType'>
 /// New type to be created.
 /// </param>
 /// <param name='context'>
 /// The Context in which the new type should be created.
 /// </param>
 public virtual void CreateNewType(AstNode newType, NewTypeContext context = NewTypeContext.CurrentNamespace)
 {
 }
		public override void CreateNewType (AstNode newType, NewTypeContext ntctx)
		{
			if (newType == null)
				throw new System.ArgumentNullException ("newType");
			var correctFileName = MoveTypeToFile.GetCorrectFileName (context, (EntityDeclaration)newType);
			
			var content = context.TextEditor.Text;
			
			var types = new List<EntityDeclaration> (context.Unit.GetTypes ());
			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);
			}
			
			var insertLocation = types.Count > 0 ? context.GetOffset (types.Last ().StartLocation) : -1;
			if (insertLocation < 0 || insertLocation > content.Length)
				insertLocation = content.Length;
			content = content.Substring (0, insertLocation) + newType.ToString (FormattingOptions) + content.Substring (insertLocation);

			var formatter = new MonoDevelop.CSharp.Formatting.CSharpFormatter ();
			var policy = context.Project.Policies.Get<CSharpFormattingPolicy> ();
			var textPolicy = context.Project.Policies.Get<TextStylePolicy> ();

			content = formatter.FormatText (policy, textPolicy, MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType, content, 0, content.Length);

			File.WriteAllText (correctFileName, content);
			context.Project.AddFile (correctFileName);
			IdeApp.ProjectOperations.Save (context.Project);
			IdeApp.Workbench.OpenDocument (correctFileName);
		}
Пример #6
0
//        public override void Rename(IVariable variable, string name)
//        {
//            FindReferences refFinder = new FindReferences();
//            refFinder.FindLocalReferences(variable,
//                                          _context.UnresolvedFile,
//                                          _context.RootNode as SyntaxTree,
//                                          _context.Compilation, (n, r) => Rename(n, name),
//                                          _context.CancellationToken);
//        }
//
//        public override void RenameTypeParameter(IType type, string name = null)
//        {
//            FindReferences refFinder = new FindReferences();
//            refFinder.FindTypeParameterReferences(type,
//                                                  _context.UnresolvedFile,
//                                                  _context.RootNode as SyntaxTree,
//                                                  _context.Compilation, (n, r) => Rename(n, name),
//                                                  _context.CancellationToken);
//        }

        public override void CreateNewType(AstNode newType, NewTypeContext context = NewTypeContext.CurrentNamespace)
        {
            var output = OutputNode(0, newType, true);

            InsertText(0, output.Text);
        }
 public override void CreateNewType(AstNode newType, NewTypeContext context)
 {
     var output = OutputNode (0, newType, true);
     InsertText (0, output.Text);
 }