private void OpenImageUploadWindow() { //Extract images HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(txtHtml.Text); HtmlNodeCollection imgNodes = doc.DocumentNode.SelectNodes("//img"); if (imgNodes == null) { MessageBox.Show("No image paths found!"); return; } ImageUploadData imageData = new ImageUploadData { MarkdownPath = _markdownPath, OldMarkdown = txtMarkdown.Text }; foreach (HtmlNode node in imgNodes) { // Skip if web link if (node.GetAttributeValue("src", "").StartsWith("http") || node.GetAttributeValue("src", "").StartsWith("www")) { continue; } string localPath = node.GetAttributeValue("src", null); string fullPath = Path.GetDirectoryName(_markdownPath) + "/" + localPath; // Check if file exists if (File.Exists(fullPath)) { imageData.LocalImagePaths.Add(localPath); imageData.FullImagePaths.Add(fullPath); } else { MessageBox.Show("File not found: " + localPath + "\nThis file will be skipped."); } } if (imageData.FullImagePaths.Count == 0) { MessageBox.Show("No local image paths found!"); return; } ImageUploadWindow uploadWindow = new ImageUploadWindow(imageData); if (uploadWindow.ShowDialog() == DialogResult.OK) { UseDataResults(uploadWindow.ImageUploadData); } }
public ImageUploadWindow(ImageUploadData imageUploadData) { InitializeComponent(); ImageUploadData = imageUploadData; ServicePointManager.ServerCertificateValidationCallback = MonoHelper.Validator; CheckConnectionToRW(); FillImageNameList(); if (Settings.Default.CredentialsSaved) { txtUsername.Text = Settings.Default.Username; txtPassword.Text = Settings.Default.Password; } if (MonoHelper.IsRunningOnMono) { btnMacPasteUsername.Visible = true; btnMacPastePassword.Visible = true; } SetLoginControlsEnabledState(true); }
private void UseDataResults(ImageUploadData data) { txtMarkdown.Text = data.NewMarkdown; txtHtml.Text = Converter.ConvertMarkdownStringToHtml(txtMarkdown.Text); }