Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 85608 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java (+1 lines)
Lines 41-46 Link Here
41
        Composite composite = createComposite(parent);
41
        Composite composite = createComposite(parent);
42
42
43
        createShowUserDialogPref(composite);
43
        createShowUserDialogPref(composite);
44
        createNoStealFocusPref(composite);
44
        createStickyCyclePref(composite);
45
        createStickyCyclePref(composite);
45
        createHeapStatusPref(composite);
46
        createHeapStatusPref(composite);
46
        
47
        
(-)Eclipse UI/org/eclipse/ui/internal/IPreferenceConstants.java (-4 / +11 lines)
Lines 214-225 Link Here
214
     * @since 3.0
214
     * @since 3.0
215
     */
215
     */
216
    public static final String SHOULD_PROMPT_FOR_ENABLEMENT = "shouldPromptForEnablement"; //$NON-NLS-1$
216
    public static final String SHOULD_PROMPT_FOR_ENABLEMENT = "shouldPromptForEnablement"; //$NON-NLS-1$
217
    
218
    /**
219
	 * Prevents views and editors from moving to the foreground automatically.
220
	 * 
221
	 * @since 3.3
222
	 */
223
	public static final String NEVER_STEAL_FOCUS = "NEVER_STEAL_FOCUS"; //$NON-NLS-1$
217
224
218
    /**
225
    /**
219
     * Experimental preference ID for automatic pinning editors on dirty.
226
	 * Experimental preference ID for automatic pinning editors on dirty.
220
     *  
227
	 * 
221
     * @since 3.3
228
	 * @since 3.3
222
     */
229
	 */
223
    public static final String EDITOR_EXPERIMENTAL_TAB_BEHAVIOUR = "EDITOR_EXPERIMENTAL_TAB_BEHAVIOUR"; //$NON-NLS-1$
230
    public static final String EDITOR_EXPERIMENTAL_TAB_BEHAVIOUR = "EDITOR_EXPERIMENTAL_TAB_BEHAVIOUR"; //$NON-NLS-1$
224
231
225
}
232
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java (+3 lines)
Lines 988-993 Link Here
988
988
989
989
990
    public static String FastViewBar_show_view;
990
    public static String FastViewBar_show_view;
991
    public static String WorkbenchPreference_NeverStealFocus;
992
    public static String WorkbenchPreference_NeverStealFocusTooltip;
993
    
991
    
994
    
992
    // Content assist support
995
    // Content assist support
993
    public static String ContentAssist_Cue_Description_Key;
996
    public static String ContentAssist_Cue_Description_Key;
(-)Eclipse UI/org/eclipse/ui/internal/messages.properties (-1 / +3 lines)
Lines 351-357 Link Here
351
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
351
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
352
WorkbenchPreference_HeapStatusButton = Sho&w heap status
352
WorkbenchPreference_HeapStatusButton = Sho&w heap status
353
WorkbenchPreference_HeapStatusButtonToolTip = Show the heap status area on the bottom of the window
353
WorkbenchPreference_HeapStatusButtonToolTip = Show the heap status area on the bottom of the window
354
      
354
WorkbenchPreference_NeverStealFocus=Never steal focus
355
WorkbenchPreference_NeverStealFocusTooltip=Prevents views and editors from opening automatically
356
355
357
356
# --- Appearance ---
358
# --- Appearance ---
357
ViewsPreference_currentPresentation = Current &Presentation:
359
ViewsPreference_currentPresentation = Current &Presentation:
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-1 / +56 lines)
Lines 107-112 Link Here
107
import org.eclipse.ui.model.IWorkbenchAdapter;
107
import org.eclipse.ui.model.IWorkbenchAdapter;
108
import org.eclipse.ui.part.MultiEditor;
108
import org.eclipse.ui.part.MultiEditor;
109
import org.eclipse.ui.presentations.IStackPresentationSite;
109
import org.eclipse.ui.presentations.IStackPresentationSite;
110
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
110
import org.eclipse.ui.views.IStickyViewDescriptor;
111
import org.eclipse.ui.views.IStickyViewDescriptor;
111
import org.eclipse.ui.views.IViewRegistry;
112
import org.eclipse.ui.views.IViewRegistry;
112
113
Lines 574-579 Link Here
574
        if (window.isClosing()) {
575
        if (window.isClosing()) {
575
			return;
576
			return;
576
		}
577
		}
