Ejemplo n.º 1
0
		public Document(string filePath, bool needSaveAs)
		{
			this.needSaveAs = needSaveAs;
		
			if (!File.Exists(filePath))
				throw new FileNotFoundException("\"{0}\" does not exist.".F(filePath), filePath);

			try
			{
				foreach (string line in GetFileContent(filePath))
					lines.Add(new Line(line, LineModification.Clean, this));
			}
			catch
			{
				throw new FileNotFoundException("\"{0}\" could not be opened.".F(filePath), filePath);
			}

			point = new Caret(this);
			mark = new Caret(this);

			this.filePath = filePath;
			this.fileType = Config.ChooseFileType(filePath);

			if (lines.Count == 0)
				lines.Add(new Line("", LineModification.Clean, this));

			lastModified = File.GetLastWriteTime(filePath);
		}
Ejemplo n.º 2
0
		public void ReplaceText(string newText, bool indent)
		{
			var before = Caret.Order(point, mark);
			BeforeReplace(Selection);

			if (before.Second != before.First)
			{
				if (before.Second.Line > before.First.Line + 1)
				{
					lines.RemoveRange(before.First.Line + 1, before.Second.Line - before.First.Line - 1);
					before.Second.Line = before.First.Line + 1;
				}

				while (before.Second > before.First)
					before.Second.DeleteLeft();

				Mark = Point = new Caret(before.First);
			}

			point.Insert(newText, indent);

			AfterReplace(Selection);
		}
Ejemplo n.º 3
0
 internal Caret(Caret other)
     : this(other.document, other.line, other.column)
 {
 }
Ejemplo n.º 4
0
 public static Pair<Caret, Caret> Order(Caret a, Caret b)
 {
     return new Pair<Caret, Caret>(Min(a, b), Max(a, b));
 }
Ejemplo n.º 5
0
 public static Caret Min(Caret l, Caret r)
 {
     return l > r ? r : l;
 }
Ejemplo n.º 6
0
 public static Caret Max(Caret l, Caret r)
 {
     return l > r ? l : r;
 }
Ejemplo n.º 7
0
 public bool Contains(Caret c)
 {
     return Start <= c && End >= c;
 }
Ejemplo n.º 8
0
 public Region(Caret start, Caret end)
 {
     Start = new Caret(Caret.Min(start, end));
     End = new Caret(Caret.Max(start, end));
 }
Ejemplo n.º 9
0
		public void MovePoint(Direction direction)
		{
			switch (direction)
			{
				case Direction.Left: point.MoveLeft(); break;
				case Direction.Right: point.MoveRight(); break;
				case Direction.Up: point.MoveVertically( -1 ); break;
				case Direction.Down: point.MoveVertically( 1 ); break;
				case Direction.DownLineStart: point.MoveDownStart( 1 ); break;
				case Direction.LineStart: point.MoveHome(); break;
				case Direction.LineEnd: point.MoveEnd(); break;
				case Direction.AbsoluteLineStart:
					point.MoveHome();
					if (point.Column > 0)
						point.MoveHome();
					break;

				case Direction.DocumentStart: point = Caret.AtStartOfDocument(this); break;
				case Direction.DocumentEnd: point = Caret.AtEndOfLine(this, lines.Count - 1);
					break;
			}
		}