Skip to content

Commit

Permalink
Merge pull request #31 from whistyun/dev
Browse files Browse the repository at this point in the history
expose link action command.
  • Loading branch information
whistyun authored Feb 21, 2022
2 parents 2140c6d + b3544c5 commit 7826daa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: windows-latest
runs-on: windows-2019

steps:
- uses: actions/checkout@v2
Expand Down
53 changes: 53 additions & 0 deletions MdXaml/LinkActions/DiaplayCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Diagnostics;
using System.Windows.Input;

#if MIG_FREE
using Markdown.Xaml;

namespace Markdown.Xaml.LinkActions
#else
using MdXaml;

namespace MdXaml.LinkActions
#endif
{
public class DiaplayCommand : ICommand
{
private MarkdownScrollViewer Owner;
private bool OpenBrowserWithAbsolutePath;

public DiaplayCommand(MarkdownScrollViewer owner, bool openBrowserWithAbsolutePath)
{
Owner = owner;
OpenBrowserWithAbsolutePath = openBrowserWithAbsolutePath;
}

public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter) => true;

public void Execute(object parameter)
{
var path = parameter.ToString();
var isAbs = Uri.IsWellFormedUriString(path, UriKind.Absolute);

if (OpenBrowserWithAbsolutePath & isAbs)
{
Process.Start(new ProcessStartInfo(path)
{
UseShellExecute = true,
Verb = "open"
});
}
else if (isAbs)
{
Owner.Open(new Uri(path), true);
}
else
{
Owner.Open(new Uri(path, UriKind.Relative), true);
}
}
}
}
29 changes: 29 additions & 0 deletions MdXaml/LinkActions/OpenCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Diagnostics;
using System.Windows.Input;

#if MIG_FREE
namespace Markdown.Xaml.LinkActions
#else
namespace MdXaml.LinkActions
#endif
{
public class OpenCommand : ICommand
{
public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter) => true;

public void Execute(object parameter)
{
var path = parameter.ToString();
var isAbs = Uri.IsWellFormedUriString(path, UriKind.Absolute);

Process.Start(new ProcessStartInfo(path)
{
UseShellExecute = true,
Verb = "open"
});
}
}
}
65 changes: 5 additions & 60 deletions MdXaml/MarkdownScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
using System.Windows.Markup;

#if MIG_FREE
using Markdown.Xaml.LinkActions;
using MdStyle = Markdown.Xaml.MarkdownStyle;

namespace Markdown.Xaml
#else
using MdXaml.LinkActions;
using MdStyle = MdXaml.MarkdownStyle;

namespace MdXaml
#endif
{
Expand Down Expand Up @@ -272,7 +276,7 @@ private void UpdateClickAction()
UpdateMarkdown(this, default(DependencyPropertyChangedEventArgs));
}

private void Open(Uri source, bool updateSourceProperty)
internal void Open(Uri source, bool updateSourceProperty)
{
bool TryOpen(Uri path)
{
Expand Down Expand Up @@ -344,65 +348,6 @@ bool TryOpen(Uri path)
}
}
}

class OpenCommand : ICommand
{

public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter) => true;

public void Execute(object parameter)
{
var path = parameter.ToString();
var isAbs = Uri.IsWellFormedUriString(path, UriKind.Absolute);

Process.Start(new ProcessStartInfo(path)
{
UseShellExecute = true,
Verb = "open"
});
}
}

class DiaplayCommand : ICommand
{
MarkdownScrollViewer Owner;
bool OpenBrowserWithAbsolutePath;

public DiaplayCommand(MarkdownScrollViewer owner, bool openBrowserWithAbsolutePath)
{
Owner = owner;
OpenBrowserWithAbsolutePath = openBrowserWithAbsolutePath;
}

public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter) => true;

public void Execute(object parameter)
{
var path = parameter.ToString();
var isAbs = Uri.IsWellFormedUriString(path, UriKind.Absolute);

if (OpenBrowserWithAbsolutePath & isAbs)
{
Process.Start(new ProcessStartInfo(path)
{
UseShellExecute = true,
Verb = "open"
});
}
else if (isAbs)
{
Owner.Open(new Uri(path), true);
}
else
{
Owner.Open(new Uri(path, UriKind.Relative), true);
}
}
}
}

public enum ClickAction
Expand Down

0 comments on commit 7826daa

Please sign in to comment.