mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
'power save mode' option (turns off daemon code analyzer)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.codeInsight.daemon;
|
||||
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.openapi.editor.HectorComponentPanel;
|
||||
import com.intellij.openapi.editor.HectorComponentPanelsProvider;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PowerSaveHectorProvider implements HectorComponentPanelsProvider {
|
||||
@Override
|
||||
public HectorComponentPanel createConfigurable(@NotNull PsiFile file) {
|
||||
return new HectorComponentPanel() {
|
||||
private JCheckBox myCheckBox = new JCheckBox("Power Save Mode");
|
||||
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return myCheckBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return myCheckBox.isSelected() != PowerSaveMode.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
PowerSaveMode.setEnabled(myCheckBox.isSelected());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myCheckBox.setSelected(PowerSaveMode.isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
@@ -27,6 +27,7 @@ import com.intellij.codeInsight.daemon.ReferenceImporter;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.intention.impl.IntentionHintComponent;
|
||||
import com.intellij.concurrency.Job;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -586,6 +587,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
if (!myUpdateByTimerEnabled) return;
|
||||
if (PowerSaveMode.isEnabled()) return;
|
||||
if (myDisposed || myProject.isDisposed()) return;
|
||||
final Collection<FileEditor> activeEditors = myDaemonListeners.getSelectedEditors();
|
||||
if (activeEditors.isEmpty()) return;
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.codeInsight.daemon.impl;
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.hint.TooltipController;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.ide.todo.TodoConfiguration;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
@@ -195,6 +196,13 @@ public class DaemonListeners implements Disposable {
|
||||
}
|
||||
});
|
||||
|
||||
connection.subscribe(PowerSaveMode.TOPIC, new PowerSaveMode.Listener() {
|
||||
@Override
|
||||
public void powerSaveStateChanged() {
|
||||
stopDaemon(true);
|
||||
}
|
||||
});
|
||||
|
||||
CommandProcessor.getInstance().addCommandListener(new MyCommandListener(), this);
|
||||
ApplicationManager.getApplication().addApplicationListener(myApplicationListener);
|
||||
EditorColorsManager.getInstance().addEditorColorsListener(myEditorColorsListener);
|
||||
|
||||
+8
-2
@@ -20,6 +20,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
|
||||
import com.intellij.codeInsight.daemon.DaemonBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.markup.ErrorStripeRenderer;
|
||||
@@ -109,7 +110,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer {
|
||||
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(myProject);
|
||||
status.errorCount = new int[severityRegistrar.getSeveritiesCount()];
|
||||
status.rootsNumber = roots.length;
|
||||
fillDaemonCodeAnalyzerErrorsSatus(status, fillErrorsCount);
|
||||
fillDaemonCodeAnalyzerErrorsStatus(status, fillErrorsCount);
|
||||
List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myFile);
|
||||
ArrayList<DaemonCodeAnalyzerStatus.PassStatus> passStati = new ArrayList<DaemonCodeAnalyzerStatus.PassStatus>();
|
||||
for (TextEditorHighlightingPass tepass : passes) {
|
||||
@@ -127,7 +128,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer {
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void fillDaemonCodeAnalyzerErrorsSatus(DaemonCodeAnalyzerStatus status, boolean fillErrorsCount) {
|
||||
protected void fillDaemonCodeAnalyzerErrorsStatus(DaemonCodeAnalyzerStatus status, boolean fillErrorsCount) {
|
||||
final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(myProject);
|
||||
List<HighlightInfo> highlights = DaemonCodeAnalyzerImpl.getHighlights(myDocument, myProject);
|
||||
if (highlights == null) highlights = Arrays.asList(HighlightInfo.EMPTY_ARRAY);
|
||||
@@ -185,6 +186,11 @@ public class TrafficLightRenderer implements ErrorStripeRenderer {
|
||||
|
||||
if (status == null) return null;
|
||||
@NonNls String text = HTML_HEADER;
|
||||
if (PowerSaveMode.isEnabled()) {
|
||||
text += "Code analysis is disabled in power save mode.";
|
||||
text += HTML_FOOTER;
|
||||
return text;
|
||||
}
|
||||
if (status.noHighlightingRoots != null && status.noHighlightingRoots.length == status.rootsNumber) {
|
||||
text += DaemonBundle.message("analysis.hasnot.been.run");
|
||||
text += HTML_FOOTER;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.ide;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PowerSaveMode {
|
||||
private boolean myEnabled = false;
|
||||
private final MessageBus myBus;
|
||||
|
||||
public PowerSaveMode(MessageBus bus) {
|
||||
myBus = bus;
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return ServiceManager.getService(PowerSaveMode.class).myEnabled;
|
||||
}
|
||||
|
||||
public static void setEnabled(boolean value) {
|
||||
final PowerSaveMode instance = ServiceManager.getService(PowerSaveMode.class);
|
||||
if (instance.myEnabled != value) {
|
||||
instance.myEnabled = value;
|
||||
instance.myBus.syncPublisher(TOPIC).powerSaveStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void powerSaveStateChanged();
|
||||
}
|
||||
|
||||
public static Topic<Listener> TOPIC = Topic.create("PowerSaveMode.Listener", Listener.class);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.ide.actions;
|
||||
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class TogglePowerSaveAction extends ToggleAction implements DumbAware {
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return PowerSaveMode.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
PowerSaveMode.setEnabled(state);
|
||||
}
|
||||
}
|
||||
+23
-6
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.impl.HectorComponent;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
@@ -38,6 +39,7 @@ import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.UIBundle;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -57,7 +59,8 @@ public class TogglePopupHintsPanel implements StatusBarWidget, StatusBarWidget.I
|
||||
|
||||
public TogglePopupHintsPanel(@NotNull final Project project) {
|
||||
myCurrentIcon = EMPTY_ICON;
|
||||
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
|
||||
final MessageBusConnection connection = project.getMessageBus().connect();
|
||||
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
|
||||
@Override
|
||||
public void selectionChanged(FileEditorManagerEvent event) {
|
||||
updateStatus();
|
||||
@@ -68,6 +71,12 @@ public class TogglePopupHintsPanel implements StatusBarWidget, StatusBarWidget.I
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
connection.subscribe(PowerSaveMode.TOPIC, new PowerSaveMode.Listener() {
|
||||
@Override
|
||||
public void powerSaveStateChanged() {
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
@@ -130,13 +139,21 @@ public class TogglePopupHintsPanel implements StatusBarWidget, StatusBarWidget.I
|
||||
|
||||
private void updateStatus(PsiFile file) {
|
||||
if (isStateChangeable(file)) {
|
||||
if (HighlightLevelUtil.shouldInspect(file)) {
|
||||
if (PowerSaveMode.isEnabled()) {
|
||||
myCurrentIcon = EMPTY_ICON;
|
||||
myToolTipText = "Code analysis is disabled in power save mode. ";
|
||||
}
|
||||
else if (HighlightLevelUtil.shouldInspect(file)) {
|
||||
myCurrentIcon = INSPECTIONS_ICON;
|
||||
myToolTipText = "Current inspection profile: " + InspectionProjectProfileManager.getInstance(file.getProject()).getInspectionProfile().getName() + ". ";
|
||||
} else if (HighlightLevelUtil.shouldHighlight(file)) {
|
||||
myToolTipText = "Current inspection profile: " +
|
||||
InspectionProjectProfileManager.getInstance(file.getProject()).getInspectionProfile().getName() +
|
||||
". ";
|
||||
}
|
||||
else if (HighlightLevelUtil.shouldHighlight(file)) {
|
||||
myCurrentIcon = SYNTAX_ONLY_ICON;
|
||||
myToolTipText = "Highlighting level is: Syntax. ";
|
||||
} else {
|
||||
myToolTipText = "Highlighting level is: Syntax. ";
|
||||
}
|
||||
else {
|
||||
myCurrentIcon = INSPECTIONS_OFF_ICON;
|
||||
myToolTipText = "Inspections are off. ";
|
||||
}
|
||||
|
||||
@@ -1171,3 +1171,5 @@ group.ToolsBasicGroup.description=Tools Basic Group
|
||||
group.ToolbarNewElement.text=Toolbar New Element Group
|
||||
action.NewElementToolbarAction.text=Create New File
|
||||
action.ShowRegistry.text=Registry
|
||||
action.TogglePowerSave.text=Power Save Mode
|
||||
action.TogglePowerSave.description=Power save mode disables background code analysis and other background operations
|
||||
|
||||
@@ -128,6 +128,9 @@
|
||||
<applicationService serviceInterface="com.intellij.patterns.compiler.PatternCompilerFactory"
|
||||
serviceImplementation="com.intellij.patterns.compiler.PatternCompilerFactoryImpl"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.ide.PowerSaveMode"
|
||||
serviceImplementation="com.intellij.ide.PowerSaveMode"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.psi.codeStyle.ProjectCodeStyleSettingsManager"
|
||||
serviceImplementation="com.intellij.psi.codeStyle.ProjectCodeStyleSettingsManager"/>
|
||||
|
||||
@@ -568,4 +571,6 @@
|
||||
<applicationService serviceInterface="com.intellij.ide.todo.TodoConfiguration"
|
||||
serviceImplementation="com.intellij.ide.todo.TodoConfiguration"/>
|
||||
<indexPatternProvider implementation="com.intellij.ide.todo.TodoIndexPatternProvider"/>
|
||||
|
||||
<hectorComponentProvider implementation="com.intellij.codeInsight.daemon.PowerSaveHectorProvider"/>
|
||||
</extensions>
|
||||
|
||||
@@ -70,6 +70,12 @@
|
||||
<add-to-group group-id="FileMenu" anchor="after" relative-to-action="ChangeFileEncodingGroup"/>
|
||||
</action>
|
||||
|
||||
<group id="PowerSaveGroup">
|
||||
<separator/>
|
||||
<action id="TogglePowerSave" class="com.intellij.ide.actions.TogglePowerSaveAction"/>
|
||||
<add-to-group group-id="FileMenu" anchor="after" relative-to-action="ToggleReadOnlyAttribute"/>
|
||||
</group>
|
||||
|
||||
<!-- Edit -->
|
||||
<action id="CopyReference" class="com.intellij.ide.actions.CopyReferenceAction">
|
||||
<add-to-group group-id="CutCopyPasteGroup" anchor="after" relative-to-action="CopyPaths"/>
|
||||
|
||||
@@ -162,7 +162,7 @@ public class DomElementsErrorPanel extends JPanel implements CommittablePanel, H
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillDaemonCodeAnalyzerErrorsSatus(DaemonCodeAnalyzerStatus status, boolean fillErrorsCount) {
|
||||
protected void fillDaemonCodeAnalyzerErrorsStatus(DaemonCodeAnalyzerStatus status, boolean fillErrorsCount) {
|
||||
for (int i = 0; i < status.errorCount.length; i++) {
|
||||
final HighlightSeverity minSeverity = SeverityRegistrar.getInstance(myProject).getSeverityByIndex(i);
|
||||
if (minSeverity == null) {
|
||||
|
||||
Reference in New Issue
Block a user