IDEA-133850 Add editor setting to disable rich-text copy

This commit is contained in:
Dmitry Batrak
2015-01-13 16:57:24 +03:00
parent f48d92dcd3
commit 9a8ea3868b
11 changed files with 156 additions and 5 deletions
@@ -317,7 +317,7 @@
</component>
</children>
</grid>
<grid id="62a96" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="62a96" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -330,7 +330,7 @@
<children>
<component id="828ad" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ApplicationBundle" key="combobox.richcopy.color.scheme"/>
@@ -338,10 +338,21 @@
</component>
<component id="3b679" class="javax.swing.JComboBox" binding="myRichCopyColorSchemeComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="75ac" class="javax.swing.JCheckBox" binding="myCbEnableRichCopyByDefault">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="257" height="22"/>
</grid>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/ApplicationBundle" key="combobox.enable.richcopy.by.default"/>
</properties>
</component>
</children>
</grid>
<grid id="7f3f5" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -102,6 +102,7 @@ public class EditorOptionsPanel {
private JComboBox myRichCopyColorSchemeComboBox;
private JCheckBox myShowInlineDialogForCheckBox;
private JBLabel myStripTrailingSpacesExplanationLabel;
private JCheckBox myCbEnableRichCopyByDefault;
private static final String ACTIVE_COLOR_SCHEME = ApplicationBundle.message("combobox.richcopy.color.scheme.active");
@@ -229,6 +230,7 @@ public class EditorOptionsPanel {
myErrorHighlightingPanel.reset();
RichCopySettings settings = RichCopySettings.getInstance();
myCbEnableRichCopyByDefault.setSelected(settings.isEnabled());
myRichCopyColorSchemeComboBox.removeAllItems();
EditorColorsScheme[] schemes = EditorColorsManager.getInstance().getAllSchemes();
myRichCopyColorSchemeComboBox.addItem(RichCopySettings.ACTIVE_GLOBAL_SCHEME_MARKER);
@@ -360,6 +362,7 @@ public class EditorOptionsPanel {
myErrorHighlightingPanel.apply();
RichCopySettings settings = RichCopySettings.getInstance();
settings.setEnabled(myCbEnableRichCopyByDefault.isSelected());
Object item = myRichCopyColorSchemeComboBox.getSelectedItem();
if (item instanceof String) {
settings.setSchemeName(item.toString());
@@ -485,6 +488,7 @@ public class EditorOptionsPanel {
isModified |= myErrorHighlightingPanel.isModified();
RichCopySettings settings = RichCopySettings.getInstance();
isModified |= isModified(myCbEnableRichCopyByDefault, settings.isEnabled());
isModified |= !Comparing.equal(settings.getSchemeName(), myRichCopyColorSchemeComboBox.getSelectedItem());
return isModified;
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2015 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.
*/
/*
* Created by IntelliJ IDEA.
* User: max
* Date: May 13, 2002
* Time: 5:37:50 PM
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package com.intellij.openapi.editor.richcopy;
public class CopyAsPlainTextAction extends ForcedCopyModeAction {
public CopyAsPlainTextAction() {
super(false);
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2015 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.
*/
/*
* Created by IntelliJ IDEA.
* User: max
* Date: May 13, 2002
* Time: 5:37:50 PM
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package com.intellij.openapi.editor.richcopy;
public class CopyAsRichTextAction extends ForcedCopyModeAction {
public CopyAsRichTextAction() {
super(true);
}
}
@@ -0,0 +1,51 @@
/*
* Copyright 2000-2015 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.richcopy;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.richcopy.settings.RichCopySettings;
public abstract class ForcedCopyModeAction extends AnAction {
private final boolean myRichCopyEnabled;
protected ForcedCopyModeAction(boolean richCopyEnabled) {
myRichCopyEnabled = richCopyEnabled;
}
@Override
public void update(AnActionEvent e) {
Presentation p = e.getPresentation();
Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
p.setVisible(RichCopySettings.getInstance().isEnabled() != myRichCopyEnabled &&
(!e.getPlace().equals(ActionPlaces.EDITOR_POPUP) ||
editor != null && editor.getSelectionModel().hasSelection(true)));
p.setEnabled(true);
}
@Override
public void actionPerformed(AnActionEvent e) {
RichCopySettings settings = RichCopySettings.getInstance();
boolean savedValue = settings.isEnabled();
try {
settings.setEnabled(myRichCopyEnabled);
ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_COPY).actionPerformed(e);
}
finally {
settings.setEnabled(savedValue);
}
}
}
@@ -71,7 +71,7 @@ public class TextWithMarkupProcessor extends CopyPastePostProcessor<RawTextWithM
@NotNull
@Override
public List<RawTextWithMarkup> collectTransferableData(PsiFile file, Editor editor, int[] startOffsets, int[] endOffsets) {
if (!Registry.is("editor.richcopy.enable")) {
if (!RichCopySettings.getInstance().isEnabled()) {
return Collections.emptyList();
}
@@ -34,6 +34,7 @@ public class RichCopySettings implements PersistentStateComponent<RichCopySettin
@NotNull public static final String ACTIVE_GLOBAL_SCHEME_MARKER = "__ACTIVE_GLOBAL_SCHEME__";
private boolean myEnabled = true;
private String mySchemeName = ACTIVE_GLOBAL_SCHEME_MARKER;
@NotNull
@@ -69,4 +70,12 @@ public class RichCopySettings implements PersistentStateComponent<RichCopySettin
public void setSchemeName(@Nullable String schemeName) {
mySchemeName = schemeName;
}
public boolean isEnabled() {
return myEnabled;
}
public void setEnabled(boolean enabled) {
myEnabled = enabled;
}
}
@@ -312,6 +312,10 @@ action.CopyPaths.text=C_opy Paths
action.CopyPaths.description=Copy paths corresponding to selected files or directories to clipboard
action.CopyReference.text=Cop_y Reference
action.CopyReference.description=Copy reference to selected class, method or function
action.CopyAsRichText.text=Copy as Rich Text
action.CopyAsRichText.description=Copy selection to clipboard as rich text (in RTF and HTML formats)
action.CopyAsPlainText.text=Copy as Plain Text
action.CopyAsPlainText.description=Copy selection to clipboard as plain text
action.$Paste.text=_Paste
action.$Paste.description=Paste from clipboard
action.PasteMultiple.text=Past_e from History...
@@ -664,6 +664,7 @@ import.scheme.chooser.destination=To\:
checkbox.reformat.on.typing.rbrace=Reformat block on typing '}'
group.richcopy=Rich-text copy
combobox.enable.richcopy.by.default=Copy as rich text by default
combobox.richcopy.color.scheme=Color scheme
combobox.richcopy.color.scheme.active=Active scheme
@@ -93,6 +93,16 @@
<add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="$Copy"/>
</action>
<action id="CopyAsRichText" class="com.intellij.openapi.editor.richcopy.CopyAsRichTextAction">
<add-to-group group-id="CutCopyPasteGroup" anchor="after" relative-to-action="CopyPaths"/>
<add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="$Copy"/>
</action>
<action id="CopyAsPlainText" class="com.intellij.openapi.editor.richcopy.CopyAsPlainTextAction">
<add-to-group group-id="CutCopyPasteGroup" anchor="after" relative-to-action="CopyPaths"/>
<add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="$Copy"/>
</action>
<group id="EditSelectWordGroup">
<reference ref="EditorSelectWord"/>
<reference ref="EditorUnSelectWord"/>
@@ -420,7 +420,6 @@ output.reader.blocking.mode=false
ide.certificate.manager=true
editor.richcopy.enable=true
editor.richcopy.max.size.megabytes=10
editor.richcopy.strip.indents=true
allow.dialog.based.popups=true