Skip to content

Commit 05ee082

Browse files
committed
Merge pull request #103 from retronym/topic/idea-14.1
Topic/idea 14.1
2 parents 756a2ed + 5909ea9 commit 05ee082

File tree

8 files changed

+27
-188
lines changed

8 files changed

+27
-188
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>net.orfjackal.idea-sbt-plugin</groupId>
66
<artifactId>sbt</artifactId>
7-
<version>1.6.2-SNAPSHOT</version>
7+
<version>1.7.0-SNAPSHOT</version>
88
<packaging>pom</packaging>
99

1010
<modules>
@@ -23,8 +23,8 @@
2323
command line with -Didea.home=...
2424
2525
Do not commit any changes to this part of the POM. -->
26-
<idea.version>110.187</idea.version>
27-
<idea.home>/Applications/Nika-IU-110.187.app</idea.home>
26+
<idea.version>141.177</idea.version>
27+
<idea.home>/Applications/IntelliJ IDEA 14.app/Contents</idea.home>
2828
</properties>
2929

3030
<name>SBT</name>

sbt-dist/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>net.orfjackal.idea-sbt-plugin</groupId>
77
<artifactId>sbt</artifactId>
8-
<version>1.6.2-SNAPSHOT</version>
8+
<version>1.7.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>sbt-dist</artifactId>

sbt-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>net.orfjackal.idea-sbt-plugin</groupId>
77
<artifactId>sbt</artifactId>
8-
<version>1.6.2-SNAPSHOT</version>
8+
<version>1.7.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>sbt-plugin</artifactId>

sbt-plugin/sbt-plugin.iml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
1111
<excludeFolder url="file://$MODULE_DIR$/target" />
1212
</content>
13-
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="jdk" jdkName="IDEA IU-139.1117.1" jdkType="IDEA JDK" />
1414
<orderEntry type="sourceFolder" forTests="false" />
1515
<orderEntry type="library" name="Maven: com.miglayout:miglayout:3.7.3.1" level="project" />
1616
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
1717
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.1" level="project" />
1818
</component>
19-
</module>
20-
19+
</module>

sbt-plugin/src/main/java/net/orfjackal/sbt/plugin/SbtConsole.java

Lines changed: 10 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,31 @@
44

55
package net.orfjackal.sbt.plugin;
66

7-
import com.intellij.execution.console.*;
7+
import com.intellij.execution.console.LanguageConsoleImpl;
88
import com.intellij.execution.filters.*;
99
import com.intellij.execution.impl.ConsoleViewImpl;
10-
import com.intellij.execution.process.ConsoleHistoryModel;
1110
import com.intellij.execution.process.ProcessAdapter;
1211
import com.intellij.execution.process.ProcessEvent;
1312
import com.intellij.execution.process.ProcessHandler;
14-
import com.intellij.execution.runners.ConsoleExecuteActionHandler;
1513
import com.intellij.execution.ui.ConsoleView;
1614
import com.intellij.execution.ui.ConsoleViewContentType;
1715
import com.intellij.openapi.actionSystem.*;
1816
import com.intellij.openapi.application.ApplicationManager;
19-
import com.intellij.openapi.application.ex.ApplicationManagerEx;
2017
import com.intellij.openapi.diagnostic.Logger;
21-
import com.intellij.openapi.editor.Document;
22-
import com.intellij.openapi.editor.ScrollingModel;
23-
import com.intellij.openapi.editor.event.VisibleAreaEvent;
24-
import com.intellij.openapi.editor.event.VisibleAreaListener;
25-
import com.intellij.openapi.editor.ex.EditorEx;
2618
import com.intellij.openapi.project.DumbAwareAction;
2719
import com.intellij.openapi.project.Project;
2820
import com.intellij.openapi.ui.SimpleToolWindowPanel;
2921
import com.intellij.openapi.util.IconLoader;
3022
import com.intellij.openapi.util.Key;
31-
import com.intellij.openapi.util.TextRange;
3223
import com.intellij.openapi.wm.ToolWindow;
3324
import com.intellij.openapi.wm.ToolWindowManager;
3425
import com.intellij.psi.search.GlobalSearchScope;
35-
import com.intellij.testFramework.LightVirtualFile;
36-
import com.intellij.ui.components.JBScrollBar;
3726
import com.intellij.ui.content.Content;
3827
import com.intellij.ui.content.ContentFactory;
39-
import com.intellij.util.ReflectionUtil;
40-
import com.intellij.util.ui.UIUtil;
41-
import net.orfjackal.sbt.plugin.sbtlang.SbtFileType;
42-
import net.orfjackal.sbt.plugin.sbtlang.SbtLanguage;
43-
import org.jetbrains.annotations.NotNull;
4428

