mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add operations
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 481 B |
Binary file not shown.
|
After Width: | Height: | Size: 513 B |
Binary file not shown.
|
After Width: | Height: | Size: 422 B |
Binary file not shown.
|
After Width: | Height: | Size: 674 B |
@@ -19,6 +19,12 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import static com.intellij.openapi.diff.impl.dir.DirDiffOperation.*;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
@@ -29,6 +35,7 @@ public class DirDiffElement {
|
||||
private final VirtualFile myTarget;
|
||||
private final long myTargetLength;
|
||||
private final String myName;
|
||||
private DirDiffOperation myOperation;
|
||||
|
||||
private DirDiffElement(@Nullable VirtualFile source, @Nullable VirtualFile target, ElementType type, String name) {
|
||||
myType = type;
|
||||
@@ -37,14 +44,28 @@ public class DirDiffElement {
|
||||
myTarget = target;
|
||||
myTargetLength = target == null || target.isDirectory() ? -1 : target.getLength();
|
||||
myName = name;
|
||||
if (isSource()) {
|
||||
myOperation = COPY_TO;
|
||||
}
|
||||
else if (isTarget()) {
|
||||
myOperation = DirDiffOperation.COPY_FROM;
|
||||
}
|
||||
else if (type == ElementType.CHANGED) {
|
||||
assert source != null;
|
||||
myOperation = source.getFileType().isBinary() ? NONE : DirDiffOperation.MERGE;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSourceModificationDate() {
|
||||
return null;
|
||||
return mySource == null ? "" : getLastModification(mySource);
|
||||
}
|
||||
|
||||
public String getTargetModificationDate() {
|
||||
return null;
|
||||
return myTarget == null ? "" : getLastModification(myTarget);
|
||||
}
|
||||
|
||||
private static String getLastModification(VirtualFile file) {
|
||||
return SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(file.getTimeStamp()));
|
||||
}
|
||||
|
||||
public static DirDiffElement createChange(@NotNull VirtualFile source, @NotNull VirtualFile target) {
|
||||
@@ -105,5 +126,28 @@ public class DirDiffElement {
|
||||
return myType == ElementType.SEPARATOR;
|
||||
}
|
||||
|
||||
public boolean isSource() {
|
||||
return myType == ElementType.SOURCE;
|
||||
}
|
||||
|
||||
public boolean isTarget() {
|
||||
return myType == ElementType.TARGET;
|
||||
}
|
||||
|
||||
public DirDiffOperation getOperation() {
|
||||
return myOperation;
|
||||
}
|
||||
|
||||
public void setNextOperation() {
|
||||
final DirDiffOperation o = myOperation;
|
||||
if (isSource()) {
|
||||
myOperation = o == COPY_TO ? REMOVE : o == REMOVE ? NONE : COPY_TO;
|
||||
} else if (isTarget()) {
|
||||
myOperation = o == COPY_FROM ? REMOVE : o == REMOVE ? NONE : COPY_FROM;
|
||||
} else {
|
||||
myOperation = o == MERGE ? COPY_TO : o == COPY_TO ? COPY_FROM : o == COPY_FROM ? NONE : MERGE;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ElementType {SOURCE, TARGET, SEPARATOR, CHANGED}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.diff.impl.dir;
|
||||
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public enum DirDiffOperation {
|
||||
COPY_TO, COPY_FROM, REMOVE, MERGE, NONE;
|
||||
|
||||
public Icon getIcon() {
|
||||
switch (this) {
|
||||
case COPY_TO: return IconLoader.getIcon("/vcs/arrow_right.png");
|
||||
case COPY_FROM: return IconLoader.getIcon("/vcs/arrow_left.png");
|
||||
case REMOVE: return IconLoader.getIcon("/vcs/remove.png");
|
||||
case MERGE: return IconLoader.getIcon("/vcs/merge.png");
|
||||
case NONE: return EmptyIcon.create(12);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.diff.impl.dir.DirDiffPanel">
|
||||
<grid id="27dc6" binding="myComponent" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<grid id="27dc6" binding="myComponent" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="876" height="554"/>
|
||||
</constraints>
|
||||
@@ -9,11 +8,7 @@
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<splitpane id="2c9d2" binding="mySplitPanel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="200" height="200"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties>
|
||||
<orientation value="0"/>
|
||||
</properties>
|
||||
@@ -51,6 +46,48 @@
|
||||
</scrollpane>
|
||||
</children>
|
||||
</splitpane>
|
||||
<grid id="bc3dc" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints border-constraint="North"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="d29c8" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="fd341" class="com.intellij.ui.components.JBLabel" binding="mySourceDirLabel">
|
||||
<constraints border-constraint="West"/>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="ee75f" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="mySourceDirField">
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="23086" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="cba0d" class="com.intellij.ui.components.JBLabel" binding="myTargetDirLabel">
|
||||
<constraints border-constraint="West"/>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="cc2ae" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myTargetDirField">
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -25,13 +25,17 @@ import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.Icons;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -44,6 +48,10 @@ public class DirDiffPanel {
|
||||
private JBTable myTable;
|
||||
private JPanel myComponent;
|
||||
private JSplitPane mySplitPanel;
|
||||
private TextFieldWithBrowseButton mySourceDirField;
|
||||
private TextFieldWithBrowseButton myTargetDirField;
|
||||
private JBLabel myTargetDirLabel;
|
||||
private JBLabel mySourceDirLabel;
|
||||
private final DirDiffTableModel myModel;
|
||||
private final DirDiffDialog myDialog;
|
||||
private DiffPanel myDiffPanelComponent;
|
||||
@@ -52,6 +60,10 @@ public class DirDiffPanel {
|
||||
public DirDiffPanel(DirDiffTableModel model, DirDiffDialog dirDiffDialog) {
|
||||
myModel = model;
|
||||
myDialog = dirDiffDialog;
|
||||
mySourceDirField.setText(model.getSourceDir().getPath());
|
||||
myTargetDirField.setText(model.getTargetDir().getPath());
|
||||
mySourceDirLabel.setIcon(Icons.FOLDER_ICON);
|
||||
myTargetDirLabel.setIcon(Icons.FOLDER_ICON);
|
||||
myTable.setModel(myModel);
|
||||
final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer(myTable);
|
||||
myTable.setDefaultRenderer(Object.class, renderer);
|
||||
@@ -83,7 +95,7 @@ public class DirDiffPanel {
|
||||
} else {
|
||||
clearDiffPanel();
|
||||
|
||||
final VirtualFile file = element.getType() == DirDiffElement.ElementType.SOURCE ? element.getSource() : element.getTarget();
|
||||
final VirtualFile file = element.isSource() ? element.getSource() : element.getTarget();
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
myEditor = (EditorEx)EditorFactory.getInstance().createEditor(document, project, file, true);
|
||||
myEditor.getSettings().setFoldingOutlineShown(false);
|
||||
@@ -91,6 +103,7 @@ public class DirDiffPanel {
|
||||
myDiffPanel.revalidate();
|
||||
}
|
||||
}
|
||||
myDialog.setTitle(myModel.getTitle());
|
||||
}
|
||||
});
|
||||
myTable.addKeyListener(new KeyAdapter() {
|
||||
@@ -118,6 +131,9 @@ public class DirDiffPanel {
|
||||
}
|
||||
}
|
||||
});
|
||||
final TableColumn operationColumn = myTable.getColumnModel().getColumn(3);
|
||||
operationColumn.setMaxWidth(25);
|
||||
operationColumn.setMinWidth(25);
|
||||
}
|
||||
|
||||
private void clearDiffPanel() {
|
||||
|
||||
+33
-3
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.intellij.openapi.diff.impl.dir;
|
||||
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
@@ -68,14 +70,42 @@ public class DirDiffTableCellRenderer extends DefaultTableCellRenderer {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
if (c instanceof JLabel && (hasFocus || isSelected)) {
|
||||
((JLabel)c).setBorder(noFocusBorder);
|
||||
if (c instanceof JLabel) {
|
||||
final JLabel label = (JLabel)c;
|
||||
if (hasFocus || isSelected) {
|
||||
label.setBorder(noFocusBorder);
|
||||
}
|
||||
|
||||
final DirDiffOperation op = element.getOperation();
|
||||
if (column == 3) {
|
||||
label.setIcon(op.getIcon());
|
||||
label.setHorizontalAlignment(CENTER);
|
||||
return label;
|
||||
} else {
|
||||
label.setIcon(null);
|
||||
}
|
||||
|
||||
Color fg = isSelected ? UIUtil.getTableSelectionForeground() : getForegroundColor(op);
|
||||
label.setForeground(fg);
|
||||
if (column == 2 || column == 4) {
|
||||
label.setHorizontalAlignment(CENTER);
|
||||
} else if (column == 1 || column == 5) {
|
||||
label.setHorizontalAlignment(RIGHT);
|
||||
label.setText(label.getText() + " ");
|
||||
} else {
|
||||
label.setHorizontalAlignment(LEFT);
|
||||
label.setText(" " + label.getText());
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static Color getForegroundColor(DirDiffOperation op) {
|
||||
return op == DirDiffOperation.COPY_TO || op == DirDiffOperation.COPY_FROM
|
||||
? FileStatus.COLOR_ADDED : FileStatus.COLOR_MODIFIED;
|
||||
}
|
||||
|
||||
private BufferedImage getOrCreate(String path) {
|
||||
final BufferedImage image = cache.get(path);
|
||||
if (image != null) {
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.util.*;
|
||||
*/
|
||||
public class DirDiffTableModel extends AbstractTableModel {
|
||||
private final Project myProject;
|
||||
private VirtualFile mySrc;
|
||||
private VirtualFile myTrg;
|
||||
final List<DirDiffElement> myElements = new ArrayList<DirDiffElement>();
|
||||
|
||||
public DirDiffTableModel(Project project, VirtualFile src, VirtualFile trg, ProgressIndicator indicator) {
|
||||
@@ -37,7 +39,9 @@ public class DirDiffTableModel extends AbstractTableModel {
|
||||
loadModel(src, trg, indicator);
|
||||
}
|
||||
|
||||
private void loadModel(VirtualFile src, VirtualFile trg, ProgressIndicator indicator) {
|
||||
public void loadModel(VirtualFile src, VirtualFile trg, ProgressIndicator indicator) {
|
||||
mySrc = src;
|
||||
myTrg = trg;
|
||||
final HashSet<String> files = new HashSet<String>();
|
||||
scan("", src, files, indicator, true);
|
||||
scan("", trg, files, indicator, true);
|
||||
@@ -93,6 +97,10 @@ public class DirDiffTableModel extends AbstractTableModel {
|
||||
removeEmptyDirs(myElements);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Diff for " + mySrc.getPath() + " and " + myTrg.getPath();
|
||||
}
|
||||
|
||||
private static void removeEmptyDirs(List<DirDiffElement> elements) {
|
||||
final DirDiffElement[] tmp = elements.toArray(new DirDiffElement[elements.size()]);
|
||||
boolean prevItemIsSeparator = true;
|
||||
@@ -124,6 +132,14 @@ public class DirDiffTableModel extends AbstractTableModel {
|
||||
return myElements.get(index);
|
||||
}
|
||||
|
||||
public VirtualFile getSourceDir() {
|
||||
return mySrc;
|
||||
}
|
||||
|
||||
public VirtualFile getTargetDir() {
|
||||
return myTrg;
|
||||
}
|
||||
|
||||
private static void scan(String prefix, VirtualFile file, HashSet<String> files, ProgressIndicator indicator, boolean isRoot) {
|
||||
if (file.isDirectory()) {
|
||||
indicator.setText2(file.getPath());
|
||||
@@ -174,7 +190,7 @@ public class DirDiffTableModel extends AbstractTableModel {
|
||||
case 0: case 6: return "Name";
|
||||
case 1: case 5: return "Size";
|
||||
case 2: case 4: return "Date";
|
||||
case 3: return "<=>";
|
||||
case 3: return "*";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user