Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344309

Summary: [diagram] Support turning on/off grid in the diagram in the definition language
Product: z_Archived Reporter: Shenxue Zhou <shenxue.zhou>
Component: SapphireAssignee: Shenxue Zhou <shenxue.zhou>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: gregory.amerson, konstantin, ram.venkataswamy
Version: unspecifiedKeywords: usability
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Shenxue Zhou CLA 2011-04-29 12:24:49 EDT
For some editors, grid adds noise to them and users would prefer to turn off the grid. Let's support the switch the grid in the diagram definition language and the default state for the switch should be off.
Comment 1 Konstantin Komissarchik CLA 2011-04-29 13:02:32 EDT
In sdef, let's have an implied element property for grid definition, with a single visible boolean inside it. In the future, we will likely want to add settings for spacing, color, etc. This will gives us place to do so.

<grid>
  <visible>true</visible>
</grid>

I am fine with defaulting visible to false. Make sure that when grid is not visible, that there is no snap-to-grid either.

Once we have support for actions, I'd like to see a grid visibility toggle in the editor context menu. The grid definition settings in sdef should be treated as initial values that user can change.
Comment 2 Shenxue Zhou CLA 2011-05-26 12:29:00 EDT
The grid property has been added to the diagram page definition. This feature works as the following:

1. In diagram page def, user can specify whether grid is shown using 
<grid>
  <visible>true</visible>
</grid>

under <diagram-page> element. Its default value is "false".

2. A Grid toggle action has been added to the diagram context menu.

3. When user toggles the grid using the above action, the diagram editor is marked "dirty" and the grid visibility is saved in diagram layout file.

4. When a diagram is created, the grid visibility is controlled by the grid visible element as described in 1.

5. When a diagram is opened, the grid visibility is controlled by what's persisted in the diagram layout file.
Comment 3 Greg Amerson CLA 2011-05-26 15:53:10 EDT
Verified this with the latest build.  One question I had.  Should we add a "View > Show Grid" checkbox option in the global menu bar that is only visible when the diagram editor is focused?
Comment 4 Shenxue Zhou CLA 2011-05-26 16:29:16 EDT
(In reply to comment #3)
> Verified this with the latest build.  One question I had.  Should we add a
> "View > Show Grid" checkbox option in the global menu bar that is only visible
> when the diagram editor is focused?

Yes we should. Graphiti's DiagramEditorInternal class actually registers the grid action to the view menu. I didn't override that. But in the multipage sapphire diagram editor, I don't see the "view" menu. Need further investigation inside the action registry...
Comment 5 Ram Venkataswamy CLA 2011-06-01 15:17:25 EDT
verified with build 0.3.0.201105261624
Comment 6 Konstantin Komissarchik CLA 2011-06-03 15:20:54 EDT
1. The menu item should be labeled "Show Grid" rather than just "Grid".

2. Looking at the action definition, I see the type specified as "push" rather than "toggle", yet the menu action is clearly behaving like a toggle. That tells me that there is something questionable in the implementation.

3. Let's change action id from "Sapphire.Diagram.ToggleGrid" to "Sapphire.Diagram.Grid.Toggle". We may have more grid-related actions in the future, so it seems prudent to set a side a namespace.
Comment 7 Shenxue Zhou CLA 2011-06-16 18:36:01 EDT
The grid action handler has been reworked so that it doesn't require SapphireDiagramEditor to be passed in. As a result, in SapphireDiagramEditorContextMenuProvider class, no special code is required for grid action handler.
Comment 8 Konstantin Komissarchik CLA 2011-06-17 14:20:55 EDT
Found two problems during verification.

1. Item #3 from Comment #6 was not done. I took care of it.

2. There was still a reference to the toggle action remaining in the SapphireDiagramEditorContextMenuProvider. There didn't appear to be a reason for this dependency, so I removed it.

Verified functionality of the toggle and saving of the toggle state after making the above changes.

Closing.