From 4849002ecabeef5298a67a3d4f86a7348651398a Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 26 Jun 2015 18:59:30 +0300 Subject: [PATCH] Added Upload and Copy buttons to webpage capture --- ShareX/Forms/WebpageCaptureForm.Designer.cs | 20 ++++++ ShareX/Forms/WebpageCaptureForm.cs | 27 ++++++-- ShareX/Forms/WebpageCaptureForm.resx | 75 ++++++++++++++++++--- ShareX/TaskHelpers.cs | 15 ++++- 4 files changed, 122 insertions(+), 15 deletions(-) diff --git a/ShareX/Forms/WebpageCaptureForm.Designer.cs b/ShareX/Forms/WebpageCaptureForm.Designer.cs index 961c3a050..5e082aa33 100644 --- a/ShareX/Forms/WebpageCaptureForm.Designer.cs +++ b/ShareX/Forms/WebpageCaptureForm.Designer.cs @@ -46,6 +46,8 @@ private void InitializeComponent() this.lblWebpageX = new System.Windows.Forms.Label(); this.lblCaptureDelay = new System.Windows.Forms.Label(); this.nudCaptureDelay = new System.Windows.Forms.NumericUpDown(); + this.btnCopy = new System.Windows.Forms.Button(); + this.btnUpload = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pbResult)).BeginInit(); this.pResult.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudWebpageWidth)).BeginInit(); @@ -160,11 +162,27 @@ private void InitializeComponent() this.nudCaptureDelay.Name = "nudCaptureDelay"; this.nudCaptureDelay.ValueChanged += new System.EventHandler(this.nudCaptureDelay_ValueChanged); // + // btnCopy + // + resources.ApplyResources(this.btnCopy, "btnCopy"); + this.btnCopy.Name = "btnCopy"; + this.btnCopy.UseVisualStyleBackColor = true; + this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click); + // + // btnUpload + // + resources.ApplyResources(this.btnUpload, "btnUpload"); + this.btnUpload.Name = "btnUpload"; + this.btnUpload.UseVisualStyleBackColor = true; + this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click); + // // WebpageCaptureForm // this.AcceptButton = this.btnCapture; resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.btnUpload); + this.Controls.Add(this.btnCopy); this.Controls.Add(this.nudCaptureDelay); this.Controls.Add(this.lblCaptureDelay); this.Controls.Add(this.nudWebpageHeight); @@ -200,5 +218,7 @@ private void InitializeComponent() private System.Windows.Forms.Label lblWebpageX; private System.Windows.Forms.Label lblCaptureDelay; private System.Windows.Forms.NumericUpDown nudCaptureDelay; + private System.Windows.Forms.Button btnCopy; + private System.Windows.Forms.Button btnUpload; } } \ No newline at end of file diff --git a/ShareX/Forms/WebpageCaptureForm.cs b/ShareX/Forms/WebpageCaptureForm.cs index 717c3de3a..ca5901e5c 100644 --- a/ShareX/Forms/WebpageCaptureForm.cs +++ b/ShareX/Forms/WebpageCaptureForm.cs @@ -38,6 +38,9 @@ namespace ShareX { public partial class WebpageCaptureForm : Form { + public event Action OnImageUploadRequested; + public event Action OnImageCopyRequested; + public bool IsBusy { get; private set; } private WebpageCapture webpageCapture; @@ -70,15 +73,13 @@ private void LoadSettings() nudWebpageHeight.Value = browserSize.Height.Between((int)nudWebpageHeight.Minimum, (int)nudWebpageHeight.Maximum); nudCaptureDelay.Value = (decimal)Program.Settings.WebpageCaptureDelay.Between((float)nudCaptureDelay.Minimum, (float)nudCaptureDelay.Maximum); - - btnCapture.Enabled = txtURL.TextLength > 0; } private void webpageCapture_CaptureCompleted(Bitmap bmp) { pbResult.Image = bmp; IsBusy = false; - btnCapture.Enabled = txtURL.Enabled = !IsBusy; + btnCapture.Enabled = txtURL.Enabled = btnUpload.Enabled = btnCopy.Enabled = !IsBusy; } private void txtURL_TextChanged(object sender, EventArgs e) @@ -104,7 +105,7 @@ private void nudCaptureDelay_ValueChanged(object sender, EventArgs e) private void btnCapture_Click(object sender, EventArgs e) { IsBusy = true; - btnCapture.Enabled = txtURL.Enabled = !IsBusy; + btnCapture.Enabled = txtURL.Enabled = btnUpload.Enabled = btnCopy.Enabled = !IsBusy; if (pbResult.Image != null) { pbResult.Image.Dispose(); @@ -114,5 +115,23 @@ private void btnCapture_Click(object sender, EventArgs e) webpageCapture.CaptureDelay = (int)nudCaptureDelay.Value * 1000; webpageCapture.CapturePage(txtURL.Text, new Size((int)nudWebpageWidth.Value, (int)nudWebpageWidth.Value)); } + + private void btnUpload_Click(object sender, EventArgs e) + { + if (pbResult.Image != null) + { + Image img = (Image)pbResult.Image.Clone(); + OnImageUploadRequested(img); + } + } + + private void btnCopy_Click(object sender, EventArgs e) + { + if (pbResult.Image != null) + { + Image img = (Image)pbResult.Image.Clone(); + OnImageCopyRequested(img); + } + } } } \ No newline at end of file diff --git a/ShareX/Forms/WebpageCaptureForm.resx b/ShareX/Forms/WebpageCaptureForm.resx index 705846aa1..2153ee7b4 100644 --- a/ShareX/Forms/WebpageCaptureForm.resx +++ b/ShareX/Forms/WebpageCaptureForm.resx @@ -142,7 +142,7 @@ $this - 9 + 11 True @@ -169,7 +169,10 @@ $this - 8 + 10 + + + False 336, 35 @@ -193,7 +196,7 @@ $this - 7 + 9 0, 0 @@ -244,7 +247,7 @@ $this - 6 + 8 True @@ -271,7 +274,7 @@ $this - 5 + 7 80, 36 @@ -295,7 +298,7 @@ $this - 4 + 6 168, 36 @@ -319,7 +322,7 @@ $this - 2 + 4 True @@ -349,7 +352,7 @@ $this - 3 + 5 True @@ -376,7 +379,7 @@ $this - 1 + 3 280, 36 @@ -400,6 +403,60 @@ $this + 2 + + + False + + + 576, 35 + + + 112, 23 + + + 11 + + + Copy + + + btnCopy + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + False + + + 456, 35 + + + 113, 23 + + + 12 + + + Upload + + + btnUpload + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 9c76a3ce9..60c5ca74e 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -499,9 +499,20 @@ public static void OpenAutoCapture() AutoCaptureForm.Instance.ShowActivate(); } - public static void OpenWebpageCapture() + public static void OpenWebpageCapture(TaskSettings taskSettings = null) { - new WebpageCaptureForm().Show(); + if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); + + WebpageCaptureForm webpageCaptureForm = new WebpageCaptureForm(); + webpageCaptureForm.OnImageUploadRequested += img => UploadManager.RunImageTask(img, taskSettings); + webpageCaptureForm.OnImageCopyRequested += img => + { + using (img) + { + ClipboardHelpers.CopyImage(img); + } + }; + webpageCaptureForm.Show(); } public static void StartAutoCapture()