void IOptionsPanel.ApplyChanges ()
		{
			var chars = new CompletionCharacters[store.RowCount];
			for (int i = 0; i < chars.Length; i++) {
				chars [i] = new CompletionCharacters (
					store.GetValue (i, language),
					store.GetValue (i, completeOnSpace),
					store.GetValue (i, completeOnChars)
				);
			}
			CompletionCharacters.SetCompletionCharacters (chars);
		}
Exemplo n.º 2
0
        public KeyActions PreProcessKey(KeyDescriptor descriptor)
        {
            switch (descriptor.SpecialKey)
            {
            case SpecialKey.Home:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    return(KeyActions.Process);
                }
                List.SelectionFilterIndex = 0;
                return(KeyActions.Ignore);

            case SpecialKey.End:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    return(KeyActions.Process);
                }
                List.SelectionFilterIndex = List.filteredItems.Count - 1;
                return(KeyActions.Ignore);

            case SpecialKey.Up:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    if (!SelectionEnabled /*&& !CompletionWindowManager.ForceSuggestionMode*/)
                    {
                        AutoCompleteEmptyMatch = AutoSelect = true;
                    }
                    if (!List.InCategoryMode)
                    {
                        IdeApp.Preferences.EnableCompletionCategoryMode.Set(true);
                        List.UpdateCategoryMode();
                        return(KeyActions.Ignore);
                    }
                    List.MoveToCategory(-1);
                    return(KeyActions.Ignore);
                }
                if (SelectionEnabled && list.filteredItems.Count < 1)
                {
                    return(KeyActions.CloseWindow | KeyActions.Process);
                }
                if (!SelectionEnabled /*&& !CompletionWindowManager.ForceSuggestionMode*/)
                {
                    AutoCompleteEmptyMatch = AutoSelect = true;
                }
                else
                {
                    list.MoveCursor(-1);
                }
                return(KeyActions.Ignore);

            case SpecialKey.Tab:
                //tab always completes current item even if selection is disabled
                if (!AutoSelect)
                {
                    AutoSelect = true;
                }
                goto case SpecialKey.Return;

            case SpecialKey.Return:
                if (descriptor.ModifierKeys != ModifierKeys.None && descriptor.ModifierKeys != ModifierKeys.Shift)
                {
                    return(KeyActions.CloseWindow);
                }
                if (completionDataList == null || completionDataList.Count == 0)
                {
                    return(KeyActions.CloseWindow);
                }
                WasShiftPressed = (descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift;

                if (SelectedItem != null)
                {
                    switch (SelectedItem.Rules.EnterKeyRule)
                    {
                    case Microsoft.CodeAnalysis.Completion.EnterKeyRule.Always:
                        return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);

                    case Microsoft.CodeAnalysis.Completion.EnterKeyRule.AfterFullyTypedWord:
                        if (PartialWord.Length == SelectedItem.CompletionText.Length)
                        {
                            return(KeyActions.Complete | KeyActions.Ignore | KeyActions.CloseWindow);
                        }
                        return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);

                    case Microsoft.CodeAnalysis.Completion.EnterKeyRule.Never:
                    case Microsoft.CodeAnalysis.Completion.EnterKeyRule.Default:
                    default:
                        return(KeyActions.Complete | KeyActions.Ignore | KeyActions.CloseWindow);
                    }
                }
                return(KeyActions.Complete | KeyActions.Ignore | KeyActions.CloseWindow);

            case SpecialKey.Down:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    if (!SelectionEnabled /*&& !CompletionWindowManager.ForceSuggestionMode*/)
                    {
                        AutoCompleteEmptyMatch = AutoSelect = true;
                    }
                    if (!List.InCategoryMode)
                    {
                        IdeApp.Preferences.EnableCompletionCategoryMode.Set(true);
                        List.UpdateCategoryMode();
                        return(KeyActions.Ignore);
                    }
                    List.MoveToCategory(1);
                    return(KeyActions.Ignore);
                }
                if (SelectionEnabled && list.filteredItems.Count < 1)
                {
                    return(KeyActions.CloseWindow | KeyActions.Process);
                }

                if (!SelectionEnabled /*&& !CompletionWindowManager.ForceSuggestionMode*/)
                {
                    AutoCompleteEmptyMatch = AutoSelect = true;
                }
                else
                {
                    list.MoveCursor(1);
                }
                return(KeyActions.Ignore);

            case SpecialKey.PageUp:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    return(KeyActions.Process);
                }
                if (list.filteredItems.Count < 2)
                {
                    return(KeyActions.CloseWindow | KeyActions.Process);
                }
                scrollbar.Vadjustment.Value = Math.Max(0, scrollbar.Vadjustment.Value - scrollbar.Vadjustment.PageSize);
                list.MoveCursor(-8);
                return(KeyActions.Ignore);

            case SpecialKey.PageDown:
                if ((descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    return(KeyActions.Process);
                }
                if (list.filteredItems.Count < 2)
                {
                    return(KeyActions.CloseWindow | KeyActions.Process);
                }
                scrollbar.Vadjustment.Value = Math.Max(0, Math.Min(scrollbar.Vadjustment.Upper - scrollbar.Vadjustment.PageSize, scrollbar.Vadjustment.Value + scrollbar.Vadjustment.PageSize));
                list.MoveCursor(8);
                return(KeyActions.Ignore);

            case SpecialKey.Left:
                //if (curPos == 0) return KeyActions.CloseWindow | KeyActions.Process;
                //curPos--;
                return(KeyActions.Process);

            case SpecialKey.Right:
                //if (curPos == word.Length) return KeyActions.CloseWindow | KeyActions.Process;
                //curPos++;
                return(KeyActions.Process);

//			case Gdk.Key.Caps_Lock:
//			case Gdk.Key.Num_Lock:
//			case Gdk.Key.Scroll_Lock:
//				return KeyActions.Ignore;
//
//			case Gdk.Key.Control_L:
//			case Gdk.Key.Control_R:
//			case Gdk.Key.Alt_L:
//			case Gdk.Key.Alt_R:
//			case Gdk.Key.Shift_L:
//			case Gdk.Key.Shift_R:
//			case Gdk.Key.ISO_Level3_Shift:
//				// AltGr
//				return KeyActions.Process;
            }
            var data = SelectedItem;

            if (descriptor.KeyChar == '\0')
            {
                return(KeyActions.Process);
            }

            if (descriptor.KeyChar == ' ' && (descriptor.ModifierKeys & ModifierKeys.Shift) == ModifierKeys.Shift)
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (char.IsDigit(descriptor.KeyChar) && string.IsNullOrEmpty(CurrentCompletionText))
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (data != null && data.MuteCharacter(descriptor.KeyChar, PartialWord))
            {
                if (data.IsCommitCharacter(descriptor.KeyChar, PartialWord))
                {
                    return(KeyActions.CloseWindow | KeyActions.Ignore | KeyActions.Complete);
                }
                return(KeyActions.CloseWindow | KeyActions.Ignore);
            }


            // special case end with punctuation like 'param:' -> don't input double punctuation, otherwise we would end up with 'param::'
            if (char.IsPunctuation(descriptor.KeyChar) && descriptor.KeyChar != '_')
            {
                if (descriptor.KeyChar == ':')
                {
                    foreach (var item in FilteredItems)
                    {
                        if (DataProvider.GetText(item).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                        {
                            list.SelectedItemIndex = item;
                            return(KeyActions.Complete | KeyActions.CloseWindow | KeyActions.Ignore);
                        }
                    }
                }
                else
                {
                    var selectedItem = list.SelectedItemIndex;
                    if (selectedItem < 0 || selectedItem >= DataProvider.ItemCount)
                    {
                        return(KeyActions.CloseWindow);
                    }
                    if (DataProvider.GetText(selectedItem).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                    {
                        return(KeyActions.Complete | KeyActions.CloseWindow | KeyActions.Ignore);
                    }
                }
            }
            if (data != null && data.IsCommitCharacter(descriptor.KeyChar, PartialWord))
            {
                var curword = PartialWord;
                var match   = FindMatchedEntry(curword).Index;
                if (match >= 0 && System.Char.IsPunctuation(descriptor.KeyChar))
                {
                    string text = DataProvider.GetCompletionText(FilteredItems [match]);
                    if (!text.StartsWith(curword, StringComparison.OrdinalIgnoreCase))
                    {
                        match = -1;
                    }
                }
                //if (match >= 0 && keyChar != '<' && keyChar != ' ') {
                //	ResetSizes ();
                //	UpdateWordSelection ();
                //	return KeyActions.CloseWindow | KeyActions.Process;
                //}

                if (list.SelectionEnabled && CompletionCharacters.CompleteOn(descriptor.KeyChar))
                {
                    if (descriptor.KeyChar == '{' && !list.AutoCompleteEmptyMatchOnCurlyBrace && string.IsNullOrEmpty(list.CompletionString))
                    {
                        return(KeyActions.CloseWindow | KeyActions.Process);
                    }
                    return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);
                }
                return(KeyActions.CloseWindow | KeyActions.Process);
            }


            /*		//don't input letters/punctuation etc when non-shift modifiers are active
             *              bool nonShiftModifierActive = ((Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask
             | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.SuperMask)
             |                      & modifier) != 0;
             |              if (nonShiftModifierActive) {
             |                      if (modifier.HasFlag (Gdk.ModifierType.ControlMask) && char.IsLetterOrDigit ((char)key))
             |                              return KeyActions.Process | KeyActions.CloseWindow;
             |                      return KeyActions.Ignore;
             |              }*/


            return(KeyActions.Process);
        }
