From e3e54bf7203520b6339ffebaa3feb3e0bfcc8895 Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 3 Apr 2019 13:56:15 +0300 Subject: [PATCH] If settings save fail balloon tip clicked then debug log window will open --- ShareX/BalloonTipAction.cs | 39 ++++++++++++++++++++++++++++++++++++++ ShareX/Enums.cs | 7 +++++++ ShareX/Forms/MainForm.cs | 28 ++++++++++++--------------- ShareX/SettingManager.cs | 7 ++++++- ShareX/ShareX.csproj | 1 + ShareX/TaskHelpers.cs | 22 +++++++++++++++++++-- ShareX/TaskManager.cs | 8 +++++++- 7 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 ShareX/BalloonTipAction.cs diff --git a/ShareX/BalloonTipAction.cs b/ShareX/BalloonTipAction.cs new file mode 100644 index 000000000..0168b18b4 --- /dev/null +++ b/ShareX/BalloonTipAction.cs @@ -0,0 +1,39 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2019 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShareX +{ + public class BalloonTipAction + { + public BalloonTipClickAction ClickAction { get; set; } + public string Text { get; set; } + } +} \ No newline at end of file diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs index 0a5b13e67..a3860247d 100644 --- a/ShareX/Enums.cs +++ b/ShareX/Enums.cs @@ -297,4 +297,11 @@ public enum StartupState EnabledByPolicy = StartupTaskState.EnabledByPolicy } #endif + + public enum BalloonTipClickAction + { + None, + OpenURL, + OpenDebugLog + } } \ No newline at end of file diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 4c0862c1d..ab5571503 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -1752,19 +1752,7 @@ private void tsbImageHistory_Click(object sender, EventArgs e) private void tsmiShowDebugLog_Click(object sender, EventArgs e) { - DebugForm form = DebugForm.GetFormInstance(DebugHelper.Logger); - if (!form.HasUploadRequested) - { - form.UploadRequested += (text) => - { - DialogResult result = MessageBox.Show(form, Resources.MainForm_UploadDebugLogWarning, "ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); - if (result == DialogResult.Yes) - { - UploadManager.UploadText(text); - } - }; - } - form.ForceActivate(); + TaskHelpers.OpenDebugLog(); } private void tsmiTestImageUpload_Click(object sender, EventArgs e) @@ -1860,11 +1848,19 @@ private void niTray_MouseDoubleClick(object sender, MouseEventArgs e) private void niTray_BalloonTipClicked(object sender, EventArgs e) { - string url = niTray.Tag as string; + BalloonTipAction action = niTray.Tag as BalloonTipAction; - if (!string.IsNullOrEmpty(url)) + if (action != null) { - URLHelpers.OpenURL(url); + switch (action.ClickAction) + { + case BalloonTipClickAction.OpenURL: + URLHelpers.OpenURL(action.Text); + break; + case BalloonTipClickAction.OpenDebugLog: + TaskHelpers.OpenDebugLog(); + break; + } } } diff --git a/ShareX/SettingManager.cs b/ShareX/SettingManager.cs index cb12c98e9..c5fd57448 100644 --- a/ShareX/SettingManager.cs +++ b/ShareX/SettingManager.cs @@ -162,7 +162,12 @@ private static void Settings_SettingsSaveFailed(Exception e) message = e.Message; } - TaskHelpers.ShowBalloonTip(message, ToolTipIcon.Warning, 5000, "ShareX failed to save settings"); + BalloonTipAction action = new BalloonTipAction() + { + ClickAction = BalloonTipClickAction.OpenDebugLog + }; + + TaskHelpers.ShowBalloonTip(message, ToolTipIcon.Warning, 5000, "ShareX failed to save settings", action); settingsSaveFailWarningCount++; } diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 7c9006b23..101663922 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -139,6 +139,7 @@ + diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 2e9e73483..1127aab43 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -772,6 +772,24 @@ public static void OpenImageHistory() imageHistoryForm.Show(); } + public static void OpenDebugLog() + { + DebugForm form = DebugForm.GetFormInstance(DebugHelper.Logger); + + if (!form.HasUploadRequested) + { + form.UploadRequested += text => + { + if (MessageBox.Show(form, Resources.MainForm_UploadDebugLogWarning, "ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) + { + UploadManager.UploadText(text); + } + }; + } + + form.ForceActivate(); + } + public static void ShowScreenColorPickerDialog(TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); @@ -1765,11 +1783,11 @@ public static bool CheckQRCodeContent(string content) return !string.IsNullOrEmpty(content) && Encoding.UTF8.GetByteCount(content) <= 2952; } - public static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout, string title = "ShareX", string tag = null) + public static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout, string title = "ShareX", BalloonTipAction clickAction = null) { if (Program.MainForm != null && !Program.MainForm.IsDisposed && Program.MainForm.niTray != null && Program.MainForm.niTray.Visible) { - Program.MainForm.niTray.Tag = tag; + Program.MainForm.niTray.Tag = clickAction; Program.MainForm.niTray.ShowBalloonTip(timeout, title, text, icon); } } diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index 79b579118..6522365c7 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -418,8 +418,14 @@ private static void task_TaskCompleted(WorkerTask task) switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: + BalloonTipAction action = new BalloonTipAction() + { + ClickAction = BalloonTipClickAction.OpenURL, + Text = result + }; + TaskHelpers.ShowBalloonTip(result, ToolTipIcon.Info, 5000, - "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, result); + "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, action); break; case PopUpNotificationType.ToastNotification: task.KeepImage = true;