IDEA-153844 Switch off line numbers works for current editor only

This commit is contained in:
Dmitry Batrak
2016-04-07 19:13:05 +03:00
parent a2a4c7f433
commit 3828544e53
7 changed files with 127 additions and 10 deletions
@@ -19,8 +19,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.project.DumbAware;
@@ -54,6 +54,7 @@ public abstract class AbstractToggleUseSoftWrapsAction extends ToggleAction impl
@Override
public boolean isSelected(AnActionEvent e) {
if (myGlobal) return EditorSettingsExternalizable.getInstance().isUseSoftWraps();
Editor editor = getEditor(e);
return editor != null && editor.getSettings().isUseSoftWraps();
}
@@ -71,15 +72,12 @@ public abstract class AbstractToggleUseSoftWrapsAction extends ToggleAction impl
if (myGlobal) {
EditorSettingsExternalizable.getInstance().setUseSoftWraps(state, myAppliancePlace);
EditorFactory.getInstance().refreshAllEditors();
}
else {
if (editor.getSettings().isUseSoftWraps() != state) {
editor.getSettings().setUseSoftWraps(state);
}
if (editor instanceof EditorEx) {
((EditorEx)editor).reinitSettings();
}
editor.getScrollingModel().disableAnimation();
editor.getScrollingModel().scrollVertically(editor.logicalPositionToXY(anchorPosition).y + intraLineShift);
editor.getScrollingModel().enableAnimation();
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2016 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.openapi.editor.actions;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.project.Project;
public class ToggleShowIndentLinesGloballyAction extends ToggleAction {
@Override
public boolean isSelected(AnActionEvent e) {
return EditorSettingsExternalizable.getInstance().isIndentGuidesShown();
}
@Override
public void setSelected(AnActionEvent e, boolean state) {
EditorSettingsExternalizable.getInstance().setIndentGuidesShown(state);
Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor != null && editor.getSettings().isIndentGuidesShown() != state) {
editor.getSettings().setIndentGuidesShown(state);
}
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project != null) {
DaemonCodeAnalyzer.getInstance(project).restart();
}
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2016 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.openapi.editor.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
public class ToggleShowLineNumbersGloballyAction extends ToggleAction {
@Override
public boolean isSelected(AnActionEvent e) {
return EditorSettingsExternalizable.getInstance().isLineNumbersShown();
}
@Override
public void setSelected(AnActionEvent e, boolean state) {
EditorSettingsExternalizable.getInstance().setLineNumbersShown(state);
Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor != null && editor.getSettings().isLineNumbersShown() != state) {
editor.getSettings().setLineNumbersShown(state);
}
EditorFactory.getInstance().refreshAllEditors();
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2000-2016 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.openapi.editor.actions;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
public class ToggleSoftWrapsGloballyAction extends AbstractToggleUseSoftWrapsAction {
public ToggleSoftWrapsGloballyAction() {
super(SoftWrapAppliancePlaces.MAIN_EDITOR, true);
}
}
@@ -15,9 +15,11 @@
*/
package com.intellij.openapi.editor.actions;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import org.jetbrains.annotations.NotNull;
/**
* Action that toggles <code>'show soft wraps at editor'</code> option and is expected to be used at various menus.
@@ -32,11 +34,14 @@ public class ToggleUseSoftWrapsMenuAction extends AbstractToggleUseSoftWrapsActi
}
@Override
public void update(AnActionEvent e){
public void update(@NotNull AnActionEvent e){
super.update(e);
if (!ActionPlaces.isToolbarPlace(e.getPlace())) {
e.getPresentation().setIcon(null);
}
if (ActionPlaces.UNKNOWN.equals(e.getPlace())) {
e.getPresentation().setText(ActionsBundle.message("action.EditorGutterToggleLocalSoftWraps.gutterText"));
}
e.getPresentation().setEnabled(getEditor(e) != null);
}
}
@@ -1451,6 +1451,10 @@ action.CreateLauncherScript.description=Create a script for opening files and pr
action.CreateDesktopEntry.text=Create Desktop Entry...
action.CreateDesktopEntry.description=Create a desktop entry for integration with system application menu
group.EditorGutterPopupMenu.text=Editor Gutter Popup Menu
action.EditorGutterToggleGlobalSoftWraps.text=Soft-Wrap All Files
action.EditorGutterToggleLocalSoftWraps.gutterText=Soft-Wrap Current File
action.EditorGutterToggleGlobalLineNumbers.text=Show Line Numbers
action.EditorGutterToggleGlobalIndentLines.text=Show Indent Guides
action.ExcludeFromProject.text=Exclude From Project...
group.MarkFileAs.text=Mark File As
action.MarkAsPlainTextAction.text=Mark as Plain Text
@@ -603,9 +603,11 @@
</group>
<group id="EditorGutterPopupMenu">
<reference ref="EditorToggleShowLineNumbers"/>
<reference ref="EditorToggleShowIndentLines" />
<reference ref="EditorToggleUseSoftWraps" />
<action id="EditorGutterToggleGlobalLineNumbers" class="com.intellij.openapi.editor.actions.ToggleShowLineNumbersGloballyAction"/>
<action id="EditorGutterToggleGlobalIndentLines" class="com.intellij.openapi.editor.actions.ToggleShowIndentLinesGloballyAction"/>
<separator/>
<action id="EditorGutterToggleGlobalSoftWraps" class="com.intellij.openapi.editor.actions.ToggleSoftWrapsGloballyAction"/>
<reference ref="EditorToggleUseSoftWraps"/>
</group>
<group id="FileChooserToolbar">