VCS: quick search for shelf

This commit is contained in:
irengrig
2010-02-03 20:23:04 +03:00
parent c719947294
commit 347b9a770e
2 changed files with 29 additions and 0 deletions
@@ -65,6 +65,14 @@ public class ShelvedChange {
return myAfterPath;
}
@Nullable
public String getAfterFileName() {
if (myAfterPath == null) return null;
int pos = myAfterPath.lastIndexOf('/');
if (pos >= 0) return myAfterPath.substring(pos+1);
return myAfterPath;
}
public String getBeforeFileName() {
int pos = myBeforePath.lastIndexOf('/');
if (pos >= 0) return myBeforePath.substring(pos+1);
@@ -47,9 +47,11 @@ import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.TreeSpeedSearch;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.containers.Convertor;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.annotations.NonNls;
@@ -126,6 +128,25 @@ public class ShelvedChangesViewManager implements ProjectComponent {
DiffShelvedChangesAction.showShelvedChangesDiff(DataManager.getInstance().getDataContext(myTree));
}
});
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
public String convert(TreePath o) {
final Object lc = o.getLastPathComponent();
final Object lastComponent = lc == null ? null : ((DefaultMutableTreeNode) lc).getUserObject();
if (lastComponent instanceof ShelvedChangeList) {
return ((ShelvedChangeList) lastComponent).DESCRIPTION;
} else if (lastComponent instanceof ShelvedChange) {
final ShelvedChange shelvedChange = (ShelvedChange)lastComponent;
return shelvedChange.getBeforeFileName() == null ? shelvedChange.getAfterFileName() : shelvedChange.getBeforeFileName();
} else if (lastComponent instanceof ShelvedBinaryFile) {
final ShelvedBinaryFile sbf = (ShelvedBinaryFile) lastComponent;
final String value = sbf.BEFORE_PATH == null ? sbf.AFTER_PATH : sbf.BEFORE_PATH;
int idx = value.lastIndexOf("/");
idx = (idx == -1) ? value.lastIndexOf("\\") : idx;
return idx > 0 ? value.substring(idx + 1) : value;
}
return null;
}
}, true);
}
public void projectOpened() {