TCF Debugger: add new option to the reset dropdown button

Add new option "Suspend after reset" to the reset menu to allow
the target to suspend after reset is asserted.

Change-Id: Ibcc2aa14e8c3053683f410cbb7bca454db1097c6
Signed-off-by: Sanimir Agovic <sanimir@subpath.org>
diff --git a/plugins/org.eclipse.tcf.debug.ui/plugin.xml b/plugins/org.eclipse.tcf.debug.ui/plugin.xml
index ae5c793..56c0dc0 100644
--- a/plugins/org.eclipse.tcf.debug.ui/plugin.xml
+++ b/plugins/org.eclipse.tcf.debug.ui/plugin.xml
@@ -398,6 +398,16 @@
                optional="true">
          </commandParameter>
       </command>
+      <command
+            categoryId="org.eclipse.tcf.debug.ui.commands"
+            defaultHandler="org.eclipse.tcf.internal.debug.ui.commands.ToggleSuspendAfterResetHandler"
+            id="org.eclipse.tcf.debug.ui.commands.toggleSuspendAfterReset"
+            name="Suspend after reset">
+         <state
+               class="org.eclipse.ui.handlers.RegistryToggleState"
+               id="org.eclipse.ui.commands.toggleState">
+         </state>
+      </command>
    </extension>
 
    <extension point="org.eclipse.ui.handlers">
@@ -790,6 +800,15 @@
                class="org.eclipse.tcf.internal.debug.ui.commands.ResetMenu"
                id="org.eclipse.tcf.debug.ui.menu.dynamic">
          </dynamic>
+         <separator
+               name="group.reset"
+               visible="true">
+         </separator>
+         <command
+               commandId="org.eclipse.tcf.debug.ui.commands.toggleSuspendAfterReset"
+               label="Suspend after reset"
+               style="toggle">
+         </command>
       </menuContribution>
    </extension>
 
diff --git a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ResetHandler.java b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ResetHandler.java
index add7eeb..7a411f6 100644
--- a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ResetHandler.java
+++ b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ResetHandler.java
@@ -8,6 +8,7 @@
 package org.eclipse.tcf.internal.debug.ui.commands;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.eclipse.core.commands.AbstractHandler;
@@ -18,6 +19,7 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.tcf.internal.debug.ui.model.TCFNode;
 import org.eclipse.tcf.internal.debug.ui.model.TCFNodeExecContext;
+import org.eclipse.tcf.internal.debug.ui.preferences.TCFPreferences;
 import org.eclipse.tcf.services.IContextReset;
 import org.eclipse.tcf.util.TCFDataCache;
 import org.eclipse.tcf.util.TCFTask;
@@ -59,7 +61,10 @@
                         TCFNodeExecContext exec = (TCFNodeExecContext)node;
                         String type = event.getParameter("org.eclipse.tcf.debug.ui.commands.reset.param.type");
                         if (type == null) type = getDefaultResetType(exec);
-                        exec.reset(type, null);
+                        boolean suspend = exec.getModel().getSuspendAfterReset();
+                        Map<String, Object> params = new HashMap<String, Object>();
+                        if (suspend) params.put(IContextReset.PARAM_SUSPEND, true);
+                        exec.reset(type, params);
                         break;
                     }
                     node = node.getParent();
diff --git a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ToggleSuspendAfterResetHandler.java b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ToggleSuspendAfterResetHandler.java
new file mode 100644
index 0000000..f65fd20
--- /dev/null
+++ b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/commands/ToggleSuspendAfterResetHandler.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2019.
+ * 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
+ *******************************************************************************/
+package org.eclipse.tcf.internal.debug.ui.commands;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.tcf.internal.debug.ui.preferences.TCFPreferences;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+
+public class ToggleSuspendAfterResetHandler extends AbstractHandler implements IElementUpdater {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        boolean state = !HandlerUtil.toggleCommandState(event.getCommand());
+        TCFPreferences.getPreferenceStore().setValue(TCFPreferences.PREF_SUSPEND_AFTER_RESET, state);
+        return null;
+    }
+
+    @Override
+    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
+        element.setChecked(TCFPreferences.getPreferenceStore().getBoolean(TCFPreferences.PREF_SUSPEND_AFTER_RESET));
+    }
+}
diff --git a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/TCFModel.java b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/TCFModel.java
index 26e938b..08934ab 100644
--- a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/TCFModel.java
+++ b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/model/TCFModel.java
@@ -246,6 +246,7 @@
     private boolean hover_while_running;
     private boolean qualified_type_names_enabled;
     private boolean filter_variants_by_discriminant;
+    private boolean suspend_after_reset;
 
     private final Map<String,String> action_results = new HashMap<String,String>();
     private final HashMap<String,TCFAction> active_actions = new HashMap<String,TCFAction>();
@@ -772,6 +773,7 @@
             hover_while_running = prefs_store.getBoolean(TCFPreferences.PREF_HOVER_WHILE_RUNNING);
             qualified_type_names_enabled = prefs_store.getBoolean(TCFPreferences.PREF_SHOW_QUALIFIED_TYPE_NAMES);
             filter_variants_by_discriminant = prefs_store.getBoolean(TCFPreferences.PREF_FILTER_VARIANTS_BY_DISCRIMINANT);
+            suspend_after_reset = prefs_store.getBoolean(TCFPreferences.PREF_SUSPEND_AFTER_RESET);
             final boolean affectsExpressionsOnly = event != null && (
                     TCFPreferences.PREF_SHOW_QUALIFIED_TYPE_NAMES.equals(event.getProperty()) ||
                     TCFPreferences.PREF_FILTER_VARIANTS_BY_DISCRIMINANT.equals(event.getProperty()));
@@ -1130,6 +1132,10 @@
         return hover_while_running;
     }
 
+    public boolean getSuspendAfterReset() {
+        return suspend_after_reset;
+    }
+
     void onProxyInstalled(TCFModelProxy mp) {
         IPresentationContext pc = mp.getPresentationContext();
         model_proxies.add(mp);
diff --git a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/preferences/TCFPreferences.java b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/preferences/TCFPreferences.java
index f21f973..e14fd47 100644
--- a/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/preferences/TCFPreferences.java
+++ b/plugins/org.eclipse.tcf.debug.ui/src/org/eclipse/tcf/internal/debug/ui/preferences/TCFPreferences.java
@@ -32,7 +32,8 @@
         PREF_FULL_ERROR_REPORTS = "FullErrorReports",
         PREF_HOVER_WHILE_RUNNING = "HoverWhileRunning",
         PREF_SHOW_QUALIFIED_TYPE_NAMES = "ShowQualifiedTypeNames",
-        PREF_FILTER_VARIANTS_BY_DISCRIMINANT = "FilterVariantsByDiscriminant";
+        PREF_FILTER_VARIANTS_BY_DISCRIMINANT = "FilterVariantsByDiscriminant",
+        PREF_SUSPEND_AFTER_RESET = "SuspendAfterReset";
 
     public static IPreferenceStore getPreferenceStore() {
         return Activator.getDefault().getPreferenceStore();