public void Execute(IDataContext context, DelegateExecute nextExecute) { var solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION); if (solution == null) return; Lifetimes.Define( lifetime: solution.GetLifetime(), FAtomic: (definition, lifetime) => { var shell = Shell.Instance; var shellLocks = shell.GetComponent<IShellLocks>(); var taskExecutor = shell.GetComponent<UITaskExecutor>(); var controller = new GotoWordIndexController( definition.Lifetime, solution, LibrariesFlag.SolutionOnly, shellLocks #if RESHARPER81 , shell.GetComponent<ITaskHost>() #endif ); SetShowInFindResultsAction(controller, definition, shellLocks, taskExecutor); var gotoByNameMenu = shell.GetComponent<GotoByNameMenuComponent>(); var uiApplication = shell.GetComponent<UIApplication>(); var initialText = context.GetData(GotoByNameDataConstants.CurrentSearchText); var textControl = context.GetData(DataConstants.TEXT_CONTROL); if (textControl != null) { var selection = textControl.Selection.Ranges.Value; if (selection != null && selection.Count == 1) { var docRange = selection[0].ToDocRangeNormalized(); if (docRange.Length > 0) { var selectedText = textControl.Document.GetText(docRange); initialText = new GotoByNameDataConstants.SearchTextData( selectedText, TextRange.FromLength(selectedText.Length)); } } } new GotoByNameMenu( gotoByNameMenu, definition, controller.Model, uiApplication.MainWindow, initialText); }); }
public void ShowMenu( [NotNull] IProjectModelElement projectElement, [CanBeNull] ITextControl textControl, [CanBeNull] GotoByNameDataConstants.SearchTextData initialText) { var solution = projectElement.GetSolution(); var definition = Lifetimes.Define(solution.GetLifetime()); var controller = new GotoWordController( definition.Lifetime, myShellLocks, projectElement, textControl); if (textControl != null) { // use selected text if there is no initial // todo: how to make this work with recent list? var selection = textControl.Selection.Ranges.Value; if (selection != null && selection.Count == 1) { var docRange = selection[0].ToDocRangeNormalized(); if (docRange.Length > 0) { var selectedText = textControl.Document.GetText(docRange); initialText = new GotoByNameDataConstants.SearchTextData( selectedText, TextRange.FromLength(selectedText.Length)); } } } var menu = new GotoByNameMenu( myMenuComponent, definition, controller.Model, myUiApplication.MainWindow, initialText); var menuDoc = menu.MenuView.Value.Document.NotNull("menuDoc != null"); menuDoc.SelectedItem.FlowInto( definition.Lifetime, controller.SelectedItem, FConverter: item => (item != null) ? item.Key : null); }