Skip to content

Commit dbca89b

Browse files
committed
kotlin all the things
1 parent afe7300 commit dbca89b

24 files changed

+184
-341
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
insert_final_newline = true
9+
charset = utf-8
10+
indent_style = space
11+
indent_size = 2
12+
trim_trailing_whitespace = true

src/main/java/com/mallowigi/idea/MTStartup.kt

+30-31
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,37 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea
2425

25-
package com.mallowigi.idea;
26+
import com.intellij.openapi.startup.StartupActivity
27+
import com.mallowigi.idea.MTStartup
28+
import com.intellij.util.messages.MessageBusConnection
29+
import com.intellij.openapi.application.ApplicationManager
30+
import com.intellij.ide.AppLifecycleListener
31+
import com.intellij.openapi.project.Project
32+
import com.intellij.openapi.util.registry.Registry
2633

27-
import com.intellij.ide.AppLifecycleListener;
28-
import com.intellij.openapi.application.ApplicationManager;
29-
import com.intellij.openapi.project.Project;
30-
import com.intellij.openapi.startup.StartupActivity;
31-
import com.intellij.openapi.util.registry.Registry;
32-
import com.intellij.util.messages.MessageBusConnection;
33-
import org.jetbrains.annotations.NotNull;
34+
class MTStartup : StartupActivity {
35+
override fun runActivity(project: Project) {
36+
modifyRegistry()
37+
ApplicationManager.getApplication().messageBus.connect().also {
38+
it.subscribe(AppLifecycleListener.TOPIC, object : AppLifecycleListener {
39+
override fun appClosing() {
40+
Registry.get(IDE_BALLOON_SHADOW_SIZE).setValue(15)
41+
Registry.get(IDE_INTELLIJ_LAF_ENABLE_ANIMATION).setValue(false)
42+
it.disconnect()
43+
}
44+
})
45+
}
46+
}
3447

35-
public final class MTStartup implements StartupActivity {
36-
public static final String IDE_BALLOON_SHADOW_SIZE = "ide.balloon.shadow.size";
37-
public static final String IDE_INTELLIJ_LAF_ENABLE_ANIMATION = "ide.intellij.laf.enable.animation";
48+
companion object {
49+
private const val IDE_BALLOON_SHADOW_SIZE = "ide.balloon.shadow.size"
50+
private const val IDE_INTELLIJ_LAF_ENABLE_ANIMATION = "ide.intellij.laf.enable.animation"
3851

39-
@Override
40-
public void runActivity(@NotNull final Project project) {
41-
modifyRegistry();
42-
43-
final MessageBusConnection connect = ApplicationManager.getApplication().getMessageBus().connect();
44-
connect.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() {
45-
@Override
46-
public void appClosing() {
47-
Registry.get(IDE_BALLOON_SHADOW_SIZE).setValue(15);
48-
Registry.get(IDE_INTELLIJ_LAF_ENABLE_ANIMATION).setValue(false);
49-
connect.disconnect();
50-
}
51-
});
52-
}
53-
54-
private static void modifyRegistry() {
55-
Registry.get(IDE_BALLOON_SHADOW_SIZE).setValue(0);
56-
Registry.get(IDE_INTELLIJ_LAF_ENABLE_ANIMATION).setValue(true);
57-
}
58-
}
52+
private fun modifyRegistry() {
53+
Registry.get(IDE_BALLOON_SHADOW_SIZE).setValue(0)
54+
Registry.get(IDE_INTELLIJ_LAF_ENABLE_ANIMATION).setValue(true)
55+
}
56+
}
57+
}

src/main/java/com/mallowigi/idea/MaterialThemeBundle.kt

+10-21
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,16 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea
2425

25-
package com.mallowigi.idea;
26+
import com.intellij.AbstractBundle
27+
import org.jetbrains.annotations.NonNls
28+
import org.jetbrains.annotations.PropertyKey
2629

