Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Alexander Kirillin
2010-12-21 16:08:16 +03:00
12 changed files with 206 additions and 73 deletions
@@ -77,7 +77,7 @@ public class CreateClassDialog extends DialogWrapper {
init();
if (!myClassNameEditable) {
setTitle(CodeInsightBundle.message("dialog.create.class.name", kind.getDescription(), targetClassName));
setTitle(CodeInsightBundle.message("dialog.create.class.name", StringUtil.capitalize(kind.getDescription()), targetClassName));
}
else {
myInformationLabel.setText(CodeInsightBundle.message("dialog.create.class.label", kind.getDescription()));
@@ -192,7 +192,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
this.endOffset = endOffset;
attributes = contentType.getAttributes();
}
public int getLength() {
return endOffset - startOffset;
}
@@ -256,7 +256,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
* Target offsets are anchored to the {@link #myDeferredOutput deferred buffer}.
*/
private final List<TokenInfo> myDeferredTokens = new ArrayList<TokenInfo>();
private final Hyperlinks myHyperlinks = new Hyperlinks();
private final TIntObjectHashMap<ConsoleFolding> myFolding = new TIntObjectHashMap<ConsoleFolding>();
@@ -529,13 +529,13 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
/**
* IJ console works as follows - it receives managed process outputs from dedicated thread that serves that process and
* pushes it to the {@link Document document} of editor used to represent process console. Important point here is that process
* output is received in a control flow of the thread over than EDT but push to the document is performed from EDT. Hence, we
* output is received in a control flow of the thread over than EDT but push to the document is performed from EDT. Hence, we
* have a potential situation when particular process outputs a lot and EDT is busy or push to the document is performed slowly.
* <p/>
* We don't want to keep too many information from the underlying process then and want to trim text buffer that holds text
* to push to the document then. Current method serves exactly that purpose, i.e. it's expected to be called when new chunk of
* text is received from the underlying process and trims existing text buffer if necessary.
*
*
* @param numberOfNewSymbols number of symbols read from the managed process output
* @return number of newly read symbols that should be accepted
*/
@@ -543,15 +543,15 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
if (!USE_CYCLIC_BUFFER || myDeferredOutput.length() <= 0 || myDeferredOutput.length() + numberOfNewSymbols <= CYCLIC_BUFFER_SIZE) {
return numberOfNewSymbols;
}
final int numberOfSymbolsToRemove = myDeferredOutput.length() + numberOfNewSymbols - CYCLIC_BUFFER_SIZE;
myDeferredTypes.clear();
int removedSymbolsNumber = 0;
int endIndex = -1;
for (int i = 0; i < myDeferredTokens.size(); i++) {
TokenInfo tokenInfo = myDeferredTokens.get(i);
if (removedSymbolsNumber < numberOfSymbolsToRemove) {
int tokenLength = tokenInfo.getLength();
@@ -562,7 +562,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
removedSymbolsNumber += tokenLength;
continue;
}
int remainingNumberOfSymbolsToRemove = numberOfSymbolsToRemove - removedSymbolsNumber;
if (remainingNumberOfSymbolsToRemove >= tokenLength) {
// We assume here that token construction is smart enough to extend end index in case of subsequent tokens of the same type,
@@ -581,11 +581,11 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
removedSymbolsNumber = numberOfSymbolsToRemove;
}
}
if (removedSymbolsNumber < numberOfSymbolsToRemove) {
continue;
}
if (endIndex < 0) {
endIndex = i;
}
@@ -594,7 +594,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
tokenInfo.endOffset -= numberOfSymbolsToRemove;
myDeferredTypes.add(tokenInfo.contentType);
}
if (endIndex < 0) {
myDeferredTokens.clear();
}
@@ -622,7 +622,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
return numberOfNewSymbols;
}
protected void beforeExternalAddContentToDocument(int length, ConsoleViewContentType contentType) {
myContentSize+=length;
addToken(length, null, contentType);
@@ -1698,11 +1698,11 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
if (state && placeholder == null) {
return;
}
final FoldingModel foldingModel = myEditor.getFoldingModel();
FoldRegion[] foldRegions = foldingModel.getAllFoldRegions();
Runnable foldTask = null;
final int endFoldRegionOffset = myEditor.getDocument().getLineEndOffset(0);
Runnable addCollapsedFoldRegionTask = new Runnable() {
@Override
@@ -1733,7 +1733,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
foldTask = addCollapsedFoldRegionTask;
}
}
if (foldTask != null) {
foldingModel.runBatchFoldingOperation(foldTask);
}
@@ -1957,6 +1957,10 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
return endOffset;
}
public boolean isRunning() {
return myState.isRunning();
}
/**
* Command line used to launch application/test from idea is quite a big most of the time (it's likely that classpath definition
* takes a lot of space). Hence, it takes many visual lines during representation if soft wraps are enabled.
@@ -92,6 +92,14 @@ public class FacetPointersManagerImpl extends FacetPointersManager implements Pr
public void initComponent() {
final FacetManagerListener facetListener = new FacetManagerAdapter() {
@Override
public void beforeFacetRenamed(@NotNull Facet facet) {
final FacetPointerImpl pointer = myPointers.get(constructId(facet));
if (pointer != null) {
pointer.refresh();
}
}
public void facetRenamed(@NotNull final Facet facet, @NotNull final String oldName) {
refreshPointers(facet.getModule());
}
@@ -20,6 +20,8 @@ import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NonNls;
public abstract class PropertiesComponent {
public abstract void unsetValue(String name);
public static PropertiesComponent getInstance(Project project) {
return project.getComponent(PropertiesComponent.class);
}
@@ -110,6 +110,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
"ModuleName",
"ModuleSourcePath",
"OutputPath",
"PhpExecutable",
"ProjectFileDir",
"ProjectFilePath",
"ProjectName",
@@ -22,8 +22,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class PropertiesComponentImpl extends PropertiesComponent
implements PersistentStateComponent<Element> {
public class PropertiesComponentImpl extends PropertiesComponent implements PersistentStateComponent<Element> {
private final HashMap<String, String> myMap = new HashMap<String, String>();
@NonNls private static final String ELEMENT_PROPERTY = "property";
@NonNls private static final String ATTRIBUTE_NAME = "name";
@@ -76,6 +75,11 @@ public class PropertiesComponentImpl extends PropertiesComponent
myMap.put(name, value);
}
@Override
public void unsetValue(String name) {
myMap.remove(name);
}
public boolean isValueSet(String name) {
return myMap.containsKey(name);
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
/**
* @author oleg
@@ -28,7 +29,7 @@ import com.intellij.openapi.util.IconLoader;
public class ScrollToTheEndToolbarAction extends AnAction {
private final Editor myEditor;
public ScrollToTheEndToolbarAction(Editor editor) {
public ScrollToTheEndToolbarAction(@NotNull final Editor editor) {
super();
myEditor = editor;
final String message = ActionsBundle.message("action.EditorConsoleScrollToTheEnd.text");
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.util.ui.ValidatingTableEditor">
<grid id="27dc6" binding="myContentPane" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myContentPane" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -8,9 +8,9 @@
<properties/>
<border type="none"/>
<children>
<scrollpane class="com.intellij.ui.components.JBScrollPane" id="11f79">
<scrollpane id="11f79" class="com.intellij.ui.components.JBScrollPane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="4" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -39,13 +39,13 @@
</component>
<hspacer id="ef5dc">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="a830f" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -73,6 +73,14 @@
</component>
</children>
</grid>
<component id="fab81" class="javax.swing.JButton" binding="myExtraButton">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</form>
@@ -91,6 +91,11 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
public Class getColumnClass() {
return myDelegate.getColumnClass();
}
@Override
public TableCellRenderer getRenderer(Item item) {
return myDelegate.getRenderer(item);
}
}
private JPanel myContentPane;
@@ -99,6 +104,7 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
private JButton myRemoveButton;
private JLabel myMessageLabel;
private HoverHyperlinkLabel myFixLink;
private JButton myExtraButton;
private final List<String> myWarnings = new ArrayList<String>();
private Fix myFixRunnable;
@@ -211,6 +217,19 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
removeSelected();
}
});
myExtraButton.setVisible(false);
}
protected ValidatingTableEditor(final ActionListener actionListener, String buttonText) {
this();
myExtraButton.setVisible(true);
myExtraButton.setText(buttonText);
myExtraButton.addActionListener(actionListener);
}
public List<Item> getSelectedItems() {
return myTable.getSelectedObjects();
}
private void removeSelected() {
@@ -379,5 +398,4 @@ public abstract class ValidatingTableEditor<Item> implements ComponentWithEmptyT
header.setReorderingAllowed(value);
}
}
}
@@ -34,13 +34,12 @@ import java.awt.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
/**
* @author Irina Chernushina
* @author Konstantin Bulenkov
*/
class AnnotationFieldGutter implements ActiveAnnotationGutter {
public class AnnotationFieldGutter implements ActiveAnnotationGutter {
protected final FileAnnotation myAnnotation;
private final Editor myEditor;
protected final LineAnnotationAspect myAspect;
@@ -75,57 +74,39 @@ class AnnotationFieldGutter implements ActiveAnnotationGutter {
public String getLineText(int line, Editor editor) {
final String value = isAvailable() ? myAspect.getValue(line) : "";
if (myAspect.getId() == LineAnnotationAspect.AUTHOR && ShowShortenNames.isSet()) {
return shorten(value);
return shorten(value, ShowShortenNames.getType());
}
return value;
}
@Nullable
private static String shorten(String value) {
if (value != null) {
// Vasya Pupkin <vasya.pupkin@jetbrains.com>
final int[] ind = {value.indexOf('<'), value.indexOf('@'), value.indexOf('>')};
public static String shorten(String name, ShortNameType type) {
if (name != null) {
// Vasya Pupkin <vasya.pupkin@jetbrains.com> -> Vasya Pupkin
final int[] ind = {name.indexOf('<'), name.indexOf('@'), name.indexOf('>')};
if (0 < ind[0] && ind[0] < ind[1] && ind[1] < ind[2]) {
return shorten(value.substring(0, ind[0]).trim());
return shorten(name.substring(0, ind[0]).trim(), type);
}
// vasya.pupkin@email.com --> vasya pupkin
if (isEmail(value)) {
final String firstPart = value.substring(0, value.indexOf('@')).replace('.', ' ').replace('_', ' ').replace('-', ' ');
if (firstPart.length() < value.length()) {
return shorten(firstPart);
if (!name.contains(" ") && name.contains("@")) { //simple e-mail check. john@localhost
final String firstPart = name.substring(0, name.indexOf('@')).replace('.', ' ').replace('_', ' ').replace('-', ' ');
if (firstPart.length() < name.length()) {
return shorten(firstPart, type);
} else {
return firstPart;
}
}
final List<String> strings = StringUtil.split(value, " ");
final List<String> strings = StringUtil.split(name.replace('.', ' ').replace('_', ' ').replace('-', ' '), " ");
if (strings.size() > 1) {
//Middle name check: Vasya S. Pupkin
return strings.get(1).length() < 3 && strings.size() > 2 && strings.get(2).length() > 1 ? strings.get(2) : strings.get(1);
}
if (value.contains(".")) {
strings.clear();
strings.addAll(StringUtil.split(value, "."));
// vasya.pupkin case
if (strings.size() > 1) {
//Middle name check: Vasya.S.Pupkin
return strings.get(1).length() == 1 && strings.size() > 2 && strings.get(2).length() > 1 ? strings.get(2) : strings.get(1);
}
return StringUtil.capitalize(type == ShortNameType.FIRSTNAME ? strings.get(0) : strings.get(strings.size() - 1));
}
}
return value;
return name;
}
private static final Pattern EMAIL = Pattern.compile("^[\\w\\.-]+@([\\w\\-]+\\.)+[a-z]{2,15}$");
public static boolean isEmail(String s) {
if (!StringUtil.isEmpty(s)) {
return EMAIL.matcher(s).matches();
}
return false;
}
@Nullable
public String getToolTip(final int line, final Editor editor) {
return isAvailable() ?
@@ -211,4 +192,14 @@ class AnnotationFieldGutter implements ActiveAnnotationGutter {
public String getID() {
return myAspect == null ? null : myAspect.getId();
}
public static void main(String[] args) {
assert shorten("Vasya Pavlovich Pupkin <asdasd@localhost>", ShortNameType.FIRSTNAME).equals("Vasya");
assert shorten("Vasya Pavlovich Pupkin <asdasd@localhost>", ShortNameType.LASTNAME).equals("Pupkin");
assert shorten("Vasya Pavlovich Pupkin", ShortNameType.FIRSTNAME).equals("Vasya");
assert shorten("Vasya Pavlovich Pupkin", ShortNameType.LASTNAME).equals("Pupkin");
assert shorten("vasya.pupkin@localhost.com", ShortNameType.LASTNAME).equals("Pupkin");
assert shorten("vasya.pupkin@localhost.com", ShortNameType.FIRSTNAME).equals("Vasya");
}
}
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.actions;
import com.intellij.ide.util.PropertiesComponent;
/**
* @author Konstantin Bulenkov
*/
public enum ShortNameType {
LASTNAME("lastname", "Last Name"),
FIRSTNAME("firstname", "First Name"),
NONE("full", "Full name");
private static final String KEY = "annotate.short.names.type";
private final String myId;
private final String myDescription;
ShortNameType(String id, String description) {
myId = id;
myDescription = description;
}
public String getDescription() {
return myDescription;
}
boolean isSet() {
return myId.equals(PropertiesComponent.getInstance().getValue(KEY));
}
void set(boolean enable) {
if (enable) {
PropertiesComponent.getInstance().setValue(KEY, myId);
} else {
PropertiesComponent.getInstance().unsetValue(KEY);
}
}
}
@@ -16,34 +16,78 @@
package com.intellij.openapi.vcs.actions;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.editor.ex.EditorGutterComponentEx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
/**
* @author Konstantin Bulenkov
*/
public class ShowShortenNames extends ToggleAction {
public class ShowShortenNames extends ActionGroup {
public static final String KEY = "annotate.show.short.names";
private final EditorGutterComponentEx myGutter;
public ShowShortenNames(EditorGutterComponentEx gutter) {
super("Short names");
myGutter = gutter;
private final AnAction[] myChildren;
public ShowShortenNames(final EditorGutterComponentEx gutter) {
super("Names", true);
final ArrayList<AnAction> kids = new ArrayList<AnAction>(ShortNameType.values().length);
for (ShortNameType type : ShortNameType.values()) {
kids.add(new SetShortNameTypeAction(type, gutter));
}
myChildren = kids.toArray(new AnAction[kids.size()]);
}
@NotNull
@Override
public boolean isSelected(AnActionEvent e) {
return isSet();
}
@Override
public void setSelected(AnActionEvent e, boolean state) {
PropertiesComponent.getInstance().setValue(KEY, String.valueOf(state));
myGutter.revalidateMarkup();
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return myChildren;
}
public static boolean isSet() {
return PropertiesComponent.getInstance().getBoolean(KEY, true);
return getType() != ShortNameType.NONE;
}
public static ShortNameType getType() {
for (ShortNameType type : ShortNameType.values()) {
if (type.isSet()) {
return type;
}
}
return ShortNameType.LASTNAME;
}
public static class SetShortNameTypeAction extends ToggleAction {
private final ShortNameType myType;
private final EditorGutterComponentEx myGutter;
public SetShortNameTypeAction(ShortNameType type, EditorGutterComponentEx gutter) {
super(type.getDescription());
myType = type;
myGutter = gutter;
}
@Override
public boolean isSelected(AnActionEvent e) {
return myType == getType();
}
@Override
public void setSelected(AnActionEvent e, boolean enabled) {
PropertiesComponent.getInstance().unsetValue(KEY);
if (enabled) {
myType.set(enabled);
} else {
if (myType == ShortNameType.NONE) {
ShortNameType.LASTNAME.set(true);
} else {
ShortNameType.NONE.set(true);
}
}
myGutter.revalidateMarkup();
}
}
}