mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-12 05:34:06 +02:00
Add a Settings Form with notification window position setting
This commit is contained in:
parent
d235ea85ef
commit
340cee3354
@ -3,6 +3,7 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using TweetDick.Core.Handling;
|
||||
|
||||
namespace TweetDick.Configuration{
|
||||
[Serializable]
|
||||
@ -17,6 +18,22 @@ sealed class UserConfig{
|
||||
public Point WindowLocation { get; set; }
|
||||
public Size WindowSize { get; set; }
|
||||
|
||||
public TweetNotification.Position NotificationPosition { get; set; }
|
||||
public Point CustomNotificationPosition { get; set; }
|
||||
public int NotificationEdgeDistance { get; set; }
|
||||
|
||||
public bool IsCustomWindowLocationSet{
|
||||
get{
|
||||
return WindowLocation.X != 32000;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCustomNotificationPositionSet{
|
||||
get{
|
||||
return CustomNotificationPosition.X != 32000;
|
||||
}
|
||||
}
|
||||
|
||||
// END OF CONFIGURATION
|
||||
|
||||
[NonSerialized]
|
||||
@ -24,6 +41,12 @@ sealed class UserConfig{
|
||||
|
||||
private UserConfig(string file){
|
||||
this.file = file;
|
||||
|
||||
IsMaximized = true;
|
||||
WindowLocation = new Point(32000,32000);
|
||||
NotificationPosition = TweetNotification.Position.TopRight;
|
||||
CustomNotificationPosition = new Point(32000,32000);
|
||||
NotificationEdgeDistance = 8;
|
||||
}
|
||||
|
||||
public bool Save(){
|
||||
|
@ -22,6 +22,7 @@ private static UserConfig Config{
|
||||
private readonly TweetDeckBridge bridge;
|
||||
private readonly FormNotification notification;
|
||||
|
||||
private FormSettings currentFormSettings;
|
||||
private FormAbout currentFormAbout;
|
||||
|
||||
public FormBrowser(){
|
||||
@ -56,13 +57,13 @@ private void ShowChildForm(Form form){
|
||||
// window setup
|
||||
|
||||
private void SetupWindow(){
|
||||
if (!Config.WindowSize.IsEmpty){
|
||||
if (Config.IsCustomWindowLocationSet){
|
||||
Location = Config.WindowLocation;
|
||||
Size = Config.WindowSize;
|
||||
WindowState = Config.IsMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
|
||||
}
|
||||
|
||||
if (Config.WindowSize.IsEmpty || !Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(Bounds))){
|
||||
if (!Config.IsCustomWindowLocationSet || !Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(Bounds))){
|
||||
Location = Screen.PrimaryScreen.WorkingArea.Location;
|
||||
Size = Screen.PrimaryScreen.WorkingArea.Size;
|
||||
WindowState = FormWindowState.Maximized;
|
||||
@ -104,7 +105,14 @@ public void InvokeSafe(Action func){
|
||||
}
|
||||
|
||||
public void OpenSettings(){
|
||||
// TODO
|
||||
if (currentFormSettings != null){
|
||||
currentFormSettings.BringToFront();
|
||||
}
|
||||
else{
|
||||
currentFormSettings = new FormSettings(this);
|
||||
currentFormSettings.FormClosed += (sender, args) => currentFormSettings = null;
|
||||
ShowChildForm(currentFormSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenAbout(){
|
||||
|
@ -5,15 +5,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TweetDick.Core.Handling;
|
||||
using TweetDick.Configuration;
|
||||
|
||||
namespace TweetDick.Core{
|
||||
partial class FormNotification : Form{
|
||||
private readonly FormBrowser owner;
|
||||
private readonly Form owner;
|
||||
private readonly ChromiumWebBrowser browser;
|
||||
|
||||
private readonly Queue<TweetNotification> tweetQueue = new Queue<TweetNotification>(4);
|
||||
|
||||
public FormNotification(FormBrowser owner){
|
||||
public FormNotification(Form owner){
|
||||
InitializeComponent();
|
||||
|
||||
this.owner = owner;
|
||||
@ -23,8 +24,7 @@ public FormNotification(FormBrowser owner){
|
||||
}
|
||||
|
||||
public void ShowNotification(TweetNotification notification){
|
||||
Screen screen = Screen.FromControl(owner);
|
||||
Location = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-16-Width,screen.WorkingArea.Y+16);
|
||||
MoveToVisibleLocation();
|
||||
|
||||
tweetQueue.Enqueue(notification);
|
||||
|
||||
@ -33,6 +33,11 @@ public void ShowNotification(TweetNotification notification){
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowNotificationForSettings(){
|
||||
browser.Load("about:blank");
|
||||
MoveToVisibleLocation();
|
||||
}
|
||||
|
||||
public void HideNotification(){
|
||||
browser.Load("about:blank");
|
||||
Location = new Point(32000,32000);
|
||||
@ -49,6 +54,40 @@ private void LoadNextNotification(){
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
private void MoveToVisibleLocation(){
|
||||
UserConfig config = Program.UserConfig;
|
||||
Screen screen = Screen.FromControl(owner);
|
||||
|
||||
int edgeDist = config.NotificationEdgeDistance;
|
||||
|
||||
switch(config.NotificationPosition){
|
||||
case TweetNotification.Position.TopLeft:
|
||||
Location = new Point(screen.WorkingArea.X+edgeDist,screen.WorkingArea.Y+edgeDist);
|
||||
break;
|
||||
|
||||
case TweetNotification.Position.TopRight:
|
||||
Location = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width,screen.WorkingArea.Y+edgeDist);
|
||||
break;
|
||||
|
||||
case TweetNotification.Position.BottomLeft:
|
||||
Location = new Point(screen.WorkingArea.X+edgeDist,screen.WorkingArea.Y+screen.WorkingArea.Height-edgeDist-Height);
|
||||
break;
|
||||
|
||||
case TweetNotification.Position.BottomRight:
|
||||
Location = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width,screen.WorkingArea.Y+screen.WorkingArea.Height-edgeDist-Height);
|
||||
break;
|
||||
|
||||
case TweetNotification.Position.Custom:
|
||||
if (!config.IsCustomNotificationPositionSet){
|
||||
config.CustomNotificationPosition = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width,screen.WorkingArea.Y+edgeDist);
|
||||
config.Save();
|
||||
}
|
||||
|
||||
Location = config.CustomNotificationPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void timer_Tick(object sender, EventArgs e){
|
||||
if (tweetQueue.Count > 0){
|
||||
LoadNextNotification();
|
||||
|
@ -13,6 +13,10 @@ public static void SetHeadTag(string headContents){
|
||||
HeadTag = headContents;
|
||||
}
|
||||
|
||||
public enum Position{
|
||||
TopLeft, TopRight, BottomLeft, BottomRight, Custom
|
||||
}
|
||||
|
||||
private readonly string html;
|
||||
|
||||
public TweetNotification(string html){
|
||||
|
171
Core/Other/FormSettings.Designer.cs
generated
Normal file
171
Core/Other/FormSettings.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
namespace TweetDick.Core.Other {
|
||||
partial class FormSettings {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing && (components != null)) {
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
this.groupNotificationLocation = new System.Windows.Forms.GroupBox();
|
||||
this.labelEdgeDistance = new System.Windows.Forms.Label();
|
||||
this.trackBarEdgeDistance = new System.Windows.Forms.TrackBar();
|
||||
this.radioLocCustom = new System.Windows.Forms.RadioButton();
|
||||
this.radioLocBR = new System.Windows.Forms.RadioButton();
|
||||
this.radioLocBL = new System.Windows.Forms.RadioButton();
|
||||
this.radioLocTR = new System.Windows.Forms.RadioButton();
|
||||
this.radioLocTL = new System.Windows.Forms.RadioButton();
|
||||
this.groupNotificationLocation.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarEdgeDistance)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupNotificationLocation
|
||||
//
|
||||
this.groupNotificationLocation.Controls.Add(this.labelEdgeDistance);
|
||||
this.groupNotificationLocation.Controls.Add(this.trackBarEdgeDistance);
|
||||
this.groupNotificationLocation.Controls.Add(this.radioLocCustom);
|
||||
this.groupNotificationLocation.Controls.Add(this.radioLocBR);
|
||||
this.groupNotificationLocation.Controls.Add(this.radioLocBL);
|
||||
this.groupNotificationLocation.Controls.Add(this.radioLocTR);
|
||||
this.groupNotificationLocation.Controls.Add(this.radioLocTL);
|
||||
this.groupNotificationLocation.Location = new System.Drawing.Point(13, 13);
|
||||
this.groupNotificationLocation.Name = "groupNotificationLocation";
|
||||
this.groupNotificationLocation.Size = new System.Drawing.Size(149, 217);
|
||||
this.groupNotificationLocation.TabIndex = 0;
|
||||
this.groupNotificationLocation.TabStop = false;
|
||||
this.groupNotificationLocation.Text = "Notification Location";
|
||||
//
|
||||
// labelEdgeDistance
|
||||
//
|
||||
this.labelEdgeDistance.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.labelEdgeDistance.AutoSize = true;
|
||||
this.labelEdgeDistance.Location = new System.Drawing.Point(6, 150);
|
||||
this.labelEdgeDistance.Name = "labelEdgeDistance";
|
||||
this.labelEdgeDistance.Size = new System.Drawing.Size(103, 13);
|
||||
this.labelEdgeDistance.TabIndex = 6;
|
||||
this.labelEdgeDistance.Text = "Distance From Edge";
|
||||
//
|
||||
// trackBarEdgeDistance
|
||||
//
|
||||
this.trackBarEdgeDistance.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.trackBarEdgeDistance.LargeChange = 8;
|
||||
this.trackBarEdgeDistance.Location = new System.Drawing.Point(6, 166);
|
||||
this.trackBarEdgeDistance.Maximum = 40;
|
||||
this.trackBarEdgeDistance.Minimum = 8;
|
||||
this.trackBarEdgeDistance.Name = "trackBarEdgeDistance";
|
||||
this.trackBarEdgeDistance.Size = new System.Drawing.Size(137, 45);
|
||||
this.trackBarEdgeDistance.SmallChange = 2;
|
||||
this.trackBarEdgeDistance.TabIndex = 5;
|
||||
this.trackBarEdgeDistance.TickFrequency = 2;
|
||||
this.trackBarEdgeDistance.Value = 8;
|
||||
this.trackBarEdgeDistance.ValueChanged += new System.EventHandler(this.trackBarEdgeDistance_ValueChanged);
|
||||
//
|
||||
// radioLocCustom
|
||||
//
|
||||
this.radioLocCustom.AutoSize = true;
|
||||
this.radioLocCustom.Location = new System.Drawing.Point(7, 116);
|
||||
this.radioLocCustom.Name = "radioLocCustom";
|
||||
this.radioLocCustom.Size = new System.Drawing.Size(60, 17);
|
||||
this.radioLocCustom.TabIndex = 4;
|
||||
this.radioLocCustom.TabStop = true;
|
||||
this.radioLocCustom.Text = "Custom";
|
||||
this.radioLocCustom.UseVisualStyleBackColor = true;
|
||||
this.radioLocCustom.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
|
||||
//
|
||||
// radioLocBR
|
||||
//
|
||||
this.radioLocBR.AutoSize = true;
|
||||
this.radioLocBR.Location = new System.Drawing.Point(7, 92);
|
||||
this.radioLocBR.Name = "radioLocBR";
|
||||
this.radioLocBR.Size = new System.Drawing.Size(86, 17);
|
||||
this.radioLocBR.TabIndex = 3;
|
||||
this.radioLocBR.TabStop = true;
|
||||
this.radioLocBR.Text = "Bottom Right";
|
||||
this.radioLocBR.UseVisualStyleBackColor = true;
|
||||
this.radioLocBR.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
|
||||
//
|
||||
// radioLocBL
|
||||
//
|
||||
this.radioLocBL.AutoSize = true;
|
||||
this.radioLocBL.Location = new System.Drawing.Point(7, 68);
|
||||
this.radioLocBL.Name = "radioLocBL";
|
||||
this.radioLocBL.Size = new System.Drawing.Size(79, 17);
|
||||
this.radioLocBL.TabIndex = 2;
|
||||
this.radioLocBL.TabStop = true;
|
||||
this.radioLocBL.Text = "Bottom Left";
|
||||
this.radioLocBL.UseVisualStyleBackColor = true;
|
||||
this.radioLocBL.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
|
||||
//
|
||||
// radioLocTR
|
||||
//
|
||||
this.radioLocTR.AutoSize = true;
|
||||
this.radioLocTR.Location = new System.Drawing.Point(7, 44);
|
||||
this.radioLocTR.Name = "radioLocTR";
|
||||
this.radioLocTR.Size = new System.Drawing.Size(72, 17);
|
||||
this.radioLocTR.TabIndex = 1;
|
||||
this.radioLocTR.TabStop = true;
|
||||
this.radioLocTR.Text = "Top Right";
|
||||
this.radioLocTR.UseVisualStyleBackColor = true;
|
||||
this.radioLocTR.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
|
||||
//
|
||||
// radioLocTL
|
||||
//
|
||||
this.radioLocTL.AutoSize = true;
|
||||
this.radioLocTL.Location = new System.Drawing.Point(7, 20);
|
||||
this.radioLocTL.Name = "radioLocTL";
|
||||
this.radioLocTL.Size = new System.Drawing.Size(65, 17);
|
||||
this.radioLocTL.TabIndex = 0;
|
||||
this.radioLocTL.TabStop = true;
|
||||
this.radioLocTL.Text = "Top Left";
|
||||
this.radioLocTL.UseVisualStyleBackColor = true;
|
||||
this.radioLocTL.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
|
||||
//
|
||||
// FormSettings
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(284, 242);
|
||||
this.Controls.Add(this.groupNotificationLocation);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "FormSettings";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "TweetDick Settings";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormSettings_FormClosing);
|
||||
this.groupNotificationLocation.ResumeLayout(false);
|
||||
this.groupNotificationLocation.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarEdgeDistance)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupNotificationLocation;
|
||||
private System.Windows.Forms.RadioButton radioLocCustom;
|
||||
private System.Windows.Forms.RadioButton radioLocBR;
|
||||
private System.Windows.Forms.RadioButton radioLocBL;
|
||||
private System.Windows.Forms.RadioButton radioLocTR;
|
||||
private System.Windows.Forms.RadioButton radioLocTL;
|
||||
private System.Windows.Forms.Label labelEdgeDistance;
|
||||
private System.Windows.Forms.TrackBar trackBarEdgeDistance;
|
||||
}
|
||||
}
|
65
Core/Other/FormSettings.cs
Normal file
65
Core/Other/FormSettings.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using TweetDick.Configuration;
|
||||
using TweetDick.Core.Handling;
|
||||
|
||||
namespace TweetDick.Core.Other{
|
||||
public partial class FormSettings : Form{
|
||||
private static UserConfig Config{
|
||||
get{
|
||||
return Program.UserConfig;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly FormNotification notification;
|
||||
|
||||
public FormSettings(FormBrowser browserForm){
|
||||
InitializeComponent();
|
||||
|
||||
notification = new FormNotification(browserForm);
|
||||
notification.Show(this);
|
||||
|
||||
notification.Move += (sender, args) => {
|
||||
if (radioLocCustom.Checked){
|
||||
Config.CustomNotificationPosition = notification.Location;
|
||||
}
|
||||
};
|
||||
|
||||
switch(Config.NotificationPosition){
|
||||
case TweetNotification.Position.TopLeft: radioLocTL.Checked = true; break;
|
||||
case TweetNotification.Position.TopRight: radioLocTR.Checked = true; break;
|
||||
case TweetNotification.Position.BottomLeft: radioLocBL.Checked = true; break;
|
||||
case TweetNotification.Position.BottomRight: radioLocBR.Checked = true; break;
|
||||
}
|
||||
|
||||
trackBarEdgeDistance.Value = Config.NotificationEdgeDistance;
|
||||
notification.HideNotification();
|
||||
}
|
||||
|
||||
private void FormSettings_FormClosing(object sender, FormClosingEventArgs e){
|
||||
Config.Save();
|
||||
}
|
||||
|
||||
private void radioLoc_CheckedChanged(object sender, EventArgs e){
|
||||
if (radioLocTL.Checked)Config.NotificationPosition = TweetNotification.Position.TopLeft;
|
||||
else if (radioLocTR.Checked)Config.NotificationPosition = TweetNotification.Position.TopRight;
|
||||
else if (radioLocBL.Checked)Config.NotificationPosition = TweetNotification.Position.BottomLeft;
|
||||
else if (radioLocBR.Checked)Config.NotificationPosition = TweetNotification.Position.BottomRight;
|
||||
else if (radioLocCustom.Checked){
|
||||
if (!Config.IsCustomNotificationPositionSet){
|
||||
Config.CustomNotificationPosition = notification.Location;
|
||||
}
|
||||
|
||||
Config.NotificationPosition = TweetNotification.Position.Custom;
|
||||
}
|
||||
|
||||
trackBarEdgeDistance.Enabled = !radioLocCustom.Checked;
|
||||
notification.ShowNotificationForSettings();
|
||||
}
|
||||
|
||||
private void trackBarEdgeDistance_ValueChanged(object sender, EventArgs e){
|
||||
Config.NotificationEdgeDistance = trackBarEdgeDistance.Value;
|
||||
notification.ShowNotificationForSettings();
|
||||
}
|
||||
}
|
||||
}
|
@ -112,6 +112,12 @@
|
||||
<DependentUpon>FormBackgroundWork.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Core\Handling\TweetDeckBridge.cs" />
|
||||
<Compile Include="Core\Other\FormSettings.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Core\Other\FormSettings.Designer.cs">
|
||||
<DependentUpon>FormSettings.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migration\FormMigrationQuestion.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@ -167,6 +173,11 @@
|
||||
<TargetPath>code.js</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Core\Other\FormSettings.resx">
|
||||
<DependentUpon>FormSettings.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets" Condition="Exists('packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
Loading…
Reference in New Issue
Block a user