27-
import com.intellij.AbstractBundle;
28-
import org.jetbrains.annotations.NonNls;
29-
import org.jetbrains.annotations.NotNull;
30-
import org.jetbrains.annotations.PropertyKey;
31-
32-
/**
33-
* Messages Bundle for Material Theme
34-
*/
35-
public final class MaterialThemeBundle extends AbstractBundle {
36-
public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) final String key, @NotNull final Object... params) {
37-
return INSTANCE.getMessage(key, params);
38-
}
39-
40-
@NonNls
41-
private static final String BUNDLE = "messages.MaterialThemeBundle";
42-
private static final MaterialThemeBundle INSTANCE = new MaterialThemeBundle();
43-
44-
private MaterialThemeBundle() {
45-
super(BUNDLE);
46-
}
30+
object MaterialThemeBundle : AbstractBundle(MATERIAL_THEME_BUNDLE) {
31+
@JvmStatic
32+
fun message(@PropertyKey(resourceBundle = MATERIAL_THEME_BUNDLE) key: String, vararg params: Any?): String {
33+
return getMessage(key, *params)
34+
}
4735
}
36+
const val MATERIAL_THEME_BUNDLE: String = "messages.MaterialThemeBundle"

src/main/java/com/mallowigi/idea/ThemesBundle.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
package com.mallowigi.idea
2525

2626
import com.intellij.AbstractBundle
27-
import com.mallowigi.idea.ThemesBundle
28-
import org.jetbrains.annotations.NonNls
2927
import org.jetbrains.annotations.PropertyKey
3028

