use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ApplicationActivationStateManager method updateState.
public static boolean updateState(final WindowEvent windowEvent) {
final Application application = ApplicationManager.getApplication();
if (!(application instanceof ApplicationImpl))
return false;
final Window eventWindow = windowEvent.getWindow();
if (windowEvent.getID() == WindowEvent.WINDOW_ACTIVATED || windowEvent.getID() == WindowEvent.WINDOW_GAINED_FOCUS) {
if (state.isInactive()) {
Window window = windowEvent.getWindow();
return setActive(application, window);
}
} else if (windowEvent.getID() == WindowEvent.WINDOW_DEACTIVATED && windowEvent.getOppositeWindow() == null) {
requestToDeactivateTime.getAndSet(System.currentTimeMillis());
// For stuff that cannot wait windowEvent notify about deactivation immediately
if (state.isActive()) {
IdeFrame ideFrame = getIdeFrameFromWindow(windowEvent.getWindow());
if (ideFrame != null) {
application.getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationDeactivated(ideFrame);
}
}
// We do not know for sure that application is going to be inactive,
// windowEvent could just be showing a popup or another transient window.
// So let's postpone the application deactivation for a while
state = State.DEACTIVATING;
LOG.debug("The app is in the deactivating state");
Timer timer = UIUtil.createNamedTimer("ApplicationDeactivation", Registry.intValue("application.deactivation.timeout"), new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (state.equals(State.DEACTIVATING)) {
state = State.DEACTIVATED;
LOG.debug("The app is in the deactivated state");
IdeFrame ideFrame = getIdeFrameFromWindow(windowEvent.getWindow());
if (ideFrame != null) {
application.getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).delayedApplicationDeactivated(ideFrame);
}
}
}
});
timer.setRepeats(false);
timer.start();
return true;
}
return false;
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class DisablePluginWarningDialog method disablePlugin.
public static void disablePlugin(@NotNull PluginId pluginId, @NotNull JComponent parentComponent) {
IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
final Ref<Boolean> hasDependants = new Ref<>(false);
PluginManagerCore.checkDependants(plugin, pluginId1 -> PluginManager.getPlugin(pluginId1), pluginId12 -> {
if (PluginManagerCore.CORE_PLUGIN_ID.equals(pluginId12.getIdString())) {
return true;
}
hasDependants.set(true);
return false;
});
Application app = ApplicationManager.getApplication();
DisablePluginWarningDialog d = new DisablePluginWarningDialog(parentComponent, plugin.getName(), hasDependants.get(), app.isRestartCapable());
d.show();
switch(d.getExitCode()) {
case CANCEL_EXIT_CODE:
return;
case DISABLE_EXIT_CODE:
PluginManagerCore.disablePlugin(pluginId.getIdString());
break;
case DISABLE_AND_RESTART_EXIT_CODE:
PluginManagerCore.disablePlugin(pluginId.getIdString());
app.restart();
break;
}
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class NotificationsManagerImpl method showNotification.
private static void showNotification(@NotNull final Notification notification, @Nullable final Project project) {
Application application = ApplicationManager.getApplication();
if (application instanceof ApplicationEx && !((ApplicationEx) application).isLoaded()) {
application.invokeLater(() -> showNotification(notification, project), ModalityState.current());
return;
}
String groupId = notification.getGroupId();
final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(groupId);
NotificationDisplayType type = settings.getDisplayType();
String toolWindowId = NotificationsConfigurationImpl.getInstanceImpl().getToolWindowId(groupId);
if (type == NotificationDisplayType.TOOL_WINDOW && (toolWindowId == null || project == null || !ToolWindowManager.getInstance(project).canShowNotification(toolWindowId))) {
type = NotificationDisplayType.BALLOON;
}
switch(type) {
case NONE:
return;
// break;
case STICKY_BALLOON:
case BALLOON:
default:
Balloon balloon = notifyByBalloon(notification, type, project);
if (project == null || project.isDefault()) {
return;
}
if (!settings.isShouldLog() || type == NotificationDisplayType.STICKY_BALLOON) {
if (balloon == null) {
notification.expire();
} else {
balloon.addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
if (!event.isOk()) {
notification.expire();
}
}
});
}
}
break;
case TOOL_WINDOW:
MessageType messageType = notification.getType() == NotificationType.ERROR ? MessageType.ERROR : notification.getType() == NotificationType.WARNING ? MessageType.WARNING : MessageType.INFO;
final NotificationListener notificationListener = notification.getListener();
HyperlinkListener listener = notificationListener == null ? null : new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
notificationListener.hyperlinkUpdate(notification, e);
}
};
assert toolWindowId != null;
String msg = notification.getTitle();
if (StringUtil.isNotEmpty(notification.getContent())) {
if (StringUtil.isNotEmpty(msg)) {
msg += "<br>";
}
msg += notification.getContent();
}
Window window = findWindowForBalloon(project);
if (window instanceof IdeFrame) {
BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
if (layout != null) {
((BalloonLayoutImpl) layout).remove(notification);
}
}
//noinspection SSBasedInspection
ToolWindowManager.getInstance(project).notifyByBalloon(toolWindowId, messageType, msg, notification.getIcon(), listener);
}
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class EditorColorsManagerImpl method setGlobalScheme.
@Override
public void setGlobalScheme(@Nullable EditorColorsScheme scheme) {
Application application = ApplicationManager.getApplication();
boolean notify = (application instanceof ApplicationImpl && ((ApplicationImpl) application).isLoaded());
mySchemeManager.setCurrent(scheme == null ? getDefaultScheme() : scheme, notify);
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ModuleManagerImpl method loadModules.
protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
myFailedModulePaths.clear();
if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
return;
}
myFailedModulePaths.addAll(myModulePathsToLoad);
ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
progressIndicator.setText("Loading modules...");
progressIndicator.setText2("");
List<Module> modulesWithUnknownTypes = new SmartList<>();
List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
ModuleGroupInterner groupInterner = new ModuleGroupInterner();
ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
Set<String> paths = new THashSet<>();
boolean parallel = Registry.is("parallel.modules.loading");
for (ModulePath modulePath : myModulePathsToLoad) {
if (progressIndicator.isCanceled()) {
break;
}
try {
String path = modulePath.getPath();
if (!paths.add(path))
continue;
if (!parallel) {
tasks.add(Pair.create(null, modulePath));
continue;
}
ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
Future<Module> future = service.submit(() -> {
progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
try {
return computable.compute();
} catch (IOException e) {
reportError(errors, modulePath, e);
} catch (Exception e) {
LOG.error(e);
}
return null;
});
tasks.add(Pair.create(future, modulePath));
} catch (IOException e) {
reportError(errors, modulePath, e);
}
}
for (Pair<Future<Module>, ModulePath> task : tasks) {
if (progressIndicator.isCanceled()) {
break;
}
try {
Module module;
if (parallel) {
module = task.first.get();
} else {
module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
}
if (module == null)
continue;
if (isUnknownModuleType(module)) {
modulesWithUnknownTypes.add(module);
}
ModulePath modulePath = task.second;
final String groupPathString = modulePath.getGroup();
if (groupPathString != null) {
// model should be updated too
groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
}
myFailedModulePaths.remove(modulePath);
} catch (IOException e) {
reportError(errors, task.second, e);
} catch (Exception e) {
LOG.error(e);
}
}
service.shutdown();
progressIndicator.checkCanceled();
Application app = ApplicationManager.getApplication();
if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
Map<String, Module> track = new THashMap<>();
for (Module module : moduleModel.getModules()) {
for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
Module oldModule = track.put(url, module);
if (oldModule != null) {
//Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
//VirtualFilePointer pointer = track1.get(url);
LOG.error("duplicated content url: " + url);
}
}
}
}
onModuleLoadErrors(moduleModel, errors);
showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
Aggregations