• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.facebook.ktfmt.intellij;
18 
19 import com.intellij.notification.Notification;
20 import com.intellij.notification.NotificationDisplayType;
21 import com.intellij.notification.NotificationGroup;
22 import com.intellij.notification.NotificationType;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.project.ProjectManagerListener;
25 import org.jetbrains.annotations.NotNull;
26 
27 final class InitialConfigurationProjectManagerListener implements ProjectManagerListener {
28 
29   private static final String NOTIFICATION_TITLE = "Enable ktfmt";
30   private static final NotificationGroup NOTIFICATION_GROUP =
31       new NotificationGroup(NOTIFICATION_TITLE, NotificationDisplayType.STICKY_BALLOON, true);
32 
33   @Override
projectOpened(@otNull Project project)34   public void projectOpened(@NotNull Project project) {
35 
36     KtfmtSettings settings = KtfmtSettings.getInstance(project);
37 
38     if (settings.isUninitialized()) {
39       settings.setEnabled(false);
40       displayNewUserNotification(project, settings);
41     }
42   }
43 
displayNewUserNotification(Project project, KtfmtSettings settings)44   private void displayNewUserNotification(Project project, KtfmtSettings settings) {
45     Notification notification =
46         new Notification(
47             NOTIFICATION_GROUP.getDisplayId(),
48             NOTIFICATION_TITLE,
49             "The ktfmt plugin is disabled by default. "
50                 + "<a href=\"enable\">Enable for this project</a>.",
51             NotificationType.INFORMATION,
52             (n, e) -> {
53               settings.setEnabled(true);
54               n.expire();
55             });
56     notification.notify(project);
57   }
58 }
59