578
    	// There is a preference to prevent background threads from activating views or bringing
579
    	// them to the top. If the user has set this preference, just bold the tab whenever
580
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
581
    	
582
    	if (composite != null && composite.isVisible() && isGrabFocusDisabled() && !InputMonitor.isProcessingUserInput()) {
583
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
584
    		
585
    		// Bold the tab if possible
586
    		if (progressService != null) {
587
    			progressService.warnOfContentChange();
588
    		}
589
    		
590
    		// And exit to ensure we don't mess with activation or layout
591
    		return;
592
    	}
577
593
578
        // If zoomed, unzoom.
594
        // If zoomed, unzoom.
579
        zoomOutIfNecessary(part);
595
        zoomOutIfNecessary(part);
Lines 780-785 Link Here
780
        if (persp == null || !certifyPart(part)) {
796
        if (persp == null || !certifyPart(part)) {
781
			return;
797
			return;
782
		}
798
		}
799
    	// There is a preference to prevent background threads from activating views or bringing
800
    	// them to the top. If the user has set this preference, just bold the tab whenever
801
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
802
    	
803
    	if (isGrabFocusDisabled() && !InputMonitor.isProcessingUserInput()) {
804
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
805
    		
806
    		// Bold the tab if possible
807
    		if (progressService != null) {
808
    			progressService.warnOfContentChange();
809
    		}
810
    		
811
    		// And exit to ensure we don't mess with activation or layout
812
    		return;
813
    	}
783
814
784
        String label = null; // debugging only
815
        String label = null; // debugging only
785
        if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) {
816
        if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) {
Lines 1004-1010 Link Here
1004
     * Performs showing of the view in the given mode.
1035
     * Performs showing of the view in the given mode.
1005
     */
1036
     */
1006
    private void busyShowView(IViewPart part, int mode) {
1037
    private void busyShowView(IViewPart part, int mode) {
1007
        if (mode == VIEW_ACTIVATE) {
1038
1039
    	// There is a preference to prevent background threads from activating views or bringing
1040
    	// them to the top. If the user has set this preference, just bold the tab whenever
1041
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
1042
    	
1043
    	if (isGrabFocusDisabled() && mode != VIEW_CREATE && !InputMonitor.isProcessingUserInput()) {
1044
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
1045
    		
1046
    		// Bold the tab if possible
1047
    		if (progressService != null) {
1048
    			progressService.warnOfContentChange();
1049
    		}
1050
    		
1051
    		// And exit to ensure we don't mess with activation or layout
1052
    		return;
1053
    	}
1054
1055
    	if (mode == VIEW_ACTIVATE) {
1008
			activate(part);
1056
			activate(part);
1009
		} else if (mode == VIEW_VISIBLE) {
1057
		} else if (mode == VIEW_VISIBLE) {
1010
            IWorkbenchPartReference ref = getActivePartReference();
1058
            IWorkbenchPartReference ref = getActivePartReference();
Lines 2224-2229 Link Here
2224
        // Save args.
2272
        // Save args.
2225
        this.window = w;
2273
        this.window = w;
2226
        this.input = input;
2274
        this.input = input;
2275
        
2276
        InputMonitor.init();
2227
2277
2228
        // Create presentation.
2278
        // Create presentation.
2229
        createClientComposite();
2279
        createClientComposite();
Lines 3538-3543 Link Here
3538
        return showView(viewID, null, VIEW_ACTIVATE);
3588
        return showView(viewID, null, VIEW_ACTIVATE);
3539
    }
3589
    }
3540
3590
3591
    private boolean isGrabFocusDisabled() {
3592
        return WorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(
3593
                IPreferenceConstants.NEVER_STEAL_FOCUS);
3594
    }
3595
3541
    /*
3596
    /*
3542
     * (non-Javadoc)
3597
     * (non-Javadoc)
3543
     * 
3598
     * 
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java (-1 / +22 lines)
Lines 54-59 Link Here
54
    private Button openAfterDelayButton;
54
    private Button openAfterDelayButton;
55
55
56
    private Button showUserDialogButton;
56
    private Button showUserDialogButton;
57
    
58
    private Button neverStealFocusButton;
57
59
58
    private boolean openOnSingleClick;
60
    private boolean openOnSingleClick;
59
61
Lines 93-98 Link Here
93
     */
95
     */
94
	protected void createButtons(Composite composite) {
96
	protected void createButtons(Composite composite) {
95
		createShowUserDialogPref(composite);
97
		createShowUserDialogPref(composite);
98
		createNoStealFocusPref(composite);
96
        createStickyCyclePref(composite);
99
        createStickyCyclePref(composite);
97
        createHeapStatusPref(composite);
100
        createHeapStatusPref(composite);
98
	}
101
	}
Lines 110-116 Link Here
110
                .getPreferenceStore().getBoolean(
113
                .getPreferenceStore().getBoolean(
111
                        IPreferenceConstants.RUN_IN_BACKGROUND));
114
                        IPreferenceConstants.RUN_IN_BACKGROUND));
112
    }
