/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void ExecuteAsync(object sender, EventArgs e) { try { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var item = _dte.SelectedItems.Item(1); Helpers.DteHelpers.GetSelectionData(_dte, out var targetFile, out var projectFolderPath, out var projectFullName); var targetFolder = Path.GetDirectoryName(targetFile); if (string.IsNullOrEmpty(targetFolder) || !Directory.Exists(targetFolder)) { return; } var selectedItem = item as ProjectItem; var selectedProject = item as Project; var project = selectedItem?.ContainingProject ?? selectedProject ?? DteHelpers.GetActiveProject(_dte); var root = Directory.GetParent(AureliaHelper.RootFolder).FullName.Replace(@"\", @"\\"); //escape for pregex var relativePath = Regex.Replace(targetFolder, root, "", RegexOptions.IgnoreCase).Substring(1); // remove starting slash var fileNameDialog = new FileNameDialog(relativePath) { Title = "Generate Aurelia Item", IsGlobal = true, PreviewText = "Please enter the name aurelia item to create using Aurelia Conventions" }; var lowerFolder = targetFolder.ToLower(); fileNameDialog.GlobalChecked(lowerFolder == AureliaHelper.GetResouceDirectory.ToLower() || lowerFolder == AureliaHelper.GetAttributesDirectory.ToLower() || lowerFolder == AureliaHelper.GetBindingBehaviorsDirectory.ToLower() || lowerFolder == AureliaHelper.GetElementsDirectory.ToLower() || lowerFolder == AureliaHelper.GetValueConvertersDirectory.ToLower() || targetFile.ToLower().Equals(AureliaHelper.ResourceGlobalFile.ToLower() )); var dialog = _dte.OpenDialog(fileNameDialog); if (!(dialog.ShowDialog() ?? false)) { return; } var moduleName = dialog.Input; var aureliaType = AureliaHelper.ParseModuleName(moduleName); var templates = Template.GetTemplateFilesByType(aureliaType.ToString().ToLower()).ToList(); var globalFolder = AureliaHelper.GetDirectory(aureliaType); targetFolder = dialog.IsGlobal && !string.IsNullOrWhiteSpace(globalFolder) ? globalFolder : targetFolder; var filesToOpen = await Task.WhenAll(templates.Select(templateName => Template.GenerateTemplatesAsync(templateName, targetFolder, dialog.Input, dialog.IsGlobal))); filesToOpen.ToList().ForEach(fullFileName => VsShellUtilities.OpenDocument(package, fullFileName)); } catch (Exception ex) { Logger.Log(ex.Message); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void ExecuteAsync(object sender, EventArgs e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var item = _dte.SelectedItems.Item(1); Helpers.DteHelpers.GetSelectionData(_dte, out var targetFile, out var projectFolderPath, out var projectFullName); var targetFolder = Path.GetDirectoryName(targetFile); if (string.IsNullOrEmpty(targetFolder) || !Directory.Exists(targetFolder)) return; var selectedItem = item as ProjectItem; var selectedProject = item as Project; var project = selectedItem?.ContainingProject ?? selectedProject ?? DteHelpers.GetActiveProject(_dte); var root = Directory.GetParent(AureliaHelper.RootFolder).FullName.Replace(@"\", @"\\"); //escape for pregex var relativePath = Regex.Replace(targetFolder, root, "", RegexOptions.IgnoreCase).Substring(1); // remove starting slash var fileNameDialog = new FileNameDialog(relativePath) { Title = "Generate Attribute", IsGlobal = true, PreviewText = "Please enter the name of the attribute you would like to create. eg. RedBox" }; fileNameDialog.GlobalChecked(targetFolder.ToLower() == AureliaHelper.GetResouceDirectory.ToLower() || targetFolder.ToLower() == AureliaHelper.GetAttributesDirectory.ToLower() || targetFile.ToLower().Equals(AureliaHelper.ResourceGlobalFile.ToLower())); var dialog = _dte.OpenDialog(fileNameDialog); if (!(dialog.ShowDialog() ?? false)) { return; } var elementName = dialog.Input; var templates = Template.GetTemplateFilesByType("attribute").ToList(); targetFolder = dialog.IsGlobal ? AureliaHelper.GetAttributesDirectory : targetFolder; var filesToOpen = await Task.WhenAll(templates.Select(templateName => Template.GenerateTemplatesAsync(templateName, targetFolder, dialog.Input, dialog.IsGlobal))); filesToOpen.ToList().ForEach(fullFileName => VsShellUtilities.OpenDocument(package, fullFileName)); }