Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4b2bfd4868ae7936a960105026988a2208444233 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
 * Copyright (c) 2002 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 * IBM - Initial implementation
 ******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.sync.ILocalSyncElement;
import org.eclipse.team.internal.ccvs.ui.AvoidableMessageDialog;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.sync.CVSSyncCompareInput;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionDelegate;

public class ContentAction extends ActionDelegate implements IEditorActionDelegate {
	
	/**
	 * Is <code>null</code> if the current active editor is not a compare editor
	 * with a CVS editor input. Or else this input refer to the input in the active
	 * CVS compare editor.
	 */
	private CVSSyncCompareInput syncInput;
	
	/**
	 * Should only be called if action is enabled and the current active editor is a
	 * CVS compare editor.
	 * 
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
		if (store.getBoolean(ICVSUIConstants.PREF_PROMPT_ON_CHANGE_GRANULARITY)) {
			Shell shell = syncInput.getViewer().getControl().getShell();
			AvoidableMessageDialog dialog = new AvoidableMessageDialog(
					shell,
					Policy.bind("ContentAction.Confirm_Long_Operation_1"), //$NON-NLS-1$
					null,	// accept the default window icon
					Policy.bind("ContentAction.Changing_this_setting_will_involve_contacting_the_server_and_may_be_long-running_2"), //$NON-NLS-1$
					MessageDialog.QUESTION, 
					new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 
					0);
					
			boolean result = dialog.open() == 0;
			if (result && dialog.isDontShowAgain()) {
				store.setValue(ICVSUIConstants.PREF_PROMPT_ON_CHANGE_GRANULARITY, false);
			}
			if (!result) return;
		}			
		syncInput.setSyncGranularity(action.isChecked() ? ILocalSyncElement.GRANULARITY_CONTENTS : ILocalSyncElement.GRANULARITY_TIMESTAMP);
	}

	/**
	 * Called when the active editor changes. Enablement of this action depends
	 * on the editor type and editr input of the active editor.
	 * 
	 * @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
	 */
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
		if (targetEditor != null) {
			IEditorInput input = targetEditor.getEditorInput();
			if (input instanceof CVSSyncCompareInput) {
				this.syncInput = (CVSSyncCompareInput)input;
				action.setEnabled(true);
				action.setChecked(syncInput.getSyncGranularity() == ILocalSyncElement.GRANULARITY_CONTENTS);
				return;
			}
		}
		syncInput = null;
		action.setEnabled(false);
	}
}

Back to the top