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:
@@ -28,6 +28,7 @@ import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
@@ -37,7 +38,11 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Set;
|
||||
@@ -77,6 +82,29 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
oldPopup.close(false);
|
||||
}
|
||||
final ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {
|
||||
@Override
|
||||
protected void initUI(Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
|
||||
super.initUI(callback, modalityState, allowMultipleSelection);
|
||||
myList.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
Object value = myList.getSelectedValue();
|
||||
myDropdownPopup.setAdText(getText(value), SwingConstants.LEFT);
|
||||
}
|
||||
|
||||
private String getText(Object o) {
|
||||
if (o instanceof GotoActionModel.MatchedValue) {
|
||||
GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue)o;
|
||||
if (mv.value instanceof BooleanOptionDescription ||
|
||||
mv.value instanceof GotoActionModel.ActionWrapper && ((GotoActionModel.ActionWrapper)mv.value).getAction() instanceof ToggleAction) {
|
||||
return "Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)) + " to toggle option";
|
||||
}
|
||||
}
|
||||
return getAdText();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Set<Object> filter(@NotNull Set<Object> elements) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.ui.UIBundle;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -88,9 +89,7 @@ public class ComponentWithBrowseButton<Comp extends JComponent> extends JPanel i
|
||||
|
||||
public void setTextFieldPreferredWidth(final int charCount) {
|
||||
final Comp comp = getChildComponent();
|
||||
Dimension size = comp.getPreferredSize();
|
||||
FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
|
||||
size.width = fontMetrics.charWidth('a') * charCount;
|
||||
Dimension size = GuiUtils.getSizeByChars(charCount, comp);
|
||||
comp.setPreferredSize(size);
|
||||
final Dimension preferredSize = myBrowseButton.getPreferredSize();
|
||||
setPreferredSize(new Dimension(size.width + preferredSize.width + 2, UIUtil.isUnderAquaLookAndFeel() ? preferredSize.height : preferredSize.height + 2));
|
||||
|
||||
@@ -390,4 +390,18 @@ public class GuiUtils {
|
||||
public static JTextField createUndoableTextField() {
|
||||
return new JBTextField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns dimension with width required to type certain number of chars in provided component
|
||||
* @param charCount number of chars
|
||||
* @param comp component
|
||||
* @return dimension with width enough to insert provided number of chars into component
|
||||
*/
|
||||
@NotNull
|
||||
public static Dimension getSizeByChars(int charCount, @NotNull JComponent comp) {
|
||||
Dimension size = comp.getPreferredSize();
|
||||
FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
|
||||
size.width = fontMetrics.charWidth('a') * charCount;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ public interface ScriptManager {
|
||||
@Nullable
|
||||
Script findScriptByUrl(@NotNull String rawUrl);
|
||||
|
||||
@Nullable
|
||||
Script findScriptById(@NotNull String id);
|
||||
|
||||
@Nullable
|
||||
ActionCallback getScriptSourceMapLoadCallback(@NotNull Script script);
|
||||
}
|
||||
@@ -56,4 +56,10 @@ public abstract class ScriptManagerBase<SCRIPT extends ScriptBase> implements Sc
|
||||
public static boolean isSpecial(@NotNull Url url) {
|
||||
return !url.isInLocalFileSystem() && (url.getScheme() == null || url.getScheme().equals(ScriptManager.VM_SCHEME) || url.getAuthority() == null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Script findScriptById(@NotNull String id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+8
-12
@@ -26,7 +26,6 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
|
||||
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarProcessor;
|
||||
import org.jetbrains.java.decompiler.struct.gen.VarType;
|
||||
import org.jetbrains.java.decompiler.util.InterpreterUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -113,9 +112,6 @@ public class CatchAllStatement extends Statement {
|
||||
}
|
||||
|
||||
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
|
||||
String indstr = InterpreterUtil.getIndentString(indent);
|
||||
String indstr1 = null;
|
||||
|
||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||
|
||||
TextBuffer buf = new TextBuffer();
|
||||
@@ -124,7 +120,7 @@ public class CatchAllStatement extends Statement {
|
||||
|
||||
boolean labeled = isLabeled();
|
||||
if (labeled) {
|
||||
buf.append(indstr).append("label").append(this.id.toString()).append(":").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
@@ -133,33 +129,33 @@ public class CatchAllStatement extends Statement {
|
||||
!labeled && !first.isLabeled() && (lstSuccs.isEmpty() || !lstSuccs.get(0).explicit)) {
|
||||
TextBuffer content = ExprProcessor.jmpWrapper(first, indent, true, tracer);
|
||||
content.setLength(content.length() - new_line_separator.length());
|
||||
tracer.incrementCurrentSourceLine(-1);
|
||||
buf.append(content);
|
||||
}
|
||||
else {
|
||||
buf.append(indstr).append("try {").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("try {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true, tracer));
|
||||
buf.append(indstr).append("}");
|
||||
buf.appendIndent(indent).append("}");
|
||||
}
|
||||
|
||||
buf.append(isFinally ? " finally" :
|
||||
" catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").append(new_line_separator);
|
||||
" catch (" + vars.get(0).toJava(indent, tracer) + ")").append(" {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
|
||||
if (monitor != null) {
|
||||
indstr1 = InterpreterUtil.getIndentString(indent + 1);
|
||||
buf.append(indstr1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").append(new_line_separator);
|
||||
buf.appendIndent(indent+1).append("if(").append(monitor.toJava(indent, tracer)).append(") {").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true, tracer));
|
||||
|
||||
if (monitor != null) {
|
||||
buf.append(indstr1).append("}").append(new_line_separator);
|
||||
buf.appendIndent(indent + 1).append("}").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
}
|
||||
|
||||
buf.append(indstr).append("}").append(new_line_separator);
|
||||
buf.appendIndent(indent).append("}").appendLineSeparator();
|
||||
tracer.incrementCurrentSourceLine();
|
||||
|
||||
return buf;
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
+14
-12
@@ -21,8 +21,10 @@ public class TestClassSimpleBytecodeMapping {
|
||||
public void test2(String var1) {
|
||||
try {
|
||||
Integer.parseInt(var1);
|
||||
} catch (Exception var3) {
|
||||
System.out.println(var3);
|
||||
} catch (Exception var6) {
|
||||
System.out.println(var6);
|
||||
} finally {
|
||||
System.out.println("Finally");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,23 +83,23 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
|
||||
}
|
||||
|
||||
method 'run (Ljava/lang/Runnable;)V' {
|
||||
1 30
|
||||
1 32
|
||||
}
|
||||
}
|
||||
|
||||
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass2' {
|
||||
method 'print ()V' {
|
||||
0 35
|
||||
3 35
|
||||
5 35
|
||||
0 37
|
||||
3 37
|
||||
5 37
|
||||
}
|
||||
}
|
||||
|
||||
class 'pkg/TestClassSimpleBytecodeMapping$InnerClass' {
|
||||
method 'print ()V' {
|
||||
0 41
|
||||
3 41
|
||||
5 41
|
||||
0 43
|
||||
3 43
|
||||
5 43
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +114,6 @@ Lines mapping:
|
||||
27 <-> 16
|
||||
28 <-> 17
|
||||
34 <-> 23
|
||||
42 <-> 42
|
||||
47 <-> 31
|
||||
52 <-> 36
|
||||
44 <-> 44
|
||||
49 <-> 33
|
||||
54 <-> 38
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
package pkg;
|
||||
|
||||
public class TestTryCatchFinally {
|
||||
public void test1(String var1) {
|
||||
try {
|
||||
System.out.println("sout1");
|
||||
} catch (Exception var9) {
|
||||
try {
|
||||
System.out.println("sout2");
|
||||
} catch (Exception var8) {
|
||||
;
|
||||
}
|
||||
} finally {
|
||||
System.out.println("finally");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int test(String var1) {
|
||||
try {
|
||||
int var2 = Integer.parseInt(var1);
|
||||
|
||||
@@ -34,6 +34,8 @@ public class TestClassSimpleBytecodeMapping {
|
||||
Integer.parseInt(a);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
} finally {
|
||||
System.out.println("Finally");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,22 @@
|
||||
package pkg;
|
||||
|
||||
public class TestTryCatchFinally {
|
||||
public void test1(String x) {
|
||||
try {
|
||||
System.out.println("sout1");
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
System.out.println("sout2");
|
||||
} catch (Exception e2) {
|
||||
// Empty
|
||||
// Empty
|
||||
// Empty
|
||||
}
|
||||
} finally {
|
||||
System.out.println("finally");
|
||||
}
|
||||
}
|
||||
|
||||
public int test(String a) {
|
||||
try {
|
||||
return Integer.parseInt(a);
|
||||
|
||||
@@ -12,6 +12,6 @@ def test_task_windows():
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_common_tests()
|
||||
test_task_windows()
|
||||
# test_task_windows()
|
||||
|
||||
|
||||
|
||||
+6
@@ -12,9 +12,11 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
@@ -68,6 +70,10 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
|
||||
for (VirtualFile virtualFile : fileEditorManager.getOpenFiles()) {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
EditorHelper.openInEditor(testsFile, false);
|
||||
EditorHelper.openInEditor(taskPyFile, false);
|
||||
view.selectElement(taskFile);
|
||||
|
||||
+41
-30
@@ -21,12 +21,15 @@ import com.jetbrains.python.edu.course.TaskWindow;
|
||||
import com.jetbrains.python.edu.editor.StudyEditor;
|
||||
import icons.StudyIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StudyShowHintAction extends DumbAwareAction {
|
||||
public static final String ACTION_ID = "ShowHintAction";
|
||||
public static final String SHORTCUT = "ctrl pressed 7";
|
||||
public static final String OUTSIDE_TASK_WINDOW_MESSAGE = "Put caret to task window to get hint for it.";
|
||||
public static final String HINT_NOT_AVAILABLE = "There is no hint for this task window";
|
||||
|
||||
public StudyShowHintAction() {
|
||||
super("Show hint", "Show hint", StudyIcons.ShowHint);
|
||||
@@ -53,41 +56,49 @@ public class StudyShowHintAction extends DumbAwareAction {
|
||||
final Editor editor = studyState.getEditor();
|
||||
LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
|
||||
TaskWindow taskWindow = studyState.getTaskFile().getTaskWindow(editor.getDocument(), pos);
|
||||
if (file == null || taskWindow == null) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
String hint = taskWindow.getHint();
|
||||
if (hint == null) {
|
||||
return;
|
||||
String hintText = OUTSIDE_TASK_WINDOW_MESSAGE;
|
||||
if (taskWindow != null) {
|
||||
hintText = getHintText(taskWindow, course);
|
||||
}
|
||||
File resourceFile = new File(course.getResourcePath());
|
||||
File resourceRoot = resourceFile.getParentFile();
|
||||
if (resourceRoot == null || !resourceRoot.exists()) {
|
||||
return;
|
||||
}
|
||||
File hintsDir = new File(resourceRoot, Course.HINTS_DIR);
|
||||
if (hintsDir.exists()) {
|
||||
String hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hint, true);
|
||||
int offset = editor.getDocument().getLineStartOffset(pos.line) + pos.column;
|
||||
PsiElement element = file.findElementAt(offset);
|
||||
if (hintText == null || element == null) {
|
||||
return;
|
||||
}
|
||||
int offset = editor.getDocument().getLineStartOffset(pos.line) + pos.column;
|
||||
PsiElement element = file.findElementAt(offset);
|
||||
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
|
||||
DocumentationComponent component = new DocumentationComponent(documentationManager);
|
||||
component.setData(element != null ? element : file, element != null ? hintText : OUTSIDE_TASK_WINDOW_MESSAGE, true, null);
|
||||
showHintPopUp(project, editor, component);
|
||||
}
|
||||
|
||||
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
|
||||
DocumentationComponent component = new DocumentationComponent(documentationManager);
|
||||
component.setData(element, hintText, true, null);
|
||||
final JBPopup popup =
|
||||
JBPopupFactory.getInstance().createComponentPopupBuilder(component, component)
|
||||
.setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false)
|
||||
.setResizable(true)
|
||||
.setMovable(true)
|
||||
.setRequestFocus(true)
|
||||
.createPopup();
|
||||
component.setHint(popup);
|
||||
popup.showInBestPositionFor(editor);
|
||||
Disposer.dispose(component);
|
||||
@Nullable
|
||||
private static String getHintText(@NotNull final TaskWindow taskWindow, @NotNull final Course course) {
|
||||
String hintFileName = taskWindow.getHint();
|
||||
String hintText = HINT_NOT_AVAILABLE;
|
||||
if (hintFileName != null && !hintFileName.isEmpty()) {
|
||||
File resourceFile = new File(course.getResourcePath());
|
||||
File resourceRoot = resourceFile.getParentFile();
|
||||
if (resourceRoot != null && resourceRoot.exists()) {
|
||||
File hintsDir = new File(resourceRoot, Course.HINTS_DIR);
|
||||
if (hintsDir.exists()) {
|
||||
hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hintFileName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hintText != null ? hintText : OUTSIDE_TASK_WINDOW_MESSAGE;
|
||||
}
|
||||
|
||||
private static void showHintPopUp(Project project, Editor editor, DocumentationComponent component) {
|
||||
final JBPopup popup =
|
||||
JBPopupFactory.getInstance().createComponentPopupBuilder(component, component)
|
||||
.setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false)
|
||||
.setResizable(true)
|
||||
.setMovable(true)
|
||||
.setRequestFocus(true)
|
||||
.createPopup();
|
||||
component.setHint(popup);
|
||||
popup.showInBestPositionFor(editor);
|
||||
Disposer.dispose(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user