mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
mountain lion notifications support
This commit is contained in:
@@ -27,7 +27,7 @@ import java.util.TreeSet;
|
||||
/**
|
||||
* @author mike
|
||||
*/
|
||||
class GrowlNotifications {
|
||||
class GrowlNotifications implements MacNotifications {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ui.GrowlNotifications");
|
||||
|
||||
private static GrowlNotifications ourNotifications;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public interface MacNotifications {
|
||||
void notify(Set<String> allNotifications, @NotNull String notificationName, String title, String description);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.ide.AppLifecycleListener;
|
||||
import com.intellij.openapi.application.ApplicationActivationListener;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.ui.mac.foundation.Foundation;
|
||||
import com.intellij.ui.mac.foundation.ID;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.ui.mac.foundation.Foundation.invoke;
|
||||
import static com.intellij.ui.mac.foundation.Foundation.nsString;
|
||||
|
||||
/**
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public class MountainLionNotifications implements MacNotifications {
|
||||
private static MountainLionNotifications ourNotifications;
|
||||
|
||||
public MountainLionNotifications() {
|
||||
final MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
|
||||
connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() {
|
||||
@Override
|
||||
public void applicationActivated(IdeFrame ideFrame) {
|
||||
cleanupDeliveredNotifications();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applicationDeactivated(IdeFrame ideFrame) {}
|
||||
});
|
||||
connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() {
|
||||
@Override
|
||||
public void appClosing() {
|
||||
cleanupDeliveredNotifications();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized MacNotifications getNotifications() {
|
||||
if (ourNotifications == null) {
|
||||
ourNotifications = new MountainLionNotifications();
|
||||
}
|
||||
|
||||
return ourNotifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notify(Set<String> allNotifications, @NotNull String notificationName, String title, String description) {
|
||||
final ID notification = invoke(Foundation.getObjcClass("NSUserNotification"), "new");
|
||||
invoke(notification, "setTitle:", nsString(StringUtil.stripHtml(title == null ? "" : title, true).replace("%", "%%")));
|
||||
invoke(notification, "setInformativeText:", nsString(StringUtil.stripHtml(description == null ? "" : description, true).replace("%", "%%")));
|
||||
final ID center = invoke(Foundation.getObjcClass("NSUserNotificationCenter"), "defaultUserNotificationCenter");
|
||||
invoke(center, "deliverNotification:", notification);
|
||||
}
|
||||
|
||||
public static void cleanupDeliveredNotifications() {
|
||||
final ID center = invoke(Foundation.getObjcClass("NSUserNotificationCenter"), "defaultUserNotificationCenter");
|
||||
invoke(center, "removeAllDeliveredNotifications");
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -41,11 +42,11 @@ public class SystemNotificationsImpl extends SystemNotifications implements Pers
|
||||
private boolean myGrowlDisabled = false;
|
||||
|
||||
public void notify(@NotNull String notificationName, @NotNull String title, @NotNull String text) {
|
||||
if (!isGrowlEnabled() || ApplicationManager.getApplication().isActive()) return;
|
||||
if (!areNotificationsEnabled() || ApplicationManager.getApplication().isActive()) return;
|
||||
|
||||
final GrowlNotifications nofications;
|
||||
final MacNotifications notifications;
|
||||
try {
|
||||
nofications = GrowlNotifications.getNotifications();
|
||||
notifications = getMacNotifications();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
myGrowlDisabled = true;
|
||||
@@ -53,11 +54,17 @@ public class SystemNotificationsImpl extends SystemNotifications implements Pers
|
||||
}
|
||||
|
||||
myState.NOTIFICATIONS.add(notificationName);
|
||||
nofications.notify(myState.NOTIFICATIONS, notificationName, title, text);
|
||||
notifications.notify(myState.NOTIFICATIONS, notificationName, title, text);
|
||||
}
|
||||
|
||||
private boolean isGrowlEnabled() {
|
||||
private static MacNotifications getMacNotifications() {
|
||||
return SystemInfo.isMacOSMountainLion && Registry.is("ide.mac.mountain.lion.notifications.enabled") ?
|
||||
MountainLionNotifications.getNotifications() : GrowlNotifications.getNotifications();
|
||||
}
|
||||
|
||||
private boolean areNotificationsEnabled() {
|
||||
if (myGrowlDisabled || !SystemInfo.isMac) return false;
|
||||
if (SystemInfo.isMacOSMountainLion && Registry.is("ide.mac.mountain.lion.notifications.enabled")) return true;
|
||||
|
||||
if ("true".equalsIgnoreCase(System.getProperty("growl.disable"))) {
|
||||
myGrowlDisabled = true;
|
||||
|
||||
@@ -116,6 +116,7 @@ ide.tabbedPane.dragOutMultiplier=1.2
|
||||
ide.mac.file.chooser.show.hidden.files=false
|
||||
ide.mac.file.chooser.native=true
|
||||
ide.mac.message.dialogs.as.sheets=true
|
||||
ide.mac.mountain.lion.notifications.enabled=true
|
||||
ide.mac.inplaceDialogMnemonicsFix=true
|
||||
ide.mac.fix.dialog.showing=false
|
||||
ide.mac.hide.cursor.when.typing=true
|
||||
|
||||
Reference in New Issue
Block a user