31-
object ThemesBundle : AbstractBundle(MESSAGE_BUNDLE) {
29+
object ThemesBundle : AbstractBundle(THEMES_BUNDLE) {
3230
@JvmStatic
33-
fun message(@PropertyKey(resourceBundle = MESSAGE_BUNDLE) key: String, vararg params: Any?): String {
31+
fun message(@PropertyKey(resourceBundle = THEMES_BUNDLE) key: String, vararg params: Any?): String {
3432
return getMessage(key, *params)
3533
}
3634
}
37-
const val MESSAGE_BUNDLE = "messages.ThemesBundle"
35+
const val THEMES_BUNDLE: String = "messages.ThemesBundle"

src/main/java/com/mallowigi/idea/themes/MTAbstractThemeAction.kt

+19-44
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,32 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26+
import com.intellij.ide.ui.LafManager
27+
import com.intellij.openapi.actionSystem.AnActionEvent
28+
import com.intellij.openapi.project.DumbAware
29+
import com.mallowigi.idea.MaterialThemeBundle.message
30+
import org.jetbrains.annotations.NonNls
31+
import java.text.MessageFormat
2632

27-
import com.intellij.ide.ui.LafManager;
28-
import com.intellij.openapi.actionSystem.AnActionEvent;
29-
import com.intellij.openapi.project.DumbAware;
30-
import com.intellij.util.containers.ContainerUtil;
31-
import com.mallowigi.idea.MaterialThemeBundle;
32-
import org.jetbrains.annotations.NonNls;
33-
import org.jetbrains.annotations.NotNull;
34-
35-
import javax.swing.*;
36-
import java.text.MessageFormat;
37-
import java.util.Objects;
38-
39-
/**
40-
* Abstract Material Theme switch action
41-
*/
42-
public abstract class MTAbstractThemeAction extends MTToggleAction implements DumbAware {
43-
44-
@Override
45-
public final void setSelected(@NotNull final AnActionEvent e, final boolean state) {
33+
abstract class MTAbstractThemeAction : MTToggleAction(), DumbAware {
34+
override fun setSelected(e: AnActionEvent, state: Boolean) {
4635
// Find LAF theme and trigger a theme change
47-
final LafManager lafManager = LafManager.getInstance();
48-
final UIManager.LookAndFeelInfo lafInfo = ContainerUtil.find(lafManager.getInstalledLookAndFeels(),
49-
lookAndFeelInfo -> lookAndFeelInfo.getName().equals(getThemeName(e)));
50-
51-
if (lafInfo != null) {
52-
lafManager.setCurrentLookAndFeel(lafInfo);
53-
}
36+
val lafManager = LafManager.getInstance()
37+
val lafInfo = lafManager.installedLookAndFeels.find { it.name == getThemeName(e) }
38+
if (lafInfo != null) lafManager.currentLookAndFeel = lafInfo
5439
}
5540

56-
@Override
57-
public final boolean isSelected(@NotNull final AnActionEvent e) {
58-
return Objects.requireNonNull(LafManager.getInstance().getCurrentLookAndFeel()).getName().equals(getThemeName(e));
59-
}
41+
override fun isSelected(e: AnActionEvent): Boolean = LafManager.getInstance().currentLookAndFeel!!.name == getThemeName(e)
6042

61-
/**
62-
* Returns the theme to apply
63-
*
64-
* @return the theme
65-
*/
66-
protected abstract MTThemes getTheme();
43+
protected abstract val theme: MTThemes
6744

6845
@NonNls
69-
private String getThemeName(@NotNull final AnActionEvent e) {
70-
final String contrast = MaterialThemeBundle.message("contrast");
71-
72-
final boolean isContrast = e.getPresentation().getText() != null && e.getPresentation().getText().contains(contrast);
73-
final String name = getTheme().getName();
74-
75-
return isContrast ? MessageFormat.format("{0} {1}", name, contrast) : name;
46+
private fun getThemeName(e: AnActionEvent): String {
47+
val contrast = message("contrast")
48+
val isContrast = e.presentation.text!!.contains(contrast)
49+
val name = theme.themeName
50+
return if (isContrast) MessageFormat.format("{0} {1}", name, contrast) else name
7651
}
7752
}

src/main/java/com/mallowigi/idea/themes/MTArcDarkThemeAction.kt

+4-9
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
28-
public final class MTArcDarkThemeAction extends MTAbstractThemeAction {
29-
30-
@Override
31-
protected MTThemes getTheme() {
32-
return MTThemes.ARC_DARK;
33-
}
26+
class MTArcDarkThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.ARC_DARK
3429
}

src/main/java/com/mallowigi/idea/themes/MTDarkerThemeAction.kt

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTDarkerThemeAction extends MTAbstractThemeAction {
30-
31-
@Override
32-
@NotNull
33-
public MTThemes getTheme() {
34-
return MTThemes.DARKER;
35-
}
26+
class MTDarkerThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.DARKER
3629
}
30+

src/main/java/com/mallowigi/idea/themes/MTDeepOceanThemeAction.kt

+5-12
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTDeepOceanThemeAction extends MTAbstractThemeAction {
30-
@SuppressWarnings("MethodReturnAlwaysConstant")
31-
@Override
32-
@NotNull
33-
public MTThemes getTheme() {
34-
return MTThemes.DEEPOCEAN;
35-
}
36-
26+
class MTDeepOceanThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.DEEPOCEAN
3729
}
30+

src/main/java/com/mallowigi/idea/themes/MTDraculaThemeAction.kt

+5-12
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTDraculaThemeAction extends MTAbstractThemeAction {
30-
31-
@Override
32-
@NotNull
33-
public MTThemes getTheme() {
34-
return MTThemes.DRACULA;
35-
}
36-
26+
class MTDraculaThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.DRACULA
3729
}
30+

src/main/java/com/mallowigi/idea/themes/MTGithubDarkThemeAction.kt

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTGithubDarkThemeAction extends MTAbstractThemeAction {
30-
@Override
31-
@NotNull
32-
public MTThemes getTheme() {
33-
return MTThemes.GITHUB_DARK;
34-
}
35-
26+
class MTGithubDarkThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.GITHUB_DARK
3629
}
30+

src/main/java/com/mallowigi/idea/themes/MTGithubThemeAction.kt

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTGithubThemeAction extends MTAbstractThemeAction {
30-
@Override
31-
@NotNull
32-
public MTThemes getTheme() {
33-
return MTThemes.GITHUB;
34-
}
35-
26+
class MTGithubThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.GITHUB
3629
}
30+

src/main/java/com/mallowigi/idea/themes/MTLightOwlThemeAction.kt

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTLightOwlThemeAction extends MTAbstractThemeAction {
30-
@Override
31-
@NotNull
32-
public MTThemes getTheme() {
33-
return MTThemes.LIGHT_OWL;
34-
}
35-
26+
class MTLightOwlThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.LIGHT_OWL
3629
}
30+

src/main/java/com/mallowigi/idea/themes/MTLighterThemeAction.kt

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
package com.mallowigi.idea.themes
2425

25-
package com.mallowigi.idea.themes;
26-
27-
import org.jetbrains.annotations.NotNull;
28-
29-
public final class MTLighterThemeAction extends MTAbstractThemeAction {
30-
@Override
31-
@NotNull
32-
public MTThemes getTheme() {
33-
return MTThemes.LIGHTER;
34-
}
35-
26+
class MTLighterThemeAction : MTAbstractThemeAction() {
27+
override val theme: MTThemes
28+
get() = MTThemes.LIGHTER
3629
}
30+

0 commit comments

Comments
 (0)