1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-25 08:34:05 +02:00

Make the example notification its own class

This commit is contained in:
chylex 2017-10-31 12:01:53 +01:00
parent 512b5666ac
commit d9da14b5dc
7 changed files with 54 additions and 47 deletions

View File

@ -295,10 +295,6 @@ protected override void WndProc(ref Message m){
// notification helpers // notification helpers
public FormNotificationMain CreateNotificationForm(bool enableContextMenu){
return new FormNotificationMain(this, plugins, enableContextMenu);
}
public void PauseNotification(){ public void PauseNotification(){
notification.PauseNotification(); notification.PauseNotification();
} }

View File

@ -0,0 +1,29 @@
using TweetDuck.Plugins;
using TweetDuck.Resources;
namespace TweetDuck.Core.Notification.Example{
sealed class FormNotificationExample : FormNotificationMain{
private readonly TweetNotification exampleNotification;
public FormNotificationExample(FormBrowser owner, PluginManager pluginManager) : base(owner, pluginManager, false){
string exampleTweetHTML = ScriptLoader.LoadResource("pages/example.html", true);
#if DEBUG
exampleTweetHTML = exampleTweetHTML.Replace("</p>", @"</p><div style='margin-top:256px'>Scrollbar test padding...</div>");
#endif
exampleNotification = TweetNotification.Example(exampleTweetHTML, 95);
}
public void ShowExampleNotification(bool reset){
if (reset){
LoadTweet(exampleNotification);
}
else{
PrepareAndDisplayWindow();
}
UpdateTitle();
}
}
}

View File

@ -12,7 +12,7 @@
using TweetDuck.Resources; using TweetDuck.Resources;
namespace TweetDuck.Core.Notification{ namespace TweetDuck.Core.Notification{
partial class FormNotificationMain : FormNotificationBase{ abstract partial class FormNotificationMain : FormNotificationBase{
private const string NotificationScriptFile = "notification.js"; private const string NotificationScriptFile = "notification.js";
private const int TimerBarHeight = 4; private const int TimerBarHeight = 4;
@ -194,17 +194,6 @@ public virtual void ShowNotification(TweetNotification notification){
LoadTweet(notification); LoadTweet(notification);
} }
public void ShowNotificationForSettings(bool reset){
if (reset){
LoadTweet(TweetNotification.ExampleTweet);
}
else{
PrepareAndDisplayWindow();
}
UpdateTitle();
}
public override void HideNotification(){ public override void HideNotification(){
base.HideNotification(); base.HideNotification();
@ -269,7 +258,7 @@ protected override void SetNotificationSize(int width, int height){
browser.ClientSize = new Size(width, height); browser.ClientSize = new Size(width, height);
} }
private void PrepareAndDisplayWindow(){ protected void PrepareAndDisplayWindow(){
if (RequiresResize){ if (RequiresResize){
RequiresResize = false; RequiresResize = false;
SetNotificationSize(BaseClientWidth, BaseClientHeight); SetNotificationSize(BaseClientWidth, BaseClientHeight);

View File

@ -8,20 +8,8 @@ sealed class TweetNotification{
private const string DefaultHeadLayout = @"<html class='os-windows txt-size--14' data-td-font='medium' data-td-theme='dark'><head><meta charset='utf-8'><meta http-equiv='X-UA-Compatible' content='chrome=1'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/font.5ef884f9f9.css'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/app-dark.5631e0dd42.css'><style type='text/css'>body{background:#222426}</style>"; private const string DefaultHeadLayout = @"<html class='os-windows txt-size--14' data-td-font='medium' data-td-theme='dark'><head><meta charset='utf-8'><meta http-equiv='X-UA-Compatible' content='chrome=1'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/font.5ef884f9f9.css'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/app-dark.5631e0dd42.css'><style type='text/css'>body{background:#222426}</style>";
private static readonly string CustomCSS = ScriptLoader.LoadResource("styles/notification.css"); private static readonly string CustomCSS = ScriptLoader.LoadResource("styles/notification.css");
private static string ExampleTweetHTML; public static TweetNotification Example(string html, int characters){
return new TweetNotification(string.Empty, string.Empty, "Home", html, characters, string.Empty, string.Empty, true);
public static TweetNotification ExampleTweet{
get{
if (ExampleTweetHTML == null){
ExampleTweetHTML = ScriptLoader.LoadResource("pages/example.html", true);
#if DEBUG
ExampleTweetHTML = ExampleTweetHTML.Replace("</p>", @"</p><div style='margin-top:256px'>Scrollbar test padding...</div>");
#endif
}
return new TweetNotification(string.Empty, string.Empty, "Home", ExampleTweetHTML, 95, string.Empty, string.Empty, true);
}
} }
public enum Position{ public enum Position{

View File

@ -3,6 +3,7 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Notification.Example;
using TweetDuck.Core.Other.Settings; using TweetDuck.Core.Other.Settings;
using TweetDuck.Core.Other.Settings.Dialogs; using TweetDuck.Core.Other.Settings.Dialogs;
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
@ -35,7 +36,7 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateHandler up
AddButton("General", () => new TabSettingsGeneral(updates)); AddButton("General", () => new TabSettingsGeneral(updates));
AddButton("System Tray", () => new TabSettingsTray()); AddButton("System Tray", () => new TabSettingsTray());
AddButton("Notifications", () => new TabSettingsNotifications(browser.CreateNotificationForm(false))); AddButton("Notifications", () => new TabSettingsNotifications(new FormNotificationExample(browser, plugins)));
AddButton("Sounds", () => new TabSettingsSounds()); AddButton("Sounds", () => new TabSettingsSounds());
AddButton("Feedback", () => new TabSettingsFeedback()); AddButton("Feedback", () => new TabSettingsFeedback());
AddButton("Advanced", () => new TabSettingsAdvanced(browser.ReinjectCustomCSS)); AddButton("Advanced", () => new TabSettingsAdvanced(browser.ReinjectCustomCSS));

View File

@ -2,21 +2,22 @@
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Notification; using TweetDuck.Core.Notification;
using TweetDuck.Core.Notification.Example;
namespace TweetDuck.Core.Other.Settings{ namespace TweetDuck.Core.Other.Settings{
sealed partial class TabSettingsNotifications : BaseTabSettings{ sealed partial class TabSettingsNotifications : BaseTabSettings{
private static readonly int[] IdlePauseSeconds = { 0, 30, 60, 120, 300 }; private static readonly int[] IdlePauseSeconds = { 0, 30, 60, 120, 300 };
private readonly FormNotificationMain notification; private readonly FormNotificationExample notification;
public TabSettingsNotifications(FormNotificationMain notification){ public TabSettingsNotifications(FormNotificationExample notification){
InitializeComponent(); InitializeComponent();
this.notification = notification; this.notification = notification;
this.notification.Initialized += (sender, args) => { this.notification.Initialized += (sender, args) => {
this.InvokeAsyncSafe(() => { this.InvokeAsyncSafe(() => {
this.notification.ShowNotificationForSettings(true); this.notification.ShowExampleNotification(true);
this.notification.Move += notification_Move; this.notification.Move += notification_Move;
this.notification.ResizeEnd += notification_ResizeEnd; this.notification.ResizeEnd += notification_ResizeEnd;
}); });
@ -113,7 +114,7 @@ private void TabSettingsNotifications_ParentChanged(object sender, EventArgs e){
notification.HideNotification(); notification.HideNotification();
} }
else{ else{
notification.ShowNotificationForSettings(true); notification.ShowExampleNotification(true);
} }
} }
@ -131,7 +132,7 @@ private void notification_Move(object sender, EventArgs e){
private void notification_ResizeEnd(object sender, EventArgs e){ private void notification_ResizeEnd(object sender, EventArgs e){
if (radioSizeCustom.Checked){ if (radioSizeCustom.Checked){
Config.CustomNotificationSize = notification.BrowserSize; Config.CustomNotificationSize = notification.BrowserSize;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
} }
@ -142,7 +143,7 @@ private void radioLoc_CheckedChanged(object sender, EventArgs e){
else if (radioLocBR.Checked)Config.NotificationPosition = TweetNotification.Position.BottomRight; else if (radioLocBR.Checked)Config.NotificationPosition = TweetNotification.Position.BottomRight;
comboBoxDisplay.Enabled = trackBarEdgeDistance.Enabled = true; comboBoxDisplay.Enabled = trackBarEdgeDistance.Enabled = true;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
private void radioLocCustom_Click(object sender, EventArgs e){ private void radioLocCustom_Click(object sender, EventArgs e){
@ -153,7 +154,7 @@ private void radioLocCustom_Click(object sender, EventArgs e){
Config.NotificationPosition = TweetNotification.Position.Custom; Config.NotificationPosition = TweetNotification.Position.Custom;
comboBoxDisplay.Enabled = trackBarEdgeDistance.Enabled = false; comboBoxDisplay.Enabled = trackBarEdgeDistance.Enabled = false;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
if (notification.IsFullyOutsideView() && FormMessage.Question("Notification is outside view", "The notification seems to be outside of view, would you like to reset its position?", FormMessage.Yes, FormMessage.No)){ if (notification.IsFullyOutsideView() && FormMessage.Question("Notification is outside view", "The notification seems to be outside of view, would you like to reset its position?", FormMessage.Yes, FormMessage.No)){
Config.NotificationPosition = TweetNotification.Position.TopRight; Config.NotificationPosition = TweetNotification.Position.TopRight;
@ -169,7 +170,7 @@ private void radioLocCustom_Click(object sender, EventArgs e){
private void radioSize_CheckedChanged(object sender, EventArgs e){ private void radioSize_CheckedChanged(object sender, EventArgs e){
if (radioSizeAuto.Checked)Config.NotificationSize = TweetNotification.Size.Auto; if (radioSizeAuto.Checked)Config.NotificationSize = TweetNotification.Size.Auto;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
notification.CanResizeWindow = false; // must be after ShowNotificationForSettings notification.CanResizeWindow = false; // must be after ShowNotificationForSettings
} }
@ -181,7 +182,7 @@ private void radioSizeCustom_Click(object sender, EventArgs e){
Config.NotificationSize = TweetNotification.Size.Custom; Config.NotificationSize = TweetNotification.Size.Custom;
notification.CanResizeWindow = true; notification.CanResizeWindow = true;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
private void trackBarDuration_ValueChanged(object sender, EventArgs e){ private void trackBarDuration_ValueChanged(object sender, EventArgs e){
@ -206,18 +207,18 @@ private void btnDurationLong_Click(object sender, EventArgs e){
private void checkColumnName_CheckedChanged(object sender, EventArgs e){ private void checkColumnName_CheckedChanged(object sender, EventArgs e){
Config.DisplayNotificationColumn = checkColumnName.Checked; Config.DisplayNotificationColumn = checkColumnName.Checked;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
private void checkNotificationTimer_CheckedChanged(object sender, EventArgs e){ private void checkNotificationTimer_CheckedChanged(object sender, EventArgs e){
Config.DisplayNotificationTimer = checkNotificationTimer.Checked; Config.DisplayNotificationTimer = checkNotificationTimer.Checked;
checkTimerCountDown.Enabled = checkNotificationTimer.Checked; checkTimerCountDown.Enabled = checkNotificationTimer.Checked;
notification.ShowNotificationForSettings(true); notification.ShowExampleNotification(true);
} }
private void checkTimerCountDown_CheckedChanged(object sender, EventArgs e){ private void checkTimerCountDown_CheckedChanged(object sender, EventArgs e){
Config.NotificationTimerCountDown = checkTimerCountDown.Checked; Config.NotificationTimerCountDown = checkTimerCountDown.Checked;
notification.ShowNotificationForSettings(true); notification.ShowExampleNotification(true);
} }
private void checkMediaPreviews_CheckedChanged(object sender, EventArgs e){ private void checkMediaPreviews_CheckedChanged(object sender, EventArgs e){
@ -245,17 +246,17 @@ private void trackBarScrollSpeed_ValueChanged(object sender, EventArgs e){
private void comboBoxDisplay_SelectedValueChanged(object sender, EventArgs e){ private void comboBoxDisplay_SelectedValueChanged(object sender, EventArgs e){
Config.NotificationDisplay = comboBoxDisplay.SelectedIndex; Config.NotificationDisplay = comboBoxDisplay.SelectedIndex;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
private void trackBarEdgeDistance_ValueChanged(object sender, EventArgs e){ private void trackBarEdgeDistance_ValueChanged(object sender, EventArgs e){
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value+" px"; labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value+" px";
Config.NotificationEdgeDistance = trackBarEdgeDistance.Value; Config.NotificationEdgeDistance = trackBarEdgeDistance.Value;
notification.ShowNotificationForSettings(false); notification.ShowExampleNotification(false);
} }
private void durationUpdateTimer_Tick(object sender, EventArgs e){ private void durationUpdateTimer_Tick(object sender, EventArgs e){
notification.ShowNotificationForSettings(true); notification.ShowExampleNotification(true);
durationUpdateTimer.Stop(); durationUpdateTimer.Stop();
} }
} }

View File

@ -105,6 +105,9 @@
<Compile Include="Core\Handling\RequestHandlerBrowser.cs" /> <Compile Include="Core\Handling\RequestHandlerBrowser.cs" />
<Compile Include="Core\Handling\General\RequestHandlerBase.cs" /> <Compile Include="Core\Handling\General\RequestHandlerBase.cs" />
<Compile Include="Core\Handling\ResourceHandlerNotification.cs" /> <Compile Include="Core\Handling\ResourceHandlerNotification.cs" />
<Compile Include="Core\Notification\Example\FormNotificationExample.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Core\Notification\FormNotificationMain.cs"> <Compile Include="Core\Notification\FormNotificationMain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>