Skip to content

Commit

Permalink
Extract NotificationGroups.kt (#1204)
Browse files Browse the repository at this point in the history
## Test plan
1. nothing specific - it's just a minor refactor
  • Loading branch information
mkondratek authored Mar 28, 2024
1 parent e94ce34 commit 745209a
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.sourcegraph.cody.config.CodyAuthenticationManager;
import com.sourcegraph.cody.initialization.Activity;
import com.sourcegraph.cody.statusbar.CodyManageAccountsAction;
import com.sourcegraph.common.NotificationGroups;
import org.jetbrains.annotations.NotNull;

public class CodyAuthNotificationActivity implements Activity {
Expand Down Expand Up @@ -45,7 +46,10 @@ private void showOpenCodySidebarNotification(@NotNull Project project) {
// Display notification
Notification notification =
new Notification(
"cody.auth", "Open Cody sidebar to get started", "", NotificationType.WARNING);
NotificationGroups.CODY_AUTH,
"Open Cody sidebar to get started",
"",
NotificationType.WARNING);

AnAction openCodySidebar =
new DumbAwareAction("Open Cody") {
Expand Down Expand Up @@ -79,7 +83,8 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
private void showMissingTokenNotification() {
// Display notification
Notification notification =
new Notification("cody.auth", "Missing access token", "", NotificationType.WARNING);
new Notification(
NotificationGroups.CODY_AUTH, "Missing access token", "", NotificationType.WARNING);

notification.setIcon(Icons.CodyLogo);
notification.addAction(new CodyManageAccountsAction());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sourcegraph/find/FindPopupPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.sourcegraph.Icons;
import com.sourcegraph.common.NotificationGroups;
import com.sourcegraph.find.browser.BrowserAndLoadingPanel;
import com.sourcegraph.find.browser.JSToJavaBridgeRequestHandler;
import com.sourcegraph.find.browser.JavaToJSBridge;
Expand Down Expand Up @@ -105,7 +106,7 @@ public FindPopupPanel(@NotNull Project project, @NotNull FindService findService
private void showNoBrowserErrorNotification() {
Notification notification =
new Notification(
"Sourcegraph errors",
NotificationGroups.SOURCEGRAPH_ERRORS,
"Sourcegraph",
"Your IDE doesn't support JCEF. You won't be able to use \"Find with Sourcegraph\". If you believe this is an error, please raise this at support@sourcegraph.com, specifying your OS and IDE version.",
NotificationType.ERROR);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sourcegraph/website/CopyAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.notification.Notifications;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.sourcegraph.common.NotificationGroups;
import java.awt.datatransfer.StringSelection;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,7 +21,7 @@ protected void handleFileUri(@NotNull Project project, @NotNull String uri) {
// Display notification
Notification notification =
new Notification(
"Sourcegraph: URL sharing",
NotificationGroups.SOURCEGRAPH_URL_SHARING,
"Sourcegraph",
"File URL copied to clipboard: " + urlWithoutUtm,
NotificationType.INFORMATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.sourcegraph.cody.history.HistoryService
import com.sourcegraph.cody.initialization.EndOfTrialNotificationScheduler
import com.sourcegraph.cody.vscode.CancellationToken
import com.sourcegraph.common.CodyBundle
import com.sourcegraph.common.NotificationGroups
import java.util.concurrent.TimeUnit

class ExportChatsBackgroundable(
Expand Down Expand Up @@ -58,7 +59,7 @@ class ExportChatsBackgroundable(

val notification =
Notification(
"Sourcegraph Cody",
NotificationGroups.TOOLWINDOW,
CodyBundle.getString("export.failed"),
"",
NotificationType.WARNING)
Expand All @@ -72,7 +73,7 @@ class ExportChatsBackgroundable(

val notification =
Notification(
"Sourcegraph Cody",
NotificationGroups.TOOLWINDOW,
CodyBundle.getString("export.timed-out"),
"",
NotificationType.WARNING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.updateSettings.impl.PluginDownloader
import com.intellij.openapi.updateSettings.impl.UpdateChecker
import com.intellij.openapi.util.BuildNumber
import com.sourcegraph.common.NotificationGroups
import java.lang.reflect.InvocationTargetException

class CheckUpdatesTask(project: Project) :
Expand Down Expand Up @@ -60,7 +61,7 @@ class CheckUpdatesTask(project: Project) :
fun notifyAboutTheUpdate(project: Project) {
val notification =
FullContent(
"Sourcegraph Cody + Code Search plugin updates",
NotificationGroups.CODY_UPDATES,
"Update Available",
"A new version of Sourcegraph Cody + Code Search is available. Go to plugin settings to update.",
NotificationType.IDE_UPDATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.sourcegraph.Icons
import com.sourcegraph.common.BrowserOpener.openInBrowser
import com.sourcegraph.common.CodyBundle
import com.sourcegraph.common.NotificationGroups

class TrialEndedNotification(val disposable: Disposable) :
Notification(
"Sourcegraph errors",
NotificationGroups.SOURCEGRAPH_ERRORS,
CodyBundle.getString("TrialEndedNotification.ended.title"),
CodyBundle.getString("TrialEndedNotification.ended.content"),
NotificationType.WARNING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.sourcegraph.Icons
import com.sourcegraph.common.BrowserOpener.openInBrowser
import com.sourcegraph.common.CodyBundle
import com.sourcegraph.common.NotificationGroups

class TrialEndingSoonNotification :
Notification(
"Sourcegraph errors",
NotificationGroups.SOURCEGRAPH_ERRORS,
CodyBundle.getString("TrialEndingSoonNotification.ending-soon.title"),
CodyBundle.getString("TrialEndingSoonNotification.ending-soon.content"),
NotificationType.WARNING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object BrowserErrorNotification {
fun show(project: Project?, uri: URI) {
val notification =
Notification(
"Sourcegraph errors",
NotificationGroups.SOURCEGRAPH_ERRORS,
"Sourcegraph",
"Opening an external browser is not supported. You can still copy the URL to your clipboard and open it manually.",
NotificationType.WARNING)
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/sourcegraph/common/ErrorNotification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ object ErrorNotification {

fun create(errorMessage: String): Notification {
val notification =
Notification("Sourcegraph errors", "Sourcegraph", errorMessage, NotificationType.WARNING)
Notification(
NotificationGroups.SOURCEGRAPH_ERRORS,
"Sourcegraph",
errorMessage,
NotificationType.WARNING)
notification.setIcon(Icons.CodyLogo)
return notification
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/sourcegraph/common/NotificationGroups.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sourcegraph.common

object NotificationGroups {
const val CODY_AUTH = "cody.auth"
const val SOURCEGRAPH_ERRORS = "Sourcegraph errors"
const val SOURCEGRAPH_URL_SHARING = "Sourcegraph: URL sharing"
const val CODY_UPDATES = "Sourcegraph Cody + Code Search plugin updates"
const val TOOLWINDOW = "Sourcegraph Cody"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicReference

class UpgradeToCodyProNotification
private constructor(title: String, content: String, shouldShowUpgradeOption: Boolean) :
Notification("Sourcegraph errors", title, content, NotificationType.WARNING),
Notification(NotificationGroups.SOURCEGRAPH_ERRORS, title, content, NotificationType.WARNING),
NotificationFullContent {
init {
icon = Icons.CodyLogo
Expand Down

0 comments on commit 745209a

Please sign in to comment.