Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b56132adc0a1c78b0c8f15ef745bd0c3d6c84b7d (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
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.launchConfigurations;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;


public class DebugModePromptStatusHandler implements IStatusHandler {
	
	/* (non-Javadoc)
	 * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
	 */
	public Object handleStatus(IStatus status, Object source) throws CoreException {
		if (source instanceof ILaunchConfiguration) {
			ILaunchConfiguration config = (ILaunchConfiguration)source;
			if (DebugUITools.isPrivate(config)) {
				return Boolean.FALSE;
			}	
		}
		
		IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
        ILaunchConfiguration configuration = (ILaunchConfiguration)source;
        String pref = store.getString(IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE); 
        if (pref != null) {
            if (pref.equals(MessageDialogWithToggle.NEVER)) {
                return Boolean.FALSE;
            } else if (pref.equals(MessageDialogWithToggle.ALWAYS)) { 
                relaunchInDebugMode(configuration);
                return Boolean.TRUE;
            }
        }
        
		Shell activeShell = DebugUIPlugin.getShell();
		String title = LaunchConfigurationsMessages.DebugModePromptStatusHandler_0; 
		String message = LaunchConfigurationsMessages.DebugModePromptStatusHandler_1; 
		
		MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(activeShell, title, message, null, false, store, IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE); 
		int buttonId = dialog.getReturnCode();
		if (buttonId == IDialogConstants.YES_ID) { 
			relaunchInDebugMode(configuration);
			return Boolean.TRUE; // stops launch
		} else if (buttonId == IDialogConstants.NO_ID) {
			return Boolean.FALSE; // continue launch
		} else { //CANCEL 
			return Boolean.TRUE; // stops the launch
		}
	}
	/**
	 * @param configuration
	 */
	private void relaunchInDebugMode(ILaunchConfiguration configuration) {
		DebugUITools.launch(configuration, ILaunchManager.DEBUG_MODE);
	}
}

Back to the top