Пример #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);
		}
Пример #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);
		}
Пример #3
0
 internal Caret(Caret other)
     : this(other.document, other.line, other.column)
 {
 }
Пример #4
0
 public static Pair<Caret, Caret> Order(Caret a, Caret b)
 {
     return new Pair<Caret, Caret>(Min(a, b), Max(a, b));
 }
Пример #5
0
 public static Caret Min(Caret l, Caret r)
 {
     return l > r ? r : l;
 }
Пример #6
0
 public static Caret Max(Caret l, Caret r)
 {
     return l > r ? l : r;
 }
Пример #7
0
 public bool Contains(Caret c)
 {
     return Start <= c && End >= c;
 }
Пример #8
0
 public Region(Caret start, Caret end)
 {
     Start = new Caret(Caret.Min(start, end));
     End = new Caret(Caret.Max(start, end));
 }
Пример #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;
			}
		}