void delete_Click(object sender, RoutedEventArgs e) { if (selection != null) { editorModel.Montage.Patches.Remove(selection.Item); } selection = null; InvalidateVisual(); }
/// <summary> /// Make the desired changes in the document. /// </summary> /// <param name="desiredLength">The desired character length for the region. Selections will be retrieved and reflected in the document</param> public void makeChangesInDocument(int desiredLength) { /* This is the way we have to make changes in the document when the slider moves. * What we should be able to do: Range.Text = PatchSelection.selection * What we have to do instead: * Collapse the patch's range to the beginning of the range * Add the new text after this 0-length range. The range now extends to contain this new text. * Collapse the range to it's end. This puts a 0-length range between the new text and the old text to be deleted. * Delete the next n characters, where n is the length of the old text. i.e. delete the old text. * Move the starting point of the range to the beginning of the new text. Now the range reflects the location of the new text. * * Why do we have to do this? Ranges behave weirdly when you add/remove text at the point where ranges touch. * By doing this convoluted process, we ensure that we never add/remove text in a way that causes ranges to overlap. */ List <PatchSelection> pSelections = getPatchSelections(desiredLength); for (int i = 0; i < pSelections.Count; i++) { PatchSelection selection1 = pSelections[i]; if (selection1.isCurrent) { continue; } int originalLength = selection1.patch.range.End - selection1.patch.range.Start; string newString = selection1.selection; int newLength = newString.Length; /* * if (newLength == 0) * { * newString = " "; * newLength = 1; * } */ selection1.patch.range.Collapse(); //Collapse to the beginning selection1.patch.range.InsertAfter(newString); //Insert the new text int newStart = selection1.patch.range.Start; int newEnd = selection1.patch.range.End; selection1.patch.range.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd); //Collapse to the end selection1.patch.range.Delete(Microsoft.Office.Interop.Word.WdUnits.wdCharacter, originalLength); //Delete old text selection1.patch.range.SetRange(newStart, newEnd); // Fix the range if (originalLength == 0) { fixFutureRangeStarts(pSelections, i, newStart); } } }
public IEnumerable <PatchLocation> Select(PatchSelection selection) { //return new EnumHelper<PatchLocation>(GetEnumerator(selection)); var iSelection = (int)selection; for (var i = 0; i < 25; i++) { if ((iSelection & (1 << i)) != 0) { yield return(_locations[i]); } } yield break; }
public static void fixFutureRangeStarts(List <PatchSelection> pSelections, int i, int start) { PatchSelection first = pSelections[i]; if (i + 1 < pSelections.Count) { PatchSelection next = pSelections[i + 1]; if (next.patch.range.Start == start) { next.patch.range.Start = first.patch.range.End; fixFutureRangeStarts(pSelections, i + 1, start); } else { return; } } }
void PatchPanel_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (editorModel == null) { return; } selection = FindSelection(e.GetPosition(this)); drag = selection != null; InvalidateVisual(); if (selection == null && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { OnTimeSelected(MsAtPoint(e.GetPosition(this)), false); } if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed) { menuCalled = e.GetPosition(this); ContextMenu = selection == null?forEmpty:forExisting; //ContextMenu.IsOpen=true; } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Get Updated Text //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static string GetUpdatedText(PatchSelection ePatchSelection, string defaultText = "") { // Has updated text from latest text file? if (sm_sResultingText != "") { switch (ePatchSelection) { case PatchSelection.FACEBOOK_TITLE: return(GetRegexMatch("FacebookTitle" + SelectedLanguage + "=\"(.+)\"", defaultText)); case PatchSelection.FACEBOOK_CAPTION: return(GetRegexMatch("FacebookCaption" + SelectedLanguage + "=\"(.+)\"", defaultText)); case PatchSelection.FACEBOOK_LINK: return(GetRegexMatch("FacebookLink" + SelectedLanguage + "=\"(.+)\"", defaultText)); default: return(defaultText); } } // Don't have anything for you. Whatever was provided will have to do. else { return(defaultText); } }
public IEnumerable<PatchLocation> Select(PatchSelection selection) { //return new EnumHelper<PatchLocation>(GetEnumerator(selection)); var iSelection = (int)selection; for (var i = 0; i < 25; i++) if ((iSelection & (1 << i)) != 0) yield return _locations[i]; yield break; }