Ejemplo n.º 1
0
        static void CheckStartPoint(IDocument doc, InsertionPoint point, bool isEndPoint)
        {
            var line = GetLineOrNull(doc, point.Location.Line);

            if (line == null)
            {
                return;
            }
            if (GetLineIndent(doc, line).Length + 1 == point.Location.Column)
            {
                int lineNr = point.Location.Line;
                while (lineNr > 1 && GetLineIndent(doc, lineNr - 1).Length == doc.GetLineByNumber(lineNr - 1).Length)
                {
                    lineNr--;
                }
                line           = GetLineOrNull(doc, lineNr);
                point.Location = new TextLocation(lineNr, GetLineIndent(doc, line).Length + 1);
            }

            if (GetLineIndent(doc, line).Length + 1 < point.Location.Column)
            {
                point.LineBefore = NewLineInsertion.Eol;
            }
            if (point.Location.Column < line.Length + 1)
            {
                point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine;
            }
        }
Ejemplo n.º 2
0
        public override Task <Script> InsertWithCursor(string operation, InsertPosition defaultPosition, IList <AstNode> nodes)
        {
            // TODO : Use undo group
            var tcs             = new TaskCompletionSource <Script>();
            var loc             = editor.Caret.Location;
            var currentPart     = context.UnresolvedFile.GetInnermostTypeDefinition(loc);
            var insertionPoints = InsertionPoint.GetInsertionPoints(editor.Document, currentPart);

            if (insertionPoints.Count == 0)
            {
                SD.MessageService.ShowErrorFormatted("No valid insertion point can be found in type '{0}'.", currentPart.Name);
                return(tcs.Task);
            }

            TextArea area = editor.GetService <TextArea>();

            if (area == null)
            {
                return(tcs.Task);
            }

            var layer = new InsertionCursorLayer(area, operation, insertionPoints);

            switch (defaultPosition)
            {
            case InsertPosition.Start:
                layer.CurrentInsertionPoint = 0;
                break;

            case InsertPosition.End:
                layer.CurrentInsertionPoint = insertionPoints.Count - 1;
                break;

            case InsertPosition.Before:
                for (int i = 0; i < insertionPoints.Count; i++)
                {
                    if (insertionPoints[i].Location < loc)
                    {
                        layer.CurrentInsertionPoint = i;
                    }
                }
                break;

            case InsertPosition.After:
                for (int i = 0; i < insertionPoints.Count; i++)
                {
                    if (insertionPoints[i].Location > loc)
                    {
                        layer.CurrentInsertionPoint = i;
                        break;
                    }
                }
                break;
            }
            InsertWithCursorOnLayer(this, layer, tcs, nodes, editor.Document);
            return(tcs.Task);
        }
Ejemplo n.º 3
0
 public InsertionCursorEventArgs(InsertionPoint insertionPoint, bool success)
 {
     if (insertionPoint == null)
     {
         throw new ArgumentNullException("insertionPoint");
     }
     this.InsertionPoint = insertionPoint;
     this.Success        = success;
 }
Ejemplo n.º 4
0
        static void CheckEndPoint(IDocument doc, InsertionPoint point, bool isStartPoint)
        {
            var line = GetLineOrNull(doc, point.Location.Line);

            if (line == null)
            {
                return;
            }

            if (GetLineIndent(doc, line).Length + 1 < point.Location.Column)
            {
                point.LineBefore = NewLineInsertion.BlankLine;
            }
            if (point.Location.Column < line.Length + 1)
            {
                point.LineAfter = NewLineInsertion.Eol;
            }
        }
