From 811119cc36916743b40a7518c4fbab197be5be0b Mon Sep 17 00:00:00 2001 From: Roberto Leinardi Date: Wed, 29 Aug 2018 23:51:50 +0200 Subject: [PATCH] Added Clear All action --- .../pycharm/pylint/actions/ClearAll.java | 55 +++++++++++++++++++ .../toolwindow/PylintToolWindowPanel.java | 5 ++ .../pycharm/pylint/ui/PylintConfigPanel.java | 2 - .../pycharm/pylint/util/Notifications.java | 7 ++- src/main/resources/META-INF/plugin.xml | 9 +++ .../pycharm/pylint/PylintBundle.properties | 6 +- 6 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/leinardi/pycharm/pylint/actions/ClearAll.java diff --git a/src/main/java/com/leinardi/pycharm/pylint/actions/ClearAll.java b/src/main/java/com/leinardi/pycharm/pylint/actions/ClearAll.java new file mode 100644 index 0000000..6febda1 --- /dev/null +++ b/src/main/java/com/leinardi/pycharm/pylint/actions/ClearAll.java @@ -0,0 +1,55 @@ +/* + * Copyright 2018 Roberto Leinardi. + * + * 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.leinardi.pycharm.pylint.actions; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.content.Content; +import com.leinardi.pycharm.pylint.PylintPlugin; +import com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel; + +/** + * Action to toggle error display in tool window. + */ +public class ClearAll extends BaseAction { + + @Override + public void actionPerformed(final AnActionEvent event) { + final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); + if (project == null) { + return; + } + + final PylintPlugin pylintPlugin + = project.getComponent(PylintPlugin.class); + if (pylintPlugin == null) { + throw new IllegalStateException("Couldn't get pylint plugin"); + } + + final ToolWindow toolWindow = ToolWindowManager.getInstance( + project).getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW); + + final Content content = toolWindow.getContentManager().getContent(0); + if (content != null && content.getComponent() instanceof PylintToolWindowPanel) { + ((PylintToolWindowPanel) content.getComponent()).clearResult(); + } + } + +} diff --git a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java index 5ee663c..1fe9f87 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java +++ b/src/main/java/com/leinardi/pycharm/pylint/toolwindow/PylintToolWindowPanel.java @@ -479,6 +479,11 @@ public void displayWarningResult(final String messageKey, treeModel.setRootMessage(messageKey, messageArgs); } + public void clearResult() { + treeModel.clear(); + treeModel.setRootText(null); + } + /** * Clear the results and display notice to say an error occurred. * diff --git a/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java b/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java index 417db0a..ee633e8 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java +++ b/src/main/java/com/leinardi/pycharm/pylint/ui/PylintConfigPanel.java @@ -141,14 +141,12 @@ public void actionPerformed(final ActionEvent e) { testButton.setIcon(Icons.icon("/general/inspectionsOK.png")); Notifications.showInfo( project, - PylintBundle.message("config.pylint.path.success.title"), PylintBundle.message("config.pylint.path.success.message") ); } else { testButton.setIcon(Icons.icon("/general/error.png")); Notifications.showError( project, - PylintBundle.message("config.pylint.path.failure.title"), PylintBundle.message("config.pylint.path.failure.message", pathToPylint) ); } diff --git a/src/main/java/com/leinardi/pycharm/pylint/util/Notifications.java b/src/main/java/com/leinardi/pycharm/pylint/util/Notifications.java index 712f518..710e66b 100644 --- a/src/main/java/com/leinardi/pycharm/pylint/util/Notifications.java +++ b/src/main/java/com/leinardi/pycharm/pylint/util/Notifications.java @@ -36,13 +36,14 @@ public final class Notifications { private static final NotificationGroup BALLOON_GROUP = balloonGroup(message("plugin.notification.alerts")); private static final NotificationGroup LOG_ONLY_GROUP = logOnlyGroup(message("plugin.notification.logging")); + private static final String TITLE = message("plugin.name"); private Notifications() { } public static void showInfo(final Project project, final String infoText) { BALLOON_GROUP - .createNotification("", infoText, INFORMATION, URL_OPENING_LISTENER) + .createNotification(TITLE, infoText, INFORMATION, URL_OPENING_LISTENER) .notify(project); } @@ -54,7 +55,7 @@ public static void showInfo(final Project project, final String title, final Str public static void showWarning(final Project project, final String warningText) { BALLOON_GROUP - .createNotification("", warningText, WARNING, URL_OPENING_LISTENER) + .createNotification(TITLE, warningText, WARNING, URL_OPENING_LISTENER) .notify(project); } @@ -66,7 +67,7 @@ public static void showWarning(final Project project, final String title, final public static void showError(final Project project, final String errorText) { BALLOON_GROUP - .createNotification("", errorText, ERROR, URL_OPENING_LISTENER) + .createNotification(TITLE, errorText, ERROR, URL_OPENING_LISTENER) .notify(project); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 26c3cad..af44be1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -120,6 +120,15 @@ text="Display Refactor" description="Display Refactor results" icon="/actions/forceRefresh.png"/> + + + + + diff --git a/src/main/resources/com/leinardi/pycharm/pylint/PylintBundle.properties b/src/main/resources/com/leinardi/pycharm/pylint/PylintBundle.properties index bd27d47..c423996 100644 --- a/src/main/resources/com/leinardi/pycharm/pylint/PylintBundle.properties +++ b/src/main/resources/com/leinardi/pycharm/pylint/PylintBundle.properties @@ -73,10 +73,8 @@ pylint.exception-with-root-cause=The scan failed due to an exception: