locked
binding shortcut key to a connection tool RRS feed

  • Question

  • Hi,

    I have dsl that contains entities (DomainClass) and relations (Connector). What I want to achive is that the user can press the ctrl key and then drag a relation from one entity to another. Instead of first selecting the Relation tool from the toolbox.

    Can someone help me with this?

    Kind regards,

    Jeffrey Opdam

     

     

    Sunday, February 27, 2011 11:15 AM

Answers

  • I invite you to copy the logic that is executed when you click on a connector tool. So, take the time to see the method OnViewMouseEnter implemented by your diagram class.

    In a partial class associated with your diagram, override the methods OnKeyDown and OnKeyUp in order to capture keyboard events and to execute expected behavior.

    Below, a code example based on the minimal langage dsl project template.

    public partial class Language6Diagram
    {
     private bool m_control = false;
    
     public override void OnKeyDown(DiagramKeyEventArgs e)
     {
      m_control = e.Control;
      if (m_control && this.ActiveDiagramView != null)
      {
       if (this.exampleRelationshipConnectAction == null)
       {
        this.exampleRelationshipConnectAction = new ExampleRelationshipConnectAction(this);
        this.exampleRelationshipConnectAction.MouseActionDeactivated += new MouseAction.MouseActionDeactivatedEventHandler(this.OnConnectActionDeactivated);
       }
       this.SetActiveMouseAction(this.exampleRelationshipConnectAction);
      }
      base.OnKeyDown(e);
     }
    
     public override void OnKeyUp(DiagramKeyEventArgs e)
     {
      if (m_control && this.ActiveDiagramView != null)
      {
       m_control = false;
       this.SetActiveMouseAction(null);
      }
      base.OnKeyUp(e);
     }
    
     private void SetActiveMouseAction(MouseAction action)
     {
      if (this.ActiveDiagramView.ActiveMouseAction != action)
      {
       try
       {
        this.changingMouseAction = true;
        this.ActiveDiagramView.ActiveMouseAction = action;
       }
       finally
       {
        this.changingMouseAction = false;
       }
      }
     }
    }
    

    The mechanism starts when the user press the ctrl key when the diagram is selected or is focused.

    Note that you can propagate the logic to shapes, they have a reference to the diagram.

    To conclude, I would reference an article that presents an aternative solution to offer actions directly from shape : Pimp my shape.

    Rgds,

    Pascal. 


    http://www.netfxfactory.org/
    Sunday, February 27, 2011 10:10 PM

All replies

  • I invite you to copy the logic that is executed when you click on a connector tool. So, take the time to see the method OnViewMouseEnter implemented by your diagram class.

    In a partial class associated with your diagram, override the methods OnKeyDown and OnKeyUp in order to capture keyboard events and to execute expected behavior.

    Below, a code example based on the minimal langage dsl project template.

    public partial class Language6Diagram
    {
     private bool m_control = false;
    
     public override void OnKeyDown(DiagramKeyEventArgs e)
     {
      m_control = e.Control;
      if (m_control && this.ActiveDiagramView != null)
      {
       if (this.exampleRelationshipConnectAction == null)
       {
        this.exampleRelationshipConnectAction = new ExampleRelationshipConnectAction(this);
        this.exampleRelationshipConnectAction.MouseActionDeactivated += new MouseAction.MouseActionDeactivatedEventHandler(this.OnConnectActionDeactivated);
       }
       this.SetActiveMouseAction(this.exampleRelationshipConnectAction);
      }
      base.OnKeyDown(e);
     }
    
     public override void OnKeyUp(DiagramKeyEventArgs e)
     {
      if (m_control && this.ActiveDiagramView != null)
      {
       m_control = false;
       this.SetActiveMouseAction(null);
      }
      base.OnKeyUp(e);
     }
    
     private void SetActiveMouseAction(MouseAction action)
     {
      if (this.ActiveDiagramView.ActiveMouseAction != action)
      {
       try
       {
        this.changingMouseAction = true;
        this.ActiveDiagramView.ActiveMouseAction = action;
       }
       finally
       {
        this.changingMouseAction = false;
       }
      }
     }
    }
    

    The mechanism starts when the user press the ctrl key when the diagram is selected or is focused.

    Note that you can propagate the logic to shapes, they have a reference to the diagram.

    To conclude, I would reference an article that presents an aternative solution to offer actions directly from shape : Pimp my shape.

    Rgds,

    Pascal. 


    http://www.netfxfactory.org/
    Sunday, February 27, 2011 10:10 PM
  • Thank you, this is exactly what I needed.
    Monday, February 28, 2011 11:31 PM