115
    }
113
    
116
117
    /**
118
     * Create the widget for the user dialog preference.
119
     * 
120
     * @param composite
121
     */
122
    protected void createNoStealFocusPref(Composite composite) {
123
        neverStealFocusButton = new Button(composite, SWT.CHECK);
124
        neverStealFocusButton.setText(WorkbenchMessages.WorkbenchPreference_NeverStealFocus);
125
        neverStealFocusButton.setToolTipText(WorkbenchMessages.WorkbenchPreference_NeverStealFocusTooltip);
126
        neverStealFocusButton.setSelection(WorkbenchPlugin.getDefault()
127
                .getPreferenceStore().getBoolean(
128
                        IPreferenceConstants.NEVER_STEAL_FOCUS));
129
    }
130
114
    /**
131
    /**
115
     * Create the widget for the heap status preference.
132
     * Create the widget for the heap status preference.
116
     * 
133
     * 
Lines 337-342 Link Here
337
                IPreferenceConstants.RUN_IN_BACKGROUND));
354
                IPreferenceConstants.RUN_IN_BACKGROUND));
338
        showHeapStatusButton.setSelection(PrefUtil.getAPIPreferenceStore().getDefaultBoolean(
355
        showHeapStatusButton.setSelection(PrefUtil.getAPIPreferenceStore().getDefaultBoolean(
339
                IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR));
356
                IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR));
357
        neverStealFocusButton.setSelection(store.getDefaultBoolean(
358
        		IPreferenceConstants.NEVER_STEAL_FOCUS));
340
		
359
		
341
        super.performDefaults();
360
        super.performDefaults();
342
    }
361
    }
Lines 358-363 Link Here
358
                showUserDialogButton.getSelection());
377
                showUserDialogButton.getSelection());
359
        PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, showHeapStatusButton.getSelection());
378
        PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, showHeapStatusButton.getSelection());
360
        updateHeapStatus(showHeapStatusButton.getSelection());
379
        updateHeapStatus(showHeapStatusButton.getSelection());
380
        store.setValue(IPreferenceConstants.NEVER_STEAL_FOCUS,
381
        		neverStealFocusButton.getSelection());
361
        
382
        
362
        int singleClickMethod = openOnSingleClick ? OpenStrategy.SINGLE_CLICK
383
        int singleClickMethod = openOnSingleClick ? OpenStrategy.SINGLE_CLICK
363
                : OpenStrategy.DOUBLE_CLICK;
384
                : OpenStrategy.DOUBLE_CLICK;
(-)Eclipse (+144 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.swt.widgets.Event;
17
import org.eclipse.swt.widgets.Listener;
18
19
/**
20
 * This class monitors an SWT display and attempts to determine if the display
21
 * is currently reacting to user input. This can be used to disable certain
22
 * APIs (for example, APIs that steal focus or change the workbench layout)
23
 * when they are called from an *syncExec.
24
 * 
25
 * @since 3.2
26
 */