4529
import javax.swing.*;
46-
import javax.swing.plaf.basic.BasicScrollBarUI;
4730
import java.awt.*;
48-
import java.lang.reflect.Field;
49-
import java.util.*;
31+
import java.util.Arrays;
5032
import java.util.concurrent.atomic.AtomicBoolean;
5133

5234
public class SbtConsole {
@@ -69,17 +51,16 @@ public class SbtConsole {
6951
public SbtConsole(String title, Project project, SbtRunnerComponent runnerComponent) {
7052
this.title = title;
7153
this.project = project;
72-
this.consoleView = createConsoleView(project, this);
54+
this.consoleView = createConsoleView(project);
7355
this.runnerComponent = runnerComponent;
7456
}
7557

76-
private static ConsoleView createConsoleView(Project project, SbtConsole sbtConsole) {
77-
boolean useClassicConsole = "true".equalsIgnoreCase(System.getProperty("idea.sbt.plugin.classic"));
78-
if (useClassicConsole) {
79-
return createTextConsole(project);
80-
} else {
81-
return createLanguageConsole(project, sbtConsole);
82-
}
58+
private static ConsoleView createConsoleView(Project project) {
59+
// TODO can we figure out how to make this a LanguageConsole with IDEA 14.1+
60+
// We need that for console history
61+
ConsoleView consoleView = createTextConsole(project);
62+
addFilters(project, consoleView);
63+
return consoleView;
8364
}
8465

8566
private static ConsoleView createTextConsole(final Project project) {
@@ -94,150 +75,7 @@ private static ConsoleView createTextConsole(final Project project) {
9475
return builder.getConsole();
9576
}
9677

97-
private static ConsoleView createLanguageConsole(final Project project, final SbtConsole sbtConsole) {
98-
LightVirtualFile lightFile = new LightVirtualFile("SBT", SbtLanguage.INSTANCE, "");
99-
lightFile.setFileType(SbtFileType.INSTANCE);
100-
final LanguageConsoleImpl sbtLanguageConsole = new LanguageConsoleImpl(project, "SBT", lightFile, false);
101-
sbtLanguageConsole.setShowSeparatorLine(false);
102-
sbtLanguageConsole.initComponents();
103-
enableLinkedHorizontalScrollFromHistoryViewer(sbtLanguageConsole);
104-
105-
// important to only have one history controller, even if SBT is restarted.
106-
final ConsoleHistoryModel myConsoleHistoryModel = new ConsoleHistoryModel();
107-
final ConsoleHistoryController historyController = new ConsoleHistoryController("scala", null, sbtLanguageConsole, myConsoleHistoryModel);
108-
historyController.install();
109-
LanguageConsoleViewImpl consoleView = new LanguageConsoleViewImpl(sbtLanguageConsole) {
110-
@Override
111-
public void attachToProcess(ProcessHandler processHandler) {
112-
super.attachToProcess(processHandler);
113-
ConsoleExecuteActionHandler executeActionHandler = new ConsoleExecuteActionHandler(processHandler, false) {
114-
@Override
115-
public ConsoleHistoryModel getConsoleHistoryModel() {
116-
return myConsoleHistoryModel;
117-
}
118-
119-
public void runExecuteAction(LanguageConsoleImpl languageConsole) {
120-
EditorEx consoleEditor = languageConsole.getConsoleEditor();
121-
consoleEditor.setCaretEnabled(false);
122-
123-
super.runExecuteAction(languageConsole);
124-
125-
// hide the prompts until the command has completed.
126-
languageConsole.setPrompt(" ");
127-
consoleEditor.setCaretEnabled(true);
128-
}
129-
protected void execute(@NotNull String text, @NotNull LanguageConsoleView console) {
130-
EditorEx consoleEditor = console.getConsole().getConsoleEditor();
131-
consoleEditor.setCaretEnabled(false);
132-
super.execute(text, console);
133-
// hide the prompts until the command has completed.
134-
console.getConsole().setPrompt(" ");
135-
consoleEditor.setCaretEnabled(true);
136-
}
137-
138-
};
139-
// SBT echos the command, don't add it to the output a second time.
140-
executeActionHandler.setAddCurrentToHistory(true);
141-
try {
142-
java.util.List<Field> fields = ReflectionUtil.collectFields(executeActionHandler.getClass());
143-
for (Field field : fields) {
144-
if (field.getType() == ConsoleHistoryModel.class) {
145-
field.setAccessible(true);
146-
field.set(executeActionHandler, myConsoleHistoryModel);
147-
}
148-
}
149-
} catch (Exception err) {
150-
logger.warn("Unable to reflectively set field in " + executeActionHandler.getClass() + ", history in the SBT console may not work.", err);
151-
}
152-
AnAction action = new ConsoleExecuteAction(this, executeActionHandler);
153-
action.registerCustomShortcutSet(action.getShortcutSet(), sbtLanguageConsole.getComponent());
154-
}
155-
156-
@Override
157-
public boolean hasDeferredOutput() {
158-
return super.hasDeferredOutput();
159-
}
160-
};
161-
sbtLanguageConsole.setPrompt(" ");
162-
addFilters(project, consoleView);
163-
164-
return consoleView;
165-
}
166-
167-
private static void enableLinkedHorizontalScrollFromHistoryViewer(final LanguageConsoleImpl sbtLanguageConsole) {
168-
JBScrollBar horizontalScrollBar = new JBScrollBar(Adjustable.HORIZONTAL);
169-
horizontalScrollBar.setUI(new BasicScrollBarUI() {
170-
@Override
171-
public Dimension getPreferredSize(JComponent c) {
172-
return new Dimension(0, 0);
173-
}
174-
});
175-
sbtLanguageConsole.getHistoryViewer().getScrollPane().setHorizontalScrollBar(horizontalScrollBar);
176-
sbtLanguageConsole.getHistoryViewer().setHorizontalScrollbarVisible(true);
177-
178-
final VisibleAreaListener areaListener = new VisibleAreaListener() {
179-
public void visibleAreaChanged(VisibleAreaEvent e) {
180-
final int offset = sbtLanguageConsole.getHistoryViewer().getScrollingModel().getHorizontalScrollOffset();
181-
final ScrollingModel model = sbtLanguageConsole.getConsoleEditor().getScrollingModel();
182-
final int historyOffset = model.getHorizontalScrollOffset();
183-
if (historyOffset != offset) {
184-
try {
185-
model.disableAnimation();
186-
model.scrollHorizontally(offset);
187-
} finally {
188-
model.enableAnimation();
189-
}
190-
}
191-
}
192-
};
193-
sbtLanguageConsole.getHistoryViewer().getScrollingModel().addVisibleAreaListener(areaListener);
194-
}
195-
196-
public void enablePrompt() {
197-
if (consoleView instanceof LanguageConsoleViewImpl) {
198-
final LanguageConsoleViewImpl languageConsoleView = (LanguageConsoleViewImpl) consoleView;
199-
final LanguageConsoleImpl console = languageConsoleView.getConsole();
200-
201-
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
202-
public void run() {
203-
languageConsoleView.flushDeferredText();
204-
ApplicationManagerEx.getApplication().runWriteAction(new Runnable() {
205-
public void run() {
206-
Document document = console.getHistoryViewer().getDocument();
207-
EditorEx consoleEditor = console.getConsoleEditor();
208-
if (deleteTextFromEnd(document, "\n> ", "\n")) {
209-
console.setPrompt("> ");
210-
} else if (deleteTextFromEnd(document, "\nscala> ", "\n")) {
211-
console.setPrompt("scala> ");
212-
// not sure why this works, but it moves the caret to the end of the prompt.
213-
// without this, it apppears between the `c` and `a`.
214-
consoleEditor.getCaretModel().moveCaretRelatively(-1, 0, false, false, false);
215-
}
216-
consoleEditor.setCaretEnabled(true);
217-
}
218-
});
219-
}
220-
});
221-
}
222-
}
223-
224-
private static boolean deleteTextFromEnd(final Document document, String lastPrompt, final String replacement) {
225-
final int startOffset = document.getTextLength() - lastPrompt.length();
226-
if (startOffset > 0) {
227-
String text = document.getText(TextRange.create(startOffset, document.getTextLength()));
228-
if (text.equals(lastPrompt)) {
229-
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
230-
public void run() {
231-
document.replaceString(startOffset, document.getTextLength(), replacement);
232-
}
233-
});
234-
return true;
235-
}
236-
}
237-
return false;
238-
}
239-
240-
private static void addFilters(Project project, LanguageConsoleViewImpl consoleView) {
78+
private static void addFilters(Project project, ConsoleView consoleView) {
24179
consoleView.addMessageFilter(new ExceptionFilter(GlobalSearchScope.allScope(project)));
24280
consoleView.addMessageFilter(new RegexpFilter(project, CONSOLE_FILTER_REGEXP));
24381
consoleView.addMessageFilter(new SbtColorizerFilter());

sbt-plugin/src/main/java/net/orfjackal/sbt/plugin/SbtRunnerComponent.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public boolean executeAndWait(String action) throws IOException {
145145
boolean success;
146146
try {
147147
success = sbt.execute(action);
148-
this.getConsole().enablePrompt();
149148
// TODO: update target folders (?)
150149
// org.jetbrains.idea.maven.project.MavenProjectsManager#updateProjectFolders
151150
// org.jetbrains.idea.maven.execution.MavenRunner#runBatch
@@ -202,11 +201,6 @@ public void run() {
202201
} catch (Exception e) {
203202
// ignore
204203
}
205-
SwingUtilities.invokeLater(new Runnable() {
206-
public void run() {
207-
console.enablePrompt();
208-
}
209-
});
210204
}
211205
});
212206
}

