Bug 537525 - Follow up of Bug 312397 - Run Configuration Command Line to
Clipboard

Change-Id: Idfb989cb7ff3d47c4162becea5227a7c04e975cc
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
index 3c8104b..4a2c500 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java
@@ -47,6 +47,7 @@
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ColorRegistry;
 import org.eclipse.jface.resource.JFaceResources;
@@ -1554,9 +1555,48 @@
 	 * Dialog to Show the Command line
 	 */
 	protected void handleShowCommandLinePressed() {
-		ShowCommandLineDialog dialog = new ShowCommandLineDialog(getShell(), getLaunchConfigurationDialog().getMode(),
-				fOriginal);
-		dialog.open();
+		boolean showCommandLineDialog = true;
+		if (isDirty()) {
+			int returnVal = showSaveChangesDialog();
+			if (returnVal == IDialogConstants.YES_ID) {
+				handleApplyPressed();
+			} else if (returnVal == IDialogConstants.NO_ID) {
+				handleRevertPressed();
+			} else {
+				showCommandLineDialog = false;
+			}
+		}
+		if (showCommandLineDialog) {
+			ShowCommandLineDialog dialog = new ShowCommandLineDialog(getShell(),
+					getLaunchConfigurationDialog().getMode(),
+					fWorkingCopy);
+			dialog.open();
+		}
+	}
+
+	private int showSaveChangesDialog() {
+		String message = MessageFormat.format(
+				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Question,
+				new Object[] { getWorkingCopy().getName() });
+		MessageDialog dialog = new MessageDialog(getShell(),
+				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Title, null,
+				message,
+				MessageDialog.QUESTION,
+				new String[] {
+						LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Apply,
+						LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Revert,
+						LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Cancel },
+				0);
+		int ret = dialog.open();
+		int val = IDialogConstants.CANCEL_ID;
+		if (ret == 0 || ret == 1) {
+			if (ret == 0) {
+				val = IDialogConstants.YES_ID;
+			} else {
+				val = IDialogConstants.NO_ID;
+			}
+		}
+		return val;
 	}
 
 	/**
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
index edaf3c9..cdab75d 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java
@@ -107,7 +107,13 @@
 	public static String LaunchConfigurationDialog_ShowCommandLine;
 	public static String LaunchConfigurationDialog_ShowCommandLine_Title;
 	public static String LaunchConfigurationDialog_ShowCommandLine_Copy;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Close;
 	public static String LaunchConfigurationDialog_ShowCommandLine_Default;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Title;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Question;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Apply;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Revert;
+	public static String LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Cancel;
 	public static String LaunchConfigurationSelectionDialog_0;
 	public static String LaunchConfigurationSelectionDialog_1;
 	public static String LaunchConfigurationSelectionDialog_deleteButtonLabel;
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
index 2fd2bd8..4315df2 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties
@@ -118,7 +118,13 @@
 LaunchConfigurationDialog_ShowCommandLine=Sho&w Command Line
 LaunchConfigurationDialog_ShowCommandLine_Title=Command Line
 LaunchConfigurationDialog_ShowCommandLine_Copy=C&opy && Close
+LaunchConfigurationDialog_ShowCommandLine_Close=&Close
 LaunchConfigurationDialog_ShowCommandLine_Default=Command Line could not be retrieved.
+LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Title=Apply Changes
+LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Question=The configuration "{0}" has unsaved changes.  Do you wish to apply the changes before showing command line?
+LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Apply=&Apply
+LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Revert=&Revert
+LaunchConfigurationDialog_ShowCommandLine_Apply_Revert_Cancel=&Close
 LaunchConfigurationsDialog_0=New launch configuration
 LaunchConfigurationsDialog_1=Delete selected launch configuration(s)
 LaunchConfigurationsDialog_2=New launch configuration prototype
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
index 6a4f541..542eae5 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ShowCommandLineDialog.java
@@ -73,7 +73,8 @@
 	protected void createButtonsForButtonBar(Composite parent) {
 		createButton(parent, IDialogConstants.OK_ID,
 				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Copy, true);
-		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+		createButton(parent, IDialogConstants.CANCEL_ID,
+				LaunchConfigurationsMessages.LaunchConfigurationDialog_ShowCommandLine_Close, false);
 	}
 
 	private LaunchManager getLaunchManager() {