Community
Participate
Working Groups
Hi, the selection state of org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction and org.eclipse.gef.ui.actions.ToggleGridAction does not seem to be in sync with the corresponding setting, when these actions are used in a menubar or toolbar. I guess, there is a problem with the isChecked() method, which is overwritten from org.eclipse.jface.action.Action! Cheers Sven
I agree. When I add ToggleSnapToGeometryAction to another place in the UI (e.g. into a context menu or toolbar), behaviour gets totally confused: checkmarks not consistent with each other and with the internal graphicalViewer state. Basically, the implementation of run() is incorrect: public void run() { diagramViewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(!isChecked())); } This never calls setChecked() on the action, which means the ActionContributionItems which control the menu and toolbar items won't get notified about the state change, and the checked state of other menu items won't get updated. setChecked() must be called because that' what fires the property change that causes ActionContributionItems to update themselves. The fix: run() method must call setChecked(): private void setSnapEnabled(boolean enabled) { diagramViewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(enabled)); } @Override public void run() { setSnapEnabled(!isSnapEnabled()); setChecked(isSnapEnabled()); }
Created attachment 238065 [details] Patch to track checked status correctly The problem is not that run needs to call setChecked, it's that setChecked should be responsible for setting the appropriate state of the viewer. The attached patch fixes ToggleSnapToGeometryAction, ToggleGridAction, and ToggleRulerVisibilityAction.