use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.
the class EditorSmartKeysConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
editorSettings.setSmartHome(myCbSmartHome.isSelected());
codeInsightSettings.SMART_END_ACTION = myCbSmartEnd.isSelected();
codeInsightSettings.SMART_INDENT_ON_ENTER = myCbSmartIndentOnEnter.isSelected();
codeInsightSettings.INSERT_BRACE_ON_ENTER = myCbInsertPairCurlyBraceOnEnter.isSelected();
codeInsightSettings.JAVADOC_STUB_ON_ENTER = myCbInsertJavadocStubOnEnter.isSelected();
codeInsightSettings.AUTOINSERT_PAIR_BRACKET = myCbInsertPairBracket.isSelected();
codeInsightSettings.AUTOINSERT_PAIR_QUOTE = myCbInsertPairQuote.isSelected();
codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE = myCbReformatBlockOnTypingRBrace.isSelected();
codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED = myCbSurroundSelectionOnTyping.isSelected();
editorSettings.setCamelWords(myCbCamelWords.isSelected());
codeInsightSettings.REFORMAT_ON_PASTE = getReformatPastedBlockValue();
codeInsightSettings.setBackspaceMode(getSmartBackspaceModeValue());
editorSettings.setAddCaretsOnDoubleCtrl(myCbEnableAddingCaretsOnDoubleCtrlArrows.isSelected());
super.apply();
}
use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.
the class PasteHandler method doPaste.
private static void doPaste(final Editor editor, final Project project, final PsiFile file, final Document document, @NotNull final Transferable content) {
CopyPasteManager.getInstance().stopKillRings();
String text = null;
try {
text = (String) content.getTransferData(DataFlavor.stringFlavor);
} catch (Exception e) {
editor.getComponent().getToolkit().beep();
}
if (text == null)
return;
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
final Map<CopyPastePostProcessor, List<? extends TextBlockTransferableData>> extraData = new HashMap<>();
final Collection<TextBlockTransferableData> allValues = new ArrayList<>();
for (CopyPastePostProcessor<? extends TextBlockTransferableData> processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) {
List<? extends TextBlockTransferableData> data = processor.extractTransferableData(content);
if (!data.isEmpty()) {
extraData.put(processor, data);
allValues.addAll(data);
}
}
text = TextBlockTransferable.convertLineSeparators(editor, text, allValues);
final CaretModel caretModel = editor.getCaretModel();
final SelectionModel selectionModel = editor.getSelectionModel();
final int col = caretModel.getLogicalPosition().column;
// There is a possible case that we want to perform paste while there is an active selection at the editor and caret is located
// inside it (e.g. Ctrl+A is pressed while caret is not at the zero column). We want to insert the text at selection start column
// then, hence, inserted block of text should be indented according to the selection start as well.
final int blockIndentAnchorColumn;
final int caretOffset = caretModel.getOffset();
if (selectionModel.hasSelection() && caretOffset >= selectionModel.getSelectionStart()) {
blockIndentAnchorColumn = editor.offsetToLogicalPosition(selectionModel.getSelectionStart()).column;
} else {
blockIndentAnchorColumn = col;
}
// We assume that EditorModificationUtil.insertStringAtCaret() is smart enough to remove currently selected text (if any).
RawText rawText = RawText.fromTransferable(content);
String newText = text;
for (CopyPastePreProcessor preProcessor : Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) {
newText = preProcessor.preprocessOnPaste(project, file, editor, newText, rawText);
}
int indentOptions = text.equals(newText) ? settings.REFORMAT_ON_PASTE : CodeInsightSettings.REFORMAT_BLOCK;
text = newText;
if (LanguageFormatting.INSTANCE.forContext(file) == null && indentOptions != CodeInsightSettings.NO_REFORMAT) {
indentOptions = CodeInsightSettings.INDENT_BLOCK;
}
final String _text = text;
ApplicationManager.getApplication().runWriteAction(() -> {
EditorModificationUtil.insertStringAtCaret(editor, _text, false, true);
});
int length = text.length();
int offset = caretModel.getOffset() - length;
if (offset < 0) {
length += offset;
offset = 0;
}
final RangeMarker bounds = document.createRangeMarker(offset, offset + length);
caretModel.moveToOffset(bounds.getEndOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
selectionModel.removeSelection();
final Ref<Boolean> indented = new Ref<>(Boolean.FALSE);
for (Map.Entry<CopyPastePostProcessor, List<? extends TextBlockTransferableData>> e : extraData.entrySet()) {
//noinspection unchecked
e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue());
}
boolean pastedTextContainsWhiteSpacesOnly = CharArrayUtil.shiftForward(document.getCharsSequence(), bounds.getStartOffset(), " \n\t") >= bounds.getEndOffset();
VirtualFile virtualFile = file.getVirtualFile();
if (!pastedTextContainsWhiteSpacesOnly && (virtualFile == null || !SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile))) {
final int indentOptions1 = indentOptions;
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
switch(indentOptions1) {
case CodeInsightSettings.INDENT_BLOCK:
if (!indented.get()) {
indentBlock(project, editor, bounds.getStartOffset(), bounds.getEndOffset(), blockIndentAnchorColumn);
}
break;
case CodeInsightSettings.INDENT_EACH_LINE:
if (!indented.get()) {
indentEachLine(project, editor, bounds.getStartOffset(), bounds.getEndOffset());
}
break;
case CodeInsightSettings.REFORMAT_BLOCK:
// this is needed for example when inserting a comment before method
indentEachLine(project, editor, bounds.getStartOffset(), bounds.getEndOffset());
reformatBlock(project, editor, bounds.getStartOffset(), bounds.getEndOffset());
break;
}
});
}
if (bounds.isValid()) {
caretModel.moveToOffset(bounds.getEndOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
selectionModel.removeSelection();
editor.putUserData(EditorEx.LAST_PASTED_REGION, TextRange.create(bounds));
}
}
use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.
the class EndHandler method doExecute.
@Override
protected void doExecute(final Editor editor, Caret caret, DataContext dataContext) {
CodeInsightSettings settings = CodeInsightSettings.getInstance();
if (!settings.SMART_END_ACTION) {
if (myOriginalHandler != null) {
myOriginalHandler.execute(editor, caret, dataContext);
}
return;
}
final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent()));
if (project == null) {
if (myOriginalHandler != null) {
myOriginalHandler.execute(editor, caret, dataContext);
}
return;
}
final Document document = editor.getDocument();
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file == null) {
if (myOriginalHandler != null) {
myOriginalHandler.execute(editor, caret, dataContext);
}
return;
}
final EditorNavigationDelegate[] extensions = EditorNavigationDelegate.EP_NAME.getExtensions();
for (EditorNavigationDelegate delegate : extensions) {
if (delegate.navigateToLineEnd(editor, dataContext) == EditorNavigationDelegate.Result.STOP) {
return;
}
}
final CaretModel caretModel = editor.getCaretModel();
final int caretOffset = caretModel.getOffset();
CharSequence chars = editor.getDocument().getCharsSequence();
int length = editor.getDocument().getTextLength();
if (caretOffset < length) {
final int offset1 = CharArrayUtil.shiftBackward(chars, caretOffset - 1, " \t");
if (offset1 < 0 || chars.charAt(offset1) == '\n' || chars.charAt(offset1) == '\r') {
final int offset2 = CharArrayUtil.shiftForward(chars, offset1 + 1, " \t");
boolean isEmptyLine = offset2 >= length || chars.charAt(offset2) == '\n' || chars.charAt(offset2) == '\r';
if (isEmptyLine) {
// There is a possible case that indent string is not calculated for particular document (that is true at least for plain text
// documents). Hence, we check that and don't finish processing in case we have such a situation.
boolean stopProcessing = true;
PsiDocumentManager.getInstance(project).commitAllDocuments();
CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
final String lineIndent = styleManager.getLineIndent(file, caretOffset);
if (lineIndent != null) {
int col = calcColumnNumber(lineIndent, editor.getSettings().getTabSize(project));
int line = caretModel.getVisualPosition().line;
caretModel.moveToVisualPosition(new VisualPosition(line, col));
if (caretModel.getLogicalPosition().column != col) {
if (!ApplicationManager.getApplication().isWriteAccessAllowed() && !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
editor.getSelectionModel().removeSelection();
WriteAction.run(() -> document.replaceString(offset1 + 1, offset2, lineIndent));
}
} else {
stopProcessing = false;
}
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
if (stopProcessing) {
return;
}
}
}
}
if (myOriginalHandler != null) {
myOriginalHandler.execute(editor, caret, dataContext);
}
}
use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.
the class JavaAutoImportOptions method isModified.
public boolean isModified() {
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
DaemonCodeAnalyzerSettings daemonSettings = DaemonCodeAnalyzerSettings.getInstance();
boolean isModified = isModified(myCbShowImportPopup, daemonSettings.isImportHintEnabled());
isModified |= isModified(myCbOptimizeImports, CodeInsightWorkspaceSettings.getInstance(myProject).optimizeImportsOnTheFly);
isModified |= isModified(myCbAddUnambiguousImports, codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY);
isModified |= isModified(myCbAddMethodImports, codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY);
isModified |= getSmartPasteValue() != codeInsightSettings.ADD_IMPORTS_ON_PASTE;
isModified |= myExcludePackagesTable.isModified();
return isModified;
}
use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.
the class JavaAutoImportOptions method reset.
public void reset() {
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
DaemonCodeAnalyzerSettings daemonSettings = DaemonCodeAnalyzerSettings.getInstance();
switch(codeInsightSettings.ADD_IMPORTS_ON_PASTE) {
case CodeInsightSettings.YES:
mySmartPasteCombo.setSelectedItem(INSERT_IMPORTS_ALWAYS);
break;
case CodeInsightSettings.NO:
mySmartPasteCombo.setSelectedItem(INSERT_IMPORTS_NONE);
break;
case CodeInsightSettings.ASK:
mySmartPasteCombo.setSelectedItem(INSERT_IMPORTS_ASK);
break;
}
myCbShowImportPopup.setSelected(daemonSettings.isImportHintEnabled());
myCbOptimizeImports.setSelected(CodeInsightWorkspaceSettings.getInstance(myProject).optimizeImportsOnTheFly);
myCbAddUnambiguousImports.setSelected(codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY);
myCbAddMethodImports.setSelected(codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY);
myExcludePackagesTable.reset();
}
Aggregations