/// <summary> /// Called by the export command. This fucntion will determin the exported language /// and the exported code and build a ExportToSnippetData object. It then creates a new snippet /// which will read this export to snippet object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExportToSnippet(object sender, EventArgs e) { // The selected item is the active window pane // in Visual Studio. // Get the code from the Document into TextDocument codeDoc TextDocument codeDoc = CurrentTextDocument; if (codeDoc == null) //if the active window isnt a textwindow get the last active text window { codeDoc = GetTextDocumentFromWindow(previousWindow); } if (codeDoc != null) { try { //build export object var snippetText = codeDoc.Selection.Text.Normalize(); ExportSnippetData = new ExportToSnippetData(snippetText, codeDoc.Language.ToLower()); //launch new file CreateNewSnippetFile(); } catch (Exception ex) { Logger.Log(ex.Message, "ExportToSnippet", ex); } return; } }
/// <summary> /// The vs command line argument parser. When you do File.NewSnippet and then args of /// /lang langyage and/or /code myCode it will create new snippet with those options /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CreateSnippet(object sender, EventArgs e) { var eventArgs = e as OleMenuCmdEventArgs; if (eventArgs != null && Dte != null) { var newSnippet = new NewSnippetCommand(eventArgs.InValue.ToString().Split(' ')); //build export object ExportSnippetData = new ExportToSnippetData(newSnippet.Code, newSnippet.Language.ToLower()); CreateNewSnippetFile(); } }