-
Notifications
You must be signed in to change notification settings - Fork 330
Add a flutter pub add action #7924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
flutter-idea/src/io/flutter/actions/FlutterPackagesAddAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2025 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package io.flutter.actions; | ||
|
||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.project.Project; | ||
import io.flutter.FlutterMessages; | ||
import io.flutter.pub.PubRoot; | ||
import io.flutter.sdk.FlutterSdk; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class FlutterPackagesAddAction extends FlutterSdkAction { | ||
@Override | ||
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) { | ||
if (root == null) { | ||
FlutterMessages.showError( | ||
"Cannot Find Pub Root", | ||
"Flutter pub add can only be run within a directory with a pubspec.yaml file", | ||
project); | ||
return; | ||
} | ||
PackageDialogWrapper dialog = new PackageDialogWrapper(); | ||
if (dialog.showAndGet()) { | ||
sdk.startPubAdd(root, project, dialog.getPackageName(), dialog.getDevOnly()); | ||
} | ||
} | ||
} | ||
|
73 changes: 73 additions & 0 deletions
73
flutter-idea/src/io/flutter/actions/PackageDialogWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2025 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package io.flutter.actions; | ||
|
||
import com.intellij.openapi.ui.DialogWrapper; | ||
import com.intellij.openapi.ui.ValidationInfo; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
public class PackageDialogWrapper extends DialogWrapper { | ||
|
||
@NotNull | ||
private JTextField packageInput = new JTextField("", 16); | ||
|
||
@NotNull | ||
private JCheckBox devOnlyCheckBox = new JCheckBox(); | ||
|
||
public PackageDialogWrapper() { | ||
super(true); // use current window as parent | ||
setTitle("Add Package"); | ||
init(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected JComponent createCenterPanel() { | ||
JPanel dialogPanel = new JPanel(); | ||
|
||
JLabel packageNameLabel = new JLabel("Package name:"); | ||
dialogPanel.add(packageNameLabel, BorderLayout.LINE_START); | ||
dialogPanel.add(packageInput, BorderLayout.CENTER); | ||
|
||
dialogPanel.add(new JSeparator()); | ||
|
||
JLabel devOnlyLabel = new JLabel("Dev only:"); | ||
dialogPanel.add(devOnlyLabel, BorderLayout.LINE_START); | ||
dialogPanel.add(devOnlyCheckBox, BorderLayout.CENTER); | ||
|
||
return dialogPanel; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected ValidationInfo doValidate() { | ||
if (getPackageName().isEmpty()) { | ||
return new ValidationInfo("A package name is required", packageInput); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return packageInput; | ||
} | ||
|
||
@NotNull | ||
public String getPackageName() { | ||
String text = packageInput.getText(); | ||
return text == null ? "" : text; | ||
} | ||
|
||
public boolean getDevOnly() { | ||
Object[] selectedObjects = devOnlyCheckBox.getSelectedObjects(); | ||
if (selectedObjects == null) return false; | ||
return selectedObjects.length > 0; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.