private void SelectLocalLinkFile_Click(object sender, RoutedEventArgs e) { var fd = new OpenFileDialog { DefaultExt = ".html", Filter = "Linkable Files (*.htm,*.html,*.md,*.pdf;*.zip)|*.html;*.htm;*.md;*.pdf;*.zip|All Files (*.*)|*.*", CheckFileExists = true, RestoreDirectory = true, Multiselect = false, Title = "Embed a local relative link" }; if (!string.IsNullOrEmpty(MarkdownFile)) { fd.InitialDirectory = System.IO.Path.GetDirectoryName(MarkdownFile); } else { fd.InitialDirectory = mmApp.Configuration.LastFolder; } var res = fd.ShowDialog(); if (res == null || !res.Value) { return; } Link = fd.FileName; // Normalize the path relative to the Markdown file if (!string.IsNullOrEmpty(MarkdownFile)) { string mdPath = System.IO.Path.GetDirectoryName(MarkdownFile); string relPath = fd.FileName; try { relPath = FileUtils.GetRelativePath(fd.FileName, mdPath); } catch (Exception ex) { mmApp.Log($"Failed to get relative path.\r\nFile: {fd.FileName}, Path: {mdPath}", ex); } // not relative if (!relPath.StartsWith("..\\")) { Link = relPath; } // is it a physical path? if (Link.Contains(":\\")) { Link = "file:///" + Link; } } mmApp.Configuration.LastFolder = System.IO.Path.GetDirectoryName(fd.FileName); TextLink.Focus(); }
private void PasteHref_Loaded(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(Link)) { if (IsLink(LinkText)) { Link = LinkText; } else { string clipText = ClipboardHelper.GetText(); if (IsLink(clipText)) { Link = clipText; } } } if (string.IsNullOrEmpty(LinkText) && !string.IsNullOrEmpty(Link)) { LinkText = Link; } if (string.IsNullOrEmpty(LinkText)) { TextLinkText.Focus(); } else { TextLink.Focus(); } }