void OnEnterInactive() { m_targetEditor = null; m_targetWindow = null; m_targetHost.Closed -= targetHost_Closed; m_targetHost = null; SelectionState = null; }
void OnEnterCanceling() { // move VS window into the foreground m_dte.MainWindow.Activate(); // move editor into the foreground m_targetWindow.Activate(); // restore selection & caret TextSelectionState.Restore(SelectionState, m_targetHost.TextView.Selection, m_targetHost.TextView.Caret); _SetState(PasteToTargetState.Inactive); }
public static TextSelectionState Save(ITextSelection selection, ITextCaret caret) { TextSelectionState ret = new TextSelectionState(); ret.m_mode = selection.Mode; ret.m_isReversed = selection.IsReversed; ret.m_caretPosition = caret.Position; ret.m_trackedSpans = new List <ITrackingSpan>(); foreach (var span in selection.SelectedSpans) { ret.m_trackedSpans.Add(selection.TextView.TextBuffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive)); } return(ret); }
public PasteToTargetOperation(Win32ClipboardMonitor monitor, DTE dte, IVsTextView targetEditor, EnvDTE.Window targetWindow) { m_monitor = monitor; Win32Operations.AddClipboardFormatListener(m_monitor.Handle); m_monitor.ClipboardChanged += monitor_ClipboardChanged; m_dte = dte; m_targetEditor = targetEditor; m_targetWindow = targetWindow; m_targetHost = VSHelpers.GetViewHost(m_targetEditor); m_targetHost.Closed += targetHost_Closed; SelectionState = TextSelectionState.Save(m_targetHost.TextView.Selection, m_targetHost.TextView.Caret); _SetState(PasteToTargetState.CaptureMode); }
void OnEnterPasting() { // get actual text string sourceText = Clipboard.GetText(); // move VS window into the foreground m_dte.MainWindow.Activate(); // move editor into the foreground m_targetWindow.Activate(); // restore selection & caret TextSelectionState.Restore(SelectionState, m_targetHost.TextView.Selection, m_targetHost.TextView.Caret); // Paste clipboard m_dte.ExecuteCommand("Edit.Paste"); _SetState(PasteToTargetState.Inactive); }
public static void Restore(TextSelectionState state, ITextSelection selection, ITextCaret caret) { caret.MoveTo( state.m_caretPosition.BufferPosition.TranslateTo(selection.TextView.TextSnapshot, PointTrackingMode.Positive), state.m_caretPosition.Affinity); selection.Mode = state.m_mode; SnapshotSpan newSpan; if (state.m_mode == TextSelectionMode.Box) { newSpan = new SnapshotSpan( state.m_trackedSpans[0].GetStartPoint(selection.TextView.TextBuffer.CurrentSnapshot), state.m_trackedSpans[state.m_trackedSpans.Count - 1].GetEndPoint(selection.TextView.TextBuffer.CurrentSnapshot)); } else { newSpan = state.m_trackedSpans[0].GetSpan(selection.TextView.TextBuffer.CurrentSnapshot); } selection.Select(newSpan, state.m_isReversed); }