mercurialeclipse / main (http://vectrace.com/mercurialeclipse)

MercurialEclipse is an Eclipse plugin for the Mercurial version control system. This is the main and official development repository of the plugin. Please check out the wiki for information. You can file bugs in our issue tracker here at Bitbucket.

Clone this repository (size: 9.3 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/mercurialeclipse/main/
commit 1048: 8a8d83851762
parent 1047: def5b0808b38
branch: default
Recreated revert dialog and enabled diff tray for it. Refactored CommitFilesChooser to support arbitrary TrayDialogs. Moved stuff there in order to encapsulate it as component. RevertDialog now used GridLayout and was massively simplified. The code redundancy is now gone, instead it uses CommitFileChooser as displaying component. ActionRevert has lost some of its code, so it will be easy to get rid of this ancient code in a next step.
Bastian Doetsch / bastiand
13 months ago

Changed (Δ13.4 KB):

Up to file-list src/com/vectrace/MercurialEclipse/dialogs/CommitDialog.java:

1
1
/*******************************************************************************
2
 * Copyright (c) 2006-2008 VecTrace (Zingo Andersen) and others.
2
 * Copyright (c) 2006-2009 VecTrace (Zingo Andersen) and others.
3
3
 * All rights reserved. This program and the accompanying materials
4
4
 * are made available under the terms of the Eclipse Public License v1.0
5
5
 * which accompanies this distribution, and is available at
7
7
 *
8
8
 * Contributors:
9
9
 *     Software Balm Consulting Inc (Peter Hunnisett <peter_hge at softwarebalm dot com>) - implementation
10
 *     Bastian Doetsch - Added spellchecking.
10
 *     Bastian Doetsch - Added spellchecking and some other stuff
11
11
 *     StefanC - many updates
12
12
 *     Zingo Andersen - some updates
13
13
 *******************************************************************************/
@@ -18,9 +18,6 @@ import static com.vectrace.MercurialEcli
18
18
import java.util.ArrayList;
19
19
import java.util.List;
20
20
21
import org.eclipse.compare.CompareEditorInput;
22
import org.eclipse.compare.ResourceNode;
23
import org.eclipse.core.resources.IFile;
24
21
import org.eclipse.core.resources.IResource;
25
22
import org.eclipse.core.runtime.CoreException;
26
23
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -30,21 +27,14 @@ import org.eclipse.jface.text.IDocument;
30
27
import org.eclipse.jface.text.source.AnnotationModel;
31
28
import org.eclipse.jface.text.source.ISourceViewer;
32
29
import org.eclipse.jface.text.source.SourceViewer;
33
import org.eclipse.jface.viewers.ISelection;
34
import org.eclipse.jface.viewers.ISelectionChangedListener;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.viewers.SelectionChangedEvent;
37
30
import org.eclipse.swt.SWT;
38
31
import org.eclipse.swt.events.DisposeEvent;
39
32
import org.eclipse.swt.events.DisposeListener;
40
33
import org.eclipse.swt.events.KeyEvent;
41
34
import org.eclipse.swt.events.KeyListener;
42
import org.eclipse.swt.events.MouseEvent;
43
import org.eclipse.swt.events.MouseListener;
44
35
import org.eclipse.swt.events.SelectionAdapter;
45
36
import org.eclipse.swt.events.SelectionEvent;
46
37
import org.eclipse.swt.layout.GridData;
47
import org.eclipse.swt.widgets.Button;
48
38
import org.eclipse.swt.widgets.Combo;
49
39
import org.eclipse.swt.widgets.Composite;
50
40
import org.eclipse.swt.widgets.Control;
@@ -62,15 +52,11 @@ import com.vectrace.MercurialEclipse.com
62
52
import com.vectrace.MercurialEclipse.commands.HgClients;
63
53
import com.vectrace.MercurialEclipse.commands.HgCommitClient;
64
54
import com.vectrace.MercurialEclipse.commands.HgRemoveClient;
65
import com.vectrace.MercurialEclipse.compare.RevisionNode;
66
55
import com.vectrace.MercurialEclipse.menu.CommitMergeHandler;
67
56
import com.vectrace.MercurialEclipse.model.HgRoot;
68
import com.vectrace.MercurialEclipse.team.IStorageMercurialRevision;
69
57
import com.vectrace.MercurialEclipse.team.cache.RefreshJob;
70
58
import com.vectrace.MercurialEclipse.ui.CommitFilesChooser;
71
import com.vectrace.MercurialEclipse.ui.DiffTray;
72
59
import com.vectrace.MercurialEclipse.ui.SWTWidgetHelper;
73
import com.vectrace.MercurialEclipse.utils.CompareUtils;
74
60
75
61
/**
76
62
 * 
@@ -106,10 +92,7 @@ public class CommitDialog extends TitleA
106
92
    private List<IResource> inResources;
107
93
    private Text userTextField;
108
94
    private String user;
109
    private boolean closed = true;
110
    private IFile selectedFile;
111
    private Button trayButton;
112
95
    
113
96
    /**
114
97
     * @param shell
115
98
     */
@@ -175,35 +158,6 @@ public class CommitDialog extends TitleA
175
158
        createOldCommitCombo(container);
176
159
        createUserCommitCombo(container);
177
160
        createFilesList(container);
178
        trayButton = SWTWidgetHelper.createPushButton(container,
179
                Messages.getString("CommitDialog.showDiffButton.text"), //$NON-NLS-1$
180
                1);
181
        trayButton.setEnabled(false);
182
        trayButton.addMouseListener(new MouseListener() {
183
184
            public void mouseUp(MouseEvent e) {
185
                if (closed && inResources.size() > 0) {
186
                    try {
187
                        openTray(new DiffTray(getCompareEditorInput()));
188
                        closed = false;
189
                    } catch (Exception e1) {
190
                        MercurialEclipsePlugin.logError(e1);
191
                        setErrorMessage(e1.getMessage());
192
                    }
193
                } else {
194
                    closeTray();
195
                    closed = true;
196
                }
197
            }
198
199
            public void mouseDown(MouseEvent e) {
200
201
            }
202
203
            public void mouseDoubleClick(MouseEvent e) {
204
205
            }
206
        });
207
161
        setupDefaultCommitMessage();
208
162
209
163
        commitTextBox.getTextWidget().setFocus();
@@ -211,48 +165,14 @@ public class CommitDialog extends TitleA
211
165
    }
212
166
213
167
    /**
214
     * @return
215
     */
216
    protected CompareEditorInput getCompareEditorInput() {
217
218
        if (selectedFile == null) {
219
            return null;
220
        }
221
        IStorageMercurialRevision iStorage = new IStorageMercurialRevision(
222
                selectedFile);
223
        ResourceNode right = new RevisionNode(iStorage);
224
        ResourceNode left = new ResourceNode(selectedFile);
225
        return CompareUtils.getCompareInput(left, right, false);
226
    }
227
228
    /**
229
168
     * @param container
230
169
     */
231
170
    private void createFilesList(Composite container) {
232
171
        SWTWidgetHelper.createLabel(container, Messages
233
172
                .getString("CommitDialog.selectFiles")); //$NON-NLS-1$
234
235
        commitFilesList = new CommitFilesChooser(container, selectableFiles,
173
        commitFilesList = new CommitFilesChooser(this, container,
174
                selectableFiles,
236
175
                this.inResources, this.root, true);
237
        commitFilesList.setLayoutData(getFillGD(200));
238
        commitFilesList.getViewer().addSelectionChangedListener(
239
                new ISelectionChangedListener() {
240
241
                    public void selectionChanged(SelectionChangedEvent event) {
242
                        ISelection selection = event.getSelection();
243
244
                        if (selection instanceof IStructuredSelection) {
245
                            IStructuredSelection sel = (IStructuredSelection) selection;
246
                            selectedFile = (IFile) ((CommitResource) sel
247
                                    .getFirstElement()).getResource();
248
                            trayButton.setEnabled(true);
249
                            if (!closed) {
250
                                closeTray();
251
                                openTray(new DiffTray(getCompareEditorInput()));
252
                            }
253
                        }
254
                    }
255
                });
256
176
    }
257
177
258
178
    /**

Up to file-list src/com/vectrace/MercurialEclipse/dialogs/RevertDialog.java:

10
10
 *******************************************************************************/
11
11
package com.vectrace.MercurialEclipse.dialogs;
12
12
13
import java.util.ArrayList;
13
import static com.vectrace.MercurialEclipse.ui.SWTWidgetHelper.getFillGD;
14
14
15
import java.util.Arrays;
15
16
import java.util.List;
16
17
17
import org.eclipse.compare.ResourceNode;
18
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.viewers.ArrayContentProvider;
21
import org.eclipse.jface.viewers.CheckboxTableViewer;
22
import org.eclipse.jface.viewers.DoubleClickEvent;
23
import org.eclipse.jface.viewers.IDoubleClickListener;
24
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.jface.dialogs.TitleAreaDialog;
25
20
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.events.SelectionAdapter;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.layout.FormAttachment;
30
import org.eclipse.swt.layout.FormData;
31
import org.eclipse.swt.layout.FormLayout;
32
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.layout.GridData;
33
22
import org.eclipse.swt.widgets.Composite;
34
23
import org.eclipse.swt.widgets.Control;
35
import org.eclipse.swt.widgets.Label;
36
24
import org.eclipse.swt.widgets.Shell;
37
import org.eclipse.swt.widgets.Table;
38
import org.eclipse.swt.widgets.TableColumn;
39
25
40
import com.vectrace.MercurialEclipse.compare.RevisionNode;
41
import com.vectrace.MercurialEclipse.team.IStorageMercurialRevision;
42
import com.vectrace.MercurialEclipse.ui.UntrackedFilesFilter;
43
import com.vectrace.MercurialEclipse.utils.CompareUtils;
26
import com.vectrace.MercurialEclipse.model.HgRoot;
27
import com.vectrace.MercurialEclipse.ui.CommitFilesChooser;
28
import com.vectrace.MercurialEclipse.ui.SWTWidgetHelper;
44
29
45
public class RevertDialog extends Dialog {
30
public class RevertDialog extends TitleAreaDialog {
46
31
47
    private Table table;
48
    private List<CommitResource> resources;
49
    private List<CommitResource> selection;
50
    private CheckboxTableViewer selectFilesList;
51
    private Button selectAllButton;
52
    private Button deselectAllButton;
32
    private List<IResource> resources;
33
    private CommitFilesChooser selectFilesList;
34
    private HgRoot root;
35
    private List<IResource> selection;
36
37
    public static final String FILE_MODIFIED = Messages
38
            .getString("CommitDialog.modified"); //$NON-NLS-1$
39
    public static final String FILE_ADDED = Messages
40
            .getString("CommitDialog.added"); //$NON-NLS-1$
41
    public static final String FILE_REMOVED = Messages
42
            .getString("CommitDialog.removed"); //$NON-NLS-1$
43
    public static final String FILE_UNTRACKED = Messages
44
            .getString("CommitDialog.untracked"); //$NON-NLS-1$
45
    public static final String FILE_DELETED = Messages
46
            .getString("CommitDialog.deletedInWorkspace"); //$NON-NLS-1$
53
47
54
48
    /**
55
49
     * Create the dialog
56
50
     * 
57
51
     * @param parentShell
58
52
     */
59
    public RevertDialog(Shell parentShell) {
53
    public RevertDialog(Shell parentShell, HgRoot root) {
60
54
        super(parentShell);
61
55
        setShellStyle(getShellStyle() | SWT.RESIZE);
56
        this.root = root;
62
57
    }
63
58
64
59
    /**
@@ -68,157 +63,42 @@ public class RevertDialog extends Dialog
68
63
     */
69
64
    @Override
70
65
    protected Control createDialogArea(Composite parent) {
71
        Composite container = (Composite) super.createDialogArea(parent);
72
        container.setLayout(new FormLayout());
73
74
        final Label label = new Label(container, SWT.NONE);
75
        final FormData fd_label = new FormData();
76
        fd_label.top = new FormAttachment(0, 10);
77
        fd_label.left = new FormAttachment(0, 5);
78
        label.setLayoutData(fd_label);
79
        label.setText(Messages.getString("RevertDialog.header")); //$NON-NLS-1$
66
        Composite container = SWTWidgetHelper.createComposite(parent, 1);
67
        GridData gd = getFillGD(400);
68
        container.setLayoutData(gd);
69
        super.createDialogArea(parent);
70
        setMessage(Messages.getString("RevertDialog.header")); //$NON-NLS-1$
80
71
81
72
        createFilesList(container);
82
        final FormData fd_table = new FormData();
83
        fd_table.right = new FormAttachment(100, -5);
84
        fd_table.top = new FormAttachment(0, 35);
85
        fd_table.left = new FormAttachment(label, 0, SWT.LEFT);
86
        table.setLayoutData(fd_table);
87
88
        selectAllButton = new Button(container, SWT.NONE);
89
        fd_table.bottom = new FormAttachment(selectAllButton, -5, SWT.TOP);
90
        final FormData fd_selectAllButton = new FormData();
91
        fd_selectAllButton.bottom = new FormAttachment(100, -3);
92
        fd_selectAllButton.right = new FormAttachment(0, 90);
93
        fd_selectAllButton.left = new FormAttachment(0, 5);
94
        selectAllButton.setLayoutData(fd_selectAllButton);
95
        selectAllButton.setText(Messages.getString("RevertDialog.option.selectAll")); //$NON-NLS-1$
96
97
        deselectAllButton = new Button(container, SWT.NONE);
98
        final FormData fd_deselectAllButton = new FormData();
99
        fd_deselectAllButton.left = new FormAttachment(selectAllButton, 10,
100
                SWT.DEFAULT);
101
        fd_deselectAllButton.bottom = new FormAttachment(100, -3);
102
        fd_deselectAllButton.right = new FormAttachment(0, 185);
103
        deselectAllButton.setLayoutData(fd_deselectAllButton);
104
        deselectAllButton.setText(Messages.getString("RevertDialog.option.deselectAll")); //$NON-NLS-1$
105
        //
106
107
        makeActions();
108
73
        return container;
109
74
    }
110
75
111
76
    private void createFilesList(Composite container) {
112
        table = new Table(container, SWT.H_SCROLL | SWT.V_SCROLL
113
                | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK | SWT.BORDER);
114
        table.setHeaderVisible(true);
115
        table.setLinesVisible(true);
116
        TableColumn col;
117
118
        // File name
119
        col = new TableColumn(table, SWT.NONE);
120
        col.setResizable(true);
121
        col.setText(Messages.getString("RevertDialog.file")); //$NON-NLS-1$
122
        col.setWidth(350);
123
        col.setMoveable(true);
124
125
        // File status
126
        col = new TableColumn(table, SWT.NONE);
127
        col.setResizable(true);
128
        col.setText(Messages.getString("RevertDialog.status")); //$NON-NLS-1$
129
        col.setWidth(170);
130
        col.setMoveable(true);
131
132
        selectFilesList = new CheckboxTableViewer(table);
133
134
        selectFilesList.setContentProvider(new ArrayContentProvider());
135
136
        selectFilesList.setLabelProvider(new CommitResourceLabelProvider());
137
        selectFilesList.addFilter(new UntrackedFilesFilter());
138
        selectFilesList.setInput(resources);
139
140
        selectFilesList.setAllChecked(true);
77
        selectFilesList = new CommitFilesChooser(this, container, true,
78
                resources, root, false);
141
79
    }
142
80
143
    private void makeActions() {
144
        deselectAllButton.addSelectionListener(new SelectionAdapter() {
145
            @Override
146
            public void widgetSelected(SelectionEvent e) {
147
                selectFilesList.setAllChecked(false);
148
            }
149
        });
150
151
        selectAllButton.addSelectionListener(new SelectionAdapter() {
152
            @Override
153
            public void widgetSelected(SelectionEvent e) {
154
                selectFilesList.setAllChecked(true);
155
            }
156
        });
157
158
        selectFilesList.addDoubleClickListener(new IDoubleClickListener() {
159
            public void doubleClick(DoubleClickEvent event) {
160
                IStructuredSelection sel = (IStructuredSelection) selectFilesList
161
                        .getSelection();
162
                if (sel.getFirstElement() instanceof CommitResource) {
163
                    CommitResource resource = (CommitResource) sel
164
                            .getFirstElement();
165
166
                    // workspace version
167
                    ResourceNode leftNode = new ResourceNode(resource
168
                            .getResource());
169
170
                    // mercurial version
171
                    RevisionNode rightNode = new RevisionNode(
172
                            new IStorageMercurialRevision(resource
173
                                    .getResource()));
174
175
                    CompareUtils.openCompareDialog(leftNode, rightNode, false);
176
                }
177
            }
178
        });
179
180
    }
181
182
    /**
183
     * Create contents of the button bar
184
     * 
185
     * @param parent
186
     */
187
    @Override
188
    protected void createButtonsForButtonBar(Composite parent) {
189
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
190
                true);
191
        createButton(parent, IDialogConstants.CANCEL_ID,
192
                IDialogConstants.CANCEL_LABEL, false);
193
    }
194
195
    /**
196
     * Return the initial size of the dialog
197
     */
198
    @Override
199
    protected Point getInitialSize() {
200
        return new Point(500, 375);
201
    }
202
203
    public void setFiles(List<CommitResource> resources) {
81
    public void setFiles(List<IResource> resources) {
204
82
        this.resources = resources;
205
83
206
84
    }
207
85
208
    @SuppressWarnings("unchecked")
209
86
    @Override
210
87
    protected void okPressed() {
211
        this.selection = new ArrayList(Arrays.asList(selectFilesList
212
                .getCheckedElements()));
88
        this.selection = selectFilesList.getCheckedResources(FILE_ADDED,
89
                FILE_DELETED, FILE_MODIFIED, FILE_REMOVED);
213
90
        super.okPressed();
214
91
215
92
    }
216
93
217
    public List<CommitResource> getSelection() {
94
    public void setFiles(IResource[] commitResources) {
95
        setFiles(Arrays.asList(commitResources));
96
    }
97
98
    /**
99
     * @return the selection
100
     */
101
    public List<IResource> getSelection() {
218
102
        return selection;
219
103
    }
220
221
    public void setFiles(CommitResource[] commitResources) {
222
        setFiles(Arrays.asList(commitResources));
223
    }
224
104
}

Up to file-list src/com/vectrace/MercurialEclipse/dialogs/messages.properties:

@@ -18,7 +18,6 @@ CommitDialog.deletedInWorkspace=Already
18
18
CommitDialog.modified=Modified
19
19
CommitDialog.removed=Removed
20
20
CommitDialog.selectFiles=Select Files:
21
CommitDialog.showDiffButton.text=Show Diff
22
21
CommitDialog.title=Commit changes to local Mercurial repository
23
22
CommitDialog.untracked=Untracked
24
23
CommitDialog.userLabel.text=User to record as committer:
@@ -31,10 +30,7 @@ IgnoreDialog.onlyFileBtn.label=Only this
31
30
IgnoreDialog.selectLabel.text=Select what to ignore:
32
31
IgnoreDialog.shell.text=Add to hgignore...
33
32
RevertDialog.file=File
34
RevertDialog.header=Checked resources will be reverted
35
RevertDialog.option.deselectAll=Deselect All
36
RevertDialog.option.selectAll=Select All
37
RevertDialog.status=Status
33
RevertDialog.header=Please select the resources to be reverted.
38
34
RevisionChooserDialog.bookmarkTab.name=Bookmarks
39
35
RevisionChooserDialog.branchJob.description=Fetching branches from repository
40
36
RevisionChooserDialog.branchTab.name=Branches

Up to file-list src/com/vectrace/MercurialEclipse/team/ActionRevert.java:

@@ -36,9 +36,6 @@ import org.eclipse.ui.PlatformUI;
36
36
37
37
import com.vectrace.MercurialEclipse.MercurialEclipsePlugin;
38
38
import com.vectrace.MercurialEclipse.SafeWorkspaceJob;
39
import com.vectrace.MercurialEclipse.dialogs.CommitDialog;
40
import com.vectrace.MercurialEclipse.dialogs.CommitResource;
41
import com.vectrace.MercurialEclipse.dialogs.CommitResourceUtil;
42
39
import com.vectrace.MercurialEclipse.dialogs.RevertDialog;
43
40
import com.vectrace.MercurialEclipse.exception.HgException;
44
41
import com.vectrace.MercurialEclipse.model.HgRoot;
@@ -96,7 +93,7 @@ public class ActionRevert implements IWo
96
93
                            .getPersistentProperty(ResourceProperties.MERGING) != null;
97
94
                    boolean supervised = MercurialUtilities
98
95
                            .hgIsTeamProviderFor(resource, false) == true;
99
                    
96
100
97
                    if (supervised && !merging) {
101
98
                        resources.add(resource);
102
99
                        if (root == null) {
@@ -108,26 +105,14 @@ public class ActionRevert implements IWo
108
105
                }
109
106
            }
110
107
111
            CommitResource[] commitResources = new CommitResourceUtil(root)
112
                    .getCommitResources(resources
113
                            .toArray(new IResource[resources.size()]));
114
115
            // Check to see if there are any that are untracked.
116
            int count = 0;
117
            for (int i = 0; i < commitResources.length; i++) {
118
                if (!commitResources[i].getStatus().startsWith(
119
                        CommitDialog.FILE_UNTRACKED)) {
120
                    count++;
121
                }
122
            }
123
124
            if (count != 0) {
108
            if (resources.size() != 0) {
125
109
                RevertDialog chooser = new RevertDialog(Display.getCurrent()
126
                        .getActiveShell());
127
                chooser.setFiles(commitResources);
110
                        .getActiveShell(), root);
111
                chooser.setFiles(resources);
128
112
                if (chooser.open() == Window.OK) {
129
                    final List<CommitResource> result = chooser.getSelection();
130
                    new SafeWorkspaceJob(Messages.getString("ActionRevert.revertFiles")) { //$NON-NLS-1$
113
                    final List<IResource> result = chooser.getSelection();
114
                    new SafeWorkspaceJob(Messages
115
                            .getString("ActionRevert.revertFiles")) { //$NON-NLS-1$
131
116
                        @Override
132
117
                        protected IStatus runSafe(IProgressMonitor monitor) {
133
118
                            doRevert(monitor, result);
@@ -143,8 +128,10 @@ public class ActionRevert implements IWo
143
128
                    workbench = PlatformUI.getWorkbench();
144
129
                    shell = workbench.getActiveWorkbenchWindow().getShell();
145
130
                }
146
                MessageDialog.openInformation(shell,
147
                        Messages.getString("ActionRevert.HgRevert"), Messages.getString("ActionRevert.noFilesToRevert")); //$NON-NLS-1$ //$NON-NLS-2$
131
                MessageDialog
132
                        .openInformation(
133
                                shell,
134
                                Messages.getString("ActionRevert.HgRevert"), Messages.getString("ActionRevert.noFilesToRevert")); //$NON-NLS-1$ //$NON-NLS-2$
148
135
            }
149
136
        } catch (CoreException e) {
150
137
            MercurialEclipsePlugin.logError(e);
@@ -152,17 +139,18 @@ public class ActionRevert implements IWo
152
139
        }
153
140
    }
154
141
155
    private void doRevert(IProgressMonitor monitor,
156
            List<CommitResource> resources) {
142
    private void doRevert(IProgressMonitor monitor, List<IResource> resources) {
157
143
        // the last argument will be replaced with a path
158
144
        String launchCmd[] = { MercurialUtilities.getHGExecutable(), "revert", //$NON-NLS-1$
159
145
                "--no-backup", "--", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
160
        monitor.beginTask(Messages.getString("ActionRevert.revertingResources"), resources.size() * 2); //$NON-NLS-1$
161
        for (CommitResource revertResource : resources) {
146
        monitor
147
                .beginTask(
148
                        Messages.getString("ActionRevert.revertingResources"), resources.size() * 2); //$NON-NLS-1$
149
150
        for (IResource resource : resources) {
162
151
            if (monitor.isCanceled()) {
163
152
                break;
164
153
            }
165
            IResource resource = revertResource.getResource();
166
154
            // Resource could be inside a link or something do nothing
167
155
            // in the future this could check is this is another repository
168
156
@@ -172,7 +160,8 @@ public class ActionRevert implements IWo
172
160
            // System.out.println("Revert = " + FullPath);
173
161
            // IResourceChangeEvent event = new IResourceChangeEvent();
174
162
            try {
175
                monitor.subTask(Messages.getString("ActionRevert.reverting") + resource.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
163
                monitor
164
                        .subTask(Messages.getString("ActionRevert.reverting") + resource.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
176
165
                MercurialUtilities.executeCommand(launchCmd, workingDir, true);
177
166
                monitor.worked(1);
178
167
            } catch (HgException e) {
@@ -180,31 +169,15 @@ public class ActionRevert implements IWo
180
169
            }
181
170
        }
182
171
183
        for (CommitResource commitResource : resources) {
184
            monitor.subTask(Messages.getString("ActionRevert.refreshing") + commitResource + "..."); //$NON-NLS-1$ //$NON-NLS-2$
185
            IResource resource = commitResource.getResource();
172
        for (IResource resource : resources) {
173
            monitor
174
                    .subTask(Messages.getString("ActionRevert.refreshing") + resource.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
186
175
            try {
187
176
                resource.refreshLocal(IResource.DEPTH_ONE, monitor);
188
177
            } catch (CoreException e) {
189
178
                MercurialEclipsePlugin.logError(e);
190
179
            }
191
180
            monitor.worked(1);
192
            // if (!refreshedProjects.contains(resource.getProject())) {
193
            // final IProject proj = resource.getProject();
194
            // new SafeUiJob("Updating status") {
195
            // @Override
196
            // protected IStatus runSafe(IProgressMonitor monitor1) {
197
            // try {
198
            // MercurialStatusCache.getInstance().refresh(proj);
199
            // } catch (TeamException e) {
200
            // MercurialEclipsePlugin.logError(
201
            // "Unable to refresh project: ", e);
202
            // }
203
            // return super.runSafe(monitor1);
204
            // }
205
            // }.schedule();
206
            // refreshedProjects.add(proj);
207
            // }
208
181
        }
209
182
        monitor.done();
210
183
    }

Up to file-list src/com/vectrace/MercurialEclipse/ui/CommitFilesChooser.java:

@@ -13,30 +13,40 @@ package com.vectrace.MercurialEclipse.ui
13
13
import java.util.ArrayList;
14
14
import java.util.List;
15
15
16
import org.eclipse.compare.CompareEditorInput;
16
17
import org.eclipse.compare.ResourceNode;
18
import org.eclipse.core.resources.IFile;
17
19
import org.eclipse.core.resources.IResource;
18
20
import org.eclipse.core.runtime.ListenerList;
21
import org.eclipse.jface.dialogs.TrayDialog;
19
22
import org.eclipse.jface.viewers.ArrayContentProvider;
20
23
import org.eclipse.jface.viewers.CheckStateChangedEvent;
21
24
import org.eclipse.jface.viewers.CheckboxTableViewer;
22
25
import org.eclipse.jface.viewers.DoubleClickEvent;
23
26
import org.eclipse.jface.viewers.ICheckStateListener;
24
27
import org.eclipse.jface.viewers.IDoubleClickListener;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
30
import org.eclipse.jface.viewers.IStructuredSelection;
26
31
import org.eclipse.jface.viewers.ITableLabelProvider;
32
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
33
import org.eclipse.jface.viewers.StructuredViewer;
28
34
import org.eclipse.jface.viewers.Viewer;
29
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.MouseEvent;
37
import org.eclipse.swt.events.MouseListener;
30
38
import org.eclipse.swt.events.SelectionAdapter;
31
39
import org.eclipse.swt.events.SelectionEvent;
32
40
import org.eclipse.swt.layout.GridData;
33
41
import org.eclipse.swt.layout.GridLayout;
34
42
import org.eclipse.swt.widgets.Button;
35
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Control;
36
45
import org.eclipse.swt.widgets.Listener;
37
46
import org.eclipse.swt.widgets.Table;
38
47
import org.eclipse.swt.widgets.TableColumn;
39
48
49
import com.vectrace.MercurialEclipse.MercurialEclipsePlugin;
40
50
import com.vectrace.MercurialEclipse.TableColumnSorter;
41
51
import com.vectrace.MercurialEclipse.compare.RevisionNode;
42
52
import com.vectrace.MercurialEclipse.dialogs.CommitDialog;
@@ -63,6 +73,10 @@ public class CommitFilesChooser extends
63
73
    private CheckboxTableViewer viewer;
64
74
    private final boolean untracked;
65
75
    private ListenerList stateListeners = new ListenerList();
76
    protected Control trayButton;
77
    protected TrayDialog parentDialog;
78
    protected boolean trayClosed = true;
79
    protected IFile selectedFile;
66
80
67
81
    /**
68
82
     * @return the viewer
@@ -71,8 +85,9 @@ public class CommitFilesChooser extends
71
85
        return viewer;
72
86
    }
73
87
74
    public CommitFilesChooser(Composite container, boolean selectable,
75
            List<IResource> resources, HgRoot hgRoot, boolean showUntracked) {
88
    public CommitFilesChooser(TrayDialog trayDialog, Composite container,
89
            boolean selectable, List<IResource> resources, HgRoot hgRoot,
90
            boolean showUntracked) {
76
91
        super(container, container.getStyle());
77
92
78
93
        this.selectable = selectable;
@@ -80,6 +95,7 @@ public class CommitFilesChooser extends
80
95
        this.untracked = showUntracked;
81
96
        this.untrackedFilesFilter = new UntrackedFilesFilter();
82
97
        this.committableFilesFilter = new CommittableFilesFilter();
98
        this.parentDialog = trayDialog;
83
99
84
100
        GridLayout layout = new GridLayout();
85
101
        layout.verticalSpacing = 3;
@@ -88,6 +104,7 @@ public class CommitFilesChooser extends
88
104
        layout.marginHeight = 0;
89
105
        setLayout(layout);
90
106
        
107
        setLayoutData(SWTWidgetHelper.getFillGD(200));
91
108
92
109
        Table table = createTable();
93
110
        createOptionCheckbox();
@@ -101,9 +118,82 @@ public class CommitFilesChooser extends
101
118
        }
102
119
103
120
        setResources(resources);
121
        if (parentDialog != null) {
122
            createShowDiffButton(container);
123
            createFileSelectionListener();
124
        }
104
125
        makeActions();
105
126
    }
106
127
128
    /**
129
     * 
130
     */
131
    private void createFileSelectionListener() {
132
        getViewer().addSelectionChangedListener(
133
                new ISelectionChangedListener() {
134
135
                    public void selectionChanged(SelectionChangedEvent event) {
136
                        ISelection selection = event.getSelection();
137
138
                        if (selection instanceof IStructuredSelection) {
139
                            IStructuredSelection sel = (IStructuredSelection) selection;
140
                            CommitResource commitResource = (CommitResource) sel
141
                                    .getFirstElement();
142
                            if (commitResource != null) {
143
                                IFile oldSelectedFile = selectedFile;
144
                                selectedFile = (IFile) commitResource
145
                                        .getResource();
146
                                if (oldSelectedFile == null
147
                                        || !oldSelectedFile
148
                                                .equals(selectedFile)) {
149
                                    trayButton.setEnabled(true);
150
                                    if (!trayClosed) {
151
                                        parentDialog.closeTray();
152
                                        parentDialog.openTray(new DiffTray(
153
                                                getCompareEditorInput()));
154
                                    }
155
                                }
156
                            }
157
                        }
158
                    }
159
                });
160
    }
161
162
    /**
163
     * @param container
164
     */
165
    private void createShowDiffButton(Composite container) {
166
        trayButton = SWTWidgetHelper.createPushButton(container, Messages
167
                .getString("CommitFilesChooser.showDiffButton.text"), //$NON-NLS-1$
168
                1);
169
        trayButton.setEnabled(false);
170
        trayButton.addMouseListener(new MouseListener() {
171
172
            public void mouseUp(MouseEvent e) {
173
                if (trayClosed && selectedFile != null) {
174
                    try {
175
                        parentDialog.openTray(new DiffTray(
176
                                getCompareEditorInput()));
177
                        trayClosed = false;
178
                    } catch (Exception e1) {
179
                        MercurialEclipsePlugin.logError(e1);
180
                    }
181
                } else {
182
                    parentDialog.closeTray();
183
                    trayClosed = true;
184
                }
185
            }
186
187
            public void mouseDown(MouseEvent e) {
188
189
            }
190
191
            public void mouseDoubleClick(MouseEvent e) {
192
193
            }
194
        });
195
    }
196
107
197
    private Table createTable() {
108
198
        int flags = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
109
199
        if (selectable) {
@@ -143,7 +233,7 @@ public class CommitFilesChooser extends
143
233
        selectAllButton.setText(Messages
144
234
                .getString("Common.SelectOrUnselectAll")); //$NON-NLS-1$
145
235
        selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
146
236
        
147
237
        if (!untracked) {
148
238
            return;
149
239
        }
@@ -154,6 +244,21 @@ public class CommitFilesChooser extends
154
244
                GridData.FILL_HORIZONTAL));
155
245
    }
156
246
247
    /**
248
     * @return
249
     */
250
    protected CompareEditorInput getCompareEditorInput() {
251
252
        if (selectedFile == null) {
253
            return null;
254
        }
255
        IStorageMercurialRevision iStorage = new IStorageMercurialRevision(
256
                selectedFile);
257
        ResourceNode right = new RevisionNode(iStorage);
258
        ResourceNode left = new ResourceNode(selectedFile);
259
        return CompareUtils.getCompareInput(left, right, false);
260
    }
261
157
262
    private void makeActions() {
158
263
        getViewer().addDoubleClickListener(new IDoubleClickListener() {
159
264
            public void doubleClick(DoubleClickEvent event) {
@@ -176,7 +281,7 @@ public class CommitFilesChooser extends
176
281
                }
177
282
            }
178
283
        });
179
        getViewer().addCheckStateListener(new ICheckStateListener(){
284
        getViewer().addCheckStateListener(new ICheckStateListener() {
180
285
            public void checkStateChanged(CheckStateChangedEvent event) {
181
286
                fireStateChanged();
182
287
            }

Up to file-list src/com/vectrace/MercurialEclipse/ui/messages.properties:

@@ -33,3 +33,4 @@ Common.ColumnFile=File
33
33
Common.ColumnStatus=Status
34
34
Common.SelectOrUnselectAll=Select/unselect all
35
35
Common.ShowUntrackedFiles=Show added/removed files
36
CommitFilesChooser.showDiffButton.text=Show Diff

Up to file-list src/com/vectrace/MercurialEclipse/wizards/ExportPage.java:

@@ -51,10 +51,12 @@ public class ExportPage extends HgWizard
51
51
52
52
    protected boolean validatePage() {
53
53
        String msg = locationChooser.validate();
54
        if (msg == null && getCheckedResources().size() == 0)
54
        if (msg == null && getCheckedResources().size() == 0) {
55
55
            msg = Messages.getString("ExportWizard.InvalidPathFile"); //$NON-NLS-1$
56
        if (msg == null)
56
        }
57
        if (msg == null) {
57
58
            setMessage(null);
59
        }
58
60
        setErrorMessage(msg);
59
61
        setPageComplete(msg == null);
60
62
        return msg == null;
@@ -73,7 +75,8 @@ public class ExportPage extends HgWizard
73
75
        locationChooser.setLayoutData(data);
74
76
75
77
        // TODO no diff for untracked files, bug?
76
        commitFiles = new CommitFilesChooser(composite, true, resources, root,
78
        commitFiles = new CommitFilesChooser(null, composite, true, resources,
79
                root,
77
80
                false);
78
81
        commitFiles.setLayoutData(new GridData(GridData.FILL_BOTH));
79
82
        commitFiles.addStateListener(this);