///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new AddSnippet Form and precompiles this form with the selected text /// </summary> /// <param name="pluginManager"></param> public static IManageSnippetForm PrepareAddNewSnippetForm(IPluginManager pluginManager) { if (pluginManager == null) { return(null); } // Manage editor selection string selText = pluginManager.RetrieveSelectedText(); // Open "Add Snippet" Window pluginManager.ClosePublishSnippetWindow(); IManageSnippetForm addSnipForm = pluginManager.CreateAddSnippetForm(); if (addSnipForm != null) { addSnipForm.PrepareAddNewSnippet(selText); } return(addSnipForm); }
/// <summary> /// Creates a new ViewSnippet Form and precompiles this form with the content of the given snippet /// </summary> /// <param name="pluginManager"></param> /// <param name="snippetId">ID of the snppet to display</param> public static IManageSnippetForm PrepareViewSnippetForm(IPluginManager pluginManager, long snippetId) { if (pluginManager == null) { return(null); } if (snippetId <= 0) { return(null); } // read snippets and populate the List SnippetsWS snippetRepo = new SnippetsWS(); log.DebugFormat("Reading snippet {0}", snippetId); Snippet snip = snippetRepo.GetSnippetByID(snippetId); if (snip == null) { log.WarnFormat("Snippet {0} is null", snippetId); return(null); } //CG: Add +1 to the view stats System.Threading.Tasks.Task.Factory.StartNew(() => snippetRepo.StoreHit(snip)); // Open "Add Snippet" Window log.DebugFormat("Loading snippet {0}", snippetId); pluginManager.ClosePublishSnippetWindow(); IManageSnippetForm viewSnipForm = pluginManager.CreateViewSnippetForm(); viewSnipForm.PrepareViewSnippet(snip); return(viewSnipForm); }