Skip to content

Commit

Permalink
Update for OnApplicationInitialized()
Browse files Browse the repository at this point in the history
  • Loading branch information
RickStrahl committed Feb 15, 2022
1 parent 0bd4f59 commit de628c6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Build/Distribution/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"summary": "Create and embed code snippets as Gists, and open from and save documents to Gists",
"description": "This addin allows you to take selected code in the editor, or code pasted from the clipboard and publish it as a Github Gist and embed it into the document.\r\n\r\nThe addin can also open and save documents (Markdown and code) from Gists.\r\n\r\n*** Important: In order to use this plug in and get the <script> link to render, you have to set the `EditorAllowRenderScriptTags: true` in the Markdown Monster settings. Without this setting the script tag won't render as script and Gists are not properly embedded.",
"releaseNotes": null,
"version": "0.12",
"minVersion": "2.3.13",
"version": "0.12.5",
"minVersion": "2.3.14",
"maxVersion": "2.99.99",
"author": "© Rick Strahl, West Wind Technologies",
"updated": "2022-02-15T12:00:00Z"
"updated": "2022-02-16T12:30:00Z"
}
Binary file modified Build/addin.zip
Binary file not shown.
6 changes: 3 additions & 3 deletions Build/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"summary": "Create and embed code snippets as Gists, and open from and save documents to Gists",
"description": "This addin allows you to take selected code in the editor, or code pasted from the clipboard and publish it as a Github Gist and embed it into the document.\r\n\r\nThe addin can also open and save documents (Markdown and code) from Gists.\r\n\r\n*** Important: In order to use this plug in and get the <script> link to render, you have to set the `EditorAllowRenderScriptTags: true` in the Markdown Monster settings. Without this setting the script tag won't render as script and Gists are not properly embedded.",
"releaseNotes": null,
"version": "0.12",
"minVersion": "2.3.13",
"version": "0.12.5",
"minVersion": "2.3.14",
"maxVersion": "2.99.99",
"author": "© Rick Strahl, West Wind Technologies",
"updated": "2022-02-15T12:00:00Z"
"updated": "2022-02-16T12:30:00Z"
}
45 changes: 20 additions & 25 deletions GistIntegrationAddin/PasteCodeAsGistAddin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ namespace GistIntegration
{
public class PasteCodeAsGistAddin : MarkdownMonsterAddin
{
public PasteCodeAsGitWindow PasteCodeAsGistWindow;
public PasteCodeAsGitWindow PasteCodeAsGistWindow;
public LoadGistWindow LoadGistWindow;
private AddInMenuItem AddinMenuItem;

#region Addin Overrides

public PasteCodeAsGistAddin()
{

Id = "Gist Integration x";
}

public override Task OnApplicationStart()
public override Task OnApplicationInitialized(AppModel model)
{
Id = "GistIntegration";

Expand All @@ -51,11 +49,6 @@ public override Task OnApplicationStart()
// .ConvertFromString("pack:https://application:,,,/GistIntegrationAddin;component/icon_22.png") as ImageSource
};

return base.OnApplicationStart();
}

public override Task OnModelLoaded(AppModel model)
{
// add an additional menu item
var mi = new MenuItem()
{
Expand Down Expand Up @@ -97,7 +90,7 @@ public override Task OnWindowLoaded()
Header = "Open or Embed from Gi_st",
Name = "ButtonOpenFromGist"
};
mitemOpen.Click += (s, a) => OnExecuteLoadGist();
mitemOpen.Click += (s, a) => OnExecuteLoadGist();
if (!AddMenuItem(mitemOpen, menuItemNameToFind: "ButtonOpenFromHtml", addMode: AddMenuItemModes.AddAfter))
mmApp.Log("Unable to add custom menu item in Paste Code As Gist Addin: " + mitemOpen.Name);

Expand All @@ -107,7 +100,7 @@ public override Task OnWindowLoaded()
Name = "ButtonSaveToGist"
};
mitemSave.Click += (s, a) => OnExecuteSaveGist();
if (!AddMenuItem(mitemSave, menuItemNameToFind: "ButtonGeneratePdf", addMode: AddMenuItemModes.AddAfter ))
if (!AddMenuItem(mitemSave, menuItemNameToFind: "ButtonGeneratePdf", addMode: AddMenuItemModes.AddAfter))
mmApp.Log("Unable to add custom menu item in Paste Code As Gist Addin: " + mitemSave.Name);

return Task.CompletedTask;
Expand All @@ -116,7 +109,7 @@ public override Task OnWindowLoaded()

public override Task OnExecute(object sender)
{

Model.Window.Dispatcher.InvokeAsync(async () =>
{
var editor = GetMarkdownEditor();
Expand All @@ -127,7 +120,7 @@ public override Task OnExecute(object sender)
string syntax = "cs";
if (string.IsNullOrEmpty(code))
code = ClipboardHelper.GetText();
if (!string.IsNullOrEmpty(code))
syntax = LanguageAutoDetection.Detect(code);
if (syntax == null)
Expand All @@ -137,24 +130,24 @@ public override Task OnExecute(object sender)
{
// strip leading white space
code = StringUtils.NormalizeIndentation(code);
if (code.TrimStart().StartsWith("```") && code.TrimEnd().EndsWith("```"))
if (code.TrimStart().StartsWith("```") && code.TrimEnd().EndsWith("```"))
{
var lines = StringUtils.GetLines(code);
var synt = lines[0].Replace("```","").Trim();
var synt = lines[0].Replace("```", "").Trim();
if (!string.IsNullOrEmpty(synt))
syntax = synt;
lines = lines.Skip(1).Take(lines.Length - 2).ToArray();
code = string.Join( mmApp.NewLine, lines);
code = string.Join(mmApp.NewLine, lines);
}
}
var gist = new GistItem()
{
code = code,
language = syntax
};
PasteCodeAsGistWindow = new PasteCodeAsGitWindow(this);
PasteCodeAsGistWindow.Owner = Model.Window;
PasteCodeAsGistWindow.Gist = gist;
Expand All @@ -169,7 +162,7 @@ public override Task OnExecute(object sender)
Model.Window.ShowStatus("Gist embedded", 5000);
Model.Window.SetStatusIcon(FontAwesomeIcon.GithubAlt, Colors.Green);
}).Task.FireAndForget();

return Task.CompletedTask;
Expand All @@ -178,23 +171,23 @@ public override Task OnExecute(object sender)
public void OnExecuteLoadGist()
{
var form = new LoadGistWindow(this);
form.Owner = Model.Window;
form.Owner = Model.Window;
form.Show();
}

public void OnExecuteSaveGist()
{
var form = new SaveGistWindow(this);
form.Owner = Model.Window;
form.Owner = Model.Window;
form.Show();
}

public override Task OnExecuteConfiguration(object sender)
{
{
OpenGistConfigurationTab();
return Task.CompletedTask;
}

public override Task OnApplicationShutdown()
{
base.OnApplicationShutdown();
Expand All @@ -208,12 +201,14 @@ public override Task OnApplicationShutdown()
#endregion

#region Addin Helpers

/// <summary>
/// Opens the configuration tab to configure Gists
/// </summary>
public void OpenGistConfigurationTab()
{
mmApp.Model.Window.OpenTab(System.IO.Path.Combine(mmApp.Configuration.CommonFolder, "PasteCodeAsGistAddin.json"));
mmApp.Model.Window.OpenTab(System.IO.Path.Combine(mmApp.Configuration.CommonFolder,
"PasteCodeAsGistAddin.json"));
mmApp.Model.Window.Activate();
}

Expand Down
6 changes: 3 additions & 3 deletions GistIntegrationAddin/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"summary": "Create and embed code snippets as Gists, and open from and save documents to Gists",
"description": "This addin allows you to take selected code in the editor, or code pasted from the clipboard and publish it as a Github Gist and embed it into the document.\r\n\r\nThe addin can also open and save documents (Markdown and code) from Gists.\r\n\r\n*** Important: In order to use this plug in and get the <script> link to render, you have to set the `EditorAllowRenderScriptTags: true` in the Markdown Monster settings. Without this setting the script tag won't render as script and Gists are not properly embedded.",
"releaseNotes": null,
"version": "0.12.2",
"minVersion": "2.3.13",
"version": "0.12.5",
"minVersion": "2.3.15",
"maxVersion": "2.99.99",
"author": "© Rick Strahl, West Wind Technologies",
"updated": "2022-02-15T12:30:00Z"
"updated": "2022-02-16T12:30:00Z"
}
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ Alternately you can create a new Gist from here by checking the **Save as new Gi

![](Assets/SaveToNewGist.png)

## Not just for Markdown
The Gist features in this addin are not just useful for Markdown embedding, but can be useful for managing and updating Gists quickly and easily directly from your application folders.


Essentially you can push any document to a Gist, and edit and update any Gist regardless of the type of file and regardless of whether you end up embedding it into your Markdown document.

### Change Log
#### 0.12
#### 0.12

* **Major UI Updates**
The Gist Listing window now has easier navigation via a toolbar and a context menu with all options. The list windows now show the file type with a syntax icon for easier navigation. The two windows now backlink to each other so all functionality is accessible via either of these top level operation windows.
Expand Down

0 comments on commit de628c6

Please sign in to comment.