Bug 130728 - Selection state of ToggleSnapToGeometryAction and ToggleGridAction
Summary: Selection state of ToggleSnapToGeometryAction and ToggleGridAction
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy GEF (MVC) (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-07 07:51 EST by Sven Wende CLA
Modified: 2015-09-10 07:26 EDT (History)
1 user (show)

See Also:


Attachments
Patch to track checked status correctly (3.28 KB, patch)
2013-12-05 07:42 EST, Kevin Milburn CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Wende CLA 2006-03-07 07:51:52 EST
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
Comment 1 Andras Varga CLA 2007-08-23 04:38:35 EDT
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());
    }
Comment 2 Kevin Milburn CLA 2013-12-05 07:42:57 EST
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.