public boolean isModified() { EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance(); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); UISettings uiSettings = UISettings.getInstance(); VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance(); // Display boolean isModified = isModified(myCbSmoothScrolling, editorSettings.isSmoothScrolling()); // Brace highlighting isModified |= isModified(myCbHighlightBraces, codeInsightSettings.HIGHLIGHT_BRACES); isModified |= isModified(myCbHighlightScope, codeInsightSettings.HIGHLIGHT_SCOPE); isModified |= isModified( myCbHighlightIdentifierUnderCaret, codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET); // Virtual space isModified |= isModified( myCbUseSoftWrapsAtEditor, editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR)); isModified |= isModified(myCbUseCustomSoftWrapIndent, editorSettings.isUseCustomSoftWrapIndent()); isModified |= editorSettings.getCustomSoftWrapIndent() != getCustomSoftWrapIndent(); isModified |= isModified(myCbShowSoftWrapsOnlyOnCaretLine, !editorSettings.isAllSoftWrapsShown()); isModified |= isModified(myCbVirtualSpace, editorSettings.isVirtualSpace()); isModified |= isModified(myCbCaretInsideTabs, editorSettings.isCaretInsideTabs()); isModified |= isModified(myCbVirtualPageAtBottom, editorSettings.isAdditionalPageAtBottom()); // Limits isModified |= getMaxClipboardContents() != uiSettings.MAX_CLIPBOARD_CONTENTS; // Paste // Strip trailing spaces, ensure EOL on EOF on save isModified |= !getStripTrailingSpacesValue().equals(editorSettings.getStripTrailingSpaces()); isModified |= isModified(myCbEnsureBlankLineBeforeCheckBox, editorSettings.isEnsureNewLineAtEOF()); isModified |= isModified(myCbShowQuickDocOnMouseMove, editorSettings.isShowQuickDocOnMouseOverElement()); Long quickDocDelay = getQuickDocDelayFromGui(); if (quickDocDelay != null && !quickDocDelay.equals( Long.valueOf(editorSettings.getQuickDocOnMouseOverElementDelayMillis()))) { return true; } // advanced mouse isModified |= isModified(myCbEnableDnD, editorSettings.isDndEnabled()); isModified |= isModified(myCbEnableWheelFontChange, editorSettings.isWheelFontChangeEnabled()); isModified |= isModified( myCbHonorCamelHumpsWhenSelectingByClicking, editorSettings.isMouseClickSelectionHonorsCamelWords()); isModified |= myRbPreferMovingCaret.isSelected() != editorSettings.isRefrainFromScrolling(); isModified |= isModified(myRecentFilesLimitField, UISettings.getInstance().RECENT_FILES_LIMIT); isModified |= isModified( myCbRenameLocalVariablesInplace, editorSettings.isVariableInplaceRenameEnabled()); isModified |= isModified(myPreselectCheckBox, editorSettings.isPreselectRename()); isModified |= isModified(myShowInlineDialogForCheckBox, editorSettings.isShowInlineLocalDialog()); isModified |= isModified( myShowNotificationAfterReformatCodeCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION); isModified |= isModified( myShowNotificationAfterOptimizeImportsCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION); isModified |= isModified(myShowLSTInGutterCheckBox, vcsSettings.SHOW_LST_GUTTER_MARKERS); isModified |= isModified( myShowWhitespacesModificationsInLSTGutterCheckBox, vcsSettings.SHOW_WHITESPACES_IN_LST); isModified |= myErrorHighlightingPanel.isModified(); RichCopySettings settings = RichCopySettings.getInstance(); isModified |= isModified(myCbEnableRichCopyByDefault, settings.isEnabled()); isModified |= !Comparing.equal(settings.getSchemeName(), myRichCopyColorSchemeComboBox.getSelectedItem()); return isModified; }
public void apply() throws ConfigurationException { EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance(); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); UISettings uiSettings = UISettings.getInstance(); VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance(); // Display editorSettings.setSmoothScrolling(myCbSmoothScrolling.isSelected()); // Brace Highlighting codeInsightSettings.HIGHLIGHT_BRACES = myCbHighlightBraces.isSelected(); codeInsightSettings.HIGHLIGHT_SCOPE = myCbHighlightScope.isSelected(); codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET = myCbHighlightIdentifierUnderCaret.isSelected(); clearAllIdentifierHighlighters(); // Virtual space editorSettings.setUseSoftWraps( myCbUseSoftWrapsAtEditor.isSelected(), SoftWrapAppliancePlaces.MAIN_EDITOR); editorSettings.setUseCustomSoftWrapIndent(myCbUseCustomSoftWrapIndent.isSelected()); editorSettings.setCustomSoftWrapIndent(getCustomSoftWrapIndent()); editorSettings.setAllSoftwrapsShown(!myCbShowSoftWrapsOnlyOnCaretLine.isSelected()); editorSettings.setVirtualSpace(myCbVirtualSpace.isSelected()); editorSettings.setCaretInsideTabs(myCbCaretInsideTabs.isSelected()); editorSettings.setAdditionalPageAtBottom(myCbVirtualPageAtBottom.isSelected()); // Limits boolean uiSettingsChanged = false; int maxClipboardContents = getMaxClipboardContents(); if (uiSettings.MAX_CLIPBOARD_CONTENTS != maxClipboardContents) { uiSettings.MAX_CLIPBOARD_CONTENTS = maxClipboardContents; uiSettingsChanged = true; } if (uiSettingsChanged) { uiSettings.fireUISettingsChanged(); } // Strip trailing spaces on save if (STRIP_NONE.equals(myStripTrailingSpacesCombo.getSelectedItem())) { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE); } else if (STRIP_CHANGED.equals(myStripTrailingSpacesCombo.getSelectedItem())) { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED); } else { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE); } editorSettings.setEnsureNewLineAtEOF(myCbEnsureBlankLineBeforeCheckBox.isSelected()); if (myCbShowQuickDocOnMouseMove.isSelected() ^ editorSettings.isShowQuickDocOnMouseOverElement()) { boolean enabled = myCbShowQuickDocOnMouseMove.isSelected(); editorSettings.setShowQuickDocOnMouseOverElement(enabled); ServiceManager.getService(QuickDocOnMouseOverManager.class).setEnabled(enabled); } Long quickDocDelay = getQuickDocDelayFromGui(); if (quickDocDelay != null) { editorSettings.setQuickDocOnMouseOverElementDelayMillis(quickDocDelay); } editorSettings.setDndEnabled(myCbEnableDnD.isSelected()); editorSettings.setWheelFontChangeEnabled(myCbEnableWheelFontChange.isSelected()); editorSettings.setMouseClickSelectionHonorsCamelWords( myCbHonorCamelHumpsWhenSelectingByClicking.isSelected()); editorSettings.setRefrainFromScrolling(myRbPreferMovingCaret.isSelected()); editorSettings.setVariableInplaceRenameEnabled(myCbRenameLocalVariablesInplace.isSelected()); editorSettings.setPreselectRename(myPreselectCheckBox.isSelected()); editorSettings.setShowInlineLocalDialog(myShowInlineDialogForCheckBox.isSelected()); editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION = myShowNotificationAfterReformatCodeCheckBox.isSelected(); editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION = myShowNotificationAfterOptimizeImportsCheckBox.isSelected(); boolean updateVcsSettings = false; if (vcsSettings.SHOW_WHITESPACES_IN_LST != myShowWhitespacesModificationsInLSTGutterCheckBox.isSelected()) { vcsSettings.SHOW_WHITESPACES_IN_LST = myShowWhitespacesModificationsInLSTGutterCheckBox.isSelected(); updateVcsSettings = true; } if (vcsSettings.SHOW_LST_GUTTER_MARKERS != myShowLSTInGutterCheckBox.isSelected()) { vcsSettings.SHOW_LST_GUTTER_MARKERS = myShowLSTInGutterCheckBox.isSelected(); updateVcsSettings = true; } if (updateVcsSettings) { ApplicationManager.getApplication() .getMessageBus() .syncPublisher(LineStatusTrackerSettingListener.TOPIC) .settingsUpdated(); } reinitAllEditors(); String temp = myRecentFilesLimitField.getText(); if (temp.trim().length() > 0) { try { int newRecentFilesLimit = Integer.parseInt(temp); if (newRecentFilesLimit > 0 && uiSettings.RECENT_FILES_LIMIT != newRecentFilesLimit) { uiSettings.RECENT_FILES_LIMIT = newRecentFilesLimit; uiSettingsChanged = true; } } catch (NumberFormatException ignored) { } } if (uiSettingsChanged) { uiSettings.fireUISettingsChanged(); } myErrorHighlightingPanel.apply(); RichCopySettings settings = RichCopySettings.getInstance(); settings.setEnabled(myCbEnableRichCopyByDefault.isSelected()); Object item = myRichCopyColorSchemeComboBox.getSelectedItem(); if (item instanceof String) { settings.setSchemeName(item.toString()); } restartDaemons(); }
@Nullable @Override public TextBlockTransferableData collectTransferableData( PsiFile file, Editor editor, int[] startOffsets, int[] endOffsets) { if (!Registry.is("editor.richcopy.enable")) { return null; } try { for (TextWithMarkupBuilder builder : myBuilders) { builder.reset(); } SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasBlockSelection()) { return null; // unsupported legacy mode } RichCopySettings settings = RichCopySettings.getInstance(); List<Caret> carets = editor.getCaretModel().getAllCarets(); Caret firstCaret = carets.get(0); final int indentSymbolsToStrip; final int firstLineStartOffset; if (settings.isStripIndents() && carets.size() == 1) { Pair<Integer, Integer> p = calcIndentSymbolsToStrip( editor.getDocument(), firstCaret.getSelectionStart(), firstCaret.getSelectionEnd()); firstLineStartOffset = p.first; indentSymbolsToStrip = p.second; } else { firstLineStartOffset = firstCaret.getSelectionStart(); indentSymbolsToStrip = 0; } logInitial(editor, startOffsets, endOffsets, indentSymbolsToStrip, firstLineStartOffset); CharSequence text = editor.getDocument().getCharsSequence(); EditorColorsScheme schemeToUse = settings.getColorsScheme(editor.getColorsScheme()); EditorHighlighter highlighter = HighlighterFactory.createHighlighter( file.getVirtualFile(), schemeToUse, file.getProject()); highlighter.setText(text); MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), file.getProject(), false); Context context = new Context(text, schemeToUse, indentSymbolsToStrip); int shift = 0; int endOffset = 0; Caret prevCaret = null; for (Caret caret : carets) { int caretSelectionStart = caret.getSelectionStart(); int caretSelectionEnd = caret.getSelectionEnd(); int startOffsetToUse; if (caret == firstCaret) { startOffsetToUse = firstLineStartOffset; } else { startOffsetToUse = caretSelectionStart; assert prevCaret != null; String prevCaretSelectedText = prevCaret.getSelectedText(); // Block selection fills short lines by white spaces. int fillStringLength = prevCaretSelectedText == null ? 0 : prevCaretSelectedText.length() - (prevCaret.getSelectionEnd() - prevCaret.getSelectionStart()); int endLineOffset = endOffset + shift + fillStringLength; context.builder.addText(endLineOffset, endLineOffset + 1); shift++; // Block selection ends '\n' at line end shift += fillStringLength; } shift += endOffset - caretSelectionStart; endOffset = caretSelectionEnd; context.reset(shift); prevCaret = caret; if (endOffset <= startOffsetToUse) { continue; } MarkupIterator markupIterator = new MarkupIterator( text, new CompositeRangeIterator( schemeToUse, new HighlighterRangeIterator(highlighter, startOffsetToUse, endOffset), new MarkupModelRangeIterator( markupModel, schemeToUse, startOffsetToUse, endOffset)), schemeToUse); try { context.iterate(markupIterator, endOffset); } finally { markupIterator.dispose(); } } SyntaxInfo syntaxInfo = context.finish(); logSyntaxInfo(syntaxInfo); for (TextWithMarkupBuilder builder : myBuilders) { builder.build(syntaxInfo); } } catch (Exception e) { // catching the exception so that the rest of copy/paste functionality can still work fine LOG.error(e); } return null; }
public void reset() { EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance(); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); UISettings uiSettings = UISettings.getInstance(); VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance(); // Display myCbSmoothScrolling.setSelected(editorSettings.isSmoothScrolling()); // Brace highlighting myCbHighlightBraces.setSelected(codeInsightSettings.HIGHLIGHT_BRACES); myCbHighlightScope.setSelected(codeInsightSettings.HIGHLIGHT_SCOPE); myCbHighlightIdentifierUnderCaret.setSelected( codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET); // Virtual space myCbUseSoftWrapsAtEditor.setSelected( editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR)); myCbUseCustomSoftWrapIndent.setSelected(editorSettings.isUseCustomSoftWrapIndent()); myCustomSoftWrapIndent.setText(Integer.toString(editorSettings.getCustomSoftWrapIndent())); myCbShowSoftWrapsOnlyOnCaretLine.setSelected(!editorSettings.isAllSoftWrapsShown()); updateSoftWrapSettingsRepresentation(); myCbVirtualSpace.setSelected(editorSettings.isVirtualSpace()); myCbCaretInsideTabs.setSelected(editorSettings.isCaretInsideTabs()); myCbVirtualPageAtBottom.setSelected(editorSettings.isAdditionalPageAtBottom()); // Limits myClipboardContentLimitTextField.setText(Integer.toString(uiSettings.MAX_CLIPBOARD_CONTENTS)); // Strip trailing spaces on save String stripTrailingSpaces = editorSettings.getStripTrailingSpaces(); if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(stripTrailingSpaces)) { myStripTrailingSpacesCombo.setSelectedItem(STRIP_NONE); } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED.equals( stripTrailingSpaces)) { myStripTrailingSpacesCombo.setSelectedItem(STRIP_CHANGED); } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE.equals( stripTrailingSpaces)) { myStripTrailingSpacesCombo.setSelectedItem(STRIP_ALL); } explainTrailingSpaces(stripTrailingSpaces); myCbEnsureBlankLineBeforeCheckBox.setSelected(editorSettings.isEnsureNewLineAtEOF()); myCbShowQuickDocOnMouseMove.setSelected(editorSettings.isShowQuickDocOnMouseOverElement()); myQuickDocDelayTextField.setText( Long.toString(editorSettings.getQuickDocOnMouseOverElementDelayMillis())); myQuickDocDelayTextField.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement()); myQuickDocDelayLabel.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement()); // Advanced mouse myCbEnableDnD.setSelected(editorSettings.isDndEnabled()); myCbEnableWheelFontChange.setSelected(editorSettings.isWheelFontChangeEnabled()); myCbHonorCamelHumpsWhenSelectingByClicking.setSelected( editorSettings.isMouseClickSelectionHonorsCamelWords()); myRbPreferMovingCaret.setSelected(editorSettings.isRefrainFromScrolling()); myRbPreferScrolling.setSelected(!editorSettings.isRefrainFromScrolling()); myRecentFilesLimitField.setText(Integer.toString(uiSettings.RECENT_FILES_LIMIT)); myCbRenameLocalVariablesInplace.setSelected(editorSettings.isVariableInplaceRenameEnabled()); myPreselectCheckBox.setSelected(editorSettings.isPreselectRename()); myShowInlineDialogForCheckBox.setSelected(editorSettings.isShowInlineLocalDialog()); myShowNotificationAfterReformatCodeCheckBox.setSelected( editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION); myShowNotificationAfterOptimizeImportsCheckBox.setSelected( editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION); myShowLSTInGutterCheckBox.setSelected(vcsSettings.SHOW_LST_GUTTER_MARKERS); myShowWhitespacesModificationsInLSTGutterCheckBox.setSelected( vcsSettings.SHOW_WHITESPACES_IN_LST); myShowWhitespacesModificationsInLSTGutterCheckBox.setEnabled( myShowLSTInGutterCheckBox.isSelected()); myErrorHighlightingPanel.reset(); RichCopySettings settings = RichCopySettings.getInstance(); myCbEnableRichCopyByDefault.setSelected(settings.isEnabled()); myRichCopyColorSchemeComboBox.removeAllItems(); EditorColorsScheme[] schemes = EditorColorsManager.getInstance().getAllSchemes(); myRichCopyColorSchemeComboBox.addItem(RichCopySettings.ACTIVE_GLOBAL_SCHEME_MARKER); for (EditorColorsScheme scheme : schemes) { myRichCopyColorSchemeComboBox.addItem(scheme.getName()); } String toSelect = settings.getSchemeName(); if (!StringUtil.isEmpty(toSelect)) { myRichCopyColorSchemeComboBox.setSelectedItem(toSelect); } }
public void apply() throws ConfigurationException { EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance(); CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance(); UISettings uiSettings = UISettings.getInstance(); // Display editorSettings.setSmoothScrolling(myCbSmoothScrolling.isSelected()); // Brace Highlighting codeInsightSettings.HIGHLIGHT_BRACES = myCbHighlightBraces.isSelected(); codeInsightSettings.HIGHLIGHT_SCOPE = myCbHighlightScope.isSelected(); codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET = myCbHighlightIdentifierUnderCaret.isSelected(); clearAllIdentifierHighlighters(); // Virtual space editorSettings.setUseSoftWraps( myCbUseSoftWrapsAtEditor.isSelected(), SoftWrapAppliancePlaces.MAIN_EDITOR); editorSettings.setUseSoftWraps( myCbUseSoftWrapsAtConsole.isSelected(), SoftWrapAppliancePlaces.CONSOLE); editorSettings.setUseCustomSoftWrapIndent(myCbUseCustomSoftWrapIndent.isSelected()); editorSettings.setCustomSoftWrapIndent(getCustomSoftWrapIndent()); editorSettings.setAllSoftwrapsShown(myCbShowAllSoftWraps.isSelected()); editorSettings.setVirtualSpace(myCbVirtualSpace.isSelected()); editorSettings.setCaretInsideTabs(myCbCaretInsideTabs.isSelected()); editorSettings.setAdditionalPageAtBottom(myCbVirtualPageAtBottom.isSelected()); // Limits boolean uiSettingsChanged = false; int maxClipboardContents = getMaxClipboardContents(); if (uiSettings.MAX_CLIPBOARD_CONTENTS != maxClipboardContents) { uiSettings.MAX_CLIPBOARD_CONTENTS = maxClipboardContents; uiSettingsChanged = true; } if (uiSettingsChanged) { uiSettings.fireUISettingsChanged(); } // Strip trailing spaces on save if (STRIP_NONE.equals(myStripTrailingSpacesCombo.getSelectedItem())) { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE); } else if (STRIP_CHANGED.equals(myStripTrailingSpacesCombo.getSelectedItem())) { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED); } else { editorSettings.setStripTrailingSpaces( EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE); } editorSettings.setEnsureNewLineAtEOF(myCbEnsureBlankLineBeforeCheckBox.isSelected()); if (myCbShowQuickDocOnMouseMove.isSelected() ^ editorSettings.isShowQuickDocOnMouseOverElement()) { boolean enabled = myCbShowQuickDocOnMouseMove.isSelected(); editorSettings.setShowQuickDocOnMouseOverElement(enabled); ServiceManager.getService(QuickDocOnMouseOverManager.class).setEnabled(enabled); } Long quickDocDelay = getQuickDocDelayFromGui(); if (quickDocDelay != null) { editorSettings.setQuickDocOnMouseOverElementDelayMillis(quickDocDelay); } editorSettings.setDndEnabled(myCbEnableDnD.isSelected()); editorSettings.setWheelFontChangeEnabled(myCbEnableWheelFontChange.isSelected()); editorSettings.setMouseClickSelectionHonorsCamelWords( myCbHonorCamelHumpsWhenSelectingByClicking.isSelected()); editorSettings.setRefrainFromScrolling(myRbPreferMovingCaret.isSelected()); editorSettings.setVariableInplaceRenameEnabled(myCbRenameLocalVariablesInplace.isSelected()); editorSettings.setPreselectRename(myPreselectCheckBox.isSelected()); editorSettings.getOptions().SHOW_REFORMAT_DIALOG = myShowReformatCodeDialogCheckBox.isSelected(); editorSettings.getOptions().SHOW_OPIMIZE_IMPORTS_DIALOG = myShowOptimizeImportsDialogCheckBox.isSelected(); reinitAllEditors(); String temp = myRecentFilesLimitField.getText(); if (temp.trim().length() > 0) { try { int newRecentFilesLimit = Integer.parseInt(temp); if (newRecentFilesLimit > 0 && uiSettings.RECENT_FILES_LIMIT != newRecentFilesLimit) { uiSettings.RECENT_FILES_LIMIT = newRecentFilesLimit; uiSettingsChanged = true; } } catch (NumberFormatException ignored) { } } if (uiSettingsChanged) { uiSettings.fireUISettingsChanged(); } uiSettings.CONSOLE_COMMAND_HISTORY_LIMIT = StringUtil.parseInt( myCommandsHistoryLimitField.getText(), uiSettings.CONSOLE_COMMAND_HISTORY_LIMIT); myErrorHighlightingPanel.apply(); RichCopySettings settings = RichCopySettings.getInstance(); Object item = myRichCopyColorSchemeComboBox.getSelectedItem(); if (item instanceof String) { settings.setSchemeName(item.toString()); } settings.setStripIndents(myRichCopyStripWhitespaceCheckBox.isSelected()); restartDaemons(); }