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

(-)Eclipse UI/org/eclipse/ui/internal/IPreferenceConstants.java (+7 lines)
Lines 200-203 Link Here
200
     * @since 3.0
200
     * @since 3.0
201
     */
201
     */
202
    public static final String SHOULD_PROMPT_FOR_ENABLEMENT = "shouldPromptForEnablement"; //$NON-NLS-1$
202
    public static final String SHOULD_PROMPT_FOR_ENABLEMENT = "shouldPromptForEnablement"; //$NON-NLS-1$
203
204
    /**
205
     * Prevents views and editors from moving to the foreground automatically.
206
     * 
207
     * @since 3.2
208
     */
209
	public static final String NEVER_STEAL_FOCUS = "NEVER_STEAL_FOCUS"; //$NON-NLS-1$
203
}
210
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java (+6 lines)
Lines 902-905 Link Here
902
    public static String FastViewBar_show_view;
902
    public static String FastViewBar_show_view;
903
903
904
904
905
	public static String WorkbenchPreference_NeverStealFocus;
906
907
908
	public static String WorkbenchPreference_NeverStealFocusTooltip;
909
910
905
}
911
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-1 / +58 lines)
Lines 102-107 Link Here
102
import org.eclipse.ui.model.IWorkbenchAdapter;
102
import org.eclipse.ui.model.IWorkbenchAdapter;
103
import org.eclipse.ui.part.MultiEditor;
103
import org.eclipse.ui.part.MultiEditor;
104
import org.eclipse.ui.presentations.IStackPresentationSite;
104
import org.eclipse.ui.presentations.IStackPresentationSite;
105
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
105
import org.eclipse.ui.views.IStickyViewDescriptor;
106
import org.eclipse.ui.views.IStickyViewDescriptor;
106
import org.eclipse.ui.views.IViewRegistry;
107
import org.eclipse.ui.views.IViewRegistry;
107
108
Lines 547-552 Link Here
547
        if (window.isClosing())
548
        if (window.isClosing())
548
            return;
549
            return;
549
550
551
    	// There is a preference to prevent background threads from activating views or bringing
552
    	// them to the top. If the user has set this preference, just bold the tab whenever
553
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
554
    	
555
    	if (composite != null && composite.isVisible() && isGrabFocusDisabled() && !InputMonitor.isProcessingUserInput()) {
556
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
557
    		
558
    		// Bold the tab if possible
559
    		if (progressService != null) {
560
    			progressService.warnOfContentChange();
561
    		}
562
    		
563
    		// And exit to ensure we don't mess with activation or layout
564
    		return;
565
    	}
566
        
550
        // If zoomed, unzoom.
567
        // If zoomed, unzoom.
551
        zoomOutIfNecessary(part);
568
        zoomOutIfNecessary(part);
552
569
Lines 751-756 Link Here
751
        if (persp == null || !certifyPart(part))
768
        if (persp == null || !certifyPart(part))
752
            return;
769
            return;
753
770
771
    	// There is a preference to prevent background threads from activating views or bringing
772
    	// them to the top. If the user has set this preference, just bold the tab whenever
773
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
774
    	
775
    	if (isGrabFocusDisabled() && !InputMonitor.isProcessingUserInput()) {
776
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
777
    		
778
    		// Bold the tab if possible
779
    		if (progressService != null) {
780
    			progressService.warnOfContentChange();
781
    		}
782
    		
783
    		// And exit to ensure we don't mess with activation or layout
784
    		return;
785
    	}
786
        
754
        String label = null; // debugging only
787
        String label = null; // debugging only
