private bool CanPerformSearchAction() { ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane(true); var CheckedSelectedFolderConnection = projectWindow.SelectedItems.FirstOrDefault(x => x.GetType() == typeof(FolderConnectionProjectItem)); if (CheckedSelectedFolderConnection != null && (!string.IsNullOrEmpty(this.SearchInput))) { return(true); } else { return(false); } }
private async void PerformFocusItemCommand() { await(QueuedTask.Run(async() => { string DirectoryPath = this.SelectedFile.Directory.FullName; string SelectedFolderConnectionPath = this.SelectedFolderConnection.Path; ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane(true); var folderContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection"); Item subFolderItem = this.SelectedFolderConnection; if (DirectoryPath.Equals(SelectedFolderConnectionPath, StringComparison.OrdinalIgnoreCase)) { await projectWindow.SelectItemAsync(this.SelectedFolderConnection, true, true, folderContainer); } else { List <string> PathListToFind = new List <string>(); string HierarchyPath = DirectoryPath; while (!HierarchyPath.Equals(SelectedFolderConnectionPath, StringComparison.OrdinalIgnoreCase)) { PathListToFind.Add(HierarchyPath); HierarchyPath = (new DirectoryInfo(HierarchyPath)).Parent.FullName; } Item CurrentSearchFolder = this.SelectedFolderConnection; for (int idx = PathListToFind.Count - 1; idx >= 0; idx--) { string folderPath = PathListToFind[idx]; //Cannot be null, if null something wrong if (CurrentSearchFolder != null) { CurrentSearchFolder = CurrentSearchFolder.GetItems().FirstOrDefault(x => x.Path.Equals(folderPath, StringComparison.OrdinalIgnoreCase)); } } //Cannot be null, if null something wrong but double check if (CurrentSearchFolder != null) { await projectWindow.SelectItemAsync(CurrentSearchFolder, true, true, folderContainer); } } })); }
private void PerformSearchFileCommand() { ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane(true); this.SelectedFolderConnection = projectWindow.SelectedItems.FirstOrDefault(x => x.GetType() == typeof(FolderConnectionProjectItem)); string selectedFolderPath = ((FolderConnectionProjectItem)this.SelectedFolderConnection).Path; this.InfoMsg = $"Perform search in {selectedFolderPath} with {this.SearchInput} criteria"; if (!Directory.Exists(selectedFolderPath)) { MessageBox.Show("Please select a valid folder connection from catalog and search again"); return; } DirectoryInfo dirInfo = new DirectoryInfo(selectedFolderPath); this.SearchResult = new List <FileInfo>(); FileInfo[] resultFileList = dirInfo.GetFiles(this.SearchInput, SearchOption.AllDirectories); if (resultFileList != null && resultFileList.Length > 0) { this.SearchResult = resultFileList.ToList(); } }
public static void ItemFindAndSelection() { #region Select project containers (for use with SelectItemAsync) //Use Project.Current.ProjectItemContainers var folderContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection"); var gdbContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GDB"); var mapContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Map"); var layoutContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Layout"); var toolboxContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GP"); //etc. //or...use Project.Current.GetProjectItemContainer folderContainer = Project.Current.GetProjectItemContainer("FolderConnection"); gdbContainer = Project.Current.GetProjectItemContainer("GDB"); mapContainer = Project.Current.GetProjectItemContainer("Map"); layoutContainer = Project.Current.GetProjectItemContainer("Layout"); toolboxContainer = Project.Current.GetProjectItemContainer("GP"); //etc. #endregion #region ProjectItem: Get an Item or Find an Item //GetItems searches project content var map = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(m => m.Name == "Map1"); var layout = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(m => m.Name == "Layout1"); var folders = Project.Current.GetItems <FolderConnectionProjectItem>(); var style = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 3D"); //Find item uses a catalog path. The path can be to a file or dataset var fcPath = @"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes"; var pdfPath = @"C:\Temp\Layout1.pdf"; var imgPath = @"C:\Temp\AddinDesktop16.png"; var fc = Project.Current.FindItem(fcPath); var pdf = Project.Current.FindItem(pdfPath); var img = Project.Current.FindItem(imgPath); #endregion #region Select an item in the Catalog pane //Get the catalog pane ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetCatalogPane(); //or get the active catalog view... //ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetActiveCatalogWindow(); //eg Find a toolbox in the project string gpName = "Interacting with Maps.tbx"; var toolbox = Project.Current.GetItems <GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName); //Select it under Toolboxes projectWindow.SelectItemAsync(toolbox, true, true, null);//null selects it in the first container - optionally await //Note: Project.Current.GetProjectItemContainer("GP") would get toolbox container... //assume toolbox is also under Folders container. Select it under Folders instead of Toolboxes var foldersContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection"); //We must specify the container because Folders comes second (after Toolboxes) projectWindow.SelectItemAsync(toolbox, true, true, foldersContainer);//optionally await //Find a map and select it var mapItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(m => m.Name == "Map"); //Map only occurs under "Maps" so the container need not be specified projectWindow.SelectItemAsync(mapItem, true, false, null); #endregion }