diff --git a/base/src/com/google/idea/blaze/base/wizard2/BazelImportCurrentProjectAction.java b/base/src/com/google/idea/blaze/base/wizard2/BazelImportCurrentProjectAction.java index ce64ee4d987..c9f7cc43038 100644 --- a/base/src/com/google/idea/blaze/base/wizard2/BazelImportCurrentProjectAction.java +++ b/base/src/com/google/idea/blaze/base/wizard2/BazelImportCurrentProjectAction.java @@ -23,14 +23,13 @@ import com.google.idea.blaze.base.settings.BuildSystemName; import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver; import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl; -import com.intellij.ide.DataManager; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.project.Project; -import com.intellij.ui.EditorNotificationPanel; import java.io.File; import org.jetbrains.annotations.NotNull; @@ -49,7 +48,7 @@ public static boolean projectCouldBeImported(Project project) { return BazelWorkspaceRootProvider.INSTANCE.isWorkspaceRoot(new File(root)); } - public static Runnable createAction(EditorNotificationPanel panel, String basePath) { + public static Runnable createAction(String basePath) { File baseFile = new File(basePath); BazelImportCurrentProjectAction action = new BazelImportCurrentProjectAction(baseFile); @@ -58,7 +57,7 @@ public static Runnable createAction(EditorNotificationPanel panel, String basePa action, null, ActionPlaces.UNKNOWN, - DataManager.getInstance().getDataContext(panel) + DataContext.EMPTY_CONTEXT ); if (ActionUtil.lastUpdateAndCheckDumb(action, event, true)) { @@ -69,7 +68,8 @@ public static Runnable createAction(EditorNotificationPanel panel, String basePa final File workspaceRootFile; - private BazelImportCurrentProjectAction(File workspaceRootFile) { + public BazelImportCurrentProjectAction(File workspaceRootFile) { + super("Import current project"); this.workspaceRootFile = workspaceRootFile; } diff --git a/base/src/com/google/idea/blaze/base/wizard2/BazelNotificationProvider.java b/base/src/com/google/idea/blaze/base/wizard2/BazelNotificationProvider.java index 4696a0ffe29..5f6b775ee4b 100644 --- a/base/src/com/google/idea/blaze/base/wizard2/BazelNotificationProvider.java +++ b/base/src/com/google/idea/blaze/base/wizard2/BazelNotificationProvider.java @@ -34,7 +34,7 @@ public class BazelNotificationProvider implements EditorNotificationProvider, Du @Override public @Nullable Function collectNotificationData( @NotNull Project project, @NotNull VirtualFile file) { - if (file.getFileType() != BuildFileType.INSTANCE) { + if (!isProjectAwareFile(file)) { return null; } if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { @@ -51,7 +51,7 @@ public class BazelNotificationProvider implements EditorNotificationProvider, Du return fileEditor -> { EditorNotificationPanel panel = new EditorNotificationPanel(fileEditor, Status.Warning); - Runnable importAction = BazelImportCurrentProjectAction.createAction(panel, root); + Runnable importAction = BazelImportCurrentProjectAction.createAction(root); panel.setText("Project is not configured"); panel.createActionLabel("Import Bazel project", importAction); @@ -60,4 +60,8 @@ public class BazelNotificationProvider implements EditorNotificationProvider, Du return panel; }; } + + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return file.getFileType() == BuildFileType.INSTANCE; + } } diff --git a/clwb/sdkcompat/BUILD b/clwb/sdkcompat/BUILD index db0d621c5f8..5e499cab293 100644 --- a/clwb/sdkcompat/BUILD +++ b/clwb/sdkcompat/BUILD @@ -28,5 +28,8 @@ java_library( "clion-2024.2": ["//clwb/sdkcompat/v242"], }), visibility = ["//clwb:__pkg__"], - deps = ["//intellij_platform_sdk:plugin_api"], + deps = [ + "//base", + "//intellij_platform_sdk:plugin_api", + ], ) diff --git a/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/BazelCNotificationProvider.java new file mode 100644 index 00000000000..0648eac40b8 --- /dev/null +++ b/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.vfs.VirtualFile; + +import com.jetbrains.cidr.lang.OCLanguageUtilsBase; +import org.jetbrains.annotations.NotNull; + +/** + * Provide notification for C-family files temporarily until moving to new CLion project status + * api. + */ +// #api241 +public class BazelCNotificationProvider extends BazelNotificationProvider { + + @Override + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return OCLanguageUtilsBase.isSupported(file.getFileType()); + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..60163e17311 --- /dev/null +++ b/clwb/sdkcompat/v223/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.settings.Blaze; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; + +// #api241 +public class CLionNotificationProvider { + + public static void register(Project project) { + if (Blaze.isBlazeProject(project)) { + // Note: We want to remove the CMake notification banner in case that the project is Bazel. + var exPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + for (var extension : exPoint.getExtensions()) { + if (extension instanceof CMakeNotificationProvider) { + exPoint.unregisterExtension(extension); + } + } + } + } +} diff --git a/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/BazelCNotificationProvider.java new file mode 100644 index 00000000000..0648eac40b8 --- /dev/null +++ b/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.vfs.VirtualFile; + +import com.jetbrains.cidr.lang.OCLanguageUtilsBase; +import org.jetbrains.annotations.NotNull; + +/** + * Provide notification for C-family files temporarily until moving to new CLion project status + * api. + */ +// #api241 +public class BazelCNotificationProvider extends BazelNotificationProvider { + + @Override + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return OCLanguageUtilsBase.isSupported(file.getFileType()); + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..60163e17311 --- /dev/null +++ b/clwb/sdkcompat/v231/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.settings.Blaze; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; + +// #api241 +public class CLionNotificationProvider { + + public static void register(Project project) { + if (Blaze.isBlazeProject(project)) { + // Note: We want to remove the CMake notification banner in case that the project is Bazel. + var exPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + for (var extension : exPoint.getExtensions()) { + if (extension instanceof CMakeNotificationProvider) { + exPoint.unregisterExtension(extension); + } + } + } + } +} diff --git a/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/BazelCNotificationProvider.java new file mode 100644 index 00000000000..0648eac40b8 --- /dev/null +++ b/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.vfs.VirtualFile; + +import com.jetbrains.cidr.lang.OCLanguageUtilsBase; +import org.jetbrains.annotations.NotNull; + +/** + * Provide notification for C-family files temporarily until moving to new CLion project status + * api. + */ +// #api241 +public class BazelCNotificationProvider extends BazelNotificationProvider { + + @Override + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return OCLanguageUtilsBase.isSupported(file.getFileType()); + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..60163e17311 --- /dev/null +++ b/clwb/sdkcompat/v232/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.settings.Blaze; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; + +// #api241 +public class CLionNotificationProvider { + + public static void register(Project project) { + if (Blaze.isBlazeProject(project)) { + // Note: We want to remove the CMake notification banner in case that the project is Bazel. + var exPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + for (var extension : exPoint.getExtensions()) { + if (extension instanceof CMakeNotificationProvider) { + exPoint.unregisterExtension(extension); + } + } + } + } +} diff --git a/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/BazelCNotificationProvider.java new file mode 100644 index 00000000000..0648eac40b8 --- /dev/null +++ b/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.vfs.VirtualFile; + +import com.jetbrains.cidr.lang.OCLanguageUtilsBase; +import org.jetbrains.annotations.NotNull; + +/** + * Provide notification for C-family files temporarily until moving to new CLion project status + * api. + */ +// #api241 +public class BazelCNotificationProvider extends BazelNotificationProvider { + + @Override + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return OCLanguageUtilsBase.isSupported(file.getFileType()); + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..60163e17311 --- /dev/null +++ b/clwb/sdkcompat/v233/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.settings.Blaze; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; + +// #api241 +public class CLionNotificationProvider { + + public static void register(Project project) { + if (Blaze.isBlazeProject(project)) { + // Note: We want to remove the CMake notification banner in case that the project is Bazel. + var exPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + for (var extension : exPoint.getExtensions()) { + if (extension instanceof CMakeNotificationProvider) { + exPoint.unregisterExtension(extension); + } + } + } + } +} diff --git a/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/BazelCNotificationProvider.java new file mode 100644 index 00000000000..0648eac40b8 --- /dev/null +++ b/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.vfs.VirtualFile; + +import com.jetbrains.cidr.lang.OCLanguageUtilsBase; +import org.jetbrains.annotations.NotNull; + +/** + * Provide notification for C-family files temporarily until moving to new CLion project status + * api. + */ +// #api241 +public class BazelCNotificationProvider extends BazelNotificationProvider { + + @Override + protected boolean isProjectAwareFile(@NotNull VirtualFile file) { + return OCLanguageUtilsBase.isSupported(file.getFileType()); + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..60163e17311 --- /dev/null +++ b/clwb/sdkcompat/v241/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.settings.Blaze; +import com.intellij.openapi.project.Project; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; + +// #api241 +public class CLionNotificationProvider { + + public static void register(Project project) { + if (Blaze.isBlazeProject(project)) { + // Note: We want to remove the CMake notification banner in case that the project is Bazel. + var exPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + for (var extension : exPoint.getExtensions()) { + if (extension instanceof CMakeNotificationProvider) { + exPoint.unregisterExtension(extension); + } + } + } + } +} diff --git a/sdkcompat/v242/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/clwb/sdkcompat/v242/com/google/idea/blaze/clwb/BazelCNotificationProvider.java similarity index 54% rename from sdkcompat/v242/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java rename to clwb/sdkcompat/v242/com/google/idea/blaze/clwb/BazelCNotificationProvider.java index a2ba6e5fe91..e7bbae66b95 100644 --- a/sdkcompat/v242/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ b/clwb/sdkcompat/v242/com/google/idea/blaze/clwb/BazelCNotificationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 The Bazel Authors. All rights reserved. + * Copyright 2023 The Bazel Authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,24 @@ * limitations under the License. */ -package com.google.idea.sdkcompat.clion; +package com.google.idea.blaze.clwb; - -import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import javax.annotation.Nullable; -import javax.swing.JComponent; +import com.intellij.ui.EditorNotificationProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -// #api242 -public class CMakeNotificationProviderWrapper { +import javax.swing.*; +import java.util.function.Function; - @Nullable - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - return null; - } +// #api241 +class BazelCNotificationProvider implements EditorNotificationProvider { - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) {} -} + @Override + public @Nullable Function collectNotificationData( + @NotNull Project project, @NotNull VirtualFile virtualFile) { + return null; + } +} \ No newline at end of file diff --git a/clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.java b/clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.java new file mode 100644 index 00000000000..372a7d8b2a2 --- /dev/null +++ b/clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.java @@ -0,0 +1,143 @@ +/* + * Copyright 2023 The Bazel Authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.idea.blaze.clwb; + +import com.google.idea.blaze.base.lang.buildfile.language.BuildFileType; +import com.google.idea.blaze.base.settings.Blaze; +import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction; +import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.EditorNotificationProvider; +import com.jetbrains.cidr.project.ui.ProjectStatusHelperKt; +import com.jetbrains.cidr.project.ui.notifications.EditorNotificationWarningProvider; +import com.jetbrains.cidr.project.ui.notifications.ProjectNotification; +import com.jetbrains.cidr.project.ui.popup.ProjectFixesProvider; +import com.jetbrains.cidr.project.ui.widget.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +import static com.jetbrains.cidr.project.ui.ProjectStatusHelperKt.isProjectAwareFile; + +// #api241 +public class CLionNotificationProvider implements ProjectFixesProvider, WidgetStatusProvider, + EditorNotificationWarningProvider { + + private static void unregisterGenericProvider(Project project) { + final var extensionPoint = EditorNotificationProvider.EP_NAME.getPoint(project); + + // Note: We need to remove the default style of showing project status and fixes used in + // Android Studio and IDEA to introduce CLion's PSW style. + for (final var extension : extensionPoint.getExtensions()) { + if (extension instanceof BazelNotificationProvider) { + extensionPoint.unregisterExtension(extension); + } + } + } + + public static void register(Project project) { + unregisterGenericProvider(project); + + final var projectFixes = ProjectFixesProvider.Companion.getEP_NAME().getPoint(); + projectFixes.registerExtension(new CLionNotificationProvider()); + final var projectNotifications = EditorNotificationWarningProvider.Companion.getEP_NAME() + .getPoint(); + projectNotifications.registerExtension(new CLionNotificationProvider()); + final var widgetStatus = WidgetStatusProvider.Companion.getEP_NAME().getPoint(); + widgetStatus.registerExtension(new CLionNotificationProvider()); + } + + @NotNull + @Override + public List collectFixes(@NotNull Project project, @Nullable VirtualFile file, + @NotNull DataContext dataContext) { + if (file == null) { + return List.of(); + } + + if (Blaze.isBlazeProject(project)) { + return List.of(); + } + + if (!isProjectAwareFile(file, project) && file.getFileType() != BuildFileType.INSTANCE) { + return List.of(); + } + if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { + return List.of(); + } + + String root = project.getBasePath(); + if (root == null) { + return List.of(); + } + + return List.of(new ImportBazelAction(root)); + } + + private static class ImportBazelAction extends AnAction { + + private final String root; + + public ImportBazelAction(String root) { + super("Import Bazel project"); + this.root = root; + } + + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + BazelImportCurrentProjectAction.createAction(root).run(); + } + } + + @Nullable + @Override + public ProjectNotification getProjectNotification(@NotNull Project project, + @NotNull VirtualFile virtualFile) { + return ProjectStatusHelperKt.convertStatus(getWidgetStatus(project, virtualFile)); + } + + @Nullable + @Override + public WidgetStatus getWidgetStatus(@NotNull Project project, @Nullable VirtualFile file) { + + if (Blaze.isBlazeProject(project)) { + return new DefaultWidgetStatus(Status.OK, Scope.Project, "Project is configured"); + } + + if (file == null) { + return null; + } + + if (!isProjectAwareFile(file, project) && file.getFileType() != BuildFileType.INSTANCE) { + return null; + } + if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { + return null; + } + + String root = project.getBasePath(); + if (root == null) { + return null; + } + + return new DefaultWidgetStatus(Status.Warning, Scope.Project, "Project is not configured"); + } +} diff --git a/clwb/src/META-INF/clwb.xml b/clwb/src/META-INF/clwb.xml index 1a2e908a2a3..e949c1d07e9 100644 --- a/clwb/src/META-INF/clwb.xml +++ b/clwb/src/META-INF/clwb.xml @@ -28,7 +28,6 @@ - diff --git a/clwb/src/com/google/idea/blaze/clwb/BazelCNotificationProvider.java b/clwb/src/com/google/idea/blaze/clwb/BazelCNotificationProvider.java deleted file mode 100644 index e8189a5b0e3..00000000000 --- a/clwb/src/com/google/idea/blaze/clwb/BazelCNotificationProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2024 The Bazel Authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.idea.blaze.clwb; - -import com.google.idea.blaze.base.wizard2.BazelDisableImportNotification; -import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.EditorNotificationPanel; -import com.intellij.ui.EditorNotificationPanel.Status; -import com.intellij.ui.EditorNotificationProvider; -import com.jetbrains.cidr.lang.OCFileType; -import java.util.function.Function; -import javax.swing.JComponent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Provide notification for C-family files temporarily until moving to new CLion project status - * api. - */ -public class BazelCNotificationProvider implements EditorNotificationProvider { - - @Override - public @Nullable Function collectNotificationData( - @NotNull Project project, @NotNull VirtualFile file) { - if (file.getFileType() != OCFileType.INSTANCE) { - return null; - } - - if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { - return null; - } - if (BazelDisableImportNotification.isNotificationDisabled(project)) { - return null; - } - - String root = project.getBasePath(); - if (root == null) { - return null; - } - - return fileEditor -> { - EditorNotificationPanel panel = new EditorNotificationPanel(fileEditor, Status.Warning); - Runnable importAction = BazelImportCurrentProjectAction.createAction(panel, root); - - panel.setText("Project is not configured"); - panel.createActionLabel("Import Bazel project", importAction); - panel.createActionLabel("Dismiss", "Bazel.DisableImportNotification"); - - return panel; - }; - } -} diff --git a/clwb/src/com/google/idea/blaze/plugin/CMakeNotificationFilter.java b/clwb/src/com/google/idea/blaze/plugin/CMakeNotificationFilter.java deleted file mode 100644 index 171d708dd84..00000000000 --- a/clwb/src/com/google/idea/blaze/plugin/CMakeNotificationFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2018 The Bazel Authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.idea.blaze.plugin; - -import com.google.idea.blaze.base.settings.Blaze; -import com.google.idea.sdkcompat.clion.CMakeNotificationProviderWrapper; -import com.google.idea.sdkcompat.general.EditorNotificationCompat; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.EditorNotifications; - -import javax.annotation.Nullable; -import javax.swing.JComponent; - -/** Need to filter out CMake messages if we are a Blaze project. */ -public class CMakeNotificationFilter extends EditorNotifications.Provider - implements DumbAware { - private final CMakeNotificationProviderWrapper delegate; - - private static final Key KEY = Key.create("CMakeNotificationFilter"); - - private CMakeNotificationFilter(Project project) { - this.delegate = Blaze.isBlazeProject(project) ? null : new CMakeNotificationProviderWrapper(); - } - - @Override - public Key getKey() { - return KEY; - } - - @Nullable - @Override - public JComponent createNotificationPanel( - VirtualFile virtualFile, FileEditor fileEditor, Project project) { - return delegate == null - ? null - : delegate.createNotificationPanel(virtualFile, fileEditor, project); - } - - public static void overrideProjectExtension(Project project) { - CMakeNotificationProviderWrapper.unregisterDelegateExtension(EditorNotificationCompat.getEp(project)); - EditorNotificationCompat.getEp(project).registerExtension(new CMakeNotificationFilter(project)); - } -} diff --git a/clwb/src/com/google/idea/blaze/plugin/ClwbProjectSpecificInitializer.java b/clwb/src/com/google/idea/blaze/plugin/ClwbProjectSpecificInitializer.java index 897c55f3bdb..d5d4bc97bb9 100644 --- a/clwb/src/com/google/idea/blaze/plugin/ClwbProjectSpecificInitializer.java +++ b/clwb/src/com/google/idea/blaze/plugin/ClwbProjectSpecificInitializer.java @@ -15,6 +15,7 @@ */ package com.google.idea.blaze.plugin; +import com.google.idea.blaze.clwb.CLionNotificationProvider; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.project.Project; @@ -29,6 +30,6 @@ public ClwbProjectSpecificInitializer(Project project) { @Override public void projectOpened() { - CMakeNotificationFilter.overrideProjectExtension(project); + CLionNotificationProvider.register(project); } } diff --git a/sdkcompat/v221/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v221/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index 27f1689be89..00000000000 --- a/sdkcompat/v221/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.google.idea.sdkcompat.clion; - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper() { - value = new CMakeNotificationProvider(); - } - - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - return value.createNotificationPanel(virtualFile, fileEditor, project); - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v222/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v222/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index 27f1689be89..00000000000 --- a/sdkcompat/v222/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.google.idea.sdkcompat.clion; - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper() { - value = new CMakeNotificationProvider(); - } - - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - return value.createNotificationPanel(virtualFile, fileEditor, project); - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v223/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v223/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index 27f1689be89..00000000000 --- a/sdkcompat/v223/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.google.idea.sdkcompat.clion; - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper() { - value = new CMakeNotificationProvider(); - } - - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - return value.createNotificationPanel(virtualFile, fileEditor, project); - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v231/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v231/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index edb0594090b..00000000000 --- a/sdkcompat/v231/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.google.idea.sdkcompat.clion; - - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import java.util.function.Function; -import javax.annotation.Nullable; -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper(){ - this.value = new CMakeNotificationProvider(); - } - - @Nullable - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - Function notificationProducer = - this.value.collectNotificationData(project, virtualFile); - - if (notificationProducer != null) { - return notificationProducer.apply(fileEditor); - } - - return null; - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v232/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v232/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index edb0594090b..00000000000 --- a/sdkcompat/v232/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.google.idea.sdkcompat.clion; - - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import java.util.function.Function; -import javax.annotation.Nullable; -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper(){ - this.value = new CMakeNotificationProvider(); - } - - @Nullable - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - Function notificationProducer = - this.value.collectNotificationData(project, virtualFile); - - if (notificationProducer != null) { - return notificationProducer.apply(fileEditor); - } - - return null; - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v233/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v233/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index edb0594090b..00000000000 --- a/sdkcompat/v233/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.google.idea.sdkcompat.clion; - - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import java.util.function.Function; -import javax.annotation.Nullable; -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper(){ - this.value = new CMakeNotificationProvider(); - } - - @Nullable - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - Function notificationProducer = - this.value.collectNotificationData(project, virtualFile); - - if (notificationProducer != null) { - return notificationProducer.apply(fileEditor); - } - - return null; - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -} diff --git a/sdkcompat/v241/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java b/sdkcompat/v241/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java deleted file mode 100644 index 46dfdbc93e3..00000000000 --- a/sdkcompat/v241/com/google/idea/sdkcompat/clion/CMakeNotificationProviderWrapper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2023 The Bazel Authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.idea.sdkcompat.clion; - - -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeNotificationProvider; - -import java.util.function.Function; -import javax.annotation.Nullable; -import javax.swing.*; - -// #api223 -public class CMakeNotificationProviderWrapper { - CMakeNotificationProvider value; - - public CMakeNotificationProviderWrapper(){ - this.value = new CMakeNotificationProvider(); - } - - @Nullable - public JComponent createNotificationPanel(VirtualFile virtualFile, FileEditor fileEditor, Project project) { - Function notificationProducer = - this.value.collectNotificationData(project, virtualFile); - - if (notificationProducer != null) { - return notificationProducer.apply(fileEditor); - } - - return null; - } - - public static void unregisterDelegateExtension(ExtensionPoint extensionPoint) { - for (T extension : extensionPoint.getExtensions()) { - if (extension instanceof CMakeNotificationProvider) { - extensionPoint.unregisterExtension(extension); - } - } - } -}