Remove WinForms references and start on installer

This commit is contained in:
2023-04-22 09:05:41 -04:00
parent d6a2fd5a46
commit 586a0497d6
14 changed files with 572 additions and 676 deletions

View File

@@ -106,9 +106,6 @@ public partial class App
if (!IsDebugBuild)
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
// Initialize the window
mainWindow.Initialize();
// Run the app
app.Run(mainWindow);
}

View File

@@ -1,192 +1,108 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net70-windows</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<IsWebBootstrapper>false</IsWebBootstrapper>
<SccProjectName></SccProjectName>
<SccLocalPath></SccLocalPath>
<SccAuxPath></SccAuxPath>
<SccProvider></SccProvider>
<PublishUrl>\\server\d\FeedCenter\</PublishUrl>
<Install>true</Install>
<InstallFrom>Unc</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ProductName>Feed Center</ProductName>
<PublisherName>Feed Center</PublisherName>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>Publish.html</WebPage>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>215</ApplicationRevision>
<ApplicationVersion>0.1.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<PropertyGroup>
<StartupObject></StartupObject>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net70-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>false</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<PropertyGroup>
<EnableDefaultApplicationDefinition>false</EnableDefaultApplicationDefinition>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Application.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<CodeAnalysisLogFile>bin\Debug\FeedCenter.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<CodeAnalysisLogFile>bin\Release\FeedCenter.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutputPath>bin\x64\Debug\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<EntityDeploy Include="Model.edmx">
<Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Model.Designer.cs</LastGenOutput>
</EntityDeploy>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Application.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
<Visible>False</Visible>
<ProductName>Windows Installer 4.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Rss-Download.ico" />
<Resource Include="Resources\Comments-edit.ico" />
<Resource Include="Resources\Warning.ico" />
<Resource Include="Resources\News.ico" />
<Resource Include="Resources\Compile.ico" />
<Resource Include="Resources\Left.ico" />
<Resource Include="Resources\Right.ico" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ChrisKaczor.ApplicationUpdate" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.GenericSettingsProvider" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.InstalledBrowsers" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Application.SingleInstance" Version="1.0.4" />
<PackageReference Include="ChrisKaczor.Wpf.Application.StartWithWindows" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.HtmlTextBlock" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.Toolbar" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.ControlBox" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.SnappingWindow" Version="1.0.2" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="DebounceThrottle" Version="2.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="HtmlTextWriter" Version="2.1.1" />
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" GeneratePathProperty="true">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.1" />
<PackageReference Include="NameBasedGrid" Version="0.10.1">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Realm" Version="10.21.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Remove="SqlSettingsProvider.cs" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<PropertyGroup>
<PostBuildEvent>
if not exist "$(TargetDir)x86" md "$(TargetDir)x86"
xcopy /s /y "$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\x86\*.*" "$(TargetDir)x86"
if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64"
xcopy /s /y "$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\Application.ico" />
<None Remove="Resources\Comments-edit.ico" />
<None Remove="Resources\Compile.ico" />
<None Remove="Resources\Left.ico" />
<None Remove="Resources\News.ico" />
<None Remove="Resources\Right.ico" />
<None Remove="Resources\Rss-Download.ico" />
<None Remove="Resources\Warning.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Application.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ChrisKaczor.ApplicationUpdate" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.GenericSettingsProvider" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.InstalledBrowsers" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Application.SingleInstance" Version="1.0.4" />
<PackageReference Include="ChrisKaczor.Wpf.Application.StartWithWindows" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.HtmlTextBlock" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.Toolbar" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.3" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.ControlBox" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.SnappingWindow" Version="1.0.2" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="DebounceThrottle" Version="2.0.0" />
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.0.108" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="HtmlTextWriter" Version="2.1.1" />
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" GeneratePathProperty="true">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.1" />
<PackageReference Include="NameBasedGrid" Version="0.10.1">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Realm" Version="10.21.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Application.ico" />
<Resource Include="Resources\Comments-edit.ico" />
<Resource Include="Resources\Compile.ico" />
<Resource Include="Resources\Left.ico" />
<Resource Include="Resources\News.ico" />
<Resource Include="Resources\Right.ico" />
<Resource Include="Resources\Rss-Download.ico" />
<Resource Include="Resources\Warning.ico" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Target Name="AddSqlServerCompact_x86" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'win-x86'">
<Exec Command="xcopy /s /y /i &quot;$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\x86\*.*&quot; &quot;$(PublishDir)x86&quot;" />
</Target>
<Target Name="AddSqlServerCompact_x64" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<Exec Command="xcopy /s /y /i &quot;$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\amd64\*.*&quot; &quot;$(PublishDir)amd64&quot;" />
</Target>
<PropertyGroup>
<PostBuildEvent>
xcopy /s /y /i "$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\x86\*.*" "$(TargetDir)x86"
xcopy /s /y /i "$(PkgMicrosoft_SqlServer_Compact)\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"
</PostBuildEvent>
<ApplicationIcon>Resources\Application.ico</ApplicationIcon>
</PropertyGroup>
</Project>

