-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically show ToolWindow after submitting an exercise
- Loading branch information
1 parent
45006e1
commit e381747
Showing
19 changed files
with
219 additions
and
67 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
28 changes: 28 additions & 0 deletions
28
...in/java/io/github/thepieterdc/dodona/plugin/settings/listeners/ProjectCourseListener.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,28 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
package io.github.thepieterdc.dodona.plugin.settings.listeners; | ||
|
||
import com.intellij.util.messages.Topic; | ||
|
||
/** | ||
* The course of the project was either set or modified. | ||
*/ | ||
@FunctionalInterface | ||
public interface ProjectCourseListener { | ||
Topic<ProjectCourseListener> CHANGED_TOPIC = | ||
Topic.create("Project course changed", ProjectCourseListener.class); | ||
|
||
/** | ||
* Called when the course of the project has been set. | ||
* | ||
* @param course the course | ||
*/ | ||
void onCourseChanged(Long course); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/thepieterdc/dodona/plugin/settings/listeners/package-info.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,16 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
/** | ||
* Listeners for changes in project settings. | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package io.github.thepieterdc.dodona.plugin.settings.listeners; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
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
65 changes: 65 additions & 0 deletions
65
src/main/java/io/github/thepieterdc/dodona/plugin/toolwindow/ToolWindowSynchronizer.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,65 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
package io.github.thepieterdc.dodona.plugin.toolwindow; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.DumbAwareRunnable; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowAnchor; | ||
import com.intellij.openapi.wm.ToolWindowEP; | ||
import com.intellij.openapi.wm.ToolWindowFactory; | ||
import com.intellij.openapi.wm.ToolWindowManager; | ||
import io.github.thepieterdc.dodona.plugin.settings.listeners.ProjectCourseListener; | ||
|
||
/** | ||
* Displays or hides the tool window. | ||
*/ | ||
public class ToolWindowSynchronizer { | ||
private final Project project; | ||
|
||
/** | ||
* ToolWindowSynchronizer constructor. | ||
* | ||
* @param project the current active project | ||
*/ | ||
public ToolWindowSynchronizer(final Project project) { | ||
this.project = project; | ||
this.project.getMessageBus().connect().subscribe( | ||
ProjectCourseListener.CHANGED_TOPIC, | ||
id -> this.update() | ||
); | ||
} | ||
|
||
/** | ||
* Updates the state of the ToolWindow visibility. | ||
*/ | ||
private void update() { | ||
ApplicationManager.getApplication().invokeLater((DumbAwareRunnable) () -> { | ||
for (final ToolWindowEP ep : ToolWindowEP.EP_NAME.getExtensions()) { | ||
if (DodonaToolWindowFactory.class.isAssignableFrom(ep.getFactoryClass())) { | ||
final ToolWindowFactory factory = ep.getToolWindowFactory(); | ||
final ToolWindowManager mgr = ToolWindowManager.getInstance(this.project); | ||
if (mgr.getToolWindow(DodonaToolWindowFactory.TOOL_WINDOW_ID) == null) { | ||
final ToolWindow toolWindow = mgr.registerToolWindow( | ||
DodonaToolWindowFactory.TOOL_WINDOW_ID, | ||
true, | ||
ToolWindowAnchor.RIGHT, | ||
this.project, | ||
false, | ||
true | ||
); | ||
factory.createToolWindowContent(this.project, toolWindow); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.