Beispiel #1
0
        private void ShowSync(char value)
        {
            if (_editor.IsReadOnly || !_editor.Enabled)
            {
                return;
            }

            if (_codeCompletionWindow != null)
            {
                _codeCompletionWindow.Close();
            }

            ICompletionDataProvider completionDataProvider = new CompletionProviderImpl(_intellisenseImageList);

            _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(
                _editor.FindForm(),         // The parent window for the completion window
                _editor,                    // The text editor to show the window for
                "",                         // Filename - will be passed back to the provider
                completionDataProvider,     // Provider to get the list of possible completions
                value                       // Key pressed - will be passed to the provider
                );

            // ShowCompletionWindow can return null when the provider returns an empty list
            if (_codeCompletionWindow == null)
            {
                return;
            }

            _codeCompletionWindow.Closed += OnClose;

            var completions = completionDataProvider.GenerateCompletionData("", _editor.ActiveTextAreaControl.TextArea, value) ?? new ICompletionData[0];

            if (!completions.Any())
            {
                return;
            }

            _codeCompletionWindow.MouseWheel += CodeCompletionWindowOnMouseWheel;

            using (var g = _codeCompletionWindow.CreateGraphics())
            {
                var width = (int)completions.Select(data => g.MeasureString(data.Text, _codeCompletionWindow.Font).Width).Max();

                width += 16; // Icon size
                width += SystemInformation.VerticalScrollBarWidth;

                if (width > _codeCompletionWindow.Width)
                {
                    _codeCompletionWindow.Width = width;
                }
            }
        }