Ejemplo n.º 5
0
        public override Task <Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func <Script, RefactoringContext, IList <AstNode> > nodeCallback)
        {
            // TODO : Use undo group
            var tcs = new TaskCompletionSource <Script>();

            if (parentType == null)
            {
                return(tcs.Task);
            }
            IUnresolvedTypeDefinition part = null;

            foreach (var p in parentType.Parts)
            {
                if (part == null || EntityModelContextUtils.IsBetterPart(p, part, ".cs"))
                {
                    part = p;
                }
            }

            if (part == null)
            {
                return(tcs.Task);
            }

            var          fileName = new ICSharpCode.Core.FileName(part.Region.FileName);
            IViewContent document = SD.FileService.OpenFile(fileName);
            var          area     = document.GetService <TextArea>();

            if (area == null)
            {
                return(tcs.Task);
            }

            var          loc           = part.Region.Begin;
            var          parsedFile    = SD.ParserService.ParseFile(fileName, area.Document, cancellationToken: context.CancellationToken);
            var          declaringType = parsedFile.GetInnermostTypeDefinition(loc);
            EditorScript script;

            if (area.Document != context.Document)
            {
                script = new EditorScript(area.GetService <ITextEditor>(), SDRefactoringContext.Create(fileName, area.Document, loc, context.CancellationToken), FormattingOptions);
                startedScripts.Add(script);
            }
            else
            {
                script = this;
            }
            var nodes           = nodeCallback(script, script.context);
            var insertionPoints = InsertionPoint.GetInsertionPoints(area.Document, part);

            if (insertionPoints.Count == 0)
            {
                SD.MessageService.ShowErrorFormatted("No valid insertion point can be found in type '{0}'.", part.Name);
                return(tcs.Task);
            }

            var layer = new InsertionCursorLayer(area, operation, insertionPoints);

            area.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)area.TextView.InvalidateVisual);

            if (declaringType.Kind == TypeKind.Enum)
            {
                foreach (var node in nodes.Reverse())
                {
                    int indentLevel = GetIndentLevelAt(area.Document.GetOffset(declaringType.BodyRegion.Begin));
                    var output      = OutputNode(indentLevel, node);
                    var point       = insertionPoints[0];
                    var offset      = area.Document.GetOffset(point.Location);
                    var text        = output.Text + ",";
                    var delta       = point.Insert(area.Document, text);
                    output.RegisterTrackedSegments(script, delta + offset);
                }
                tcs.SetResult(script);
                return(tcs.Task);
            }
            InsertWithCursorOnLayer(script, layer, tcs, nodes, area.Document);
            return(tcs.Task);
        }
Ejemplo n.º 6
0
		public InsertionCursorEventArgs(InsertionPoint insertionPoint, bool success)
		{
			if (insertionPoint == null)
				throw new ArgumentNullException("insertionPoint");
			this.InsertionPoint = insertionPoint;
			this.Success = success;
		}
Ejemplo n.º 7
0
		static void CheckStartPoint (IDocument doc, InsertionPoint point, bool isEndPoint)
		{
			var line = GetLineOrNull(doc, point.Location.Line);
			if (line == null)
				return;
			if (GetLineIndent (doc, line).Length + 1 == point.Location.Column) {
				int lineNr = point.Location.Line;
				while (lineNr > 1 && GetLineIndent(doc, lineNr - 1).Length == doc.GetLineByNumber (lineNr - 1).Length) {
					lineNr--;
				}
				line = GetLineOrNull(doc, lineNr);
				point.Location = new TextLocation (lineNr, GetLineIndent (doc, line).Length + 1);
			}
			
			if (GetLineIndent (doc, line).Length + 1 < point.Location.Column)
				point.LineBefore = NewLineInsertion.Eol;
			if (point.Location.Column < line.Length + 1)
				point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine;
		}
Ejemplo n.º 8
0
		static void CheckEndPoint (IDocument doc, InsertionPoint point, bool isStartPoint)
		{
			var line = GetLineOrNull(doc, point.Location.Line);
			if (line == null)
				return;
			
			if (GetLineIndent (doc, line).Length + 1 < point.Location.Column)
				point.LineBefore = NewLineInsertion.BlankLine;
			if (point.Location.Column < line.Length + 1)
				point.LineAfter = NewLineInsertion.Eol;
		}