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.google.googlejavaformat.intellij; 18 19 import com.intellij.notification.Notification; 20 import com.intellij.notification.NotificationGroup; 21 import com.intellij.notification.NotificationGroupManager; 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 google-java-format"; 30 private static final NotificationGroup NOTIFICATION_GROUP = 31 NotificationGroupManager.getInstance().getNotificationGroup(NOTIFICATION_TITLE); 32 33 @Override projectOpened(@otNull Project project)34 public void projectOpened(@NotNull Project project) { 35 GoogleJavaFormatSettings settings = GoogleJavaFormatSettings.getInstance(project); 36 37 if (settings.isUninitialized()) { 38 settings.setEnabled(false); 39 displayNewUserNotification(project, settings); 40 } 41 } 42 displayNewUserNotification(Project project, GoogleJavaFormatSettings settings)43 private void displayNewUserNotification(Project project, GoogleJavaFormatSettings settings) { 44 Notification notification = 45 new Notification( 46 NOTIFICATION_GROUP.getDisplayId(), 47 NOTIFICATION_TITLE, 48 "The google-java-format plugin is disabled by default. " 49 + "<a href=\"enable\">Enable for this project</a>.", 50 NotificationType.INFORMATION, 51 (n, e) -> { 52 settings.setEnabled(true); 53 n.expire(); 54 }); 55 notification.notify(project); 56 } 57 } 58