View File

@@ -86,7 +86,7 @@ public partial class MainWindow
_database.SaveChanges(() => _database.Feeds.Add(feed));
// Show a tip
NotificationIcon.ShowBalloonTip(string.Format(Properties.Resources.FeedAddedNotification, feed.Name), System.Windows.Forms.ToolTipIcon.Info);
NotificationIcon.ShowBalloonTip(string.Format(Properties.Resources.FeedAddedNotification, feed.Name), H.NotifyIcon.Core.NotificationIcon.Info);
_currentFeed = feed;
@@ -104,7 +104,7 @@ public partial class MainWindow
var dialogResult = feedForm.Display(feed, this);
// Display the new feed form
if (!dialogResult.HasValue || !dialogResult.Value)
if (!dialogResult.HasValue || !dialogResult.Value)
return;
// Add the feed to the feed table

View File

@@ -34,6 +34,14 @@ public partial class MainWindow : IDisposable
GC.SuppressFinalize(this);
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
// Initialize the window
Initialize();
}
protected override async void OnClosed(EventArgs e)
{
base.OnClosed(e);
@@ -207,9 +215,7 @@ public partial class MainWindow : IDisposable
private void InitializeDisplay()
{
// Get the last category (defaulting to none)
_currentCategory =
_database.Categories.FirstOrDefault(category =>
category.Id.ToString() == Settings.Default.LastCategoryID);
_currentCategory = _database.Categories.FirstOrDefault(category => category.Id.ToString() == Settings.Default.LastCategoryID);
DisplayCategory();
// Get the current feed list to match the category

View File

@@ -1,6 +1,7 @@
using FeedCenter.Properties;
using System;
using System.Windows.Forms;
using System.Timers;
using System.Windows.Threading;
namespace FeedCenter;
@@ -9,11 +10,14 @@ public partial class MainWindow
private Timer _mainTimer;
private DateTime _lastFeedRead;
private DateTime _lastFeedDisplay;
private Dispatcher _dispatcher;
private void InitializeTimer()
{
_dispatcher = Dispatcher.CurrentDispatcher;
_mainTimer = new Timer { Interval = 1000 };
_mainTimer.Tick += HandleMainTimerTick;
_mainTimer.Elapsed += HandleMainTimerElapsed;
}
private void TerminateTimer()
@@ -33,26 +37,29 @@ public partial class MainWindow
_mainTimer.Stop();
}
private void HandleMainTimerTick(object sender, EventArgs e)
private void HandleMainTimerElapsed(object sender, EventArgs e)
{
// If the background worker is busy then don't do anything
if (_feedReadWorker.IsBusy)
return;
_dispatcher.Invoke(() =>
{
// If the background worker is busy then don't do anything
if (_feedReadWorker.IsBusy)
return;
// Stop the timer for now
StopTimer();
// Stop the timer for now
StopTimer();
// Move to the next feed if the scroll interval has expired and the mouse isn't hovering
if (LinkTextList.IsMouseOver)
_lastFeedDisplay = DateTime.Now;
else if (DateTime.Now - _lastFeedDisplay >= Settings.Default.FeedScrollInterval)
NextFeed();
// Move to the next feed if the scroll interval has expired and the mouse isn't hovering
if (LinkTextList.IsMouseOver)
_lastFeedDisplay = DateTime.Now;
else if (DateTime.Now - _lastFeedDisplay >= Settings.Default.FeedScrollInterval)
NextFeed();
// Check to see if we should try to read the feeds
if (DateTime.Now - _lastFeedRead >= Settings.Default.FeedCheckInterval)
ReadFeeds();
// Check to see if we should try to read the feeds
if (DateTime.Now - _lastFeedRead >= Settings.Default.FeedCheckInterval)
ReadFeeds();
// Get the timer going again
StartTimer();
// Get the timer going again
StartTimer();
});
}
}