Exemplo n.º 3
0
        public KeyActions PostProcessKey(Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
        {
            if (StartOffset > CompletionWidget.CaretOffset)
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (HideWhenWordDeleted && StartOffset >= CompletionWidget.CaretOffset)
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }
            switch (key)
            {
            case Gdk.Key.BackSpace:
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }

            const string commitChars = " <>()[]{}=+-*/%~&|!";

            if (keyChar == '[' && CloseOnSquareBrackets)
            {
                return(KeyActions.Process | KeyActions.CloseWindow);
            }

            if (char.IsLetterOrDigit(keyChar) || keyChar == '_')
            {
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }

            if (char.IsPunctuation(keyChar) || commitChars.Contains(keyChar))
            {
                bool hasMismatches;
                var  curword = PartialWord;
                int  match   = FindMatchedEntry(curword, out hasMismatches);
                if (match >= 0 && System.Char.IsPunctuation(keyChar))
                {
                    string text = DataProvider.GetCompletionText(FilteredItems [match]);
                    if (!text.ToUpper().StartsWith(curword.ToUpper(), StringComparison.Ordinal))
                    {
                        match = -1;
                    }
                }
                if (match >= 0 && !hasMismatches && keyChar != '<')
                {
                    ResetSizes();
                    UpdateWordSelection();
                    return(KeyActions.Process);
                }
                if (keyChar == '.')
                {
                    list.AutoSelect = list.AutoCompleteEmptyMatch = true;
                }
                lastCommitCharEndoffset = CompletionWidget.CaretOffset - 1;

                if (list.SelectionEnabled && CompletionCharacters.CompleteOn(keyChar))
                {
                    if (keyChar == '{' && !list.AutoCompleteEmptyMatchOnCurlyBrace && string.IsNullOrEmpty(list.CompletionString))
                    {
                        return(KeyActions.CloseWindow | KeyActions.Process);
                    }
                    return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);
                }
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            return(KeyActions.Process);
        }
