This article shows how to open an Item in a new or existing Tab using the Extensions API.


When creating a new SystemWeaver ItemView in Visual Studio, two classes are created, one with the given view name and one with the given view name appended with "Content", marked in blue in the below example:



For this example, in the OpenItemExampleViewContent class there are two methods that are used by the swExplorer client to pass information to the Extension View. 

The first method is SetHost that passes the IswItemViewHost to the Extension View. It is the IswItemViewHost that can be used to Open an Item in a new or existing Tab.


The second method is SetCurrentItem that passes the Item that has been selected in the Structure Tree top the Extension View. 


It is recommended to pass the IswItemViewHost object to your ViewModel in the SetCurrentItem method to make it available. Below is an example of how to do this:


public void SetCurrentItem(IswItem AItem)
{
    // Make a method call to the view model, pass the IswItemViewHost and the currently selected Item
    ViewModel.Init(_host, AItem);
}


The method implementation on the View Model looks like below and simply assigns the IswItemHost to a global variable: 


internal void Init(IswItemViewHost host, IswItem currentItem)
{
    _host = host;
    _currentItem = currentItem;
    // Do more things...
}


And below is the code for Opening an Item in a new Tab:


_host.OpenItem(exampleItem.Handle, THowToOpenType.InNewWindow);


where the exampleItem is an IswItem and the THowToOpenType is an enumeration indicating whether the Item shall be opened in a new Tab, the existing Tab, etc.