27
public class InputMonitor {
28
	private Display display;
29
	
30
	private int[] eventIds = {
31
			SWT.KeyDown,
32
			SWT.KeyUp,
33
			SWT.MouseDown,
34
			SWT.MouseUp,
35
			SWT.MouseDoubleClick,
36
			SWT.Selection,
37
			SWT.MenuDetect,
38
			SWT.DragDetect
39
	};
40
41
	private boolean enabled = false;
42
	private boolean filterAdded = false;
43
	
44
	private Listener listener = new Listener() {
45
		public void handleEvent(Event event) {
46
			enableInput();
47
		}
48
	};
49
50
	private Runnable disabler = new Runnable() {
51
		public void run() {
52
			enabled = false;
53
			addFilter();
54
		}
55
	};
56
	
57
	/**
58
	 * Returns true iff the Display for the current thread is currently
59
	 * processing a user input event. Must be called in the UI thread.
60
	 * 
61
	 * @return true iff the Display for the current thread is currently
62
	 * processing a user input event. 
63
	 */
64
	public static boolean isProcessingUserInput() {
65
		return getMonitor(Display.getCurrent()).checkIsProcessingUserInput();
66
	}
67
	
68
	/**
69
	 * Ensures that the input monitor for the current thread is initialized.
70
	 * Multiple calls to this method in the same thread are ignored.
71
	 */
72
	public static void init() {
73
		getMonitor(Display.getCurrent());
74
	}
75
	
76
	/**
77
	 * Returns a InputMonitor for the given display. Sucessive calls
78
	 * will return the same object instance.
79
	 * 
80
	 * @param d
81
	 * @return
82
	 */
83
	public static InputMonitor getMonitor(Display d) {
84
		String key = InputMonitor.class.getName();
85
		Object mon = d.getData(key);
86
		
87
		if (mon != null && mon instanceof InputMonitor) {
88
			return (InputMonitor) mon;
89
		}
90
		
91
		InputMonitor newMonitor = new InputMonitor(d);
92
		
93
		d.setData(key, newMonitor);
94
		
95
		return newMonitor;
96
	}
97
	
98
	public InputMonitor(Display d) {
99
		this.display = d;
100
		
101
		addFilter();
102
	}
103
104
	private void addFilter() {
105
		if (filterAdded) {
106
			return;
107
		}
108
		filterAdded = true;
109
		
110
		for (int i = 0; i < eventIds.length; i++) {
111
			int id = eventIds[i];
112
			
113
			display.addFilter(id, listener );
114
		}
115
	}
116
117
	public boolean checkIsProcessingUserInput() {
118
		return enabled;
119
	}
120
	
121
	public void dispose() {
122
		removeFilter();		
123
	}
124
125
	private void removeFilter() {
126
		if (!filterAdded) {
127
			return;
128
		}
129
		filterAdded = false;
130
		
131
		for (int i = 0; i < eventIds.length; i++) {
132
			int id = eventIds[i];
133
			
134
			display.removeFilter(id, listener);
135
		}
136
	}
137
	
138
	protected void enableInput() {
139
		if (enabled) return;
140
		enabled = true;
141
		removeFilter();
142
		display.asyncExec(disabler);
143
	}
144
}

Return to bug 85608