Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

HOWTO: Register a namespace extension under multiple locations

 
Subscribe to the RSS feed for this forum  Forum Index -> EZNamespaceExtensions.Net
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Fri Aug 22, 2008 11:44 am    Post subject: HOWTO: Register a namespace extension under multiple locations

It may be sometimes desirable to show the same namespace extension under multiple locations such as the Desktop, My Computer, a file system folder. In this case, override the GetNSETargetInfoEx method of the NSEFolder-derived class representing the root folder of the namespace extension and return an array of registration targets. The following code (taken from RegistryBrowser sample) demonstrates this :

[C#]
public override NSETargetInfo[] GetNSETargetInfoEx()
{
// Register as a protocol
NSETargetInfo nti1 = new NSETargetInfo("Registry Browser", NSETarget.ProtocolHandler,
NSEItemAttributes.Folder | NSEItemAttributes.HasSubFolder | NSEItemAttributes.Browsable
);
// Our namespace extension can be accessed through strings such as reg://HKEY_CURRENT_USER
nti1.Protocol = protocol; // protocol defined above as "reg"
nti1.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe");
nti1.IconIndex = 0;
nti1.InfoTip = "Browse the Registry";

// Register under 'My Computer'
NSETargetInfo nti2 = new NSETargetInfo("Registry Browser", NSETarget.MyComputer,
NSEItemAttributes.Folder | NSEItemAttributes.HasSubFolder | NSEItemAttributes.Browsable
);
nti2.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe");
nti2.IconIndex = 0;
nti2.InfoTip = "Browse the Registry";
return new NSETargetInfo[] { nti1,nti2 };
}


[VB.Net]

Public Overrides Function GetNSETargetInfoEx() As NSETargetInfo()

' Register as a protocol
Dim nti1 As NSETargetInfo = New NSETargetInfo("Registry Browser", NSETarget.ProtocolHandler, _
NSEItemAttributes.Folder Or NSEItemAttributes.HasSubFolder Or NSEItemAttributes.Browsable)
' Our namespace extension can be accessed through strings such as reg://HKEY_CURRENT_USER
nti1.Protocol = protocol 'protocol defined above as "reg"
nti1.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe")
nti1.IconIndex = 0
nti1.InfoTip = "Browse the Registry"

' Register under 'My Computer'
Dim nti2 As NSETargetInfo = New NSETargetInfo("Registry Browser", NSETarget.MyComputer, _
NSEItemAttributes.Folder Or NSEItemAttributes.HasSubFolder Or NSEItemAttributes.Browsable)
nti2.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe")
nti2.IconIndex = 0
nti2.InfoTip = "Browse the Registry"
Return New NSETargetInfo() {nti1, nti2}

End Function


Notes:
1. When the same namespace extension is registered under multiple file system folders (NSETarget.FileSystemFolder), the 'context' can be determined using the TargetFileOrFolder property of NSEFolder.

2. If you need to determine the 'context' in other cases (such as differentiating whether the namespace extension is under the 'Desktop' or 'My Computer'), the following must be done:

Additional classes must be derived from the class representing the root folder of the namespace extension. The GetNSETargetInfo method must be overridden in each class to target the respective location. A common variable can be initialized in the constructor of each derived class so that the 'context' is known. The following pseudo-code demonstrates this :

// This class contains all the common functionality
class BaseWithAllFunctionality : NSEFolder
{

private NSETarget target; // this will be initialized in derived classes
...
...

[ComRegisterFunction]
public static void Register(System.Type t)
{
// Register both targets
NSEFolder.RegisterExtension(typeof(NSEUnderMyComputer));
NSEFolder.RegisterExtension(typeof(NSEUnderDesktop));
}

[ComUnregisterFunction]
public static void UnRegister(System.Type t)
{
// Unregister both targets
NSEFolder.UnregisterExtension(typeof(NSEUnderMyComputer));
NSEFolder.UnregisterExtension(typeof(NSEUnderDesktop));
}

}

[Guid("xxxxxx-xxxx-xxx-.........")] // This GUID should be unique
class NSEUnderMyComputer : BaseWithAllFunctionality
{
NSEUnderMyComputer()
{
// Store target for each in parent class
target = NSETarget.MyComputer;
}

public override NSETargetInfo GetNSETargetInfo()
{
// Located under 'My Computer'
NSETargetInfo nti = new NSETargetInfo("NSEUnderMyComputer", NSETarget.MyComputer,
NSEItemAttributes.Folder | NSEItemAttributes.HasSubFolder | NSEItemAttributes.Browsable
);
nti.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe");
nti.IconIndex = 0;
nti.InfoTip = "NSEUnderMyComputer";
return nti;
}



}


[Guid("xxxxxx-xxxx-xxx-.........")] // This GUID should be unique
class NSEUnderDesktop : BaseWithAllFunctionality
{
NSEUnderDesktop ()
{
// Store target for each in parent class
target = NSETarget.Desktop;
}

public override NSETargetInfo GetNSETargetInfo()
{
// Located under 'Desktop'
NSETargetInfo nti = new NSETargetInfo("NSEUnderDesktop", NSETarget.Desktop,
NSEItemAttributes.Folder | NSEItemAttributes.HasSubFolder | NSEItemAttributes.Browsable
);
nti.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "regedit.exe");
nti.IconIndex = 0;
nti.InfoTip = "NSEUnderDesktop";
return nti;
}

}


The above is required *only* if it is necessary to know the 'context' in the namespace extension. If this is not necessary, simply returning multiple targets from the GetNSETargetInfoEx method is sufficient.
Back to top
Display posts from previous:   
Forum Index -> EZNamespaceExtensions.Net All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group