Skip to content

Commit

Permalink
Add project view path to the options and move to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mcnamara committed Aug 31, 2023
1 parent 26dcf49 commit fc0ef82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ public ImmutableList<BlazeSelectProjectViewOption> getSelectProjectViewOptions(
BlazeNewProjectBuilder builder) {
ImmutableList.Builder<BlazeSelectProjectViewOption> options = new ImmutableList.Builder<>();

options.add(new CreateFromScratchProjectViewOption());
options.add(new ImportFromWorkspaceProjectViewOption(builder));
options.add(new GenerateFromBuildFileSelectProjectViewOption(builder));
options.add(new CopyExternalProjectViewOption(builder));

String projectViewFromEnv = System.getenv(AutoImportProjectOpenProcessor.PROJECT_VIEW_FROM_ENV);
WorkspaceRoot workspaceRoot = builder.getWorkspaceData() != null ? builder.getWorkspaceData().workspaceRoot() : null;

if (workspaceRoot != null) {
if (projectViewFromEnv != null) {
File projectViewFromEnvFile = new File(projectViewFromEnv);
if (projectViewFromEnvFile.exists()) {
options.add(UseKnownProjectViewOption.fromEnvironmentVariable(projectViewFromEnvFile));
options.add(UseKnownProjectViewOption.fromEnvironmentVariable(workspaceRoot, projectViewFromEnvFile));
}
}
if (workspaceRoot.absolutePathFor(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH).toFile().exists()) {
options.add(UseKnownProjectViewOption.fromManagedProject(workspaceRoot));
}
}

options.add(new CreateFromScratchProjectViewOption());
options.add(new ImportFromWorkspaceProjectViewOption(builder));
options.add(new GenerateFromBuildFileSelectProjectViewOption(builder));
options.add(new CopyExternalProjectViewOption(builder));

return options.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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.ui.UiUtil;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.ui.components.JBLabel;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand All @@ -16,11 +19,16 @@ public class UseKnownProjectViewOption implements BlazeSelectProjectViewOption {
private final String optionName;
private final String description;
private final File projectView;
private final JComponent component;

private UseKnownProjectViewOption(String optionName, String description, File projectView) {
private UseKnownProjectViewOption(String optionName, String description, File projectView, WorkspaceRoot workspaceRoot) {
this.optionName = optionName;
this.description = description;
this.projectView = projectView;
WorkspacePath workspacePath = workspaceRoot.workspacePathForSafe(projectView);
this.component = UiUtil.createHorizontalBox(
HORIZONTAL_LAYOUT_GAP, new JBLabel("Project view:"),
new JBLabel(workspacePath != null ? workspacePath.relativePath() : projectView.getAbsolutePath()));
}

@Override
Expand Down Expand Up @@ -57,14 +65,20 @@ public void commit() throws BlazeProjectCommitException {
@Nullable
@Override
public JComponent getUiComponent() {
return null;
return component;
}

public static UseKnownProjectViewOption fromManagedProject(WorkspaceRoot root) {
return new UseKnownProjectViewOption("use-managed-view", "Clone project's default view", root.absolutePathFor(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH).toFile());
return new UseKnownProjectViewOption("use-managed-view",
"Clone project's default view",
root.absolutePathFor(AutoImportProjectOpenProcessor.MANAGED_PROJECT_RELATIVE_PATH).toFile(),
root);
}

public static UseKnownProjectViewOption fromEnvironmentVariable(File file) {
return new UseKnownProjectViewOption("use-view-from-env", "Clone project view provided from environment", file);
public static UseKnownProjectViewOption fromEnvironmentVariable(WorkspaceRoot root, File file) {
return new UseKnownProjectViewOption("use-view-from-env",
"Clone project view provided from environment",
file,
root);
}
}

0 comments on commit fc0ef82

Please sign in to comment.