public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { editorValues.RepeatLines = GetRepeatLines(cmd); if (editorValues.CurrentLine > 0) { if (editorValues.RepeatLines == 0) { // delete current line textFile.Delete(editorValues.CurrentLine); } else { // delete multiple lines if (editorValues.CommandInfo.IndexOf(editorValues.Delim) > -1) { int lastLine = editorValues.CurrentLine + editorValues.RepeatLines - 1; if (lastLine > textFile.Lines) { lastLine = textFile.Lines; } for (int i = editorValues.CurrentLine; i <= lastLine; i++) { textFile.Delete(editorValues.CurrentLine); } } } } return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { if (editorValues.CurrentLine > 0) { Output(textFile.DisplayLine(editorValues.CurrentLine, true)); } return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { textFile.Flip(); textFile.Save(); Output("Saved"); return(true); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { textFile.Cancel(); if (editorValues.CurrentLine > textFile.Lines) { editorValues.CurrentLine = textFile.Lines; } return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { // change page size and list page string temp = cmd.Substring(1); int lines = 0; bool linesOk = int.TryParse(temp, out lines); if (lines > 0) { editorValues.PageSize = lines; } if (textFile.Lines > 0) { int startLine = editorValues.CurrentLine + 1; int endLine = startLine + editorValues.PageSize; if (endLine > textFile.Lines) { endLine = textFile.Lines; } if (startLine < endLine) { for (int i = startLine; i < endLine; i++) { Output(textFile.DisplayLine(i, true)); } } else { Output(textFile.DisplayLine(editorValues.CurrentLine, true)); } editorValues.CurrentLine += editorValues.PageSize; if (editorValues.CurrentLine > textFile.Lines - 1) { editorValues.CurrentLine = textFile.Lines - 1; } } else { editorValues.CurrentLine = 0; } return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { bool exit = false; if (textFile.HasChanged) { ReceiveInputEventArgs args = new ReceiveInputEventArgs("File has changed. Exit without saving (Y/N)? "); //OnReceiveInput(args); if (args.InputValue.Substring(0, 1).ToUpper() == "Y") { exit = true; } } else { exit = true; } return(exit); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { bool exitInsert = false; while (!exitInsert) { Console.Write(string.Format("{0:000}+", editorValues.CurrentLine)); string newLine = Console.ReadLine(); if (newLine != string.Empty) { textFile.Insert(editorValues.CurrentLine, newLine, true); editorValues.CurrentLine++; } else { exitInsert = true; } } return(false); }
public bool ProcessCommand2(string command) { bool exit = false; string commandToProcess = command.ToUpper(); EditorValues editorValues = new EditorValues() { CommandInfo = string.Empty, RepeatLines = 0, Delim = string.Empty }; int lineNumber = 0; bool isLineNuber = int.TryParse(command, out lineNumber); if (isLineNuber && lineNumber <= _TextFile.Lines) { // entered a line number editorValues.CurrentLine = lineNumber; commandToProcess = "."; } CommandMetadata commandMetadata = _Commands.FirstOrDefault(item => commandToProcess.StartsWith(item.Prefix)); if (commandMetadata != null) { CommandBase commandObject = Activator.CreateInstance(commandMetadata.CommandType) as CommandBase; if (commandObject != null) { if (commandObject.PreProcess(command)) { exit = commandObject.Process(commandToProcess, _TextFile, editorValues); } } } return(exit); }
public virtual bool Process(string cmd, TextFile textFile, EditorValues editorValues) { return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { bool cont = false; editorValues.RepeatLines = GetRepeatLines(cmd); editorValues.Delim = GetDelimiter(cmd); if (editorValues.RepeatLines == 0) { editorValues.RepeatLines = 1; editorValues.CommandInfo = cmd.Substring(2); cont = true; } else { string[] sections = cmd.Substring(1).Split(Convert.ToChar(editorValues.Delim)); if (sections.Length >= 2) { int pos = cmd.IndexOf(editorValues.Delim); string lines = cmd.Substring(1, pos - 1); editorValues.RepeatLines = 1; int repeatLines = editorValues.RepeatLines; bool linesOk = int.TryParse(lines, out repeatLines); if (linesOk) { editorValues.CommandInfo = cmd.Substring(pos + 1); editorValues.RepeatLines = repeatLines; cont = true; } } } if (cont) { if (editorValues.CurrentLine > 0) { if (editorValues.CommandInfo == string.Empty) { // replace entire line Console.Write(editorValues.CurrentLine.ToString() + " "); string newLine = Console.ReadLine(); textFile.Replace(editorValues.CurrentLine, newLine); } else { // perform calculated replace if (editorValues.CommandInfo.IndexOf(editorValues.Delim) > -1) { string[] replacementInfo = editorValues.CommandInfo.Split(Convert.ToChar(editorValues.Delim)); string oldText = replacementInfo[0]; string newText = replacementInfo[1]; for (int i = editorValues.CurrentLine; i <= editorValues.CurrentLine + editorValues.RepeatLines - 1; i++) { if (oldText == "" && newText != "") { // insert new text in front of the line textFile.Insert(i, newText); } else if (oldText != "" && newText != "") { // replace old text with new text textFile.Replace(i, oldText, newText); } else if (oldText != "" && newText == "" && replacementInfo.Length > 2) { // remove old text textFile.Replace(i, oldText, ""); } Output(textFile.DisplayLine(i, true)); } } editorValues.CurrentLine += editorValues.RepeatLines - 1; } } } return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { textFile.Flip(); return(false); }
public override bool Process(string cmd, TextFile textFile, EditorValues editorValues) { Output("-- ED.Net"); Output("-- A Pick-like line editor developed in C#"); Output("-- www.melvicorp.com"); Output(""); Output("Available commands and instructions:"); Output(""); Output("."); Output(" Displays the current line."); Output("{enter}"); Output(" Displays the current line and increments the current line number."); Output("L[xx]"); Output(" Lists the next page of text lines based on the current page size"); Output(" (20 by default). If [xx] is specfied, then [xx] number of lines"); Output(" are listed and the current page size is reset to [xx] number of lines."); Output("T"); Output(" Sets the current line counter to the top of the file."); Output("R[xx][/old/new"); Output(" Performs a 'replace' operation."); Output(" If 'R' is used on its own then you are given the opportunity to"); Output(" replace the entire line. Specifying [xx] will perform the 'replace'"); Output(" operation for [xx] number of lines."); Output(" The 'old' and 'new' specify the text you want to replace and with"); Output(" what you it to be replaced. The delimiter specified as '/' can be"); Output(" any character you like in order to use any other characters"); Output(" in the 'old' and 'new' text. Specifying no 'old' text will insert"); Output(" the 'new' text at the beginning of the line(s)."); Output(" Usage examples:"); Output(" R/Using/Imports"); Output(" Replaces all instances of 'Using' with the text 'Imports'."); Output(" R12/Using/Imports"); Output(" Performs the same operation for the next 12 lines."); Output(" R5//''"); Output(" Inserts two tick marks in front of of the next 5 lines."); Output(" R5..//"); Output(" Inserts two slashes in front of the next five lines."); Output(" R.1/5/2008.01/05/2008"); Output(" Replaces the text '1/5/2008' with the text '01/05/2008'."); Output("I[xx]"); Output(" Places the editor into 'Insert' mode at a point immediately following"); Output(" the current line. Hitting {enter} on a line witout typing any text"); Output(" will exit 'Insert' mode. Specifying [xx] will end 'Insert' mode"); Output(" after [xx] number of lines are inserted."); Output("AL[xx]/text"); Output(" Performs an append opperation to a line or two [xx] number of lines."); Output(" The delimiter specified by the '/' can be any character in order to"); Output(" accomodate any text to be appended."); Output("D[xx]"); Output(" Deletes the current line, or [xx] number of lines."); Output("X"); Output(" Rolls back the all changes since the last 'flip'"); Output(" (see the commands below)."); Output("F"); Output(" Performs a 'flip' operation. When any 'replace', insert', 'append',"); Output(" or 'delete' command is performed, the operations can be rolled back"); Output(" using the 'X' command. Performing a 'flip' operation brings those"); Output(" changes to permanent status. Note, permanent does not signify 'saved'."); Output("FS"); Output(" Performs a 'flip' operation followed by a 'save' operation."); Output("FI"); Output(" Performs a 'flip' operation followed by a 'save' operation; afterwhich"); Output(" the edit is exited."); Output("EX"); Output(" Exits the editor in the current state of the file. If the file has"); Output(" changed since it was initially read in, the user will receive a"); Output(" confirmation message."); Output(""); return(false); }