-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(intellij): migrate away from internal API for status bar widget (…
- Loading branch information
Showing
5 changed files
with
77 additions
and
20 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
56 changes: 56 additions & 0 deletions
56
...src/main/kotlin/com/previewjs/intellij/plugin/statusbar/OpenMenuStatusBarWidgetFactory.kt
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,56 @@ | ||
package com.previewjs.intellij.plugin.statusbar | ||
|
||
import com.intellij.ide.BrowserUtil | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.NlsContexts.ConfigurableName | ||
import com.intellij.openapi.wm.StatusBar | ||
import com.intellij.openapi.wm.StatusBarWidget | ||
import com.intellij.openapi.wm.StatusBarWidgetFactory | ||
import com.previewjs.intellij.plugin.services.ProjectService | ||
import org.jetbrains.annotations.NonNls | ||
|
||
class OpenMenuStatusBarWidgetFactory : StatusBarWidgetFactory { | ||
companion object { | ||
private var EMPTY_WIDGET = object : StatusBarWidget { | ||
override fun ID(): String = OpenMenuStatusBarWidget.ID | ||
|
||
override fun install(statusBar: StatusBar) { | ||
// Do nothing. | ||
} | ||
|
||
override fun dispose() { | ||
// Do nothing. | ||
} | ||
} | ||
} | ||
|
||
override fun getId(): @NonNls String { | ||
return OpenMenuStatusBarWidget.ID | ||
} | ||
|
||
override fun getDisplayName(): @ConfigurableName String { | ||
return "Preview.js Status" | ||
} | ||
|
||
override fun createWidget(project: Project): StatusBarWidget { | ||
val projectService = project.getService(ProjectService::class.java) | ||
val previewBaseUrl = projectService.getPreviewBaseUrl() ?: return EMPTY_WIDGET | ||
return OpenMenuStatusBarWidget( | ||
url = previewBaseUrl, | ||
onStop = { projectService.closePreview() }, | ||
onOpenBrowser = { BrowserUtil.open(previewBaseUrl) } | ||
) | ||
} | ||
|
||
override fun disposeWidget(widget: StatusBarWidget) { | ||
widget.dispose() | ||
} | ||
|
||
override fun canBeEnabledOn(statusBar: StatusBar): Boolean { | ||
return true | ||
} | ||
|
||
override fun isAvailable(project: Project): Boolean { | ||
return project.getService(ProjectService::class.java).getPreviewBaseUrl() != null | ||
} | ||
} |
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