Skip to content

Commit

Permalink
Show different tooltip for build widget when there are no targets
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599919395
  • Loading branch information
Googler authored and copybara-github committed Jan 19, 2024
1 parent 6f759d8 commit 7f5d2f7
Showing 1 changed file with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,14 @@ public JComponent createCustomComponent(
@Override
protected void updateToolTipText() {
Project project = editor.getProject();
if (project != null) {
HelpTooltip.dispose(this);
new HelpTooltip()
.setTitle("Build dependencies")
.setShortcut(
ActionManager.getInstance().getKeyboardShortcut("Blaze.BuildDependencies"))
.setDescription(
"Builds the external dependencies needed for this file and "
+ " enables analysis")
.setLink(
"Settings...",
new Runnable() {
@Override
public void run() {
ShowSettingsUtil.getInstance()
.showSettingsDialog(
project, QuerySyncConfigurableProvider.getConfigurableClass());
}
})
.installOn(this);
if (project == null) {
return;
}
HelpTooltip.dispose(this);
createPrimaryTooltip(project).installOn(this);
}
};

button.setHorizontalTextPosition(SwingConstants.LEFT);
button.setFont(
new FontUIResource(
Expand All @@ -192,6 +177,40 @@ public void run() {
return button;
}

private HelpTooltip createPrimaryTooltip(Project project) {
if (fileInEditorHasNoTargetsToBuild(project)) {
return new HelpTooltip()
.setTitle("Build dependencies")
.setDescription(
"This file is not owned by a project target with external dependencies.");
} else {
return new HelpTooltip()
.setTitle("Build dependencies")
.setShortcut(ActionManager.getInstance().getKeyboardShortcut("Blaze.BuildDependencies"))
.setDescription(
"Builds the external dependencies needed for this file and " + " enables analysis")
.setLink(
"Settings...",
() ->
ShowSettingsUtil.getInstance()
.showSettingsDialog(
project, QuerySyncConfigurableProvider.getConfigurableClass()));
}
}

private boolean fileInEditorHasNoTargetsToBuild(Project project) {
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
VirtualFile vf = psiFile != null ? psiFile.getVirtualFile() : null;
QuerySyncManager querySyncManager = QuerySyncManager.getInstance(project);
if (vf != null
&& querySyncManager.isProjectLoaded()
&& !querySyncManager.operationInProgress()) {
TargetsToBuild toBuild = buildDepsHelper.getTargetsToEnableAnalysisFor(vf);
return toBuild.isEmpty();
}
return false;
}

private void createGotItTooltip(ActionButtonWithText button) {
Project project = editor.getProject();
if (project != null) {
Expand Down

0 comments on commit 7f5d2f7

Please sign in to comment.