2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.ide
;
18 import com
.apple
.eawt
.Application
;
19 import com
.apple
.eawt
.ApplicationAdapter
;
20 import com
.apple
.eawt
.ApplicationEvent
;
21 import com
.intellij
.ide
.actions
.AboutAction
;
22 import com
.intellij
.ide
.actions
.OpenFileAction
;
23 import com
.intellij
.ide
.impl
.ProjectUtil
;
24 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
25 import com
.intellij
.openapi
.application
.ex
.ApplicationManagerEx
;
26 import com
.intellij
.openapi
.components
.ApplicationComponent
;
27 import com
.intellij
.openapi
.options
.ConfigurableGroup
;
28 import com
.intellij
.openapi
.options
.ShowSettingsUtil
;
29 import com
.intellij
.openapi
.options
.ex
.IdeConfigurablesGroup
;
30 import com
.intellij
.openapi
.options
.ex
.ProjectConfigurablesGroup
;
31 import com
.intellij
.openapi
.project
.Project
;
32 import com
.intellij
.openapi
.project
.ProjectManager
;
33 import com
.intellij
.openapi
.util
.SystemInfo
;
40 public class MacOSApplicationProvider
implements ApplicationComponent
{
41 public String
getComponentName() {
42 return "MACOSApplicationProvider";
45 public MacOSApplicationProvider() {
46 if (SystemInfo
.isMac
) {
48 Worker
.initMacApplication();
50 catch (NoClassDefFoundError e
) {
55 public void initComponent() { }
57 public void disposeComponent() {
60 private static class Worker
{
61 public static void initMacApplication() {
62 Application application
= new Application();
63 application
.addApplicationListener(new ApplicationAdapter() {
64 public void handleAbout(ApplicationEvent applicationEvent
) {
65 AboutAction
.showAbout();
66 applicationEvent
.setHandled(true);
69 public void handlePreferences(ApplicationEvent applicationEvent
) {
70 Project project
= getProject();
72 if (project
== null) {
73 project
= ProjectManager
.getInstance().getDefaultProject();
76 ConfigurableGroup
[] group
= new ConfigurableGroup
[]{
77 new ProjectConfigurablesGroup(project
, false),
78 new IdeConfigurablesGroup()
81 ShowSettingsUtil
.getInstance().showSettingsDialog(project
, group
);
82 applicationEvent
.setHandled(true);
85 public void handleQuit(ApplicationEvent applicationEvent
) {
86 ApplicationManagerEx
.getApplicationEx().exit();
89 public void handleOpenFile(ApplicationEvent applicationEvent
) {
90 Project project
= getProject();
91 String filename
= applicationEvent
.getFilename();
92 if (filename
== null) return;
94 File file
= new File(filename
);
95 if (ProjectUtil
.openOrImport(file
.getAbsolutePath(), project
, false) != null) {
98 if (project
!= null && file
.exists()) {
99 OpenFileAction
.openFile(filename
, project
);
100 applicationEvent
.setHandled(true);
105 application
.addAboutMenuItem();
106 application
.addPreferencesMenuItem();
107 application
.setEnabledAboutMenu(true);
108 application
.setEnabledPreferencesMenu(true);
111 private static Project
getProject() {
112 return PlatformDataKeys
.PROJECT
.getData(DataManager
.getInstance().getDataContext());