755
        if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) {
788
        if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) {
756
            label = part != null ? part.getTitle() : "none"; //$NON-NLS-1$
789
            label = part != null ? part.getTitle() : "none"; //$NON-NLS-1$
Lines 927-932 Link Here
927
     */
960
     */
928
    private IViewPart busyShowView(String viewID, String secondaryID, int mode)
961
    private IViewPart busyShowView(String viewID, String secondaryID, int mode)
929
            throws PartInitException {
962
            throws PartInitException {
963
    	
930
        Perspective persp = getActivePerspective();
964
        Perspective persp = getActivePerspective();
931
        if (persp == null)
965
        if (persp == null)
932
            return null;
966
            return null;
Lines 962-967 Link Here
962
     * Performs showing of the view in the given mode.
996
     * Performs showing of the view in the given mode.
963
     */
997
     */
964
    private void busyShowView(IViewPart part, int mode) {
998
    private void busyShowView(IViewPart part, int mode) {
999
1000
    	// There is a preference to prevent background threads from activating views or bringing
1001
    	// them to the top. If the user has set this preference, just bold the tab whenever
1002
    	// a background thread tries to use VIEW_VISIBLE or VIEW_ACTIVATE
1003
    	
1004
    	if (isGrabFocusDisabled() && mode != VIEW_CREATE && !InputMonitor.isProcessingUserInput()) {
1005
    		IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService)part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
1006
    		
1007
    		// Bold the tab if possible
1008
    		if (progressService != null) {
1009
    			progressService.warnOfContentChange();
1010
    		}
1011
    		
1012
    		// And exit to ensure we don't mess with activation or layout
1013
    		return;
1014
    	}
1015
    	
965
        if (mode == VIEW_ACTIVATE)
1016
        if (mode == VIEW_ACTIVATE)
966
            activate(part);
1017
            activate(part);
967
        else if (mode == VIEW_VISIBLE) {
1018
        else if (mode == VIEW_VISIBLE) {
Lines 2061-2066 Link Here
2061
        this.window = w;
2112
        this.window = w;
2062
        this.input = input;
2113
        this.input = input;
2063
2114
2115
        InputMonitor.init();
2064
        // Create presentation.
2116
        // Create presentation.
2065
        createClientComposite();
2117
        createClientComposite();
2066
        editorPresentation = new EditorAreaHelper(this);
2118
        editorPresentation = new EditorAreaHelper(this);
Lines 3214-3219 Link Here
3214
        return showView(viewID, null, VIEW_ACTIVATE);
3266
        return showView(viewID, null, VIEW_ACTIVATE);
3215
    }
3267
    }
3216
3268
3269
    private boolean isGrabFocusDisabled() {
3270
        return WorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(
3271
                IPreferenceConstants.NEVER_STEAL_FOCUS);
3272
    }
3273
    
3217
    /*
3274
    /*
3218
     * (non-Javadoc)
3275
     * (non-Javadoc)
3219
     * 
3276
     * 
Lines 3222-3228 Link Here
3222
     */
3279
     */
3223
    public IViewPart showView(final String viewID, final String secondaryID,
3280
    public IViewPart showView(final String viewID, final String secondaryID,
3224
            final int mode) throws PartInitException {
3281
            final int mode) throws PartInitException {
3225
3282
    	
3226
        if (secondaryID != null) {
3283
        if (secondaryID != null) {
3227
            if (secondaryID.length() == 0
3284
            if (secondaryID.length() == 0
3228
                    || secondaryID.indexOf(ViewFactory.ID_SEP) != -1)
3285
                    || secondaryID.indexOf(ViewFactory.ID_SEP) != -1)
(-)Eclipse UI/org/eclipse/ui/internal/messages.properties (+2 lines)
Lines 348-353 Link Here
348
WorkbenchPreference_stickyCycleButton = Keep &next/previous part dialog open
348
WorkbenchPreference_stickyCycleButton = Keep &next/previous part dialog open
349
WorkbenchPreference_RunInBackgroundButton=Always r&un in background
349
WorkbenchPreference_RunInBackgroundButton=Always r&un in background
350
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
350
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
351
WorkbenchPreference_NeverStealFocus=Never steal focus
352
WorkbenchPreference_NeverStealFocusTooltip=Prevents views and editors from opening automatically
351
WorkbenchPreference_HeapStatusButton = Sho&w Heap Status
353
WorkbenchPreference_HeapStatusButton = Sho&w Heap Status
352
WorkbenchPreference_HeapStatusButtonToolTip = Show the Heap Status area on the bottom of the window
354
WorkbenchPreference_HeapStatusButtonToolTip = Show the Heap Status area on the bottom of the window
353
      
355
      
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/WorkbenchPreferencePage.java (+21 lines)
Lines 55-60 Link Here
55
55
56
    private Button showUserDialogButton;
56
    private Button showUserDialogButton;
57
57
58
	private Button neverStealFocusButton;
59
    
58
    private boolean openOnSingleClick;
60
    private boolean openOnSingleClick;
59
61
60
    private boolean selectOnHover;
62
    private boolean selectOnHover;
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 126-131 Link Here
126
    }
129
    }
127
130
128
    /**
131
    /**
132
     * Create the widget for the user dialog preference.
133
     * 
134
     * @param composite
135
     */
136
    protected void createNoStealFocusPref(Composite composite) {
137
        neverStealFocusButton = new Button(composite, SWT.CHECK);
138
        neverStealFocusButton.setText(WorkbenchMessages.WorkbenchPreference_NeverStealFocus);
139
        neverStealFocusButton.setToolTipText(WorkbenchMessages.WorkbenchPreference_NeverStealFocusTooltip);
140
        neverStealFocusButton.setSelection(WorkbenchPlugin.getDefault()
141
                .getPreferenceStore().getBoolean(
142
                        IPreferenceConstants.NEVER_STEAL_FOCUS));
143
    }
144
    
145
    /**
129
     * Creates the composite which will contain all the preference controls for
146
     * Creates the composite which will contain all the preference controls for
130
     * this page.
147
     * this page.
131
     * 
148
     * 
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 356-361 Link Here
356
        store.setValue(IPreferenceConstants.OPEN_AFTER_DELAY, openAfterDelay);
375
        store.setValue(IPreferenceConstants.OPEN_AFTER_DELAY, openAfterDelay);
357
        store.setValue(IPreferenceConstants.RUN_IN_BACKGROUND,
376
        store.setValue(IPreferenceConstants.RUN_IN_BACKGROUND,
358
                showUserDialogButton.getSelection());
377
                showUserDialogButton.getSelection());
378
        store.setValue(IPreferenceConstants.NEVER_STEAL_FOCUS,
379
        		neverStealFocusButton.getSelection());
359
        PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, showHeapStatusButton.getSelection());
380
        PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, showHeapStatusButton.getSelection());
360
        updateHeapStatus(showHeapStatusButton.getSelection());
381
        updateHeapStatus(showHeapStatusButton.getSelection());
361
        
382
        
(-)Eclipse (+133 lines)
Added Link Here
1
package org.eclipse.ui.internal;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.widgets.Display;
5
import org.eclipse.swt.widgets.Event;
6
import org.eclipse.swt.widgets.Listener;
7
8
/**
9
 * This class monitors an SWT display and attempts to determine if the display
10
 * is currently reacting to user input. This can be used to disable certain
11
 * APIs (for example, APIs that steal focus or change the workbench layout)
12
 * when they are called from an *syncExec.
13
 * 
14
 * @since 3.2
15
 */
16
public class InputMonitor {
17
	private Display display;
18
	
19
	private int[] eventIds = {
20
			SWT.KeyDown,
21
			SWT.KeyUp,
22
			SWT.MouseDown,
23
			SWT.MouseUp,
24
			SWT.MouseDoubleClick,
25
			SWT.Selection,
26
			SWT.MenuDetect,
27
			SWT.DragDetect
28
	};
29
30
	private boolean enabled = false;
31
	private boolean filterAdded = false;
32
	
33
	private Listener listener = new Listener() {
34
		public void handleEvent(Event event) {
35
			enableInput();
36
		}
37
	};
38
39
	private Runnable disabler = new Runnable() {
40
		public void run() {
41
			enabled = false;
42
			addFilter();
43
		}
44
	};
45
	
46
	/**
47
	 * Returns true iff the Display for the current thread is currently
48
	 * processing a user input event. Must be called in the UI thread.
49
	 * 
50
	 * @return true iff the Display for the current thread is currently
51
	 * processing a user input event. 
52
	 */
53
	public static boolean isProcessingUserInput() {
54
		return getMonitor(Display.getCurrent()).checkIsProcessingUserInput();
55
	}
56
	
57
	/**
58
	 * Ensures that the input monitor for the current thread is initialized.
59
	 * Multiple calls to this method in the same thread are ignored.
60
	 */
61
	public static void init() {
62
		getMonitor(Display.getCurrent());
63
	}
64
	
65
	/**
66
	 * Returns a InputMonitor for the given display. Sucessive calls
67
	 * will return the same object instance.
68
	 * 
69
	 * @param d
70
	 * @return
71
	 */
72
	public static InputMonitor getMonitor(Display d) {
73
		String key = InputMonitor.class.getName();
74
		Object mon = d.getData(key);
75
		
76
		if (mon != null && mon instanceof InputMonitor) {
77
			return (InputMonitor) mon;
78
		}
79
		
80
		InputMonitor newMonitor = new InputMonitor(d);
81
		
82
		d.setData(key, newMonitor);
83
		
84
		return newMonitor;
85
	}
86
	
87
	public InputMonitor(Display d) {
88
		this.display = d;
89
		
90
		addFilter();
91
	}
92
93
	private void addFilter() {
94
		if (filterAdded) {
95
			return;
96
		}
97
		filterAdded = true;
98
		
99
		for (int i = 0; i < eventIds.length; i++) {
100
			int id = eventIds[i];
101
			
102
			display.addFilter(id, listener );
103
		}
104
	}
105
106
	public boolean checkIsProcessingUserInput() {
107
		return enabled;
108
	}
109
	
110
	public void dispose() {
111
		removeFilter();		
112
	}
113
114
	private void removeFilter() {
115
		if (!filterAdded) {
116
			return;
117
		}
118
		filterAdded = false;
119
		
120
		for (int i = 0; i < eventIds.length; i++) {
121
			int id = eventIds[i];
122
			
123
			display.removeFilter(id, listener);
124
		}
125
	}
126
	
127
	protected void enableInput() {
128
		if (enabled) return;
129
		enabled = true;
130
		removeFilter();
131
		display.asyncExec(disabler);
132
	}
133
}

Return to bug 85608