Skip to content

Commit

Permalink
Add import recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mcnamara committed Aug 10, 2023
1 parent 95ca4cf commit 93f181d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
*/
public class AutoImportProjectOpenProcessor extends ProjectOpenProcessor {

public static final String MANAGED_PROJECT_RELATIVE_PATH = "tools/intellij/.managed.bazelproject";
static final Key<Boolean> PROJECT_AUTO_IMPORTED = Key.create("bazel.project.auto_imported");

private static final Logger LOG = Logger.getInstance(AutoImportProjectOpenProcessor.class);
Expand Down Expand Up @@ -228,7 +229,7 @@ private ProjectView createProjectView(VirtualFile workspaceRoot,

// second check managed project view template
Path managedProjectViewFilePath = workspaceRoot.toNioPath()
.resolve("tools/intellij/.managed.bazelproject");
.resolve(MANAGED_PROJECT_RELATIVE_PATH);
if (managedProjectViewFilePath.toFile().exists()) {
return fromFileProjectView(managedProjectViewFilePath, pathResolver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.google.idea.blaze.base.wizard2;

import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.project.AutoImportProjectOpenProcessor;
import com.google.idea.blaze.base.projectview.ProjectViewStorageManager;
import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver;
import com.google.idea.blaze.base.ui.UiUtil;
Expand All @@ -31,6 +33,7 @@
import com.intellij.ui.TextFieldWithStoredHistory;
import java.awt.Dimension;
import java.io.File;
import java.util.List;
import javax.annotation.Nullable;
import javax.swing.JButton;
import javax.swing.JComponent;
Expand All @@ -55,6 +58,22 @@ public ImportFromWorkspaceProjectViewOption(BlazeNewProjectBuilder builder) {
projectViewPathField.setText(userSettings.get(LAST_WORKSPACE_PATH, ""));
projectViewPathField.setMinimumAndPreferredWidth(MINIMUM_FIELD_WIDTH);

WorkspaceRoot workspaceRoot = builder.getWorkspaceData() != null ? builder.getWorkspaceData().workspaceRoot() : null;
//Add managed project view to the list
if (workspaceRoot != null &&
workspaceRoot.path().resolve(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH).toFile().exists()) {
if (projectViewPathField.getText().isEmpty()) {
projectViewPathField.setText(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH);
} else {
List<String> history = projectViewPathField.getHistory();
if (!history.contains(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH)) {
history.add(0, AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH);
projectViewPathField.setHistory(history);
}
}
}


JButton button = new JButton("...");
button.addActionListener(action -> chooseWorkspacePath());
int buttonSize = projectViewPathField.getPreferredSize().height;
Expand Down

0 comments on commit 93f181d

Please sign in to comment.