public void EnsureIntellisenseResults(string text, bool forceUpdate, IntellisenseDesiredResultSet desiredResultSet) { if (text == null) { text = string.Empty; } if (!DesignerProperties.GetIsInDesignMode(this)) { var calculateMode = false; if (AllowUserCalculateMode) { if (text.Length > 0 && text[0] == '=') { calculateMode = true; text = text.Substring(1); } IsInCalculateMode = calculateMode; } else { if (IsInCalculateMode) { calculateMode = true; } } if (forceUpdate) { var provider = IntellisenseProvider; var context = new IntellisenseProviderContext { FilterType = FilterType, DesiredResultSet = desiredResultSet, InputText = text, CaretPosition = CaretIndex }; context.IsInCalculateMode = calculateMode; if ((context.IsInCalculateMode) && AllowUserCalculateMode && CaretIndex > 0) { context.CaretPosition = CaretIndex - 1; } IList <IntellisenseProviderResult> results = null; try { results = provider.GetIntellisenseResults(context); _intellisenseResults = results.ToList(); } catch { //This try catch is to prevent the intellisense box from ever being crashed from a provider. //This catch is intentionally blanks since if a provider throws an exception the intellisense //box should simbly ignore that provider. } ProcessResults(text, results); } } }
public IList <IntellisenseProviderResult> GetIntellisenseResults(IntellisenseProviderContext context) { if (context == null) { return(new List <IntellisenseProviderResult>()); } if (IsDisposed) { throw new ObjectDisposedException("DefaultIntellisenseProvider"); } if (!Equals(TextBox, context.TextBox)) { TextBox = context.TextBox as IntellisenseTextBox; } IList <IIntellisenseResult> results; var input = context.InputText ?? string.Empty; var caretPosition = context.CaretPosition; if (caretPosition > input.Length || caretPosition < 0) { return(new List <IntellisenseProviderResult>()); } enIntellisensePartType filterType = context.FilterType; enIntellisensePartType altfilterType = context.FilterType; IntellisenseDesiredResultSet desiredResultSet = context.DesiredResultSet; string searchText = context.FindTextToSearch(); string recordsetIndex = string.Empty; string recordserName = string.Empty; var region = input.RegionInPostion(caretPosition); var regionName = region.Name; if (DataListUtil.IsValueRecordset(regionName)) { recordsetIndex = DataListUtil.ExtractIndexRegionFromRecordset(regionName); recordserName = DataListUtil.ExtractRecordsetNameFromValue(regionName); if (!string.IsNullOrEmpty(recordsetIndex) && DataListUtil.IsValueRecordsetWithFields(searchText)) { altfilterType = enIntellisensePartType.RecordsetFields; } } if (input.Equals(DataListUtil.OpeningSquareBrackets)) { searchText = context.InputText; } else { searchText = searchText.StartsWith(DataListUtil.OpeningSquareBrackets) || string.IsNullOrEmpty(searchText) ? searchText : DataListUtil.OpeningSquareBrackets + searchText; } switch (desiredResultSet) { case IntellisenseDesiredResultSet.EntireSet: results = GetIntellisenseResultsImpl(DataListUtil.OpeningSquareBrackets, filterType); break; default: { results = GetIntellisenseResultsImpl(searchText, filterType); if (results == null || results.Count == 0 && HandlesResultInsertion) { results = new List <IIntellisenseResult>(); string inputText = input; var regionInPostion = inputText.RegionInPostion(caretPosition); inputText = !string.IsNullOrEmpty(regionInPostion.Name) ? regionInPostion.Name : inputText; var getErrors = GetIntellisenseResultsImpl(inputText, filterType) .Where(i => i.ErrorCode != enIntellisenseErrorCode.None) .ToList(); getErrors.ForEach(results.Add); } break; } } if (altfilterType == enIntellisensePartType.RecordsetFields) { var filteredRecordsetFields = results.Where(r => r.Option.Recordset.Equals(recordserName) || r.Option.IsScalar); if (!string.IsNullOrEmpty(recordsetIndex)) { results = filteredRecordsetFields.ToList().Where(r => !r.Option.HasRecordsetIndex || r.Option.IsScalar).ToList(); } } IList <IntellisenseProviderResult> trueResults = new List <IntellisenseProviderResult>(); string[] openParts = Regex.Split(input, @"\[\["); string[] closeParts = Regex.Split(input, @"\]\]"); if (openParts.Length != closeParts.Length) { if (results != null) { results.Add(IntellisenseFactory.CreateCalculateIntellisenseResult(2, 2, "Invalid Expression", "", StringResources.IntellisenseErrorMisMacthingBrackets)); } } if (results != null) { foreach (IIntellisenseResult currentResult in results) { if (currentResult.ErrorCode != enIntellisenseErrorCode.None) { if (currentResult.Type == enIntellisenseResultType.Error && currentResult.IsClosedRegion) { var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue; trueResults.Add(new IntellisenseProviderResult(this, displayValue, currentResult.Message, currentResult.Message, true)); } } if (currentResult.Type == enIntellisenseResultType.Selectable) { var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue; var description = currentResult.Option == null ? string.Empty : currentResult.Option.Description; trueResults.Add(new IntellisenseProviderResult(this, displayValue, description, description, false)); } } } return(trueResults); }