Skip to content

Commit

Permalink
Revert back to using application-component for correct initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
halirutan committed Aug 2, 2021
1 parent 5cf9526 commit 7bbcfb7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
### Added

- Build for IntelliJ Platform version 212
- Add hot-reloading where updating the plugin does not require a restart
- UUID for serializable classes

### Changed

- Move to Gradle IntelliJ Plugin version 1.0
- Move to Gradle IntelliJ Plugin version 1.1.4

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fun properties(key: String) = project.findProperty(key).toString()

plugins {
java
id("org.jetbrains.intellij") version "1.0"
id("org.jetbrains.intellij") version "1.1.4"
id("org.jetbrains.changelog") version "1.1.2"
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ kpxPluginUntilBuild=212.*
# See https://jb.gg/intellij-platform-builds-list for available build versions
kpxPluginVerifierIdeVersions=2021.2
platformType=IC
platformVersion=LATEST-EAP-SNAPSHOT
platformVersion=2021.2
platformDownloadSources=true
--add-exports java.base/jdk.internal.vm=ALL-UNNAMED
9 changes: 5 additions & 4 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
<vendor>halirutan</vendor>
<depends>com.intellij.modules.lang</depends>

<applicationListeners>
<listener class="de.halirutan.keypromoterx.KeyPromoter"
topic="com.intellij.openapi.actionSystem.ex.AnActionListener"/>
</applicationListeners>
<application-components>
<component>
<implementation-class>de.halirutan.keypromoterx.KeyPromoter</implementation-class>
</component>
</application-components>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup
Expand Down
11 changes: 9 additions & 2 deletions src/de/halirutan/keypromoterx/KeyPromoter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

package de.halirutan.keypromoterx;

import com.intellij.application.Topics;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ex.AnActionListener;
Expand All @@ -49,7 +51,7 @@
*
* @author Patrick Scheibe, Dmitry Kashin
*/
public class KeyPromoter implements AWTEventListener, AnActionListener {
public class KeyPromoter implements AWTEventListener, AnActionListener, Disposable {

/**
* Transfers the event to {@link KeyPromoterAction} and inspects the results. Then, depending on the result and the
Expand All @@ -73,6 +75,7 @@ private void handleMouseEvent(AWTEvent e) {


public KeyPromoter() {
Topics.subscribe(AnActionListener.TOPIC, this, this);
long eventMask = AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_STATE_EVENT_MASK;
Toolkit.getDefaultToolkit().addAWTEventListener(this, eventMask);
}
Expand Down Expand Up @@ -103,7 +106,6 @@ public void eventDispatched(AWTEvent e) {
@Override
public void beforeActionPerformed(@NotNull AnAction action, AnActionEvent event) {
final InputEvent input = event.getInputEvent();

ActionType type;
if (input instanceof MouseEvent) {
type = ActionType.MouseAction;
Expand Down Expand Up @@ -183,6 +185,11 @@ private boolean disabledInDistractionFreeMode() {
return isDistractionFreeMode && keyPromoterSettings.isDisabledInDistractionFreeMode();
}

@Override
public void dispose() {
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
}

enum ActionType {
MouseAction,
KeyboardAction,
Expand Down
2 changes: 2 additions & 0 deletions src/de/halirutan/keypromoterx/statistic/StatisticsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @author Patrick Scheibe
*/
public class StatisticsList extends JBList<StatisticsItem> implements PropertyChangeListener {
private static final long serialVersionUID = 20212;
private final DefaultListModel<StatisticsItem> myModel;
private final KeyPromoterStatistics myStats = ApplicationManager.getApplication().getService(KeyPromoterStatistics.class);

Expand Down Expand Up @@ -73,6 +74,7 @@ private void updateStats() {
* Provides custom rendering of items in the Key Promoter X statistic tool-window.
*/
static class StatisticsItemCellRenderer extends JLabel implements ListCellRenderer<StatisticsItem> {
private static final long serialVersionUID = 20212;

@Override
public JLabel getListCellRendererComponent(JList<? extends StatisticsItem> list, StatisticsItem value, int index, boolean isSelected, boolean cellHasFocus) {
Expand Down
2 changes: 2 additions & 0 deletions src/de/halirutan/keypromoterx/statistic/SuppressedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @author Patrick Scheibe
*/
public class SuppressedList extends JBList<StatisticsItem> implements PropertyChangeListener, EventListener {
private static final long serialVersionUID = 20212;
private final KeyPromoterStatistics myStats = ApplicationManager.getApplication().getService(KeyPromoterStatistics.class);
private final DefaultListModel<StatisticsItem> myModel;

Expand Down Expand Up @@ -109,6 +110,7 @@ private void unsuppressItem() {
* Provides custom rendering of items in the Key Promoter X statistic tool-window.
*/
static class SuppressedItemCellRenderer extends JLabel implements ListCellRenderer<StatisticsItem> {
private static final long serialVersionUID = 20212;

SuppressedItemCellRenderer() {
setOpaque(true);
Expand Down

0 comments on commit 7bbcfb7

Please sign in to comment.