-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # CHANGELOG.md # src/main/resources/META-INF/plugin.xml
- Loading branch information
Showing
21 changed files
with
421 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/chrisrm/idea/status/MTStatusBarComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.chrisrm.idea.status; | ||
|
||
import com.intellij.openapi.components.AbstractProjectComponent; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.StatusBar; | ||
import com.intellij.openapi.wm.WindowManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MTStatusBarComponent extends AbstractProjectComponent { | ||
private MTStatusBarManager statusBarWidget; | ||
|
||
public MTStatusBarComponent(@NotNull Project project) { | ||
super(project); | ||
} | ||
|
||
@Override | ||
public void initComponent() { | ||
statusBarWidget = MTStatusBarManager.create(myProject); | ||
} | ||
|
||
@Override | ||
public void disposeComponent() { | ||
statusBarWidget.dispose(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getComponentName() { | ||
return "MTStatusBarComponent"; | ||
} | ||
|
||
@Override | ||
public void projectOpened() { | ||
statusBarWidget.install(); | ||
} | ||
|
||
@Override | ||
public void projectClosed() { | ||
statusBarWidget.uninstall(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/chrisrm/idea/status/MTStatusBarManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.chrisrm.idea.status; | ||
|
||
import com.chrisrm.idea.MTConfig; | ||
import com.chrisrm.idea.config.ConfigNotifier; | ||
import com.intellij.openapi.Disposable; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.DumbAware; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.StatusBar; | ||
import com.intellij.openapi.wm.WindowManager; | ||
import com.intellij.util.messages.MessageBusConnection; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
class MTStatusBarManager implements Disposable, DumbAware { | ||
|
||
private final Project project; | ||
private boolean statusEnabled; | ||
private MTStatusWidget mtStatusWidget; | ||
private final MessageBusConnection connect; | ||
|
||
private MTStatusBarManager(@NotNull Project project) { | ||
this.project = project; | ||
this.mtStatusWidget = new MTStatusWidget(); | ||
this.statusEnabled = MTConfig.getInstance().isStatusBarTheme(); | ||
|
||
connect = project.getMessageBus().connect(); | ||
connect.subscribe(ConfigNotifier.CONFIG_TOPIC, this::refreshWidget); | ||
} | ||
|
||
public static MTStatusBarManager create(@NotNull Project project) { | ||
return new MTStatusBarManager(project); | ||
} | ||
|
||
private void refreshWidget(MTConfig mtConfig) { | ||
if (mtConfig.isStatusBarThemeChanged(this.statusEnabled)) { | ||
statusEnabled = mtConfig.isStatusBarTheme(); | ||
|
||
if (statusEnabled){ | ||
this.install(); | ||
} else { | ||
this.uninstall(); | ||
} | ||
} | ||
|
||
mtStatusWidget.refresh(); | ||
} | ||
|
||
void install() { | ||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project); | ||
if (statusBar != null) { | ||
statusBar.addWidget(mtStatusWidget, "before Position", project); | ||
} | ||
} | ||
|
||
|
||
void uninstall() { | ||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project); | ||
if (statusBar != null) { | ||
statusBar.removeWidget(mtStatusWidget.ID()); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { | ||
if (mtStatusWidget != null) { | ||
uninstall(); | ||
mtStatusWidget = null; | ||
} | ||
} | ||
connect.disconnect(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.