/// <summary> /// Commits the or reset. /// </summary> /// <returns><c>true</c>, if or reset was commited, <c>false</c> otherwise.</returns> public bool CommitOrReset() { // don't check if we have focus - we won't if this gets called from OnLostFocus. // However, the IbusKeyboardAdapter calls this method only for the control that just // lost focus, so it's ok not to check :-) if (IsCommittingKeyboard) { if (m_InitialSelection != null && m_EndOfPreedit != null) { ITsString tss; var selection = AssociatedSimpleRootSite.RootBox.MakeRangeSelection( m_InitialSelection.RestoreSelection(), m_EndOfPreedit.SetSelection(AssociatedSimpleRootSite), true); selection.GetSelectionString(out tss, string.Empty); OnCommitText(tss.Text, false); m_InitialSelection = null; m_EndOfPreedit = null; } return(false); } return(Reset(true)); }
private void Init() { DeleteCommand = ReactiveCommand.Create( execute: () => { if (SelectedValues == null) { return; } SelectionWrapper[] vms = new SelectionWrapper[SelectedValues.Count]; for (int i = 0; i < vms.Length; i++) { vms[i] = (SelectionWrapper)SelectedValues[i] !; } Values.Remove(vms); }, canExecute: this.WhenAnyValue(x => x.SelectedValues !.Count) .Select(x => x > 0)); AddCommand = ReactiveCommand.Create( execute: () => { ; Values.Add(new SelectionWrapper() { IsSelected = true, Value = (ObjectSettingsVM)_prototype.Duplicate() }); }); }
/// <summary> /// Reset the selection and optionally cancel any open compositions. /// </summary> /// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param> /// <returns><c>true</c> if there was an open composition that we cancelled, otherwise /// <c>false</c>.</returns> private bool Reset(bool cancel) { if (m_InReset) { return(false); } bool retVal = false; m_InReset = true; try { if (cancel) { if (m_ActionHandler != null && (m_ActionHandler.get_TasksSinceMark(true) || m_Depth != m_ActionHandler.CurrentDepth)) { m_ActionHandler.Rollback(m_Depth); retVal = true; } else if (m_InitialSelection != null && m_EndOfPreedit != null) { var selHelper = SetupForTypingEventHandler(false, true); if (selHelper != null) { // Update selection so that we can delete the preedit-text UpdateSelectionForReplacingPreeditText(selHelper, 0); selHelper.SetSelection(true); if (selHelper.IsValid && selHelper.IsRange) { var tss = CreateTsStringUsingSelectionProps(string.Empty, null, false); selHelper.Selection.ReplaceWithTsString(tss); } } } } m_ActionHandler = null; if (m_InitialSelection != null) { m_InitialSelection.RestoreSelection(); } m_InitialSelection = null; m_EndOfPreedit = null; return(retVal); } finally { m_InReset = false; OnPreeditClosed(); } }
private void OnCommitText(string text, bool checkIfFocused) { var selHelper = SetupForTypingEventHandler(checkIfFocused, true); if (selHelper == null) { return; } try { var selectionProps = GetSelectionProps(selHelper); var countBackspace = TrimBeginningBackspaces(ref text); var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); selHelper.IchAnchor = Math.Max(0, selHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace); selHelper.IchEnd = bottom; selHelper.SetSelection(true); UpdateSelectionForReplacingPreeditText(selHelper, countBackspace); // Insert 'text' ITsString str = CreateTsStringUsingSelectionProps(text, selectionProps, false); selHelper.Selection.ReplaceWithTsString(str); } finally { m_InitialSelection = null; m_EndOfPreedit = null; if (m_ActionHandler != null) { m_ActionHandler.EndUndoTask(); m_ActionHandler = null; } OnPreeditClosed(); } }
public void OnUpdatePreeditText(object obj, int cursorPos) { if (AssociatedSimpleRootSite.InvokeRequired) { AssociatedSimpleRootSite.BeginInvoke(() => OnUpdatePreeditText(obj, cursorPos)); return; } var selHelper = SetupForTypingEventHandler(true, false); if (selHelper == null) { return; } if (m_InitialSelection == null) { // Create a new, independent selection helper for m_InitialSelHelper - we want // to remember the current selection m_InitialSelection = new SelectionWrapper(AssociatedSimpleRootSite); OnPreeditOpened(); } var ibusText = obj as IBusText; var compositionText = ibusText.Text; CheckAttributesForCommittingKeyboard(ibusText); // Make the correct selection if (m_EndOfPreedit != null) { selHelper = m_EndOfPreedit; } var selectionProps = GetSelectionProps(selHelper); // Replace any previous pre-edit text. if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor) { // If we have a backwards selection we insert the pre-edit before the selected // text. selHelper points to the originally selected text (which got moved because // we inserted the pre-edit before it). The top of m_InitialSelection is the // start of the pre-edit, the top of selHelper is the position before the // originally selected text Debug.Assert(m_InitialSelection.SelectionHelper.IsRange); selHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.End); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Top); } else { // selHelper points to the position after inserting the previous pre-edit text, // so it will be the end of our range selection. The bottom of m_InitialSelection // is the position at the end of the initial range selection, so it will be part // of the anchor. selHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom); } selHelper.SetSelection(true); // Update the pre-edit text ITsString str = CreateTsStringUsingSelectionProps(compositionText, selectionProps, true); selHelper.Selection.ReplaceWithTsString(str); m_EndOfPreedit = new SelectionHelper( AssociatedSimpleRootSite.EditingHelper.CurrentSelection); if (m_InitialSelection.SelectionHelper.IsRange) { // keep the range selection if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor) { // we inserted before the original selection but we want to keep the original // text selected, so we have to adjust selHelper = new SelectionHelper(m_InitialSelection.SelectionHelper); selHelper.IchAnchor += str.Length; selHelper.IchEnd += str.Length; } else { selHelper = m_InitialSelection.SelectionHelper; } } else { // Set the IP to the position IBus told us. This is tricky because compositionText // might be in NFC but we have converted it to NFD, so the position needs to // change. To simplify this we expect for now that IBus sets the cursor always // either at the start or the end of the composition string. selHelper = new SelectionHelper(AssociatedSimpleRootSite.EditingHelper.CurrentSelection); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom); if (compositionText.Length == cursorPos) { selHelper.IchAnchor += str.Length; } else { Debug.Assert(cursorPos == 0, "IBus told us a cursor position that changed because of nfc->nfd normalization"); selHelper.IchAnchor += cursorPos; } selHelper.IchEnd = selHelper.IchAnchor; } // make the selection visible selHelper.SetSelection(true); }
public void OnUpdatePreeditText(object obj, int cursorPos) { if (AssociatedSimpleRootSite.InvokeRequired) { AssociatedSimpleRootSite.BeginInvoke(() => OnUpdatePreeditText(obj, cursorPos)); return; } var selHelper = SetupForTypingEventHandler(true, false); if (selHelper == null) return; if (m_InitialSelection == null) { // Create a new, independent selection helper for m_InitialSelHelper - we want // to remember the current selection m_InitialSelection = new SelectionWrapper(AssociatedSimpleRootSite); OnPreeditOpened(); } var ibusText = obj as IBusText; var compositionText = ibusText.Text; CheckAttributesForCommittingKeyboard(ibusText); // Make the correct selection if (m_EndOfPreedit != null) selHelper = m_EndOfPreedit; var selectionProps = GetSelectionProps(selHelper); // Replace any previous pre-edit text. if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor) { // If we have a backwards selection we insert the pre-edit before the selected // text. selHelper points to the originally selected text (which got moved because // we inserted the pre-edit before it). The top of m_InitialSelection is the // start of the pre-edit, the top of selHelper is the position before the // originally selected text Debug.Assert(m_InitialSelection.SelectionHelper.IsRange); selHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.End); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Top); } else { // selHelper points to the position after inserting the previous pre-edit text, // so it will be the end of our range selection. The bottom of m_InitialSelection // is the position at the end of the initial range selection, so it will be part // of the anchor. selHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom); } selHelper.SetSelection(true); // Update the pre-edit text ITsString str = CreateTsStringUsingSelectionProps(compositionText, selectionProps, true); selHelper.Selection.ReplaceWithTsString(str); m_EndOfPreedit = new SelectionHelper( AssociatedSimpleRootSite.EditingHelper.CurrentSelection); if (m_InitialSelection.SelectionHelper.IsRange) { // keep the range selection if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor) { // we inserted before the original selection but we want to keep the original // text selected, so we have to adjust selHelper = new SelectionHelper(m_InitialSelection.SelectionHelper); selHelper.IchAnchor += str.Length; selHelper.IchEnd += str.Length; } else selHelper = m_InitialSelection.SelectionHelper; } else { // Set the IP to the position IBus told us. This is tricky because compositionText // might be in NFC but we have converted it to NFD, so the position needs to // change. To simplify this we expect for now that IBus sets the cursor always // either at the start or the end of the composition string. selHelper = new SelectionHelper(AssociatedSimpleRootSite.EditingHelper.CurrentSelection); selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom); if (compositionText.Length == cursorPos) selHelper.IchAnchor += str.Length; else { Debug.Assert(cursorPos == 0, "IBus told us a cursor position that changed because of nfc->nfd normalization"); selHelper.IchAnchor += cursorPos; } selHelper.IchEnd = selHelper.IchAnchor; } // make the selection visible selHelper.SetSelection(true); }
/// <summary> /// Commits the or reset. /// </summary> /// <returns><c>true</c>, if or reset was commited, <c>false</c> otherwise.</returns> public bool CommitOrReset() { // don't check if we have focus - we won't if this gets called from OnLostFocus. // However, the IbusKeyboardAdapter calls this method only for the control that just // lost focus, so it's ok not to check :-) if (IsCommittingKeyboard) { if (m_InitialSelection != null && m_EndOfPreedit != null) { ITsString tss; var selection = AssociatedSimpleRootSite.RootBox.MakeRangeSelection( m_InitialSelection.RestoreSelection(), m_EndOfPreedit.SetSelection(AssociatedSimpleRootSite), true); selection.GetSelectionString(out tss, string.Empty); OnCommitText(tss.Text, false); m_InitialSelection = null; m_EndOfPreedit = null; } return false; } return Reset(true); }
private void OnCommitText(string text, bool checkIfFocused) { var selHelper = SetupForTypingEventHandler(checkIfFocused, true); if (selHelper == null) return; try { var selectionProps = GetSelectionProps(selHelper); var countBackspace = TrimBeginningBackspaces(ref text); var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); selHelper.IchAnchor = Math.Max(0, selHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace); selHelper.IchEnd = bottom; selHelper.SetSelection(true); UpdateSelectionForReplacingPreeditText(selHelper, countBackspace); // Insert 'text' ITsString str = CreateTsStringUsingSelectionProps(text, selectionProps, false); selHelper.Selection.ReplaceWithTsString(str); } finally { m_InitialSelection = null; m_EndOfPreedit = null; if (m_ActionHandler != null) { m_ActionHandler.EndUndoTask(); m_ActionHandler = null; } OnPreeditClosed(); } }
/// <summary> /// Reset the selection and optionally cancel any open compositions. /// </summary> /// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param> /// <returns><c>true</c> if there was an open composition that we cancelled, otherwise /// <c>false</c>.</returns> private bool Reset(bool cancel) { if (m_InReset) return false; bool retVal = false; m_InReset = true; try { if (cancel) { if (m_ActionHandler != null && (m_ActionHandler.get_TasksSinceMark(true) || m_Depth != m_ActionHandler.CurrentDepth)) { m_ActionHandler.Rollback(m_Depth); retVal = true; } else if (m_InitialSelection != null && m_EndOfPreedit != null) { var selHelper = SetupForTypingEventHandler(false, true); if (selHelper != null) { // Update selection so that we can delete the preedit-text UpdateSelectionForReplacingPreeditText(selHelper, 0); selHelper.SetSelection(true); if (selHelper.IsValid && selHelper.IsRange) { var tss = CreateTsStringUsingSelectionProps(string.Empty, null, false); selHelper.Selection.ReplaceWithTsString(tss); } } } } m_ActionHandler = null; if (m_InitialSelection != null) m_InitialSelection.RestoreSelection(); m_InitialSelection = null; m_EndOfPreedit = null; return retVal; } finally { m_InReset = false; OnPreeditClosed(); } }
/// <summary> /// Reset the selection and optionally cancel any open compositions. /// </summary> /// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param> /// <returns><c>true</c> if there was an open composition that we cancelled, otherwise /// <c>false</c>.</returns> private bool Reset(bool cancel) { if (m_InReset) return false; bool retVal = false; m_InReset = true; try { if (cancel && m_ActionHandler != null) { m_ActionHandler.Rollback(m_Depth); retVal = true; } bool resetSelections = m_ActionHandler != null; m_ActionHandler = null; if (m_InitialSelection != null) m_InitialSelection.RestoreSelection(); if (resetSelections) { m_InitialSelection = null; m_EndOfPreedit = null; } return retVal; } finally { m_InReset = false; } }
private void OnCommitText(string text, bool checkIfFocused) { var selHelper = SetupForTypingEventHandler(checkIfFocused, true); if (selHelper == null) return; try { var selectionProps = GetSelectionProps(selHelper); var countBackspace = TrimBeginningBackspaces(ref text); var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); selHelper.IchAnchor = Math.Max(0, selHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace); selHelper.IchEnd = bottom; if (m_ActionHandler == null && m_InitialSelection != null && m_EndOfPreedit != null) { // we don't have an action handler which means we didn't roll back the // preedit. This means we have create a range selection that deletes the // preedit. selHelper.IchAnchor = Math.Max(0, m_InitialSelection.SelectionHelper.GetIch( SelectionHelper.SelLimitType.Top) - countBackspace); selHelper.IchEnd = m_EndOfPreedit.GetIch(SelectionHelper.SelLimitType.Bottom); } selHelper.SetSelection(true); // Insert 'text' ITsString str = CreateTsStringUsingSelectionProps(text, selectionProps, false); selHelper.Selection.ReplaceWithTsString(str); } finally { m_InitialSelection = null; m_EndOfPreedit = null; if (m_ActionHandler != null) { m_ActionHandler.EndUndoTask(); m_ActionHandler = null; } } }