mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
decouple InspectionProjectProfileManager from status bar
This commit is contained in:
@@ -127,8 +127,8 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
public synchronized void writeExternal(Element element) throws WriteExternalException {
|
||||
|
||||
final List<String> sortedProfiles = new ArrayList<String>(myProfiles.keySet());
|
||||
Element profiles = null;
|
||||
Collections.sort(sortedProfiles);
|
||||
Element profiles = null;
|
||||
for (String profile : sortedProfiles) {
|
||||
final Profile projectProfile = myProfiles.get(profile);
|
||||
if (projectProfile != null) {
|
||||
@@ -227,7 +227,7 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
return profile;
|
||||
}
|
||||
|
||||
public void addProfilesListener(final ProfileChangeAdapter profilesListener, Disposable parent) {
|
||||
public void addProfilesListener(@NotNull final ProfileChangeAdapter profilesListener, @NotNull Disposable parent) {
|
||||
myProfilesListener.add(profilesListener);
|
||||
Disposer.register(parent, new Disposable() {
|
||||
@Override
|
||||
@@ -237,7 +237,7 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
});
|
||||
}
|
||||
|
||||
public void removeProfilesListener(ProfileChangeAdapter profilesListener) {
|
||||
public void removeProfilesListener(@NotNull ProfileChangeAdapter profilesListener) {
|
||||
myProfilesListener.remove(profilesListener);
|
||||
}
|
||||
|
||||
@@ -299,4 +299,14 @@ public abstract class DefaultProjectProfileManager extends ProjectProfileManager
|
||||
}
|
||||
}
|
||||
|
||||
protected void fireProfilesInitialized() {
|
||||
for (ProfileChangeAdapter profileChangeAdapter : myProfilesListener) {
|
||||
profileChangeAdapter.profilesInitialized();
|
||||
}
|
||||
}
|
||||
protected void fireProfilesShutdown() {
|
||||
for (ProfileChangeAdapter profileChangeAdapter : myProfilesListener) {
|
||||
profileChangeAdapter.profilesShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,15 @@
|
||||
*/
|
||||
package com.intellij.profile;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 20-Nov-2005
|
||||
*/
|
||||
public abstract class ProfileChangeAdapter {
|
||||
public void profileChanged(Profile profile){}
|
||||
public void profileActivated(Profile oldProfile, Profile profile){}
|
||||
public void profileActivated(@NotNull Profile oldProfile, Profile profile){}
|
||||
public void profilesInitialized() {}
|
||||
public void profilesShutdown(){}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.codeInsight.daemon.impl;
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile;
|
||||
import com.intellij.codeInsight.hint.TooltipController;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.ide.todo.TodoConfiguration;
|
||||
@@ -59,6 +60,9 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileAdapter;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.VirtualFilePropertyEvent;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.ex.StatusBarEx;
|
||||
import com.intellij.openapi.wm.impl.status.TogglePopupHintsPanel;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.profile.Profile;
|
||||
import com.intellij.profile.ProfileChangeAdapter;
|
||||
@@ -504,9 +508,38 @@ public class DaemonListeners implements Disposable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void profileActivated(Profile oldProfile, Profile profile) {
|
||||
public void profileActivated(@NotNull Profile oldProfile, Profile profile) {
|
||||
stopDaemonAndRestartAllFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void profilesInitialized() {
|
||||
inspectionProfilesInitialized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void profilesShutdown() {
|
||||
HighlightingSettingsPerFile.getInstance(myProject).cleanProfileSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private TogglePopupHintsPanel myTogglePopupHintsPanel;
|
||||
private void inspectionProfilesInitialized() {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myProject.isDisposed()) return;
|
||||
StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(myProject);
|
||||
myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject);
|
||||
statusBar.addWidget(myTogglePopupHintsPanel, myProject);
|
||||
|
||||
stopDaemonAndRestartAllFiles();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateStatusBar() {
|
||||
if (myTogglePopupHintsPanel != null) myTogglePopupHintsPanel.updateStatus();
|
||||
}
|
||||
|
||||
private class MyAnActionListener implements AnActionListener {
|
||||
@@ -594,5 +627,4 @@ public class DaemonListeners implements Disposable {
|
||||
myDaemonEventPublisher.daemonCancelEventOccurred();
|
||||
myDaemonCodeAnalyzer.restart();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManagerImpl;
|
||||
import com.intellij.profile.codeInspection.ui.ErrorsConfigurable;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -272,7 +271,7 @@ public class HectorComponent extends JPanel {
|
||||
}
|
||||
}
|
||||
forceDaemonRestart();
|
||||
InspectionProjectProfileManagerImpl.getInstanceImpl(myFile.getProject()).updateStatusBar();
|
||||
DaemonListeners.getInstance(myFile.getProject()).updateStatusBar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonListeners;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
@@ -28,7 +29,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManagerImpl;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
|
||||
@@ -63,6 +63,6 @@ public class TogglePopupHintsAction extends AnAction{
|
||||
LOG.assertTrue(project!=null);
|
||||
DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
|
||||
codeAnalyzer.setImportHintsEnabled(psiFile,!codeAnalyzer.isImportHintsEnabled(psiFile));
|
||||
InspectionProjectProfileManagerImpl.getInstanceImpl(project).updateStatusBar();
|
||||
DaemonListeners.getInstance(project).updateStatusBar();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -17,6 +17,7 @@ package com.intellij.profile.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.InspectionProfileConvertor;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonListeners;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeveritiesProvider;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
@@ -127,6 +128,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
mySchemesManager = schemesManagerFactory.createSchemesManager(FILE_SPEC, processor, RoamingType.PER_USER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static InspectionProfileImpl createSampleProfile() {
|
||||
return new InspectionProfileImpl("Default");
|
||||
}
|
||||
@@ -317,6 +319,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Profile getRootProfile() {
|
||||
Profile current = mySchemesManager.getCurrentScheme();
|
||||
@@ -335,7 +338,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProfile(final Profile profile) {
|
||||
public void addProfile(@NotNull final Profile profile) {
|
||||
mySchemesManager.addNewScheme(profile, true);
|
||||
}
|
||||
|
||||
@@ -363,7 +366,9 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InspectionProjectProfileManagerImpl.getInstanceImpl(project).updateStatusBar();
|
||||
if (!project.isDisposed()) {
|
||||
DaemonListeners.getInstance(project).updateStatusBar();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
-284
@@ -1,284 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.profile.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileWrapper;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.DumbAwareRunnable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.ex.StatusBarEx;
|
||||
import com.intellij.openapi.wm.impl.status.TogglePopupHintsPanel;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.profile.Profile;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 30-Nov-2005
|
||||
*/
|
||||
@State(
|
||||
name = "InspectionProjectProfileManager",
|
||||
storages = {
|
||||
@Storage(
|
||||
file = StoragePathMacros.PROJECT_FILE
|
||||
)
|
||||
,@Storage( file = StoragePathMacros.PROJECT_CONFIG_DIR + "/inspectionProfiles/", scheme = StorageScheme.DIRECTORY_BASED, stateSplitter = InspectionProjectProfileManagerImpl.ProfileStateSplitter.class)
|
||||
}
|
||||
)
|
||||
public class InspectionProjectProfileManagerImpl extends InspectionProjectProfileManager implements SeverityProvider, ProjectComponent, PersistentStateComponent<Element> {
|
||||
private final Map<String, InspectionProfileWrapper> myName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
|
||||
private final SeverityRegistrar mySeverityRegistrar;
|
||||
private final NamedScopeManager myLocalScopesHolder;
|
||||
private TogglePopupHintsPanel myTogglePopupHintsPanel;
|
||||
private NamedScopesHolder.ScopeListener myScopeListener;
|
||||
|
||||
public InspectionProjectProfileManagerImpl(final Project project,
|
||||
InspectionProfileManager inspectionProfileManager,
|
||||
DependencyValidationManager holder,
|
||||
NamedScopeManager localScopesHolder) {
|
||||
super(project, inspectionProfileManager, holder);
|
||||
myLocalScopesHolder = localScopesHolder;
|
||||
mySeverityRegistrar = new SeverityRegistrar();
|
||||
}
|
||||
|
||||
public static InspectionProjectProfileManagerImpl getInstanceImpl(Project project){
|
||||
return (InspectionProjectProfileManagerImpl)project.getComponent(InspectionProjectProfileManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProfileName() {
|
||||
return getInspectionProfile().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
try {
|
||||
final Element e = new Element("settings");
|
||||
writeExternal(e);
|
||||
return e;
|
||||
}
|
||||
catch (WriteExternalException e1) {
|
||||
LOG.error(e1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
readExternal(state);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileLoaded() {
|
||||
return myName2Profile.containsKey(getInspectionProfile().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public synchronized InspectionProfileWrapper getProfileWrapper(){
|
||||
final InspectionProfile profile = getInspectionProfile();
|
||||
final String profileName = profile.getName();
|
||||
if (!myName2Profile.containsKey(profileName)){
|
||||
initProfileWrapper(profile);
|
||||
}
|
||||
return myName2Profile.get(profileName);
|
||||
}
|
||||
|
||||
public InspectionProfileWrapper getProfileWrapper(final String profileName){
|
||||
return myName2Profile.get(profileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProfile(@NotNull Profile profile) {
|
||||
super.updateProfile(profile);
|
||||
initProfileWrapper(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProfile(String name) {
|
||||
super.deleteProfile(name);
|
||||
final InspectionProfileWrapper profileWrapper = myName2Profile.remove(name);
|
||||
if (profileWrapper != null) {
|
||||
profileWrapper.cleanup(myProject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@NonNls
|
||||
public String getComponentName() {
|
||||
return "InspectionProjectProfileManager";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(myProject);
|
||||
myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject);
|
||||
statusBar.addWidget(myTogglePopupHintsPanel, myProject);
|
||||
StartupManager.getInstance(myProject).registerPostStartupActivity(new DumbAwareRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Set<Profile> profiles = new HashSet<Profile>();
|
||||
profiles.add(getProjectProfileImpl());
|
||||
profiles.addAll(getProfiles());
|
||||
profiles.addAll(InspectionProfileManager.getInstance().getProfiles());
|
||||
final Application app = ApplicationManager.getApplication();
|
||||
Runnable initInspectionProfilesRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Profile profile : profiles) {
|
||||
initProfileWrapper(profile);
|
||||
}
|
||||
//restart daemon when profiles are ready
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DaemonCodeAnalyzer.getInstance(myProject).restart();
|
||||
}
|
||||
}, myProject.getDisposed());
|
||||
}
|
||||
};
|
||||
if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
|
||||
initInspectionProfilesRunnable.run();
|
||||
UIUtil.dispatchAllInvocationEvents(); //do not restart daemon in the middle of the test
|
||||
} else {
|
||||
app.executeOnPooledThread(initInspectionProfilesRunnable);
|
||||
}
|
||||
myScopeListener = new NamedScopesHolder.ScopeListener() {
|
||||
@Override
|
||||
public void scopesChanged() {
|
||||
for (Profile profile : getProfiles()) {
|
||||
((InspectionProfile)profile).scopesChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
myHolder.addScopeListener(myScopeListener);
|
||||
myLocalScopesHolder.addScopeListener(myScopeListener);
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
myHolder.removeScopeListener(myScopeListener);
|
||||
myLocalScopesHolder.removeScopeListener(myScopeListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initProfileWrapper(@NotNull Profile profile) {
|
||||
final InspectionProfileWrapper wrapper = new InspectionProfileWrapper((InspectionProfile)profile);
|
||||
wrapper.init(myProject);
|
||||
myName2Profile.put(profile.getName(), wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed() {
|
||||
|
||||
final Application app = ApplicationManager.getApplication();
|
||||
Runnable cleanupInspectionProfilesRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (InspectionProfileWrapper wrapper : myName2Profile.values()) {
|
||||
wrapper.cleanup(myProject);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
|
||||
cleanupInspectionProfilesRunnable.run();
|
||||
}
|
||||
else {
|
||||
app.executeOnPooledThread(cleanupInspectionProfilesRunnable);
|
||||
}
|
||||
HighlightingSettingsPerFile.getInstance(myProject).cleanProfileSettings();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SeverityRegistrar getSeverityRegistrar() {
|
||||
return mySeverityRegistrar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SeverityRegistrar getOwnSeverityRegistrar() {
|
||||
return mySeverityRegistrar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(final Element element) throws InvalidDataException {
|
||||
mySeverityRegistrar.readExternal(element);
|
||||
super.readExternal(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(final Element element) throws WriteExternalException {
|
||||
super.writeExternal(element);
|
||||
mySeverityRegistrar.writeExternal(element);
|
||||
}
|
||||
|
||||
public void updateStatusBar() {
|
||||
if (myTogglePopupHintsPanel != null) myTogglePopupHintsPanel.updateStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile getProfile(@NotNull final String name) {
|
||||
return getProfile(name, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(Element element) throws InvalidDataException {
|
||||
super.convert(element);
|
||||
if (PROJECT_PROFILE != null) {
|
||||
((InspectionProfileImpl)getProjectProfileImpl()).convert(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user