Exemplo n.º 4
0
        public KeyActions PostProcessKey(KeyDescriptor descriptor)
        {
            if (CompletionWidget == null || StartOffset > CompletionWidget.CaretOffset)             // CompletionWidget == null may happen in unit tests.
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (HideWhenWordDeleted && StartOffset >= CompletionWidget.CaretOffset)
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }
            switch (descriptor.SpecialKey)
            {
            case SpecialKey.BackSpace:
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }
            var keyChar = descriptor.KeyChar;

            const string commitChars = " <>()[]{}=+-*/%~&^|!.,;:?\"'";

            if (keyChar == '[' && CloseOnSquareBrackets)
            {
                return(KeyActions.Process | KeyActions.CloseWindow);
            }

            if (char.IsLetterOrDigit(keyChar) || keyChar == '_')
            {
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }

            if (commitChars.Contains(keyChar))
            {
                bool hasMismatches;
                var  curword = PartialWord;
                int  match   = FindMatchedEntry(curword, out hasMismatches);
                if (match >= 0 && System.Char.IsPunctuation(keyChar))
                {
                    string text = DataProvider.GetCompletionText(FilteredItems [match]);
                    if (!text.ToUpper().StartsWith(curword.ToUpper(), StringComparison.Ordinal))
                    {
                        match = -1;
                    }
                }
                if (match >= 0 && !hasMismatches && keyChar != '<' && keyChar != ' ')
                {
                    ResetSizes();
                    UpdateWordSelection();
                    return(KeyActions.Process);
                }
                if (keyChar == '.' && !list.AutoCompleteEmptyMatch && PartialWord == ".")
                {
                    list.AutoSelect = list.AutoCompleteEmptyMatch = true;
                }
                lastCommitCharEndoffset = CompletionWidget.CaretOffset - 1;

                if (list.SelectionEnabled && CompletionCharacters.CompleteOn(keyChar))
                {
                    if (keyChar == '{' && !list.AutoCompleteEmptyMatchOnCurlyBrace && string.IsNullOrEmpty(list.CompletionString))
                    {
                        return(KeyActions.CloseWindow | KeyActions.Process);
                    }
                    return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);
                }
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (char.IsPunctuation(descriptor.KeyChar) && descriptor.KeyChar != '_')
            {
                if (descriptor.KeyChar == ':')
                {
                    foreach (var item in FilteredItems)
                    {
                        if (DataProvider.GetText(item).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                        {
                            list.SelectedItem = item;
                            return(KeyActions.Complete | KeyActions.CloseWindow | KeyActions.Ignore);
                        }
                    }
                }
                else
                {
                    var selectedItem = list.SelectedItem;
                    if (selectedItem < 0 || selectedItem >= DataProvider.ItemCount)
                    {
                        return(KeyActions.CloseWindow);
                    }
                    var text = DataProvider.GetText(selectedItem);
                    if (!text.Substring(0, Math.Min(text.Length, CurrentPartialWord.Length)).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                    {
                        return(KeyActions.Process | KeyActions.CloseWindow);
                    }
                }
            }
            return(KeyActions.Process);
        }
Exemplo n.º 5
0
        public KeyActions PostProcessKey(KeyDescriptor descriptor)
        {
            if (CompletionWidget == null || StartOffset > CompletionWidget.CaretOffset)              // CompletionWidget == null may happen in unit tests.
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (HideWhenWordDeleted && StartOffset >= CompletionWidget.CaretOffset)
            {
                return(KeyActions.CloseWindow | KeyActions.Process);
            }
            switch (descriptor.SpecialKey)
            {
            case SpecialKey.BackSpace:
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }
            var keyChar = descriptor.KeyChar;

            if (keyChar == '[' && CloseOnSquareBrackets)
            {
                return(KeyActions.Process | KeyActions.CloseWindow);
            }

            if (char.IsLetterOrDigit(keyChar) || keyChar == '_')
            {
                ResetSizes();
                UpdateWordSelection();
                return(KeyActions.Process);
            }
            if (SelectedItemIndex < 0)
            {
                return(KeyActions.Process);
            }
            var data = DataProvider.GetCompletionData(SelectedItemIndex);

            if (data.IsCommitCharacter(keyChar, PartialWord))
            {
                var curword = PartialWord;
                var match   = FindMatchedEntry(curword).Index;
                if (match >= 0 && System.Char.IsPunctuation(keyChar))
                {
                    string text = DataProvider.GetCompletionText(FilteredItems [match]);
                    if (!text.StartsWith(curword, StringComparison.OrdinalIgnoreCase))
                    {
                        match = -1;
                    }
                }
                //if (match >= 0 && keyChar != '<' && keyChar != ' ') {
                //	ResetSizes ();
                //	UpdateWordSelection ();
                //	return KeyActions.CloseWindow | KeyActions.Process;
                //}

                if (list.SelectionEnabled && CompletionCharacters.CompleteOn(keyChar))
                {
                    if (keyChar == '{' && !list.AutoCompleteEmptyMatchOnCurlyBrace && string.IsNullOrEmpty(list.CompletionString))
                    {
                        return(KeyActions.CloseWindow | KeyActions.Process);
                    }
                    return(KeyActions.Complete | KeyActions.Process | KeyActions.CloseWindow);
                }
                return(KeyActions.CloseWindow | KeyActions.Process);
            }

            if (char.IsPunctuation(descriptor.KeyChar) && descriptor.KeyChar != '_')
            {
                if (descriptor.KeyChar == ':')
                {
                    foreach (var item in FilteredItems)
                    {
                        if (DataProvider.GetText(item).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                        {
                            list.SelectedItemIndex = item;
                            return(KeyActions.Complete | KeyActions.CloseWindow | KeyActions.Ignore);
                        }
                    }
                }
                else
                {
                    var selectedItem = list.SelectedItemIndex;
                    if (selectedItem < 0 || selectedItem >= DataProvider.ItemCount)
                    {
                        return(KeyActions.CloseWindow);
                    }
                    var text = DataProvider.GetText(selectedItem);
                    if (!text.Substring(0, Math.Min(text.Length, CurrentPartialWord.Length)).EndsWith(descriptor.KeyChar.ToString(), StringComparison.Ordinal))
                    {
                        return(KeyActions.Process | KeyActions.CloseWindow);
                    }
                }
            }
            return(KeyActions.Process);
        }