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()
|
||||
{
|
||||
this.ShowActivate();
|
||||
ToastForm.ShowAsync("test", ShareXResources.Logo);
|
||||
}
|
||||
|
||||
private void InitControls()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace ShareX
|
||||
{
|
||||
partial class ToastForm
|
||||
partial class NotificationForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
@ -36,16 +36,18 @@ private void InitializeComponent()
|
|||
//
|
||||
this.tDuration.Tick += new System.EventHandler(this.tDuration_Tick);
|
||||
//
|
||||
// ToastForm
|
||||
// NotificationForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(300, 150);
|
||||
this.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.Name = "ToastForm";
|
||||
this.Name = "NotificationForm";
|
||||
this.ShowInTaskbar = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||
this.Text = "ToastForm";
|
||||
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotificationForm_MouseClick);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
|
@ -29,6 +29,8 @@ You should have received a copy of the GNU General Public License
|
|||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
@ -36,20 +38,25 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
namespace ShareX
|
||||
{
|
||||
public partial class ToastForm : Form
|
||||
public partial class NotificationForm : Form
|
||||
{
|
||||
public string ToastText { 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();
|
||||
Size = size;
|
||||
ToastText = text;
|
||||
image = ImageHelpers.ResizeImage(image, ClientRectangle.Size.Offset(-2), true, true);
|
||||
image = ImageHelpers.DrawCheckers(image);
|
||||
ToastImage = image;
|
||||
URL = url;
|
||||
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);
|
||||
tDuration.Interval = duration;
|
||||
tDuration.Start();
|
||||
|
@ -58,24 +65,37 @@ public ToastForm(int duration, string text, Image image)
|
|||
private void tDuration_Tick(object sender, EventArgs e)
|
||||
{
|
||||
tDuration.Stop();
|
||||
NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
|
||||
NativeMethods.AnimateWindow(Handle, 2000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND);
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static void ShowAsync(string text, Image image)
|
||||
public static void ShowAsync(string text, string imagePath, string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
|
||||
{
|
||||
Image cloneImage = (Image)image.Clone();
|
||||
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
using (ToastForm toastForm = new ToastForm(5000, text, cloneImage))
|
||||
using (Image img = ImageHelpers.LoadImage(imagePath))
|
||||
using (NotificationForm toastForm = new NotificationForm(5000, new Size(400, 300), text, img, url))
|
||||
{
|
||||
toastForm.ShowDialog();
|
||||
}
|
||||
|
@ -84,4 +104,21 @@ public static void ShowAsync(string text, Image image)
|
|||
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.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
|
||||
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
|
||||
this.cbShowToastWindowAfterTask = new System.Windows.Forms.CheckBox();
|
||||
this.tcHotkeySettings.SuspendLayout();
|
||||
this.tpTask.SuspendLayout();
|
||||
this.tpGeneral.SuspendLayout();
|
||||
|
@ -454,6 +455,7 @@ private void InitializeComponent()
|
|||
// panelGeneral
|
||||
//
|
||||
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.cbShowAfterCaptureTasksForm);
|
||||
this.panelGeneral.Controls.Add(this.cbTrayBalloonTipAfterUpload);
|
||||
|
@ -469,7 +471,7 @@ private void InitializeComponent()
|
|||
// chkShowAfterUploadForm
|
||||
//
|
||||
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.Size = new System.Drawing.Size(271, 17);
|
||||
this.chkShowAfterUploadForm.TabIndex = 18;
|
||||
|
@ -513,7 +515,7 @@ private void InitializeComponent()
|
|||
// cbHistorySave
|
||||
//
|
||||
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.Size = new System.Drawing.Size(139, 17);
|
||||
this.cbHistorySave.TabIndex = 17;
|
||||
|
@ -1633,6 +1635,17 @@ private void InitializeComponent()
|
|||
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
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 chkOverrideFTP;
|
||||
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;
|
||||
chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm;
|
||||
cbTrayBalloonTipAfterUpload.Checked = TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload;
|
||||
cbShowToastWindowAfterTask.Checked = TaskSettings.GeneralSettings.ShowToastWindowAfterTask;
|
||||
cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory;
|
||||
|
||||
// Image - Quality
|
||||
|
@ -422,6 +423,11 @@ private void cbTrayBalloonTipAfterUpload_CheckedChanged(object sender, EventArgs
|
|||
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)
|
||||
{
|
||||
TaskSettings.GeneralSettings.SaveHistory = cbHistorySave.Checked;
|
||||
|
|
|
@ -140,11 +140,11 @@
|
|||
<Compile Include="Forms\SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ToastForm.cs">
|
||||
<Compile Include="Forms\NotificationForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ToastForm.Designer.cs">
|
||||
<DependentUpon>ToastForm.cs</DependentUpon>
|
||||
<Compile Include="Forms\NotificationForm.Designer.cs">
|
||||
<DependentUpon>NotificationForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\UploadTestForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
@ -244,8 +244,8 @@
|
|||
<EmbeddedResource Include="Forms\MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\ToastForm.resx">
|
||||
<DependentUpon>ToastForm.cs</DependentUpon>
|
||||
<EmbeddedResource Include="Forms\NotificationForm.resx">
|
||||
<DependentUpon>NotificationForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\UploadTestForm.resx">
|
||||
<DependentUpon>UploadTestForm.cs</DependentUpon>
|
||||
|
|
|
@ -314,12 +314,20 @@ private static void task_UploadCompleted(UploadTask task)
|
|||
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))
|
||||
{
|
||||
if (task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible)
|
||||
{
|
||||
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)
|
||||
{
|
||||
AfterUploadForm dlg = new AfterUploadForm(info);
|
||||
|
|
|
@ -193,9 +193,10 @@ private void SetDefaultSettings()
|
|||
public class TaskSettingsGeneral
|
||||
{
|
||||
public bool PlaySoundAfterCapture = true;
|
||||
public bool ShowAfterCaptureTasksForm = false;
|
||||
public bool PlaySoundAfterUpload = true;
|
||||
public bool TrayBalloonTipAfterUpload = true;
|
||||
public bool ShowAfterCaptureTasksForm = false;
|
||||
public bool ShowToastWindowAfterTask = false;
|
||||
public bool ShowAfterUploadForm = false;
|
||||
public bool SaveHistory = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue