Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve clipboard destination UX #428

Open
wants to merge 2 commits into
base: release/1.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Greenshot.Base/Core/AbstractDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
Expand Down Expand Up @@ -104,6 +105,38 @@ public virtual bool IsActive

public abstract ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);

/// <summary>
/// If a balloon tip is show for a taken capture, this handles the click on it
/// </summary>
/// <param name="e">SurfaceMessageEventArgs</param>
public virtual void OnExportedNotificationClick(SurfaceMessageEventArgs e)
{
Log.Info(Designation + " Notification Clicked!");

var notifyIcon = SimpleServiceProvider.Current.GetInstance<NotifyIcon>();
if (notifyIcon.Tag is not SurfaceMessageEventArgs eventArgs)
{
Log.Warn("OpenCaptureOnClick called without SurfaceMessageEventArgs");
return;
}

var surface = eventArgs.Surface;
if (surface != null)
{
switch (eventArgs.MessageType)
{
case SurfaceMessageTyp.FileSaved:
ExplorerHelper.OpenInExplorer(surface.LastSaveFullPath);
break;
case SurfaceMessageTyp.UploadedUri:
Process.Start(surface.UploadUrl);
break;
}
}

Log.DebugFormat("Deregistering the BalloonTipClicked");
}

/// <summary>
/// A small helper method to perform some default destination actions, like inform the surface of the export
/// </summary>
Expand All @@ -125,7 +158,7 @@ public void ProcessExport(ExportInformation exportInformation, ISurface surface)
}
else
{
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription));
surface.SendMessageEvent(this, SurfaceMessageTyp.Exported, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription));
}

surface.Modified = false;
Expand Down
6 changes: 6 additions & 0 deletions src/Greenshot.Base/Interfaces/IDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,11 @@ public interface IDestination : IDisposable, IComparable
/// <param name="captureDetails"></param>
/// <returns>DestinationExportInformation with information, like if the destination has "exported" the capture</returns>
ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);

/// <summary>
/// Executed when the user clicks on the exported notification
/// </summary>
/// <param name="e">Notification event args. <see cref="ISurface"/> may be disposed.</param>
void OnExportedNotificationClick(SurfaceMessageEventArgs e);
}
}
10 changes: 7 additions & 3 deletions src/Greenshot.Base/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

using System;
using System.Drawing;

namespace Greenshot.Base.Interfaces
{
Expand All @@ -35,7 +36,8 @@ public interface INotificationService
/// <param name="timeout">TimeSpan</param>
/// <param name="onClickAction">Action called if the user clicks the notification</param>
/// <param name="onClosedAction">Action</param>
void ShowWarningMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null);
/// <param name="heroImage">Optional hero image (used only when supported by notification system)</param>
void ShowWarningMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null, Image heroImage = null);

/// <summary>
/// This will show an error message to the user
Expand All @@ -44,7 +46,8 @@ public interface INotificationService
/// <param name="timeout">TimeSpan</param>
/// <param name="onClickAction">Action called if the user clicks the notification</param>
/// <param name="onClosedAction">Action</param>
void ShowErrorMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null);
/// <param name="heroImage">Optional hero image (used only when supported by notification system)</param>
void ShowErrorMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null, Image heroImage = null);

/// <summary>
/// This will show an info message to the user
Expand All @@ -53,6 +56,7 @@ public interface INotificationService
/// <param name="timeout">TimeSpan</param>
/// <param name="onClickAction">Action called if the user clicks the notification</param>
/// <param name="onClosedAction">Action</param>
void ShowInfoMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null);
/// <param name="heroImage">Optional hero image (used only when supported by notification system)</param>
void ShowInfoMessage(string message, TimeSpan? timeout = null, Action onClickAction = null, Action onClosedAction = null, Image heroImage = null);
}
}
8 changes: 7 additions & 1 deletion src/Greenshot.Base/Interfaces/SurfaceMessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
*/

using System;
using System.Drawing;

namespace Greenshot.Base.Interfaces
{
public class SurfaceMessageEventArgs : EventArgs
public sealed class SurfaceMessageEventArgs : EventArgs, IDisposable
{
public Image Image { get; set; }
public SurfaceMessageTyp MessageType { get; set; }
public string Message { get; set; }
public ISurface Surface { get; set; }
public void Dispose()
{
Image.Dispose();
}
}
}
2 changes: 1 addition & 1 deletion src/Greenshot.Base/Interfaces/SurfaceMessageTyp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum SurfaceMessageTyp
{
FileSaved,
Error,
Info,
Exported,
UploadedUri
}
}
3 changes: 3 additions & 0 deletions src/Greenshot.Editor/Configuration/LanguageKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum LangKey
editor_clipboardfailed,
editor_close_on_save,
editor_close_on_save_title,
editor_close_on_clipboard,
editor_close_on_clipboard_title,
editor_copyimagetoclipboard,
editor_copytoclipboard,
editor_cuttoclipboard,
editor_deleteelement,
Expand Down
2 changes: 1 addition & 1 deletion src/Greenshot.Editor/Drawing/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,9 @@ public bool IsCropPossible(ref NativeRect cropRectangle, CropContainer.CropModes
public void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message)
{
if (_surfaceMessage == null) return;

var eventArgs = new SurfaceMessageEventArgs
{
Image = GetImageForExport(),
Message = message,
MessageType = messageType,
Surface = this
Expand Down
19 changes: 17 additions & 2 deletions src/Greenshot.Editor/Forms/ImageEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -935,15 +935,22 @@ private void ImageEditorFormFormClosing(object sender, FormClosingEventArgs e)
// Make sure the editor is visible
WindowDetails.ToForeground(Handle);

// If the user choose the clipboard as destination, just keep it also on close
bool saveToClipboard = _surface.CaptureDetails.CaptureDestinations.SingleOrDefault()?.Designation == nameof(WellKnownDestinations.Clipboard);

MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
// Dissallow "CANCEL" if the application needs to shutdown
if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing)
{
buttons = MessageBoxButtons.YesNo;
}

DialogResult result = MessageBox.Show(Language.GetString(LangKey.editor_close_on_save), Language.GetString(LangKey.editor_close_on_save_title), buttons,
DialogResult result = MessageBox.Show(
Language.GetString(saveToClipboard ? LangKey.editor_close_on_clipboard : LangKey.editor_close_on_save),
Language.GetString(saveToClipboard ? LangKey.editor_close_on_clipboard_title : LangKey.editor_close_on_save_title),
buttons,
MessageBoxIcon.Question);

if (result.Equals(DialogResult.Cancel))
{
e.Cancel = true;
Expand All @@ -952,7 +959,15 @@ private void ImageEditorFormFormClosing(object sender, FormClosingEventArgs e)

if (result.Equals(DialogResult.Yes))
{
BtnSaveClick(sender, e);
if (saveToClipboard)
{
BtnClipboardClick(sender, e);
}
else
{
BtnSaveClick(sender, e);
}

// Check if the save was made, if not it was cancelled so we cancel the closing
if (_surface.Modified)
{
Expand Down