View File

@@ -112,28 +112,28 @@ public partial class MainWindow
{
var windowInteropHelper = new WindowInteropHelper(this);
var screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
var screen = WpfScreenHelper.Screen.FromHandle(windowInteropHelper.Handle);
var rectangle = new System.Drawing.Rectangle
var rectangle = new Rect
{
X = (int) Left,
Y = (int) Top,
Width = (int) Width,
Height = (int) Height
X = Left,
Y = Top,
Width = Width,
Height = Height
};
var borderThickness = new Thickness();
if (rectangle.Right != screen.WorkingArea.Right)
if (!rectangle.Right.Equals(screen.WorkingArea.Right))
borderThickness.Right = 1;
if (rectangle.Left != screen.WorkingArea.Left)
if (!rectangle.Left.Equals(screen.WorkingArea.Left))
borderThickness.Left = 1;
if (rectangle.Top != screen.WorkingArea.Top)
if (!rectangle.Top.Equals(screen.WorkingArea.Top))
borderThickness.Top = 1;
if (rectangle.Bottom != screen.WorkingArea.Bottom)
if (!rectangle.Bottom.Equals(screen.WorkingArea.Bottom))
borderThickness.Bottom = 1;
WindowBorder.BorderThickness = borderThickness;

View File

@@ -1,49 +1,61 @@
using FeedCenter.Properties;
using System.Windows.Forms;
using H.NotifyIcon;
using System.Windows.Controls;
namespace FeedCenter;
internal static class NotificationIcon
{
private static MainWindow _mainForm;
private static NotifyIcon _notificationIcon;
private static MainWindow _mainWindow;
private static TaskbarIcon _notificationIcon;
private static MenuItem _lockMenuItem;
public static void Initialize(MainWindow mainForm)
public static void Initialize(MainWindow mainWindow)
{
// Store the main window
_mainForm = mainForm;
_mainWindow = mainWindow;
// Create the notification icon
_notificationIcon = new NotifyIcon { Icon = Resources.Application };
_notificationIcon.DoubleClick += HandleNotificationIconDoubleClick;
_notificationIcon = new TaskbarIcon { Icon = Resources.Application };
_notificationIcon.TrayMouseDoubleClick += HandleNotificationIconDoubleClick;
// Setup the menu
var contextMenuStrip = new ContextMenuStrip();
var contextMenu = new ContextMenu();
var toolStripMenuItem = new ToolStripMenuItem(Resources.NotificationIconContextMenuLocked, null, HandleLockWindowClicked) { Checked = Settings.Default.WindowLocked };
contextMenuStrip.Items.Add(toolStripMenuItem);
_lockMenuItem = new MenuItem()
{
Header = Resources.NotificationIconContextMenuLocked,
IsChecked = Settings.Default.WindowLocked
};
_lockMenuItem.Click += HandleLockWindowClicked;
contextMenu.Items.Add(_lockMenuItem);
contextMenuStrip.Items.Add(new ToolStripSeparator());
contextMenu.Items.Add(new Separator());
contextMenuStrip.Items.Add(Resources.NotificationIconContextMenuExit, null, HandleContextMenuExitClick);
var menuItem = new MenuItem()
{
Header = Resources.NotificationIconContextMenuExit
};
menuItem.Click += HandleContextMenuExitClick;
contextMenu.Items.Add(menuItem);
// Set the menu into the icon
_notificationIcon.ContextMenuStrip = contextMenuStrip;
_notificationIcon.ContextMenu = contextMenu;
// Show the icon
_notificationIcon.Visible = true;
_notificationIcon.ForceCreate(false);
}
private static void HandleNotificationIconDoubleClick(object sender, System.EventArgs e)
{
// Bring the main form to the front
_mainForm.Activate();
_mainWindow.Activate();
}
private static void HandleContextMenuExitClick(object sender, System.EventArgs e)
{
// Close the main form
_mainForm.Close();
_mainWindow.Close();
}
private static void HandleLockWindowClicked(object sender, System.EventArgs e)
@@ -52,26 +64,20 @@ internal static class NotificationIcon
Settings.Default.WindowLocked = !Settings.Default.WindowLocked;
// Refresh the menu choice
((ToolStripMenuItem) sender).Checked = Settings.Default.WindowLocked;
_lockMenuItem.IsChecked = Settings.Default.WindowLocked;
}
public static void Dispose()
{
// Get rid of the icon
_notificationIcon.Visible = false;
_notificationIcon.Dispose();
_notificationIcon = null;
_mainForm = null;
_mainWindow = null;
}
public static void ShowBalloonTip(string text, ToolTipIcon icon)
public static void ShowBalloonTip(string text, H.NotifyIcon.Core.NotificationIcon icon)
{
ShowBalloonTip(text, icon, Settings.Default.BalloonTipTimeout);
}
private static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout)
{
_notificationIcon.ShowBalloonTip(timeout, Resources.ApplicationDisplayName, text, icon);
_notificationIcon.ShowNotification(Resources.ApplicationDisplayName, text, icon);
}
}

