# HG changeset patch # User sl # Date 1409494379 -7200 # Node ID 9039acfde091a6b549d0df5cf586314ef2bea75c # Parent c9e3d1389d06b618a2a132b8afabb4d4b986a72d Extending our settings framework to store custom settings for each display type. diff -r c9e3d1389d06 -r 9039acfde091 Server/App.config --- a/Server/App.config Sat Aug 30 19:24:47 2014 +0200 +++ b/Server/App.config Sun Aug 31 16:12:59 2014 +0200 @@ -10,26 +10,11 @@ - - 1 - - - Microsoft Sans Serif, 9.75pt - - - False - False - - False - - - 1 - - - 100 + + 0 diff -r c9e3d1389d06 -r 9039acfde091 Server/MainForm.cs --- a/Server/MainForm.cs Sat Aug 30 19:24:47 2014 +0200 +++ b/Server/MainForm.cs Sun Aug 31 16:12:59 2014 +0200 @@ -41,16 +41,7 @@ InitializeComponent(); UpdateStatus(); - - //Load settings - marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont; - marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont; - checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders; - checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; - checkBoxReverseScreen.Checked = Properties.Settings.Default.DisplayReverseScreen; - comboBoxDisplayType.SelectedIndex = Properties.Settings.Default.DisplayType; - timer.Interval = Properties.Settings.Default.TimerInterval; - maskedTextBoxTimerInterval.Text = Properties.Settings.Default.TimerInterval.ToString(); + // tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); //We have a bug when drawing minimized and reusing our bitmap @@ -102,7 +93,7 @@ //MessageBox.Show("Ok"); marqueeLabelTop.Font = fontDialog.Font; marqueeLabelBottom.Font = fontDialog.Font; - Properties.Settings.Default.DisplayFont = fontDialog.Font; + cds.Font = fontDialog.Font; Properties.Settings.Default.Save(); // CheckFontHeight(); @@ -235,7 +226,7 @@ CoordinateTranslationDelegate screenX; CoordinateTranslationDelegate screenY; - if (Properties.Settings.Default.DisplayReverseScreen) + if (cds.ReverseScreen) { screenX = ScreenReversedX; screenY = ScreenReversedY; @@ -276,7 +267,7 @@ { CloseDisplayConnection(); - if (iDisplay.Open((Display.TMiniDisplayType)Properties.Settings.Default.DisplayType)) + if (iDisplay.Open((Display.TMiniDisplayType)cds.DisplayType)) { UpdateStatus(); iDisplay.RequestPowerSupplyStatus(); @@ -318,28 +309,62 @@ private void trackBarBrightness_Scroll(object sender, EventArgs e) { - Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value; + cds.Brightness = trackBarBrightness.Value; Properties.Settings.Default.Save(); iDisplay.SetBrightness(trackBarBrightness.Value); } + + /// + /// CDS stands for Current Display Settings + /// + private DisplaySettingsEntry cds + { + get + { + DisplaySettings settings = Properties.Settings.Default.DisplaySettings; + + //Make sure all our settings have been created + while (settings.Displays.Count <= Properties.Settings.Default.CurrentDisplayIndex) + { + settings.Displays.Add(new DisplaySettingsEntry()); + } + + DisplaySettingsEntry displaySettings = settings.Displays[Properties.Settings.Default.CurrentDisplayIndex]; + return displaySettings; + } + } + private void UpdateStatus() { + //Synchronize UI with settings + //Load settings + marqueeLabelTop.Font = cds.Font; + marqueeLabelBottom.Font = cds.Font; + checkBoxShowBorders.Checked = cds.ShowBorders; + checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; + checkBoxReverseScreen.Checked = cds.ReverseScreen; + comboBoxDisplayType.SelectedIndex = cds.DisplayType; + timer.Interval = cds.TimerInterval; + maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString(); + + if (iDisplay.IsOpen()) { + //Only setup brightness if display is open + trackBarBrightness.Minimum = iDisplay.MinBrightness(); + trackBarBrightness.Maximum = iDisplay.MaxBrightness(); + trackBarBrightness.Value = cds.Brightness; + trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5); + trackBarBrightness.SmallChange = 1; + iDisplay.SetBrightness(cds.Brightness); + // buttonFill.Enabled = true; buttonClear.Enabled = true; buttonOpen.Enabled = false; buttonClose.Enabled = true; trackBarBrightness.Enabled = true; - trackBarBrightness.Minimum = iDisplay.MinBrightness(); - trackBarBrightness.Maximum = iDisplay.MaxBrightness(); - trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness; - trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5); - trackBarBrightness.SmallChange = 1; - iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness); - toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product(); //+ " - " + iDisplay.SerialNumber(); } @@ -351,6 +376,7 @@ buttonClose.Enabled = false; trackBarBrightness.Enabled = false; toolStripStatusLabelConnect.Text = "Disconnected"; + toolStripStatusLabelPower.Text = "N/A"; } } @@ -360,7 +386,7 @@ { //Save our show borders setting tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None); - Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked; + cds.ShowBorders = checkBoxShowBorders.Checked; Properties.Settings.Default.Save(); } @@ -374,7 +400,7 @@ private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e) { //Save our reverse screen setting - Properties.Settings.Default.DisplayReverseScreen = checkBoxReverseScreen.Checked; + cds.ReverseScreen = checkBoxReverseScreen.Checked; Properties.Settings.Default.Save(); } @@ -798,7 +824,8 @@ private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e) { - Properties.Settings.Default.DisplayType = comboBoxDisplayType.SelectedIndex; + Properties.Settings.Default.CurrentDisplayIndex = comboBoxDisplayType.SelectedIndex; + cds.DisplayType = comboBoxDisplayType.SelectedIndex; Properties.Settings.Default.Save(); OpenDisplayConnection(); } @@ -809,7 +836,7 @@ if (maskedTextBoxTimerInterval.Text != "") { timer.Interval = Convert.ToInt32(maskedTextBoxTimerInterval.Text); - Properties.Settings.Default.TimerInterval = timer.Interval; + cds.TimerInterval = timer.Interval; Properties.Settings.Default.Save(); } } diff -r c9e3d1389d06 -r 9039acfde091 Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Sat Aug 30 19:24:47 2014 +0200 +++ b/Server/Properties/Settings.Designer.cs Sun Aug 31 16:12:59 2014 +0200 @@ -25,42 +25,6 @@ [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1")] - public int DisplayBrightness { - get { - return ((int)(this["DisplayBrightness"])); - } - set { - this["DisplayBrightness"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Microsoft Sans Serif, 9.75pt")] - public global::System.Drawing.Font DisplayFont { - get { - return ((global::System.Drawing.Font)(this["DisplayFont"])); - } - set { - this["DisplayFont"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool DisplayShowBorders { - get { - return ((bool)(this["DisplayShowBorders"])); - } - set { - this["DisplayShowBorders"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("False")] public bool DisplayConnectOnStartup { get { @@ -73,37 +37,24 @@ [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool DisplayReverseScreen { + public global::SharpDisplayManager.DisplaySettings DisplaySettings { get { - return ((bool)(this["DisplayReverseScreen"])); + return ((global::SharpDisplayManager.DisplaySettings)(this["DisplaySettings"])); } set { - this["DisplayReverseScreen"] = value; + this["DisplaySettings"] = value; } } [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1")] - public int DisplayType { + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int CurrentDisplayIndex { get { - return ((int)(this["DisplayType"])); + return ((int)(this["CurrentDisplayIndex"])); } set { - this["DisplayType"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("100")] - public int TimerInterval { - get { - return ((int)(this["TimerInterval"])); - } - set { - this["TimerInterval"] = value; + this["CurrentDisplayIndex"] = value; } } } diff -r c9e3d1389d06 -r 9039acfde091 Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Sat Aug 30 19:24:47 2014 +0200 +++ b/Server/Properties/Settings.settings Sun Aug 31 16:12:59 2014 +0200 @@ -2,26 +2,14 @@ - - 1 - - - Microsoft Sans Serif, 9.75pt - - - False - False - - False + + - - 1 - - - 100 + + 0 \ No newline at end of file diff -r c9e3d1389d06 -r 9039acfde091 Server/Settings.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/Settings.cs Sun Aug 31 16:12:59 2014 +0200 @@ -0,0 +1,28 @@ +namespace SharpDisplayManager.Properties { + + + // This class allows you to handle specific events on the settings class: + // The SettingChanging event is raised before a setting's value is changed. + // The PropertyChanged event is raised after a setting's value is changed. + // The SettingsLoaded event is raised after the setting values are loaded. + // The SettingsSaving event is raised before the setting values are saved. + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + public Settings() : base("default") { + // // To add event handlers for saving and changing settings, uncomment the lines below: + // + // this.SettingChanging += this.SettingChangingEventHandler; + // + // this.SettingsSaving += this.SettingsSavingEventHandler; + // + } + + private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { + // Add code to handle the SettingChangingEvent event here. + } + + private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { + // Add code to handle the SettingsSaving event here. + } + } +} diff -r c9e3d1389d06 -r 9039acfde091 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sat Aug 30 19:24:47 2014 +0200 +++ b/Server/SharpDisplayManager.csproj Sun Aug 31 16:12:59 2014 +0200 @@ -73,6 +73,7 @@ + @@ -90,6 +91,7 @@ + Form