Esempio n. 1
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.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.PlayScript.Formatting.CSharpFormatter();
            var policy     = context.Project.Policies.Get <PlayScriptFormattingPolicy> ();
            var textPolicy = context.Project.Policies.Get <TextStylePolicy> ();

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

            File.WriteAllText(correctFileName, content);
            context.Project.AddFile(correctFileName);
            IdeApp.ProjectOperations.Save(context.Project);
            IdeApp.Workbench.OpenDocument(correctFileName);
        }
		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);
		}
Esempio n. 3
0
        public void FormatSample()
        {
            var formatter = new CSharpFormatter();

            texteditor.Document.Text = formatter.FormatText(policy, null, CSharpFormatter.MimeType, example, 0, example.Length);
        }
		void UpdateExample (string example)
		{
			var formatter = new CSharpFormatter ();
			string text;
			if (!string.IsNullOrEmpty (example)) {
				text = Environment.NewLine != "\n" ? example.Replace ("\n", Environment.NewLine) : example;
			} else {
				text = "";
			}
			texteditor.Document.Text = formatter.FormatText (profile, null, CSharpFormatter.MimeType, text, 0, text.Length);
		}
		public void FormatSample ()
		{
			var formatter = new CSharpFormatter ();
			texteditor.Document.Text = formatter.FormatText (policy, null, CSharpFormatter.MimeType, example, 0, example.Length);
		}