mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+1
-23
@@ -21,16 +21,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.arrangement.Rearranger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Arranges content at the target file(s).
|
||||
*
|
||||
@@ -66,23 +61,6 @@ public class RearrangeCodeAction extends AnAction {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<TextRange> ranges = new ArrayList<TextRange>();
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (selectionModel.hasSelection()) {
|
||||
ranges.add(TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
|
||||
}
|
||||
else if (selectionModel.hasBlockSelection()) {
|
||||
int[] starts = selectionModel.getBlockSelectionStarts();
|
||||
int[] ends = selectionModel.getBlockSelectionEnds();
|
||||
for (int i = 0; i < starts.length; i++) {
|
||||
ranges.add(TextRange.create(starts[i], ends[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ranges.add(TextRange.create(0, document.getTextLength()));
|
||||
}
|
||||
|
||||
new RearrangeCodeProcessor(project, file, ranges).run();
|
||||
new RearrangeCodeProcessor(project, file, editor.getSelectionModel()).run();
|
||||
}
|
||||
}
|
||||
|
||||
+29
-21
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.actions;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -25,11 +26,12 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.arrangement.Rearranger;
|
||||
import com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
@@ -39,7 +41,7 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
public static final String PROGRESS_TEXT = "Rearranging code...";
|
||||
|
||||
@Nullable private Condition<PsiFile> myAcceptCondition;
|
||||
private Collection<TextRange> myRangesForFile = ContainerUtil.newArrayList();
|
||||
@Nullable private SelectionModel mySelectionModel;
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull AbstractLayoutCodeProcessor previousProcessor,
|
||||
@Nullable Condition<PsiFile> acceptCondition) {
|
||||
@@ -49,18 +51,15 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable Collection<TextRange> ranges) {
|
||||
@Nullable SelectionModel selectionModel) {
|
||||
super(project, file, PROGRESS_TEXT, COMMAND_NAME, false);
|
||||
if (ranges != null) {
|
||||
myRangesForFile.addAll(ranges);
|
||||
}
|
||||
mySelectionModel = selectionModel;
|
||||
}
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull Project project,
|
||||
@NotNull PsiFile[] files,
|
||||
@NotNull String commandName,
|
||||
@Nullable Runnable postRunnable)
|
||||
{
|
||||
@Nullable Runnable postRunnable) {
|
||||
super(project, files, PROGRESS_TEXT, commandName, postRunnable, false);
|
||||
}
|
||||
|
||||
@@ -74,25 +73,34 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
return new FutureTask<Boolean>(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
try {
|
||||
if (!shouldRearrangeFile(file)) return true;
|
||||
|
||||
Collection<TextRange> ranges = getRangesToFormat(file);
|
||||
RearrangeCommand rearranger = new RearrangeCommand(myProject, file, COMMAND_NAME, ranges);
|
||||
if (rearranger.couldRearrange()) {
|
||||
rearranger.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally {
|
||||
myRangesForFile.clear();
|
||||
if (!shouldRearrangeFile(file)) return true;
|
||||
|
||||
Collection<TextRange> ranges = getRangesToFormat(file);
|
||||
RearrangeCommand rearranger = new RearrangeCommand(myProject, file, COMMAND_NAME, ranges);
|
||||
if (rearranger.couldRearrange()) {
|
||||
rearranger.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Collection<TextRange> getRangesToFormat(@NotNull PsiFile file) {
|
||||
return myRangesForFile.isEmpty() ? ContainerUtil.newArrayList(file.getTextRange()) : myRangesForFile;
|
||||
final List<TextRange> ranges = new SmartList<TextRange>();
|
||||
if (mySelectionModel != null && mySelectionModel.hasSelection()) {
|
||||
ranges.add(TextRange.create(mySelectionModel.getSelectionStart(), mySelectionModel.getSelectionEnd()));
|
||||
}
|
||||
else if (mySelectionModel != null && mySelectionModel.hasBlockSelection()) {
|
||||
int[] starts = mySelectionModel.getBlockSelectionStarts();
|
||||
int[] ends = mySelectionModel.getBlockSelectionEnds();
|
||||
for (int i = 0; i < starts.length; i++) {
|
||||
ranges.add(TextRange.create(starts[i], ends[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ranges.add(TextRange.create(0, file.getTextLength()));
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
@@ -57,7 +56,6 @@ import org.jetbrains.annotations.TestOnly;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
@@ -193,11 +191,7 @@ public class ReformatCodeAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
if (rearrangeEntries && editor != null) {
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
final TextRange rangeToUse = selectionModel.hasSelection()
|
||||
? TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())
|
||||
: TextRange.create(0, editor.getDocument().getTextLength());
|
||||
new RearrangeCodeProcessor(project, file, Collections.singleton(rangeToUse)).run();
|
||||
new RearrangeCodeProcessor(project, file, editor.getSelectionModel()).run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,5 @@ org.jetbrains.plugins.vagrant 0.1 0.2
|
||||
org.intellij.clojure 0.2.1.178
|
||||
net.nicoulaj.idea.markdown 0.9.5 0.9.4 0.9.3 0.9.2 0.9.1 0.8.3 0.8.2 0.8.1 0.8 0.7 0.6.1 0.6 0.5.1 0.5 0.4 0.3 0.2 0.1
|
||||
zielu.gittoolbox 13.1.0
|
||||
com.jetbrains.chronon 134.1221 134.1414 134.1618 135.1291 135.476 135.666
|
||||
com.jetbrains.chronon 134.1221 134.1414 134.1618 135.1291 135.476 135.666
|
||||
ArgoUML.Integration 0.1.1 0.1.2
|
||||
|
||||
Reference in New Issue
Block a user