/// <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) { 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 dialog = DteHelpers.OpenDialog <RouteComponentDialog>(_dte); if (!dialog.DialogResult ?? false) { return; } if (string.IsNullOrWhiteSpace(dialog.ElementName)) { return; } var templates = Template.GetTemplateFilesByType("route").Where(y => y.Contains(dialog.Type)).ToList(); var filesToOpen = await Task.WhenAll(templates.Select(templateName => Template.GenerateTemplatesAsync(templateName, targetFolder, dialog.ElementName))); filesToOpen.ToList().ForEach(fullFileName => VsShellUtilities.OpenDocument(package, fullFileName)); }
/// <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) { 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 dialog = DteHelpers.OpenDialog <ElementGenerationDialog>(_dte); if (!(dialog.ShowDialog() ?? false)) { return; } var type = dialog.Type; var elementName = dialog.ElementName; var bindablePropertyNames = dialog.PropertyNames; var templates = Template.GetTemplateFilesByType("element").Where(y => y.Contains(type)).ToList(); targetFolder = dialog.IsGlobal ? AureliaHelper.GetElementsDirectory : targetFolder; var filesToOpen = await Task.WhenAll(templates.Select(templateName => Template.GenerateTemplatesAsync(templateName, targetFolder, dialog.ElementName, dialog.IsGlobal))); filesToOpen.ToList().ForEach(fullFileName => VsShellUtilities.OpenDocument(package, fullFileName)); }
public int UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand) { if (Common.Instance.GeneralOptions.UpdateListingOnlyIfVisible && !MsilerToolWindow.IsVisible) { return(VSConstants.S_OK); } if (fSucceeded != 1) { return(VSConstants.S_OK); } string assemblyFile = DteHelpers.GetOutputAssemblyFileName(); try { var assemblyWriteTime = new FileInfo(assemblyFile).LastWriteTime; // if assembly was not changed if (this._previousAssemblyWriteTime == assemblyWriteTime) { return(VSConstants.S_OK); } var options = new AssemblyParserOptions { ProcessPDB = Common.Instance.ListingGenerationOptions.ProcessPdbFiles }; this._assemblyReader = new AssemblyReader(assemblyFile, options); this._previousAssemblyWriteTime = assemblyWriteTime; this.OnMethodListChanged(this._assemblyReader.Methods); } catch (Exception) { this.OnMethodListChanged(new List <AssemblyMethod>()); } return(VSConstants.S_OK); }
private AmmyProject GetAmmyProject(string filename, out string projectName) { AmmyProject cachedProject; var genericProject = DteHelpers.GetProjectByFilename(filename); if (genericProject == null || genericProject.Kind == EnvDTE.Constants.vsProjectKindMisc) { throw new CompilerServiceException("Project not found for file: " + filename); } projectName = genericProject.Name; if (_projectCaches.TryGetValue(projectName, out cachedProject)) { var cachedReferences = cachedProject.References.Select(r => r.Path).ToList(); var cachedFiles = GetCachedFiles(cachedProject); var newProject = new AmmyProject(cachedReferences, cachedFiles, cachedProject.CSharpProject, cachedProject.FsProject.Data, cachedProject.FsProject.ProjectDir, cachedProject.OutputPath, cachedProject.RootNamespace, cachedProject.AssemblyName, cachedProject.TargetPath); return(newProject); } var projectItems = DteHelpers.GetFileList(genericProject); var ammyFileMetas = GetAmmyFileMetas(projectItems); var sourceFilenames = projectItems.Select(pi => DteHelpers.GetFilename(pi)).ToArray(); var project = (VSProject)genericProject.Object; var fullPath = genericProject.Properties.Item("FullPath").Value.ToString(); var objRelativePath = genericProject.ConfigurationManager.ActiveConfiguration.Properties.Item("IntermediatePath").Value.ToString(); var outputPath = genericProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); var outputFileName = genericProject.Properties.Item("OutputFileName").Value.ToString(); var targetPath = Path.Combine(fullPath, outputPath, outputFileName); var rootNamespace = genericProject.Properties.Item("RootNamespace").Value.ToString(); var assemblyName = genericProject.Properties.Item("AssemblyName").Value.ToString(); //var hostAssemblyPath = Path.Combine(outputDir, outputFileName); var references = GetReferences(project); var compilationData = NeedReferenceRefresh(references) ? null : LatestResult?.CompilationData; var csharpProject = new CSharpProject(fullPath, sourceFilenames); var ammyProject = new AmmyProject(references, ammyFileMetas, csharpProject, compilationData, fullPath, objRelativePath, rootNamespace, assemblyName, targetPath); _projectCaches[projectName] = ammyProject; SubscribeToReferenceChanges(project, projectName); return(ammyProject); }
public static VsTheme GetTheme() { string version = DteHelpers.GetDte().Application.Version; switch (version) { case "14.0": return(new VsThemeDetector().VisualStudio2015Theme()); case "12.0": return(new VsThemeDetector().VisualStudio2013Theme()); case "11.0": return(new VsThemeDetector().VisualStudio2012Theme()); default: return(VsTheme.Unknown); } }
void Caret_PositionChanged(object sender, CaretPositionChangedEventArgs e) { if (!IsFollowingEnabled) { return; } // do not use follow mode if "update listing on if visible" option // is enabled and toolbox isn't visible if (Common.Instance.GeneralOptions.UpdateListingOnlyIfVisible && !MsilerToolWindow.IsVisible) { return; } var doc = this._dte.ActiveDocument; if (doc == null) { return; } // only c# supported at this time if (doc.Language != "CSharp" && doc.Language != "Basic") { return; } var sel = (TextSelection)doc.Selection; if (sel == null) { return; } var fcm = (FileCodeModel2)doc.ProjectItem.FileCodeModel; var signature = DteHelpers.GetSignature(sel.ActivePoint, fcm); if (signature != null) { this.OnMethodSelect(signature); } }
/// <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) { 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 dialog = DteHelpers.OpenDialog <FileNameDialog>(_dte); dialog.Title = "Generate Attribute"; var relativePath = targetFolder.Substring(targetFolder.IndexOf(AureliaHelper.RootFolder)); dialog.FolderLabel = relativePath; dialog.PreviewText = "Please enter the name of the attribute you would like to create. eg. RedBox"; if (!(dialog.ShowDialog() ?? false)) { return; } var elementName = dialog.Name; var templates = Template.GetTemplateFilesByType("attribute").ToList(); targetFolder = dialog.IsGlobal ? AureliaHelper.GetElementsDirectory : 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)); }
/// <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)); }
private void DteEventHandlers(DTE dte) { var events2 = dte.Events as Events2; if (events2 == null) { return; } var solutionEvents = events2.SolutionEvents; var piEvents = events2.ProjectItemsEvents; var dEvents = events2.DebuggerEvents; var documentEvents = events2.DocumentEvents; AmmyProject project; documentEvents.DocumentSaved += document => { if (document.FullName.EndsWith(".cs")) { LatestResult?.AmmyProject.CSharpProject.MarkAsDirty(document.FullName); } }; solutionEvents.ProjectAdded += project1 => { var ammyFilename = DteHelpers.GetFileList(project1) .Select(pi => DteHelpers.GetFilename(pi)) .FirstOrDefault(f => f.EndsWith(".ammy")); if (ammyFilename != null) { Compile(ammyFilename, false); } }; dEvents.OnEnterDesignMode += reason => { LatestResult?.AmmyProject.Context.ClearBindingConverters(); _isDebugging = false; }; dEvents.OnEnterRunMode += reason => { LatestResult?.AmmyProject.Context.ClearBindingConverters(); if (!_isDebugging && LatestResult?.AmmyProject.PlatformName == "XamarinForms") { var result = _adbService.SetupAdbForwarding(); if (!result && !AmmySettings.SuppressAdbWarning) { MessageBox.Show("Ammy cannot find `adb.exe`" + Environment.NewLine + Environment.NewLine + "You can specify `adb.exe` path in settings window (top right corner)" + Environment.NewLine + "Or you can also suppress this warning in the same settings window"); } } _isDebugging = true; }; piEvents.ItemAdded += item => { _projectCaches.TryRemove(item.ContainingProject.Name, out project); }; piEvents.ItemRemoved += item => { _projectCaches.TryRemove(item.ContainingProject.Name, out project); }; piEvents.ItemRenamed += (item, name) => { _projectCaches.TryRemove(item.ContainingProject.Name, out project); }; _eventContainers.Add(piEvents); _eventContainers.Add(solutionEvents); _eventContainers.Add(dEvents); _eventContainers.Add(documentEvents); }
private IReadOnlyList <AmmyFileMeta> GetAmmyFileMetas(ProjectItem[] projectItems) { return(projectItems.Where(pi => string.Equals(Path.GetExtension(DteHelpers.GetFilename(pi)), ".ammy", StringComparison.InvariantCultureIgnoreCase)) .SelectMany(pi => new[] { ToAmmyFileMeta(DteHelpers.GetFilename(pi), pi) }) .ToList()); }
public FunctionFollower(ITextView view) { this._view = view; this._view.Caret.PositionChanged += this.Caret_PositionChanged; this._dte = DteHelpers.GetDte(); }
/// <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); } }