Showing posts with label Command. Show all posts
Showing posts with label Command. Show all posts

Saturday, February 14, 2015

How to create a command for a tool item with LinsUIWPF Suite


Prerequisite: Follow the link How to create a new project to create your application with LinsUIWPF Suite.

1.     Assign a unique ID, which is between FlexConstants.m_nUserDefinedControlStartID (1000) and FlexConstants.m_nUserDefinedControlStartID (10,000,000), to the CommandID property of the tool item.
<src:FlexMenuItem ID="1022" CommandID="1001" Text=”My Command” Name=”myToolItem”/>
2.     Create a class as follows,
class MyCommand : LinsUICommand
{
public MyCommand(long nCommandID, object data) base(nCommandID, data)
{
}

public override void Execute(object parameter)
{
base.Execute(parameter);
///////////////////////////////////
// Execute your command here
///////////////////////////////////
}

[CommandEventAttribute(COMMAND_EVENT.HELPBUTTON_CLICK)]
protected void HelpClick(object sender, EventArgs e)
{
/////////////////////////////////////////////////
// Create and show your own help document here when the ? help button is clicked
/////////////////////////////////////////////////
}

public override bool CanExecute(object parameter)
{
return true;
}
}
3.     Create the command with the given unique ID (here is 1001). This will automatically link the command to the tool item.
public partial class Window1 : LinsMDIWindow
{
public Window1()
{
InitializeComponent();
MyCommand myCommand = new MyCommand(1001, null);
}
} 



References:
Assign a Help Document to a Tool Item,
Commands,
Command Events,
Commands Manager,
Dynamically Link a Tool Item to a Command Existed in an Optional Assembly,
Features,
How To,
Index,
Instruction,

Friday, February 13, 2015

LinsUICommand


LinsUICommand class
Represents a command of a tool item.
Examples
The following example shows how to create a LinsUICommand object. 
class MyCommand : LinsUICommand
{
public MyCommand(long nCommandID, object data) : base(nCommandID, data)
{
HelpFile = "zoom.rtf";
InputKeyGesture = new System.Windows.Input.KeyGesture(
System.Windows.Input.Key.Z,
System.Windows.Input.ModifierKeys.Control);
}

public override void Execute(object parameter)
{
base.Execute(parameter);
///////////////////////////////////
// Execute your command here
///////////////////////////////////
}

[CommandEventAttribute(COMMAND_EVENT.HELPBUTTON_CLICK)]
protected void HelpClick(object sender, EventArgs e)
{
/////////////////////////////////////////////////
// Create and show your own help document here when the ? help button is clicked
/////////////////////////////////////////////////
}

public override bool CanExecute(object parameter)
{
return true;
}
}

§  Constructors
1)  public LinsUICommand(
long nCommandID,
object data)
Parameters
nCommandID
Type: long
The assigned unique ID.  
data
Type: object
Customer’s data, it can be null
Remarks
Initialize a new instance of LinsUICommand
§  Members
1)  public long CommandID { get; set; }
Remarks
Every LinsUICommand object should have a unique ID, which should be between FlexConstants.m_nUserDefinedControlStartID (1000) and FlexConstants.m_nUserDefinedControlStartID (10,000,000). You can always use LinsUICommandManager.TryGetCommand() to retrieve its instance, once it is created.
2)  public object Data { get; set; }
Remarks
Customer’s data. It can be null.
3)  public string HelpContext { get; set; }
Remarks
Gets or sets the content of the tooltip.
4)  public string HelpFile { get; set; }
Remarks
Gets or sets the file which will be loaded into the tooltip content. The file can be either a text file or a Rich Text Format(RTF) file.
5)  public KeyGesture InputKeyGesture { get; set; }
Remarks
Define a keyboard combination that can be used to invoke this command.
§  Methods
1)  public virtual bool CanExecute(
object parameter)                 
Parameters
parameter
Type: object
Customer’s data which is used to decide if the tool item should be enabled/disabled. 
Remarks
If return false, then the tool item is disabled and the command will unable to be executed.
If return true, then the tool item is enabled and the command will be able to be executed.
2)  public virtual void Execute(
object parameter)                 
Parameters
parameter
Type: object
Customer’s data. 
Remarks
Execute the command. 

LinsUICommandManager


LinsUICommandManager class
It is a static class which controls all commands.
§  Methods
1)  public static bool TryGetCommand(
long lCommandID,            
Out LinsUICommand command)            
Parameters
lCommandID
Type: long
The unique ID of the command inquired. 
command
Type: LinsUICommand
The command inquired, if it exists. 
 Return
It returns true, if the command whose unique ID is lCommandID exists. It returns false, if there is no any such command.