Commands

Topics: CAB & Smart Client Software Factory
Aug 17, 2005 at 10:31 PM
originally posted by: primozs

<CommandHandler("ShowCalendar")> _
Public Sub ShowCalendarHandler(ByVal sender As Object, ByVal e As EventArgs)
End Sub

<CommandStatus("Connect")> _
Public Sub ConnectStatus(ByVal sender As Object, ByVal e As CommandStatusEventArgs)
e.Enabled = showConnectEnabled
e.Visible = showConnectVisible
End Sub

Hello,
1. how can i access something else then youst ebabled or visible.
2.I want to store some other info. with item or command
3.how can i acces items with some info in tag

Thanks for reply!
Primoz
Aug 17, 2005 at 10:41 PM
originally posted by: primozs

I forgot a question.

<CommandHandler("ShowCalendar")> _
Public Sub ShowCalendarHandler(ByVal sender As Object, ByVal e As EventArgs)
End Sub

1.could i use i sender to get somethin?
2.to what should i cast it

Primoz
Aug 18, 2005 at 12:26 AM
originally posted by: primozs

'in controller class
Private leftMenuCommandMap As New CommandMap

<CommandHandler("ViewGridData")> _
Public Sub ViewGridDataHandler(ByVal sender As Object, ByVal e As EventArgs)
Dim c As Command
c = My.Application.Host.DefaultWorkItem.GetService(Of ICommandService)().Item("ViewGridData")

Dim ur As Uri
For Each mapping As Mapping In leftMenuCommandMap.Mapping
If mapping.CommandName = "ViewGridData" Then
ur = New Uri(mapping.ElementURI)
End If
Next

Dim i As Integer
i = CType(My.Application.Host.DefaultWorkItem.GetService(Of IUIElementService)().GetElement(ur), ToolStripItem).Tag
MsgBox("dfdsf: " + CStr(i))
End Sub

This is working but the problem is that i have a multiple commands with same command name and different uri:
Question:
How do i find out which uri belongs to the command that fired the function:

<CommandHandler("ViewGridData")> _
Public Sub ViewGridDataHandler(ByVal sender As Object, ByVal e As EventArgs)

End Sub

And when i get the element back: what kind of type is it: toolstripitem, menustripitem, treeviewnode... a, this i coud now from uri, so How to get appropriate uri??

My.Application.Host.DefaultWorkItem.GetService(Of IUIElementService)().GetElement(uri)
Aug 19, 2005 at 1:56 AM
originally posted by: primozs

mybe the question is stupid but, i want to GET something to DO something else. All the examples of commands i saw youst do something. I read about command arguments today in hands on lab. Does that mean that i have to write custom Toolstrip and MenuStrip element manager to have custom event args?
Is there an easy way to get the item that fired the event?
Please!!
Primoz
Aug 19, 2005 at 9:54 PM
originally posted by: primozs

To conclude my comunication here it was a stupid question.

<CommandHandler("ViewGridData")> _
Public Sub ViewGridDataHandler(ByVal sender As Object, ByVal e As EventArgs)
Dim u As ToolStripButton = CType(sender, ToolStripButton)
MsgBox("dfdsf: " + CStr(CType(u.Tag, MenuEventArgs).m_menuAction))
End Sub
Aug 20, 2005 at 9:27 AM
originally posted by: krijn

About your question :

How do i find out which uri belongs to the command that fired the function ?

=>

CommandService uses the EventBroker by publishing two EventHandlers for each Command :
1. The CommandHandler : published in EventBroker as 'cmd://' + CommandName
2. The CommandStatusHandler : published in EventBroker as 'qry://' + CommandName

Every item that's created by a workitem (or added) is checked for CommandHandler/Status Attributes by the DependencyInspector and when found subscribed to the EventBroker 'cmd://' and 'qry://' topics.