Skip to content

Commit

Permalink
Use UWP notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
eltos committed Mar 5, 2022
1 parent 1737590 commit 0e809b6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 44 deletions.
4 changes: 2 additions & 2 deletions PasteIntoFile/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public Dialog(string location, bool forceShowDialog = false)
{
ExplorerUtil.RequestFilenameEdit(file);

var message = string.Format(Resources.str_autosave_balloontext, file);
Program.ShowBalloon(Resources.str_autosave_balloontitle, message, 10_000);
Program.ShowBalloon(Resources.str_autosave_balloontitle,
new []{file, Resources.str_autosave_balloontext}, 10);

Environment.Exit(0);
}
Expand Down
34 changes: 10 additions & 24 deletions PasteIntoFile/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using CommandLine;
using CommandLine.Text;
using Microsoft.Toolkit.Uwp.Notifications;
using PasteIntoFile.Properties;

namespace PasteIntoFile
Expand Down Expand Up @@ -280,29 +280,15 @@ public static void RestartAppElevated(string location)
/// </summary>
/// <param name="title">Title of the message</param>
/// <param name="message">Body of the message</param>
/// <param name="timeout">Duration after which message is dismissed</param>
public static void ShowBalloon(string title, string message, ushort timeout = 5000)
{
var notification = new NotifyIcon
{
Visible = true,
Icon = Resources.icon,
// optional - BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info,
BalloonTipTitle = title,
BalloonTipText = message,
};

// Display for 5 seconds.
notification.ShowBalloonTip(timeout);

// This will let the balloon close after it's 5 second timeout
// for demonstration purposes. Comment this out to see what happens
// when dispose is called while a balloon is still visible.
Thread.Sleep(timeout);

// The notification should be disposed when you don't need it anymore,
// but doing so will immediately close the balloon if it's visible.
notification.Dispose();
/// <param name="expire">Duration after which message is dismissed in second</param>
public static void ShowBalloon(string title, string[] message, ushort expire = 5) {
var builder = new ToastContentBuilder().AddText(title);
foreach (var s in message) {
builder.AddText(s);
}
builder.Show(toast => {
toast.ExpirationTime = DateTime.Now.AddSeconds(expire);
});
}

/// <summary>
Expand Down
17 changes: 8 additions & 9 deletions PasteIntoFile/PasteIntoFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,11 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="BetterFolderBrowser, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\BetterFolderBrowser.1.2.0\lib\BetterFolderBrowser.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="CommandLine, Version=2.8.0.0, Culture=neutral, PublicKeyToken=5a870481e358d379">
<HintPath>..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll</HintPath>
<Private>True</Private>
<Reference Include="BetterFolderBrowser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\BetterFolderBrowser.1.0.0\lib\BetterFolderBrowser.dll</HintPath>
</Reference>
<Reference Include="SharpClipboard, Version=3.5.2.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\SharpClipboard.3.5.2\lib\net20\SharpClipboard.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down Expand Up @@ -143,7 +137,6 @@
<None Include="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -183,6 +176,12 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="BetterFolderBrowser" Version="1.0.0" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
<PackageReference Include="SharpClipboard" Version="3.5.2" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 2 additions & 0 deletions PasteIntoFile/PasteIntoFile.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/DesignerComponentManagerNuGet/DesignerToolboxNuGetState/@EntryValue">C:\Users\Philipp\RiderProjects\PasteIntoFile\packages\BetterFolderBrowser.1.2.0\lib\BetterFolderBrowser.dll|*C:\Users\Philipp\RiderProjects\PasteIntoFile\packages\SharpClipboard.3.5.2\lib\net20\SharpClipboard.dll|*C:\Users\Philipp\RiderProjects\PasteIntoFile\packages\MaterialSkin.0.2.1\lib\MaterialSkin.dll|*C:\Users\Philipp\RiderProjects\PasteIntoFile\packages\DarkUI.2.0.2\lib\DarkUI.dll|DarkUI.Docking.DarkDockPanel;DarkUI.Controls.DarkCheckBox;DarkUI.Controls.DarkDropdownList;DarkUI.Controls.DarkComboBox;DarkUI.Controls.DarkGroupBox;DarkUI.Controls.DarkNumericUpDown;DarkUI.Controls.DarkRadioButton;DarkUI.Controls.DarkTitle;DarkUI.Controls.DarkTreeView;DarkUI.Controls.DarkListView;DarkUI.Controls.DarkButton;DarkUI.Controls.DarkContextMenu;DarkUI.Controls.DarkLabel;DarkUI.Controls.DarkMenuStrip;DarkUI.Controls.DarkScrollBar;DarkUI.Controls.DarkSectionPanel;DarkUI.Controls.DarkSeparator;DarkUI.Controls.DarkStatusStrip;DarkUI.Controls.DarkTextBox;DarkUI.Controls.DarkToolStrip</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion PasteIntoFile/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion PasteIntoFile/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<value>Zwischenablage leeren</value>
</data>
<data name="str_autosave_balloontext" xml:space="preserve">
<value>Inhalt der Zwischenablage wurde automatisch als {0} gespeichert. Umschalttaste gedrückt halten um Optionen wieder anzuzeigen.</value>
<value>Umschalttaste gedrückt halten um Optionen wieder anzuzeigen.</value>
</data>
<data name="str_autosave_balloontitle" xml:space="preserve">
<value>Zwischenablage als Datei gespeichert</value>
Expand Down
2 changes: 1 addition & 1 deletion PasteIntoFile/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<value>Select a folder for saving this file </value>
</data>
<data name="str_autosave_balloontext" xml:space="preserve">
<value>Clipboard content has been automatically saved as {0}. Hold shift key during save to show option window.</value>
<value>Hold shift key during save to show option window.</value>
</data>
<data name="str_autosave_infotext" xml:space="preserve">
<value>Files are now automatically saved without prompting for filename and extension. Instead, the file created will be selected for renaming in the explorer window. To show the dialog again, run the PasteInfoFile executable without arguments or hold the SHIFT key while selecting the context menu entry.</value>
Expand Down
6 changes: 0 additions & 6 deletions PasteIntoFile/packages.config

This file was deleted.

0 comments on commit 0e809b6

Please sign in to comment.