Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flutter-studio/src/io/flutter/actions/OpenAndroidModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class OpenAndroidModule extends OpenInAndroidStudioAction implements DumbAware {
@Override
public void actionPerformed(AnActionEvent e) {
public void performAction(AnActionEvent e) {
final VirtualFile projectFile = findProjectFile(e);
if (projectFile == null) {
FlutterMessages.showError("Error Opening Android Studio", "Project not found.");
Expand All @@ -52,6 +52,12 @@ public void actionPerformed(AnActionEvent e) {
openOrImportProject(projectFile, e.getProject(), sourceFile, forceOpenInNewFrame);
}

@NotNull
@Override
public String getAnalyticsId() {
return "OpenModuleInAndroidStudio";
}

private static void openOrImportProject(@NotNull VirtualFile projectFile,
@Nullable Project project,
@Nullable VirtualFile sourceFile,
Expand Down
39 changes: 39 additions & 0 deletions src/io/flutter/actions/ActionWithAnalytics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2018 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.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import io.flutter.FlutterInitializer;
import org.jetbrains.annotations.NotNull;

/**
* An action that sends analytics when performed.
*/
public abstract class ActionWithAnalytics extends AnAction {

/**
* Template method. Implement @performAction.
*/
@Override
public final void actionPerformed(AnActionEvent e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final methods often end up causing unexpected problems. It would be better to omit that modifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 In general I hear you. In this case though it's a template method and I don't want it accidentally overridden since the analytics call won't happen unless they think to call super.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OverridingMethodsMustInvokeSuper will do what you want and won't do what I don't want.

screen shot 2018-05-10 at 12 43 02 pm

You'll need to add a library dependency on jsr305 to enable that annotation, but I think it's worth doing. (Remember to add it to all relevant module definitions. I think there are two.)

In its current form, this method appears to contradict the instructions from JetBrains:
https://www.jetbrains.org/intellij/sdk/docs/tutorials/action_system/working_with_custom_actions.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an opinion here, but we may want to move discussion out of a PR; perhaps when you're in the office Monday Steve?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. We can discuss and rejigger.

FlutterInitializer.getAnalytics().sendEvent("flutter", getAnalyticsId());
performAction(e);
}

/**
* Return the unique analytics Id for this action.
*/
@NotNull
public abstract String getAnalyticsId();

/**
* Perform the action.
*
* Called by @actionPerformed.
*/
public abstract void performAction(AnActionEvent e);
}
11 changes: 8 additions & 3 deletions src/io/flutter/actions/OpenInAndroidStudioAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
Expand All @@ -28,7 +27,7 @@

import java.io.File;

public class OpenInAndroidStudioAction extends AnAction {
public class OpenInAndroidStudioAction extends ActionWithAnalytics {

private static final String LABEL_FILE = FlutterBundle.message("flutter.androidstudio.open.file.text");
private static final String DESCR_FILE = FlutterBundle.message("flutter.androidstudio.open.file.description");
Expand All @@ -40,8 +39,14 @@ public void update(AnActionEvent event) {
updatePresentation(event, event.getPresentation());
}

@NotNull
@Override
public void actionPerformed(AnActionEvent e) {
public String getAnalyticsId() {
return "OpenInAndroidStudio";
}

@Override
public void performAction(AnActionEvent e) {
final String androidStudioPath = findAndroidStudio(e.getProject());
if (androidStudioPath == null) {
FlutterMessages.showError("Error Opening Android Studio", "Unable to locate Android Studio.");
Expand Down
11 changes: 8 additions & 3 deletions src/io/flutter/actions/OpenInXcodeAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
Expand All @@ -27,7 +26,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class OpenInXcodeAction extends AnAction {
public class OpenInXcodeAction extends ActionWithAnalytics {
private static VirtualFile findProjectFile(@Nullable AnActionEvent e) {
if (e != null) {
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
Expand Down Expand Up @@ -141,8 +140,14 @@ public void update(AnActionEvent event) {
}
}

@NotNull
@Override
public void actionPerformed(AnActionEvent e) {
public String getAnalyticsId() {
return "OpenInXcode";
}

@Override
public void performAction(AnActionEvent e) {
final VirtualFile projectFile = findProjectFile(e);
if (projectFile != null) {
openFile(projectFile);
Expand Down
55 changes: 34 additions & 21 deletions src/io/flutter/editor/NativeEditorNotificationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@
import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotifications;
import icons.FlutterIcons;
import org.jetbrains.annotations.NonNls;
import io.flutter.actions.ActionWithAnalytics;
import io.flutter.actions.OpenInXcodeAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class NativeEditorNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
private static final Key<EditorNotificationPanel> KEY = Key.create("flutter.native.editor.notification");

private static final ActionWithAnalytics OPEN_IN_XCODE_ACTION = new OpenInXcodeAction() {
@NotNull
@Override
public String getAnalyticsId() {
return "OpenInXcode.banner";
}
};

private static final ActionWithAnalytics OPEN_IN_ANDROID_STUDIO_ACTION = new OpenInXcodeAction() {
@NotNull
@Override
public String getAnalyticsId() {
return "OpenInAndroidStudio.banner";
}
};

private final Project myProject;

public NativeEditorNotificationProvider(@NotNull Project project) {
Expand All @@ -48,26 +65,26 @@ private EditorNotificationPanel createPanelForFile(VirtualFile file, VirtualFile
if (root == null) {
return null;
}
return createPanelForAction(file, root, getActionName(root));
return createPanelForAction(file, root, getAction(root));
}

private EditorNotificationPanel createPanelForAction(VirtualFile file, VirtualFile root, String actionName) {
if (actionName == null) {
private EditorNotificationPanel createPanelForAction(VirtualFile file, VirtualFile root, AnAction action) {
if (action == null) {
return null;
}
NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, actionName);
NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, action);
return panel.isValidForFile() ? panel : null;
}

private static String getActionName(VirtualFile root) {
private static AnAction getAction(VirtualFile root) {
if (root == null) {
return null;
}
if (root.getName().equals("android")) {
return "flutter.androidstudio.open";
return OPEN_IN_ANDROID_STUDIO_ACTION;
}
else if (root.getName().equals("ios")) {
return "flutter.xcode.open";
return OPEN_IN_XCODE_ACTION;
}
else {
return null;
Expand Down Expand Up @@ -97,11 +114,11 @@ class NativeEditorActionsPanel extends EditorNotificationPanel {
final AnAction myAction;
final boolean isVisible;

NativeEditorActionsPanel(VirtualFile file, VirtualFile root, String actionName) {
NativeEditorActionsPanel(VirtualFile file, VirtualFile root, AnAction openAction) {
super(EditorColors.GUTTER_BACKGROUND);
myFile = file;
myRoot = root;
myAction = ActionManager.getInstance().getAction(actionName);
myAction = openAction;

icon(FlutterIcons.Flutter);
text("Flutter commands");
Expand All @@ -128,18 +145,14 @@ private void performAction() {
}

private DataContext makeContext() {
return new DataContext() {
@Override
@Nullable
public Object getData(@NonNls String dataId) {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return myFile;
}
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
return null;
return dataId -> {
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return myFile;
}
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
return null;
};
}
}
Expand Down
1 change: 0 additions & 1 deletion src/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,3 @@ private static DefaultActionGroup createPopupActionGroup(FlutterView view, Flutt
return group;
}
}