mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added "Show toast window with image preview after task is completed" setting
This commit is contained in:
parent
b78fd0ac41
commit
c9dff4a04a
9 changed files with 95 additions and 28 deletions
|
@ -70,7 +70,6 @@ private void MainForm_HandleCreated(object sender, EventArgs e)
|
||||||
private void AfterShownJobs()
|
private void AfterShownJobs()
|
||||||
{
|
{
|
||||||
this.ShowActivate();
|
this.ShowActivate();
|
||||||
ToastForm.ShowAsync("test", ShareXResources.Logo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitControls()
|
private void InitControls()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace ShareX
|
namespace ShareX
|
||||||
{
|
{
|
||||||
partial class ToastForm
|
partial class NotificationForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
@ -36,16 +36,18 @@ private void InitializeComponent()
|
||||||
//
|
//
|
||||||
this.tDuration.Tick += new System.EventHandler(this.tDuration_Tick);
|
this.tDuration.Tick += new System.EventHandler(this.tDuration_Tick);
|
||||||
//
|
//
|
||||||
// ToastForm
|
// NotificationForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(300, 150);
|
this.ClientSize = new System.Drawing.Size(300, 150);
|
||||||
|
this.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||||
this.Name = "ToastForm";
|
this.Name = "NotificationForm";
|
||||||
this.ShowInTaskbar = false;
|
this.ShowInTaskbar = false;
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||||
this.Text = "ToastForm";
|
this.Text = "ToastForm";
|
||||||
|
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,6 +29,8 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -36,20 +38,25 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
namespace ShareX
|
namespace ShareX
|
||||||
{
|
{
|
||||||
public partial class ToastForm : Form
|
public partial class NotificationForm : Form
|
||||||
{
|
{
|
||||||
public string ToastText { get; private set; }
|
public string ToastText { get; private set; }
|
||||||
public Image ToastImage { get; private set; }
|
public Image ToastImage { get; private set; }
|
||||||
|
public string URL { get; private set; }
|
||||||
|
|
||||||
public ToastForm(int duration, string text, Image image)
|
private int windowOffset = 3;
|
||||||
|
|
||||||
|
public NotificationForm(int duration, Size size, string text, Image image, string url)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Size = size;
|
||||||
ToastText = text;
|
ToastText = text;
|
||||||
image = ImageHelpers.ResizeImage(image, ClientRectangle.Size.Offset(-2), true, true);
|
image = ImageHelpers.ResizeImage(image, ClientRectangle.Size.Offset(-2), true, true);
|
||||||
image = ImageHelpers.DrawCheckers(image);
|
image = ImageHelpers.DrawCheckers(image);
|
||||||
ToastImage = image;
|
ToastImage = image;
|
||||||
|
URL = url;
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
||||||
Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width, Screen.PrimaryScreen.WorkingArea.Bottom - Height);
|
Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width - windowOffset, Screen.PrimaryScreen.WorkingArea.Bottom - Height - windowOffset);
|
||||||
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_BLEND);
|
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_BLEND);
|
||||||
tDuration.Interval = duration;
|
tDuration.Interval = duration;
|
||||||
tDuration.Start();
|
tDuration.Start();
|
||||||
|
@ -58,30 +65,60 @@ public ToastForm(int duration, string text, Image image)
|
||||||
private void tDuration_Tick(object sender, EventArgs e)
|
private void tDuration_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
tDuration.Stop();
|
tDuration.Stop();
|
||||||
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
|
NativeMethods.AnimateWindow(Handle, 2000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
Graphics g = e.Graphics;
|
Graphics g = e.Graphics;
|
||||||
|
|
||||||
g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height);
|
g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height);
|
||||||
|
|
||||||
|
using (SolidBrush brush = new SolidBrush(Color.FromArgb(200, 255, 255, 255)))
|
||||||
|
{
|
||||||
|
g.FillRectangle(brush, new Rectangle(0, 0, e.ClipRectangle.Width, 40));
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Font font = new Font("Arial", 10))
|
||||||
|
{
|
||||||
|
g.DrawString(ToastText, font, Brushes.Black, e.ClipRectangle.RectangleOffset(-5));
|
||||||
|
}
|
||||||
|
|
||||||
g.DrawRectangleProper(Pens.Black, e.ClipRectangle);
|
g.DrawRectangleProper(Pens.Black, e.ClipRectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowAsync(string text, Image image)
|
public static void ShowAsync(string text, string imagePath, string url)
|
||||||
{
|
{
|
||||||
Image cloneImage = (Image)image.Clone();
|
if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
|
||||||
|
|
||||||
Thread thread = new Thread(() =>
|
|
||||||
{
|
{
|
||||||
using (ToastForm toastForm = new ToastForm(5000, text, cloneImage))
|
Thread thread = new Thread(() =>
|
||||||
{
|
{
|
||||||
toastForm.ShowDialog();
|
using (Image img = ImageHelpers.LoadImage(imagePath))
|
||||||
}
|
using (NotificationForm toastForm = new NotificationForm(5000, new Size(400, 300), text, img, url))
|
||||||
});
|
{
|
||||||
|
toastForm.ShowDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
thread.Start();
|
thread.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Button == System.Windows.Forms.MouseButtons.Left)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(URL))
|
||||||
|
{
|
||||||
|
Helpers.LoadBrowserAsync(URL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.Button == MouseButtons.Right)
|
||||||
|
{
|
||||||
|
tDuration.Stop();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
18
ShareX/Forms/TaskSettingsForm.Designer.cs
generated
18
ShareX/Forms/TaskSettingsForm.Designer.cs
generated
|
@ -155,6 +155,7 @@ private void InitializeComponent()
|
||||||
this.tpAdvanced = new System.Windows.Forms.TabPage();
|
this.tpAdvanced = new System.Windows.Forms.TabPage();
|
||||||
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
|
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
|
||||||
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
|
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
|
||||||
|
this.cbShowToastWindowAfterTask = new System.Windows.Forms.CheckBox();
|
||||||
this.tcHotkeySettings.SuspendLayout();
|
this.tcHotkeySettings.SuspendLayout();
|
||||||
this.tpTask.SuspendLayout();
|
this.tpTask.SuspendLayout();
|
||||||
this.tpGeneral.SuspendLayout();
|
this.tpGeneral.SuspendLayout();
|
||||||
|
@ -454,6 +455,7 @@ private void InitializeComponent()
|
||||||
// panelGeneral
|
// panelGeneral
|
||||||
//
|
//
|
||||||
this.panelGeneral.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
this.panelGeneral.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.panelGeneral.Controls.Add(this.cbShowToastWindowAfterTask);
|
||||||
this.panelGeneral.Controls.Add(this.chkShowAfterUploadForm);
|
this.panelGeneral.Controls.Add(this.chkShowAfterUploadForm);
|
||||||
this.panelGeneral.Controls.Add(this.cbShowAfterCaptureTasksForm);
|
this.panelGeneral.Controls.Add(this.cbShowAfterCaptureTasksForm);
|
||||||
this.panelGeneral.Controls.Add(this.cbTrayBalloonTipAfterUpload);
|
this.panelGeneral.Controls.Add(this.cbTrayBalloonTipAfterUpload);
|
||||||
|
@ -469,7 +471,7 @@ private void InitializeComponent()
|
||||||
// chkShowAfterUploadForm
|
// chkShowAfterUploadForm
|
||||||
//
|
//
|
||||||
this.chkShowAfterUploadForm.AutoSize = true;
|
this.chkShowAfterUploadForm.AutoSize = true;
|
||||||
this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 104);
|
this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 128);
|
||||||
this.chkShowAfterUploadForm.Name = "chkShowAfterUploadForm";
|
this.chkShowAfterUploadForm.Name = "chkShowAfterUploadForm";
|
||||||
this.chkShowAfterUploadForm.Size = new System.Drawing.Size(271, 17);
|
this.chkShowAfterUploadForm.Size = new System.Drawing.Size(271, 17);
|
||||||
this.chkShowAfterUploadForm.TabIndex = 18;
|
this.chkShowAfterUploadForm.TabIndex = 18;
|
||||||
|
@ -513,7 +515,7 @@ private void InitializeComponent()
|
||||||
// cbHistorySave
|
// cbHistorySave
|
||||||
//
|
//
|
||||||
this.cbHistorySave.AutoSize = true;
|
this.cbHistorySave.AutoSize = true;
|
||||||
this.cbHistorySave.Location = new System.Drawing.Point(8, 128);
|
this.cbHistorySave.Location = new System.Drawing.Point(8, 152);
|
||||||
this.cbHistorySave.Name = "cbHistorySave";
|
this.cbHistorySave.Name = "cbHistorySave";
|
||||||
this.cbHistorySave.Size = new System.Drawing.Size(139, 17);
|
this.cbHistorySave.Size = new System.Drawing.Size(139, 17);
|
||||||
this.cbHistorySave.TabIndex = 17;
|
this.cbHistorySave.TabIndex = 17;
|
||||||
|
@ -1633,6 +1635,17 @@ private void InitializeComponent()
|
||||||
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
|
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
|
||||||
this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged);
|
this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged);
|
||||||
//
|
//
|
||||||
|
// cbShowToastWindowAfterTask
|
||||||
|
//
|
||||||
|
this.cbShowToastWindowAfterTask.AutoSize = true;
|
||||||
|
this.cbShowToastWindowAfterTask.Location = new System.Drawing.Point(8, 104);
|
||||||
|
this.cbShowToastWindowAfterTask.Name = "cbShowToastWindowAfterTask";
|
||||||
|
this.cbShowToastWindowAfterTask.Size = new System.Drawing.Size(320, 17);
|
||||||
|
this.cbShowToastWindowAfterTask.TabIndex = 19;
|
||||||
|
this.cbShowToastWindowAfterTask.Text = "Show toast window with image preview after task is completed";
|
||||||
|
this.cbShowToastWindowAfterTask.UseVisualStyleBackColor = true;
|
||||||
|
this.cbShowToastWindowAfterTask.CheckedChanged += new System.EventHandler(this.cbShowToastWindowAfterTask_CheckedChanged);
|
||||||
|
//
|
||||||
// TaskSettingsForm
|
// TaskSettingsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
@ -1828,6 +1841,7 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.CheckBox chkShowImageEffectsWindowAfterCapture;
|
private System.Windows.Forms.CheckBox chkShowImageEffectsWindowAfterCapture;
|
||||||
private System.Windows.Forms.CheckBox chkOverrideFTP;
|
private System.Windows.Forms.CheckBox chkOverrideFTP;
|
||||||
private System.Windows.Forms.ComboBox cboFTPaccounts;
|
private System.Windows.Forms.ComboBox cboFTPaccounts;
|
||||||
|
private System.Windows.Forms.CheckBox cbShowToastWindowAfterTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false)
|
||||||
cbPlaySoundAfterUpload.Checked = TaskSettings.GeneralSettings.PlaySoundAfterUpload;
|
cbPlaySoundAfterUpload.Checked = TaskSettings.GeneralSettings.PlaySoundAfterUpload;
|
||||||
chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm;
|
chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm;
|
||||||
cbTrayBalloonTipAfterUpload.Checked = TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload;
|
cbTrayBalloonTipAfterUpload.Checked = TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload;
|
||||||
|
cbShowToastWindowAfterTask.Checked = TaskSettings.GeneralSettings.ShowToastWindowAfterTask;
|
||||||
cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory;
|
cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory;
|
||||||
|
|
||||||
// Image - Quality
|
// Image - Quality
|
||||||
|
@ -422,6 +423,11 @@ private void cbTrayBalloonTipAfterUpload_CheckedChanged(object sender, EventArgs
|
||||||
TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload = cbTrayBalloonTipAfterUpload.Checked;
|
TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload = cbTrayBalloonTipAfterUpload.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cbShowToastWindowAfterTask_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
TaskSettings.GeneralSettings.ShowToastWindowAfterTask = cbShowToastWindowAfterTask.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
private void cbHistorySave_CheckedChanged(object sender, EventArgs e)
|
private void cbHistorySave_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
TaskSettings.GeneralSettings.SaveHistory = cbHistorySave.Checked;
|
TaskSettings.GeneralSettings.SaveHistory = cbHistorySave.Checked;
|
||||||
|
|
|
@ -140,11 +140,11 @@
|
||||||
<Compile Include="Forms\SettingsForm.Designer.cs">
|
<Compile Include="Forms\SettingsForm.Designer.cs">
|
||||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Forms\ToastForm.cs">
|
<Compile Include="Forms\NotificationForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Forms\ToastForm.Designer.cs">
|
<Compile Include="Forms\NotificationForm.Designer.cs">
|
||||||
<DependentUpon>ToastForm.cs</DependentUpon>
|
<DependentUpon>NotificationForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Forms\UploadTestForm.cs">
|
<Compile Include="Forms\UploadTestForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
@ -244,8 +244,8 @@
|
||||||
<EmbeddedResource Include="Forms\MainForm.resx">
|
<EmbeddedResource Include="Forms\MainForm.resx">
|
||||||
<DependentUpon>MainForm.cs</DependentUpon>
|
<DependentUpon>MainForm.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Forms\ToastForm.resx">
|
<EmbeddedResource Include="Forms\NotificationForm.resx">
|
||||||
<DependentUpon>ToastForm.cs</DependentUpon>
|
<DependentUpon>NotificationForm.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Forms\UploadTestForm.resx">
|
<EmbeddedResource Include="Forms\UploadTestForm.resx">
|
||||||
<DependentUpon>UploadTestForm.cs</DependentUpon>
|
<DependentUpon>UploadTestForm.cs</DependentUpon>
|
||||||
|
|
|
@ -314,10 +314,18 @@ private static void task_UploadCompleted(UploadTask task)
|
||||||
balloonTipText = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat);
|
balloonTipText = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(balloonTipText) && task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible)
|
if (!string.IsNullOrEmpty(balloonTipText))
|
||||||
{
|
{
|
||||||
Program.MainForm.niTray.Tag = result;
|
if (task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible)
|
||||||
Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info);
|
{
|
||||||
|
Program.MainForm.niTray.Tag = result;
|
||||||
|
Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask)
|
||||||
|
{
|
||||||
|
NotificationForm.ShowAsync(balloonTipText, info.FilePath, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm)
|
if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm)
|
||||||
|
|
|
@ -193,9 +193,10 @@ private void SetDefaultSettings()
|
||||||
public class TaskSettingsGeneral
|
public class TaskSettingsGeneral
|
||||||
{
|
{
|
||||||
public bool PlaySoundAfterCapture = true;
|
public bool PlaySoundAfterCapture = true;
|
||||||
|
public bool ShowAfterCaptureTasksForm = false;
|
||||||
public bool PlaySoundAfterUpload = true;
|
public bool PlaySoundAfterUpload = true;
|
||||||
public bool TrayBalloonTipAfterUpload = true;
|
public bool TrayBalloonTipAfterUpload = true;
|
||||||
public bool ShowAfterCaptureTasksForm = false;
|
public bool ShowToastWindowAfterTask = false;
|
||||||
public bool ShowAfterUploadForm = false;
|
public bool ShowAfterUploadForm = false;
|
||||||
public bool SaveHistory = true;
|
public bool SaveHistory = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue