public static bool TrySelectItem(IVsHierarchy hierarchy, string title, string filter, string preselectedItem, out string relativePath) { if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } if (title == null) { throw new ArgumentNullException("title"); } if (filter == null) { throw new ArgumentNullException("filter"); } bool flag; int hr = ProjectItemSelector.SelectItem(hierarchy, filter, title, preselectedItem, out relativePath, out flag); return(NativeMethods.Succeeded(hr) && !flag); }
public bool TrySelectFile(Project project, string title, string filter, string storageKey, out string file) { if (project == null) { throw new ArgumentNullException("project"); } IVsSolution solution = (IVsSolution)Dialog.ServiceProvider.GetService(typeof(SVsSolution)); IVsHierarchy hierarchy; if (!NativeMethods.Succeeded(solution.GetProjectOfUniqueName(project.FullName, out hierarchy))) { file = null; return(false); } // We want to read/persist the last directory location that was used if a key is provided. string lastSelectedFile = null; ProjectSettings settings = null; IVsBuildPropertyStorage storage = null; if (storageKey != null) { storage = hierarchy as IVsBuildPropertyStorage; } if (storage != null) { try { settings = new ProjectSettings(storage); lastSelectedFile = settings[storageKey]; } catch { // We don't want to fail scaffolding/selection if we have a settings issue. We'll just // ignore the settings entirely. settings = null; } } if (ProjectItemSelector.TrySelectItem(hierarchy, title, filter, lastSelectedFile, out file)) { if (settings != null) { try { settings[storageKey] = file; } catch { // We don't want to fail scaffolding/selection if we have a settings issue. We'll just // ignore the settings entirely. settings = null; } } return(true); } else { return(false); } }