public void UpdateOccurrences( [NotNull] IList <LocalOccurrence> occurrences, [NotNull] IEnumerable <LocalOccurrence> tailOccurrences = null) { lock (mySyncRoot) { myOccurrences = occurrences; mySelectedOccurrence = (occurrences.Count == 0) ? null : occurrences[0]; if (!myShouldDropHighlightings && occurrences.Count == 0) { return; } mySequentialOccurrences.Next(lifetime => { myShellLocks.ExecuteOrQueueReadLock( lifetime, Prefix + "UpdateOccurrence", () => UpdateOccurrencesHighlighting(lifetime, occurrences)); myUpdateSelectedScheduled = true; }); mySequentialFocused.Next(lifetime => { myShellLocks.AssertReadAccessAllowed(); myShellLocks.ExecuteOrQueueReadLock( lifetime, Prefix + "UpdateOccurrence", UpdateFocusedOccurrence); }); } }
public void NavigateToParentMethod() { _shellLocks.ExecuteOrQueueReadLock(_lifetime, "NavigateToParent", () => { var node = NodeUnderCaret.Value; var parentMethod = node.GetParentOfType <IMethodDeclaration>(); parentMethod?.NavigateToTreeNode(true); }); }
protected void ShowLocations(IList <FileLocationInfo> locations, FileLocationInfo currentLocation, string caption, bool bindToPsi) { var lifetimeDefinition = Lifetimes.Define(lifetime); if (!Enumerable.Any(locations)) { agent.ShowBalloon(lifetimeDefinition.Lifetime, caption, string.Format("There are no {0}.", caption.ToLowerInvariant()), null, new[] { "OK" }, false, balloonLifetime => { agent.ButtonClicked.Advise(balloonLifetime, _ => lifetimeDefinition.Terminate()); }); return; } var options = new List <BalloonOption>(); foreach (var locationInfo in locations.Distinct().Where(l => l.ProjectFile.IsValid() || l.FileSystemPath != null)) { var descriptor = new SimpleMenuItem(); var occurence = GetOccurence(locationInfo, bindToPsi); if (occurence != null) { presentationManager.DescribeOccurence(descriptor, occurence, null); var enabled = locationInfo != currentLocation; options.Add(new BalloonOption(descriptor.Text + string.Format(" ({0})", descriptor.ShortcutText), false, enabled, locationInfo)); } } agent.ShowBalloon(lifetimeDefinition.Lifetime, caption, string.Empty, options, new[] { "Done" }, true, balloonLifetime => { agent.BalloonOptionClicked.Advise(balloonLifetime, o => { lifetimeDefinition.Terminate(); var locationInfo = o as FileLocationInfo; if (locationInfo == null) { return; } shellLocks.ExecuteOrQueueReadLock("GotoRecentFiles", () => { using (ReadLockCookie.Create()) { PsiFiles.CommitAllDocuments(); var occurence = GetOccurence(locationInfo, bindToPsi); if (occurence != null) { occurence.Navigate(solution, popupWindowContext.Source, true); } } }); }); agent.ButtonClicked.Advise(balloonLifetime, _ => lifetimeDefinition.Terminate()); }); }
// todo: rewrite private static void SetShowInFindResultsAction( [NotNull] GotoWordIndexController controller, [NotNull] LifetimeDefinition definition, [NotNull] IShellLocks shellLocks, [NotNull] UITaskExecutor taskExecutor) { controller.FuncEtcItemExecute.Value = () => shellLocks.ExecuteOrQueueReadLock("ShowInFindResults", () => { var filterString = controller.Model.FilterText.Value; if (string.IsNullOrEmpty(filterString)) { return; } definition.Terminate(); GotoWordBrowserDescriptor descriptor = null; if (taskExecutor.FreeThreaded.ExecuteTask( "Show Files In Find Results", TaskCancelable.Yes, progress => { progress.TaskName = "Collecting words matching '" + filterString + "'"; progress.Start(1); var occurrences = new List <IOccurence>(); using (ReadLockCookie.Create()) { controller.ConsumePresentableItems( filterString, -1, itemsConsumer: (items, behavior) => { foreach (var item in items) { occurrences.Add(item.Occurence); } }); } if (occurrences.Count > 0 && !progress.IsCanceled) { descriptor = new GotoWordBrowserDescriptor( controller.Solution, filterString, occurrences); } progress.Stop(); })) { if (descriptor != null) { FindResultsBrowser.ShowResults(descriptor); } } else { if (descriptor != null) { descriptor.LifetimeDefinition.Terminate(); } } }); }
public void Navigate(TutStep.TutorialStep step) { if (step.NavNode == null) { return; } if (step.NavNode.RunMethod != null) { RunCustomNavigation(step.NavNode.RunMethod); return; } if (step.NavNode.TypeName == null && step.NavNode.MethodName == null && step.NavNode.TextToFind == null) { return; } _shellLocks.ExecuteOrQueueReadLock(_lifetime, "Navigate", () => { _psiFiles.CommitAllDocumentsAsync(() => { var project = PsiNavigationHelper.GetProjectByName(_solution, step.NavNode.ProjectName); var file = PsiNavigationHelper.GetCSharpFile(project, step.NavNode.FileName); var node = PsiNavigationHelper.GetTreeNodeForStep(file, step.NavNode.TypeName, step.NavNode.MethodName, step.NavNode.MethodNameOccurrence, step.NavNode.TextToFind, step.NavNode.TextToFindOccurrence); if (node == null) { MessageBox.ShowExclamation("OOPS! Someone has changed the code in an unexpected way. " + "That wasn't you, right?;) Anyway, now it would be better to restart tutorial."); } else { PsiNavigationHelper.NavigateToNode(_documentManager, _editorManager, node, true); } }); }); }
public void Navigate(TutorialStep step) { if (step.TypeName == null && step.MethodName == null && step.TextToFind == null) { return; } _shellLocks.ExecuteOrQueueReadLock(_lifetime, "Navigate", () => { var project = PsiNavigationHelper.GetProjectByName(Solution, step.ProjectName); var file = PsiNavigationHelper.GetCSharpFile(project, step.FileName); var node = PsiNavigationHelper.GetTreeNodeForStep(file, step.TypeName, step.MethodName, step.TextToFind, step.TextToFindOccurrence); NavigateToNode(node, true); }); }
public void Execute(IDataContext context, DelegateExecute nextExecute) { var callNext = true; try { var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION); if (solution != null) { var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET); if (documentOffset == null) { return; } //var psiServices = solution.GetPsiServices(); var psiFile = documentOffset.Document.GetPsiSourceFile(solution); if (psiFile == null) { return; } var projectFile = psiFile.ToProjectFile(); if (projectFile == null) { return; } var project = projectFile.GetProject(); if (project == null) { return; } var nitraProject = _nitraSolution.GetProject(project); if (nitraProject == null) { return; } var nitraFile = nitraProject.TryGetFile(projectFile); if (nitraFile == null) { return; } var pos = documentOffset.Value; var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos)); nitraFile.Ast.Accept(visitor); var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource); if (popupWindowContext == null) { return; } var decls = visitor.Refs.Where(r => r.IsSymbolEvaluated).SelectMany(r => r.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray(); if (decls.Length == 0) { if (visitor.Names.Count == 0) { return; } decls = visitor.Names.Where(n => n.IsSymbolEvaluated).SelectMany(n => n.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray(); } if (decls.Length == 0) { return; } if (decls.Length == 1) { Navigate(decls[0], solution, project, popupWindowContext); } else { callNext = false; var jetPopupMenus = _nitraSolution._jetPopupMenus; jetPopupMenus.Show(_lifetime, JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) => { menu.ItemKeys.AddRange(Sorter(decls)); menu.PopupWindowContext = popupWindowContext.Create(lifetime); menu.Caption.Value = WindowlessControl.Create("Declaration of " + string.Join(", ", decls.Select(d => d.Name.Text))); menu.NoItemsBanner = WindowlessControl.Create("There are no declarations."); menu.DescribeItem.Advise(lifetime, args => { var decl = (Declaration)args.Key; var loc = decl.Name.ToLocation(); //args.Descriptor.Style |= MenuItemStyle.Enabled; args.Descriptor.Style |= visitor.Names.Contains(decl.Name) ? MenuItemStyle.None : args.Descriptor.Style = MenuItemStyle.Enabled; args.Descriptor.Text = new RichText(Path.GetFileName(decl.File.FullName)).Append(" ").Append("(" + loc.EndLineColumn + ")", TextStyle.FromForeColor(Color.RoyalBlue)); args.Descriptor.Tooltip = new RichText(decl.Symbol.Kind, TextStyle.FromForeColor(Color.Blue)) .Append(" ") .Append(decl.Name.Text, new TextStyle(FontStyle.Bold)); //args.Descriptor.ShortcutText = XamlToRichText(decl.ToXaml()); //args.Descriptor.Icon = ; }); menu.ItemClicked.Advise(lifetime, arg => _shellLocks.ExecuteOrQueueReadLock("Nitra GoTo Declaration", () => { var decl = (Declaration)arg; Navigate(decl, solution, project, popupWindowContext); })); }); } } } finally { if (callNext) { nextExecute(); } } }