Recently used filesCommand, MultiItem, and ComboBox
[C#]
MultiItemRecentFiles.cs
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.CATIDs; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Framework; using Microsoft.Win32; using System.IO; namespace RecentFilesCommandsCS { [Guid("8e5372ed-a185-4b52-9a2a-76f359107c58")] [ClassInterface(ClassInterfaceType.None)] [ProgId("RecentFilesCommandsCS.MultiItemRecentFiles")] public class MultiItemRecentFiles : IMultiItem { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static void RegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); } [ComUnregisterFunction()] [ComVisible(false)] static void UnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); } #region ArcGIS Component Category Registrar generated code /// <summary> /// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryRegistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); GMxCommands.Register(regKey); MxCommands.Register(regKey); SxCommands.Register(regKey); } /// <summary> /// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryUnregistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); GMxCommands.Unregister(regKey); MxCommands.Unregister(regKey); SxCommands.Unregister(regKey); } #endregion #endregion private IApplication m_application; private string[] m_filePaths = null; #region "IMultiItem Implementations" public string Caption { get { return "Recent Files MultiItem (C#)"; } } public int HelpContextID { get { return default(int); } } public string HelpFile { get { return default(string); } } public string Message { get { return default(string); } } public string Name { get { return "CSNETSamples_RecentFilesMultiItem"; } } public void OnItemClick(int index) { m_application.OpenDocument(m_filePaths[index]); } public int OnPopup(object hook) { //The incoming hook is the application, determine the number of //items by getting the recent files from the registry m_application = hook as IApplication; m_filePaths = RecentFilesRegistryHelper.GetRecentFiles(m_application); return m_filePaths.Length; } public int get_ItemBitmap(int index) { return default(int); } public string get_ItemCaption(int index) { //Caption of item is "#. <File path>" return string.Format("&{0}. {1}", index + 1, m_filePaths[index]); } public bool get_ItemChecked(int index) { return false; } public bool get_ItemEnabled(int index) { //check if file exists return File.Exists(m_filePaths[index]); } #endregion } }
[Visual Basic .NET]
MultiItemRecentFiles.vb
Imports ESRI.ArcGIS.ADF.CATIDs Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS.Framework Imports ESRI.ArcGIS.esriSystem <ComClass(MultiItemRecentFiles.ClassId, MultiItemRecentFiles.InterfaceId, MultiItemRecentFiles.EventsId), _ ProgId("RecentFilesCommandsVB.MultiItemRecentFiles")> _ Public Class MultiItemRecentFiles Implements IMultiItem #Region "COM Registration Function(s)" <ComRegisterFunction(), ComVisibleAttribute(False)> _ Public Shared Sub RegisterFunction(ByVal registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType) 'Add any COM registration code after the ArcGISCategoryRegistration() call End Sub <ComUnregisterFunction(), ComVisibleAttribute(False)> _ Public Shared Sub UnregisterFunction(ByVal registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType) 'Add any COM unregistration code after the ArcGISCategoryUnregistration() call End Sub #Region "ArcGIS Component Category Registrar generated code" ''' <summary> ''' Required method for ArcGIS Component Category registration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) GMxCommands.Register(regKey) MxCommands.Register(regKey) SxCommands.Register(regKey) End Sub ''' <summary> ''' Required method for ArcGIS Component Category unregistration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) GMxCommands.Unregister(regKey) MxCommands.Unregister(regKey) SxCommands.Unregister(regKey) End Sub #End Region #End Region #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "927b25f4-f24c-471c-a2cd-777c2c371d34" Public Const InterfaceId As String = "f4ab3750-49db-46be-aaa6-ffdd9fd8a7ac" Public Const EventsId As String = "00f31cd2-b7d7-4014-8145-801a2f49ac65" #End Region Private m_application As Iapplication Private m_filePaths As String() ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub Public ReadOnly Property Caption() As String Implements IMultiItem.Caption Get Return "Recent Files Example (VB.Net)" End Get End Property Public ReadOnly Property HelpContextID() As Integer Implements IMultiItem.HelpContextID Get Return 0 End Get End Property Public ReadOnly Property HelpFile() As String Implements IMultiItem.HelpFile Get Return String.Empty End Get End Property Public ReadOnly Property ItemBitmap(ByVal index As Integer) As Integer Implements IMultiItem.ItemBitmap Get Return 0 End Get End Property Public ReadOnly Property ItemCaption(ByVal index As Integer) As String Implements IMultiItem.ItemCaption Get 'Caption of item is "#. <File path>" Return String.Format("&{0}. {1}", index + 1, m_filePaths(index)) End Get End Property Public ReadOnly Property ItemChecked(ByVal index As Integer) As Boolean Implements IMultiItem.ItemChecked Get Return False End Get End Property Public ReadOnly Property ItemEnabled(ByVal index As Integer) As Boolean Implements IMultiItem.ItemEnabled Get 'check if file exists Return System.IO.File.Exists(m_filePaths(index)) End Get End Property Public ReadOnly Property Message() As String Implements IMultiItem.Message Get Return String.Empty End Get End Property Public ReadOnly Property Name() As String Implements IMultiItem.Name Get Return "VBNETSamples_RecentFilesMultiItem" End Get End Property Public Sub OnItemClick(ByVal index As Integer) Implements IMultiItem.OnItemClick m_application.OpenDocument(m_filePaths(index)) End Sub Public Function OnPopup(ByVal hook As Object) As Integer Implements IMultiItem.OnPopup 'The incoming hook is the application, determine the number of 'items by getting the recent files from the registry m_application = CType(hook, IApplication) m_filePaths = RecentFilesRegistryHelper.GetRecentFiles(m_application) Return m_filePaths.Length End Function End Class