Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle value for all BOOL variables while debugging #965

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions plugins/org.eclipse.fordiac.ide.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,23 @@
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.fordiac.ide.debug.ui.handler.ToggleBoolVariableHandler"
commandId="org.eclipse.fordiac.ide.application.commands.toggleBoolValue">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false"
operator="and">
<instanceof
value="org.eclipse.fordiac.ide.debug.EvaluatorDebugVariable">
</instanceof>
</iterate>
</with>
</activeWhen>
</handler>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Martin Erich Jobst
* Copyright (c) 2024, 2025 Martin Erich Jobst
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,7 +10,7 @@
* Contributors:
* Martin Jobst - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.fordiac.ide.deployment.debug.ui.handler;
package org.eclipse.fordiac.ide.debug.ui.handler;

import java.util.stream.Stream;

Expand All @@ -19,27 +19,28 @@
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.fordiac.ide.deployment.debug.watch.IVarDeclarationWatch;
import org.eclipse.fordiac.ide.debug.EvaluatorDebugVariable;
import org.eclipse.fordiac.ide.model.data.BoolType;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;

public class ToggleBoolWatchHandler extends AbstractHandler {
public class ToggleBoolVariableHandler extends AbstractHandler {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
getWatches(HandlerUtil.getCurrentStructuredSelection(event))
.forEachOrdered(ToggleBoolWatchHandler::toggleValue);
getVariables(HandlerUtil.getCurrentStructuredSelection(event))
.forEachOrdered(ToggleBoolVariableHandler::toggleValue);
return null;
}

private static void toggleValue(final IVarDeclarationWatch watch) {
if (watch.getInternalVariable().getType() instanceof BoolType) {
final String newValue = Boolean.parseBoolean(watch.getInternalValue().toString()) ? "FALSE" : "TRUE"; //$NON-NLS-1$ //$NON-NLS-2$
private static void toggleValue(final EvaluatorDebugVariable variable) {
if (variable.getInternalVariable().getType() instanceof BoolType) {
final String newValue = Boolean.parseBoolean(variable.getInternalVariable().getValue().toString()) ? "FALSE" //$NON-NLS-1$
: "TRUE"; //$NON-NLS-1$
try {
watch.setValue(newValue);
variable.setValue(newValue);
} catch (final DebugException e) {
ErrorDialog.openError(null, null, null, Status.error(e.getLocalizedMessage(), e));
}
Expand All @@ -50,14 +51,15 @@ private static void toggleValue(final IVarDeclarationWatch watch) {
public void setEnabled(final Object evaluationContext) {
setBaseEnabled(HandlerUtil.getVariable(evaluationContext,
ISources.ACTIVE_CURRENT_SELECTION_NAME) instanceof final IStructuredSelection selection
&& getWatches(selection).allMatch(ToggleBoolWatchHandler::isValidValue));
&& getVariables(selection).allMatch(ToggleBoolVariableHandler::isValidValue));
}

private static boolean isValidValue(final IVarDeclarationWatch watch) {
return watch.getInternalVariable().getType() instanceof BoolType;
private static boolean isValidValue(final EvaluatorDebugVariable variable) {
return variable.supportsValueModification() && variable.getInternalVariable().getType() instanceof BoolType;
}

private static Stream<IVarDeclarationWatch> getWatches(final IStructuredSelection selection) {
return selection.stream().filter(IVarDeclarationWatch.class::isInstance).map(IVarDeclarationWatch.class::cast);
private static Stream<EvaluatorDebugVariable> getVariables(final IStructuredSelection selection) {
return selection.stream().filter(EvaluatorDebugVariable.class::isInstance)
.map(EvaluatorDebugVariable.class::cast);
}
}
16 changes: 0 additions & 16 deletions plugins/org.eclipse.fordiac.ide.deployment.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,22 +512,6 @@
</with>
</activeWhen>
</handler>
<handler
class="org.eclipse.fordiac.ide.deployment.debug.ui.handler.ToggleBoolWatchHandler"
commandId="org.eclipse.fordiac.ide.application.commands.toggleBoolValue">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false"
operator="and">
<instanceof
value="org.eclipse.fordiac.ide.deployment.debug.watch.IVarDeclarationWatch">
</instanceof>
</iterate>
</with>
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
Expand Down
Loading