Skip to content

Commit

Permalink
Added Clear All action
Browse files Browse the repository at this point in the history
  • Loading branch information
leinardi committed Aug 31, 2018
1 parent 0d8cd78 commit 811119c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
55 changes: 55 additions & 0 deletions src/main/java/com/leinardi/pycharm/pylint/actions/ClearAll.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@
text="Display Refactor"
description="Display Refactor results"
icon="/actions/forceRefresh.png"/>

<separator/>

<action id="PylintClearAllAction"
class="com.leinardi.pycharm.pylint.actions.ClearAll"
text="Clear All"
description="Clear all elements in the tool window"
icon="/actions/gc.png"/>

</group>

<group id="PylintPluginActions" text="Pylint" popup="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ pylint.exception-with-root-cause=<html><b>The scan failed due to an exception:<b
config.pylint.path=Path to Pylint executable:
config.pylint.path.default=pylint
config.pylint.path.test=Test
config.pylint.path.success.title=Success
config.pylint.path.success.message=Pylint executable found!
config.pylint.path.failure.title=Failure
config.pylint.path.failure.message=Pylint not found on {0}
config.pylint.path.success.message=Success: executable found!
config.pylint.path.failure.message=Failure: executable "{0}" not found
config.file.tab=Configuration File
config.file.description=The active rules file may be overridden, or deactivated, by module settings.
config.file.label.text=Configuration File:
Expand Down

0 comments on commit 811119c

Please sign in to comment.