View File

@@ -1,116 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Windows.Forms;
using System.Collections.Specialized;
using Microsoft.Win32;
namespace FeedCenter
{
class RegistrySettingsProvider : SettingsProvider
{
public RegistrySettingsProvider()
{
}
public override string ApplicationName
{
get { return Application.ProductName; }
set { }
}
public override void Initialize(string name, NameValueCollection col)
{
base.Initialize(this.ApplicationName, col);
}
// SetPropertyValue is invoked when ApplicationSettingsBase.Save is called
// ASB makes sure to pass each provider only the values marked for that provider -
// though in this sample, since the entire settings class was marked with a SettingsProvider
// attribute, all settings in that class map to this provider
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
{
// Iterate through the settings to be stored
// Only IsDirty=true properties should be included in propvals
foreach (SettingsPropertyValue propval in propvals)
{
// NOTE: this provider allows setting to both user- and application-scoped
// settings. The default provider for ApplicationSettingsBase -
// LocalFileSettingsProvider - is read-only for application-scoped setting. This
// is an example of a policy that a provider may need to enforce for implementation,
// security or other reasons.
GetRegKey(propval.Property).SetValue(propval.Name, propval.SerializedValue);
}
}
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
{
// Create new collection of values
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
// Iterate through the settings to be retrieved
foreach (SettingsProperty setting in props)
{
SettingsPropertyValue value = new SettingsPropertyValue(setting);
value.IsDirty = false;
value.SerializedValue = GetRegKey(setting).GetValue(setting.Name);
values.Add(value);
}
return values;
}
// Helper method: fetches correct registry subkey.
// HKLM is used for settings marked as application-scoped.
// HKLU is used for settings marked as user-scoped.
private RegistryKey GetRegKey(SettingsProperty prop)
{
RegistryKey regKey;
if (IsUserScoped(prop))
{
regKey = Registry.CurrentUser;
}
else
{
regKey = Registry.LocalMachine;
}
regKey = regKey.CreateSubKey(GetSubKeyPath());
return regKey;
}
// Helper method: walks the "attribute bag" for a given property
// to determine if it is user-scoped or not.
// Note that this provider does not enforce other rules, such as
// - unknown attributes
// - improper attribute combinations (e.g. both user and app - this implementation
// would say true for user-scoped regardless of existence of app-scoped)
private bool IsUserScoped(SettingsProperty prop)
{
foreach (DictionaryEntry d in prop.Attributes)
{
Attribute a = (Attribute) d.Value;
if (a.GetType() == typeof(UserScopedSettingAttribute))
return true;
}
return false;
}
// Builds a key path based on the CompanyName, ProductName, and ProductVersion attributes in
// the AssemblyInfo file (editable directly or within the Project Properties UI)
private string GetSubKeyPath()
{
return "Software\\" + Application.CompanyName + "\\" + Application.ProductName + "\\" + Application.ProductVersion;
}
}
}