/// <summary> /// Load the contents of an external file to the copy buffer /// Returns the column count /// </summary> public static void Load(string filename, ref TASMovieInputCollection buffer) { StreamReader reader = File.OpenText(filename); string header = reader.ReadLine(); int controllers = 0; // TODO::This is a weak validation routine if (header.Length != 3) { MessageBox.Show(frmMain.frm, "Buffer file appears to be invalid", "Oops", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); return; } string lineItem = null; while ((lineItem = reader.ReadLine()) != null) { TASMovieInput[] frame = new TASMovieInput[1]; string[] split = lineItem.Split('|'); for (int i = 0; i < split.Length; i++) { frame[0].Controller[i] = split[i]; } TASMovieInput.Insert(ref buffer.Input, ref frame, buffer.Input.Length); controllers = split.Length; } reader.Close(); reader.Dispose(); buffer.Format = (TASForm.MovieType)Enum.Parse(typeof(TASForm.MovieType), header); buffer.Controllers = controllers; }
/// <summary> /// Insert the buffered frame input at/after the selected position. /// </summary> private void pasteFrames(bool after) { bool notEmpty = (lvInput.Items.Count > 0); if (notEmpty) { // check for a valid paste position if (lvInput.SelectedIndices.Count == 0) { return; } } int framePos = notEmpty ? (after ? lvInput.SelectedIndices[lvInput.SelectedIndices.Count - 1] + 1: lvInput.SelectedIndices[0]) : 0; // confirm whether to paste frames if (mnuEditingPrompt.Checked) { DialogResult confirmPaste = MessageBox.Show(this, "Paste " + FrameBuffer.Input.Length + " frame(s) " + (notEmpty && after ? "after frame " + (framePos - 1) : "at frame " + framePos) + " ?", "Confirm Paste", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (confirmPaste != DialogResult.OK) { return; } } UndoBuffer.Add(ref UndoHistory, ref FrameData.Input); TASMovieInput.Insert(ref FrameData.Input, ref FrameBuffer.Input, framePos); updateControlsAfterEdit(); lvInput.SelectedIndices.Clear(); for (int i = 0; i < FrameBuffer.Input.Length; i++) { lvInput.Items[framePos + i].Selected = true; } int focusPos = lvInput.SelectedIndices[lvInput.SelectedIndices.Count - 1]; lvInput.Items[focusPos].Focused = true; lvInput.Focus(); lvInput.EnsureVisible(focusPos); lvInput.Refresh(); Msg.AddMsg("Pasted " + FrameBuffer.Input.Length + " frame(s)"); }
/// <summary> /// Append a blank row into the listview after the selectedIndex point and /// update the inputArray, or prompt for insertion of multiple frames based /// on how many frames were selected. /// </summary> private void appendFrames() { int framePosition = FrameData.Input.Length; int totalFrames = 1; // make sure something is selected if (lvInput.SelectedIndices.Count > 0) { framePosition = lvInput.SelectedIndices[lvInput.SelectedIndices.Count - 1] + 1; totalFrames = lvInput.SelectedIndices.Count; } if (FrameData.Input.Length == 0) { framePosition = 0; } // prompt for multiple frame insertion if (lvInput.SelectedIndices.Count > 1 && mnuEditingPrompt.Checked) { DialogResult confirmAdd = MessageBox.Show(this, "Are you sure you want to append " + totalFrames + " frames after frame " + framePosition, "Confirm Multiple Frame Insertion", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (confirmAdd != DialogResult.OK) { return; } } UndoBuffer.Add(ref UndoHistory, ref FrameData.Input); TASMovieInput.Insert(ref FrameData.Input, new TASMovieInput(), framePosition, totalFrames); updateControlsAfterEdit(); Msg.AddMsg("Appended " + totalFrames + " frame(s) after position " + framePosition); }
/// <summary> /// Insert the buffered frame input at/after each selected position. /// </summary> private void pasteFramesMultiple(bool after) { // check for a valid paste position if (lvInput.SelectedIndices.Count <= 1) { return; } int[] selectedIndices = new int[lvInput.SelectedIndices.Count]; if (after) { for (int i = 0; i < selectedIndices.Length; i++) { selectedIndices[i] = lvInput.SelectedIndices[i] + 1; } } else { lvInput.SelectedIndices.CopyTo(selectedIndices, 0); } bool multiplePaste = false; // ask whether to paste multiple times if (mnuEditingPrompt.Checked) { DialogResult confirmPaste = MessageBox.Show(this, "Paste " + selectedIndices.Length + " chunks of " + FrameBuffer.Input.Length + " frame(s) " + (after ? "after" : "before") + " each selected frame?\nWarning: this might be extremely slow!", "Confirm Paste", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (confirmPaste == DialogResult.Yes) { multiplePaste = true; } else if (confirmPaste == DialogResult.No) { multiplePaste = false; } else { return; } } UndoBuffer.Add(ref UndoHistory, ref FrameData.Input); if (multiplePaste) { TASMovieInput.InsertMultiple(ref FrameData.Input, ref FrameBuffer.Input, selectedIndices); } else { TASMovieInput.Insert(ref FrameData.Input, ref FrameBuffer.Input, (after ? selectedIndices[selectedIndices.Length - 1] : selectedIndices[0])); } lvInput.ClearVirtualCache(); lvInput.VirtualListSource = FrameData.Input; lvInput.VirtualListSize = FrameData.Input.Length; lvInput.SelectedIndices.Clear(); lvInput.Refresh(); if (multiplePaste) { for (int i = 0; i < selectedIndices.Length; i++) { for (int j = 0; j < FrameBuffer.Input.Length; j++) { lvInput.Items[selectedIndices[i] + i * FrameBuffer.Input.Length + j].Selected = true; } } } else { int startPos = (after ? selectedIndices[selectedIndices.Length - 1] : selectedIndices[0]); for (int i = 0; i < FrameBuffer.Input.Length; i++) { lvInput.Items[startPos + i].Selected = true; } } int focusPos = lvInput.SelectedIndices[lvInput.SelectedIndices.Count - 1]; lvInput.Items[focusPos].Focused = true; lvInput.Focus(); lvInput.EnsureVisible(focusPos); updateControlsAfterEdit(); if (multiplePaste) { Msg.AddMsg("Pasted " + lvInput.SelectedIndices.Count + " chunks of " + FrameBuffer.Input.Length + " frame(s)"); } else { Msg.AddMsg("Pasted " + FrameBuffer.Input.Length + " frame(s)"); } }