sbt-plugin/src/main/java/net/orfjackal/sbt/plugin/SelectSbtActionDialog.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package net.orfjackal.sbt.plugin;
66

77
import com.intellij.openapi.project.Project;
8+
import com.intellij.openapi.ui.ComboBox;
89
import com.intellij.openapi.ui.DialogWrapper;
910
import net.miginfocom.swing.MigLayout;
1011

@@ -68,7 +69,7 @@ protected JComponent createCenterPanel() {
6869
JLabel runInCurrentModuleLabel = new JLabel(MessageBundle.message("sbt.tasks.select.action.run.current"));
6970
runInCurrentModuleLabel.setToolTipText(MessageBundle.message("sbt.tasks.select.action.run.current.tooltip"));
7071

71-
actionField = new JComboBox(SBT_ACTIONS_WITH_SEPARATOR);
72+
actionField = new ComboBox(SBT_ACTIONS_WITH_SEPARATOR);
7273
actionField.setEditable(true);
7374
actionField.setSelectedItem(selectedAction);
7475
actionField.setRenderer(new DefaultListCellRenderer() {

sbt-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<id>SBT</id>
55
<name>SBT</name>
66
<version>${project.version}</version>
7-
<idea-version since-build="135.475"/>
7+
<idea-version since-build="141.177"/>
88
<category>Build</category>
99

1010
<vendor url="http://www.orfjackal.net">Esko Luontola</vendor>
@@ -22,6 +22,13 @@
2222
]]></description>
2323
<change-notes><![CDATA[
2424
<ul>
25+
<dt><b>1.7.0 (2014-03-26)</b></dt>
26+
<li>Be compatible with / require IntelliJ 14.1</li>
27+
<li>Revert UI to a TextConsole rather than a LanguageConsole. We lose command history. Hopefully we can find a way to restore this feature in a subsequent release once we adapt to changes in IntelliJ</li>
28+
29+
<dt><b>1.6.0 (2014-05-17)</b></dt>
30+
<li>Require IntelliJ IDEA 13.1 (Cardea)</li>
31+
2532
<dt><b>1.6.1 (2014-05-17)</b></dt>
2633
<li>Relax version requirement to admit IDEA 13.1.0 (Cardea)</li>
2734
<dt><b>1.6.0 (2014-05-17)</b></dt>

0 commit comments

Comments
 (0)