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

Allow export/import/restoring system options & refactor Manage Options dialog

This commit is contained in:
chylex 2018-02-06 18:35:36 +01:00
parent 629f873bb2
commit 35500c51f1
3 changed files with 112 additions and 88 deletions

View File

@ -16,7 +16,7 @@ sealed class ProfileManager{
public enum Items{ public enum Items{
None = 0, None = 0,
UserConfig = 1, UserConfig = 1,
SystemConfig = 2, // TODO implement later SystemConfig = 2,
Session = 4, Session = 4,
PluginData = 8, PluginData = 8,
All = UserConfig|SystemConfig|Session|PluginData All = UserConfig|SystemConfig|Session|PluginData

View File

@ -26,16 +26,17 @@ private void InitializeComponent() {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.btnCancel = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button();
this.btnContinue = new System.Windows.Forms.Button(); this.btnContinue = new System.Windows.Forms.Button();
this.cbConfig = new System.Windows.Forms.CheckBox(); this.cbProgramConfig = new System.Windows.Forms.CheckBox();
this.cbSession = new System.Windows.Forms.CheckBox(); this.cbSession = new System.Windows.Forms.CheckBox();
this.cbPluginData = new System.Windows.Forms.CheckBox(); this.cbPluginData = new System.Windows.Forms.CheckBox();
this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.panelExport = new System.Windows.Forms.Panel(); this.cbSystemConfig = new System.Windows.Forms.CheckBox();
this.panelDecision = new System.Windows.Forms.Panel(); this.panelSelection = new System.Windows.Forms.FlowLayoutPanel();
this.radioReset = new System.Windows.Forms.RadioButton(); this.panelDecision = new System.Windows.Forms.FlowLayoutPanel();
this.radioExport = new System.Windows.Forms.RadioButton();
this.radioImport = new System.Windows.Forms.RadioButton(); this.radioImport = new System.Windows.Forms.RadioButton();
this.panelExport.SuspendLayout(); this.radioExport = new System.Windows.Forms.RadioButton();
this.radioReset = new System.Windows.Forms.RadioButton();
this.panelSelection.SuspendLayout();
this.panelDecision.SuspendLayout(); this.panelDecision.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -56,95 +57,92 @@ private void InitializeComponent() {
this.btnContinue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnContinue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnContinue.AutoSize = true; this.btnContinue.AutoSize = true;
this.btnContinue.Enabled = false; this.btnContinue.Enabled = false;
this.btnContinue.Location = new System.Drawing.Point(125, 97); this.btnContinue.Location = new System.Drawing.Point(119, 97);
this.btnContinue.Name = "btnContinue"; this.btnContinue.Name = "btnContinue";
this.btnContinue.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0); this.btnContinue.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnContinue.Size = new System.Drawing.Size(45, 23); this.btnContinue.Size = new System.Drawing.Size(51, 23);
this.btnContinue.TabIndex = 3; this.btnContinue.TabIndex = 3;
this.btnContinue.Text = "Next"; this.btnContinue.Text = "Next";
this.btnContinue.UseVisualStyleBackColor = true; this.btnContinue.UseVisualStyleBackColor = true;
this.btnContinue.Click += new System.EventHandler(this.btnContinue_Click); this.btnContinue.Click += new System.EventHandler(this.btnContinue_Click);
// //
// cbConfig // cbProgramConfig
// //
this.cbConfig.AutoSize = true; this.cbProgramConfig.AutoSize = true;
this.cbConfig.Location = new System.Drawing.Point(0, 3); this.cbProgramConfig.Location = new System.Drawing.Point(3, 3);
this.cbConfig.Name = "cbConfig"; this.cbProgramConfig.Name = "cbProgramConfig";
this.cbConfig.Size = new System.Drawing.Size(104, 17); this.cbProgramConfig.Size = new System.Drawing.Size(104, 17);
this.cbConfig.TabIndex = 0; this.cbProgramConfig.TabIndex = 0;
this.cbConfig.Text = "Program Options"; this.cbProgramConfig.Text = "Program Options";
this.toolTip.SetToolTip(this.cbConfig, "Interface, notification, and update options."); this.toolTip.SetToolTip(this.cbProgramConfig, "Interface, notification, and update options.");
this.cbConfig.UseVisualStyleBackColor = true; this.cbProgramConfig.UseVisualStyleBackColor = true;
this.cbConfig.CheckedChanged += new System.EventHandler(this.cbConfig_CheckedChanged); this.cbProgramConfig.CheckedChanged += new System.EventHandler(this.checkBoxSelection_CheckedChanged);
// //
// cbSession // cbSession
// //
this.cbSession.AutoSize = true; this.cbSession.AutoSize = true;
this.cbSession.Location = new System.Drawing.Point(0, 27); this.cbSession.Location = new System.Drawing.Point(3, 49);
this.cbSession.Name = "cbSession"; this.cbSession.Name = "cbSession";
this.cbSession.Size = new System.Drawing.Size(92, 17); this.cbSession.Size = new System.Drawing.Size(92, 17);
this.cbSession.TabIndex = 1; this.cbSession.TabIndex = 2;
this.cbSession.Text = "Login Session"; this.cbSession.Text = "Login Session";
this.toolTip.SetToolTip(this.cbSession, "A token that allows logging into the\r\ncurrent TweetDeck account."); this.toolTip.SetToolTip(this.cbSession, "A token that allows logging into the\r\ncurrent TweetDeck account.");
this.cbSession.UseVisualStyleBackColor = true; this.cbSession.UseVisualStyleBackColor = true;
this.cbSession.CheckedChanged += new System.EventHandler(this.cbSession_CheckedChanged); this.cbSession.CheckedChanged += new System.EventHandler(this.checkBoxSelection_CheckedChanged);
// //
// cbPluginData // cbPluginData
// //
this.cbPluginData.AutoSize = true; this.cbPluginData.AutoSize = true;
this.cbPluginData.Location = new System.Drawing.Point(0, 51); this.cbPluginData.Location = new System.Drawing.Point(3, 72);
this.cbPluginData.Name = "cbPluginData"; this.cbPluginData.Name = "cbPluginData";
this.cbPluginData.Size = new System.Drawing.Size(81, 17); this.cbPluginData.Size = new System.Drawing.Size(81, 17);
this.cbPluginData.TabIndex = 2; this.cbPluginData.TabIndex = 3;
this.cbPluginData.Text = "Plugin Data"; this.cbPluginData.Text = "Plugin Data";
this.toolTip.SetToolTip(this.cbPluginData, "Data files generated by plugins.\r\nDoes not include the plugins themselves."); this.toolTip.SetToolTip(this.cbPluginData, "Data files generated by plugins.\r\nDoes not include the plugins themselves.");
this.cbPluginData.UseVisualStyleBackColor = true; this.cbPluginData.UseVisualStyleBackColor = true;
this.cbPluginData.CheckedChanged += new System.EventHandler(this.cbPluginData_CheckedChanged); this.cbPluginData.CheckedChanged += new System.EventHandler(this.checkBoxSelection_CheckedChanged);
// //
// panelExport // cbSystemConfig
// //
this.panelExport.Controls.Add(this.cbConfig); this.cbSystemConfig.AutoSize = true;
this.panelExport.Controls.Add(this.cbPluginData); this.cbSystemConfig.Location = new System.Drawing.Point(3, 26);
this.panelExport.Controls.Add(this.cbSession); this.cbSystemConfig.Name = "cbSystemConfig";
this.panelExport.Location = new System.Drawing.Point(12, 12); this.cbSystemConfig.Size = new System.Drawing.Size(99, 17);
this.panelExport.Name = "panelExport"; this.cbSystemConfig.TabIndex = 1;
this.panelExport.Size = new System.Drawing.Size(220, 79); this.cbSystemConfig.Text = "System Options";
this.panelExport.TabIndex = 5; this.toolTip.SetToolTip(this.cbSystemConfig, "Hardware acceleration and cache options.");
this.panelExport.Visible = false; this.cbSystemConfig.UseVisualStyleBackColor = true;
this.cbSystemConfig.CheckedChanged += new System.EventHandler(this.checkBoxSelection_CheckedChanged);
//
// panelSelection
//
this.panelSelection.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelSelection.Controls.Add(this.cbProgramConfig);
this.panelSelection.Controls.Add(this.cbSystemConfig);
this.panelSelection.Controls.Add(this.cbSession);
this.panelSelection.Controls.Add(this.cbPluginData);
this.panelSelection.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.panelSelection.Location = new System.Drawing.Point(12, 12);
this.panelSelection.Name = "panelSelection";
this.panelSelection.Size = new System.Drawing.Size(220, 89);
this.panelSelection.TabIndex = 2;
this.panelSelection.Visible = false;
this.panelSelection.WrapContents = false;
// //
// panelDecision // panelDecision
// //
this.panelDecision.Controls.Add(this.radioReset); this.panelDecision.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.panelDecision.Controls.Add(this.radioExport); | System.Windows.Forms.AnchorStyles.Right)));
this.panelDecision.Controls.Add(this.radioImport); this.panelDecision.Controls.Add(this.radioImport);
this.panelDecision.Controls.Add(this.radioExport);
this.panelDecision.Controls.Add(this.radioReset);
this.panelDecision.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.panelDecision.Location = new System.Drawing.Point(12, 12); this.panelDecision.Location = new System.Drawing.Point(12, 12);
this.panelDecision.Name = "panelDecision"; this.panelDecision.Name = "panelDecision";
this.panelDecision.Size = new System.Drawing.Size(220, 79); this.panelDecision.Size = new System.Drawing.Size(220, 71);
this.panelDecision.TabIndex = 6; this.panelDecision.TabIndex = 0;
// this.panelDecision.WrapContents = false;
// radioReset
//
this.radioReset.AutoSize = true;
this.radioReset.Location = new System.Drawing.Point(3, 49);
this.radioReset.Name = "radioReset";
this.radioReset.Size = new System.Drawing.Size(104, 17);
this.radioReset.TabIndex = 2;
this.radioReset.TabStop = true;
this.radioReset.Text = "Restore Defaults";
this.radioReset.UseVisualStyleBackColor = true;
this.radioReset.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged);
//
// radioExport
//
this.radioExport.AutoSize = true;
this.radioExport.Location = new System.Drawing.Point(3, 26);
this.radioExport.Name = "radioExport";
this.radioExport.Size = new System.Drawing.Size(87, 17);
this.radioExport.TabIndex = 1;
this.radioExport.TabStop = true;
this.radioExport.Text = "Export Profile";
this.radioExport.UseVisualStyleBackColor = true;
this.radioExport.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged);
// //
// radioImport // radioImport
// //
@ -158,25 +156,49 @@ private void InitializeComponent() {
this.radioImport.UseVisualStyleBackColor = true; this.radioImport.UseVisualStyleBackColor = true;
this.radioImport.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged); this.radioImport.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged);
// //
// radioExport
//
this.radioExport.AutoSize = true;
this.radioExport.Location = new System.Drawing.Point(3, 26);
this.radioExport.Name = "radioExport";
this.radioExport.Size = new System.Drawing.Size(87, 17);
this.radioExport.TabIndex = 1;
this.radioExport.TabStop = true;
this.radioExport.Text = "Export Profile";
this.radioExport.UseVisualStyleBackColor = true;
this.radioExport.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged);
//
// radioReset
//
this.radioReset.AutoSize = true;
this.radioReset.Location = new System.Drawing.Point(3, 49);
this.radioReset.Name = "radioReset";
this.radioReset.Size = new System.Drawing.Size(104, 17);
this.radioReset.TabIndex = 2;
this.radioReset.TabStop = true;
this.radioReset.Text = "Restore Defaults";
this.radioReset.UseVisualStyleBackColor = true;
this.radioReset.CheckedChanged += new System.EventHandler(this.radioDecision_CheckedChanged);
//
// DialogSettingsManage // DialogSettingsManage
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(244, 132); this.ClientSize = new System.Drawing.Size(244, 132);
this.Controls.Add(this.panelDecision);
this.Controls.Add(this.panelExport);
this.Controls.Add(this.btnContinue); this.Controls.Add(this.btnContinue);
this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnCancel);
this.Controls.Add(this.panelDecision);
this.Controls.Add(this.panelSelection);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(200, 170); this.MinimumSize = new System.Drawing.Size(260, 170);
this.Name = "DialogSettingsManage"; this.Name = "DialogSettingsManage";
this.ShowIcon = false; this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Manage Options"; this.Text = "Manage Options";
this.panelExport.ResumeLayout(false); this.panelSelection.ResumeLayout(false);
this.panelExport.PerformLayout(); this.panelSelection.PerformLayout();
this.panelDecision.ResumeLayout(false); this.panelDecision.ResumeLayout(false);
this.panelDecision.PerformLayout(); this.panelDecision.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -188,12 +210,13 @@ private void InitializeComponent() {
private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnContinue; private System.Windows.Forms.Button btnContinue;
private System.Windows.Forms.CheckBox cbConfig; private System.Windows.Forms.CheckBox cbProgramConfig;
private System.Windows.Forms.CheckBox cbSystemConfig;
private System.Windows.Forms.CheckBox cbSession; private System.Windows.Forms.CheckBox cbSession;
private System.Windows.Forms.CheckBox cbPluginData; private System.Windows.Forms.CheckBox cbPluginData;
private System.Windows.Forms.ToolTip toolTip; private System.Windows.Forms.ToolTip toolTip;
private System.Windows.Forms.Panel panelExport; private System.Windows.Forms.FlowLayoutPanel panelSelection;
private System.Windows.Forms.Panel panelDecision; private System.Windows.Forms.FlowLayoutPanel panelDecision;
private System.Windows.Forms.RadioButton radioReset; private System.Windows.Forms.RadioButton radioReset;
private System.Windows.Forms.RadioButton radioExport; private System.Windows.Forms.RadioButton radioExport;
private System.Windows.Forms.RadioButton radioImport; private System.Windows.Forms.RadioButton radioImport;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Configuration; using TweetDuck.Configuration;
@ -16,9 +17,9 @@ private ProfileManager.Items SelectedItems{
set{ set{
// this will call events and SetFlag, which also updates the UI // this will call events and SetFlag, which also updates the UI
cbConfig.Checked = value.HasFlag(ProfileManager.Items.UserConfig); foreach(KeyValuePair<CheckBox, ProfileManager.Items> kvp in checkBoxMap){
cbSession.Checked = value.HasFlag(ProfileManager.Items.Session); kvp.Key.Checked = value.HasFlag(kvp.Value);
cbPluginData.Checked = value.HasFlag(ProfileManager.Items.PluginData); }
} }
} }
@ -26,6 +27,7 @@ private ProfileManager.Items SelectedItems{
public bool ShouldReloadBrowser { get; private set; } public bool ShouldReloadBrowser { get; private set; }
private readonly PluginManager plugins; private readonly PluginManager plugins;
private readonly Dictionary<CheckBox, ProfileManager.Items> checkBoxMap = new Dictionary<CheckBox, ProfileManager.Items>(4);
private State currentState; private State currentState;
private ProfileManager importManager; private ProfileManager importManager;
@ -37,22 +39,20 @@ public DialogSettingsManage(PluginManager plugins){
this.plugins = plugins; this.plugins = plugins;
this.currentState = State.Deciding; this.currentState = State.Deciding;
this.checkBoxMap[cbProgramConfig] = ProfileManager.Items.UserConfig;
this.checkBoxMap[cbSystemConfig] = ProfileManager.Items.SystemConfig;
this.checkBoxMap[cbSession] = ProfileManager.Items.Session;
this.checkBoxMap[cbPluginData] = ProfileManager.Items.PluginData;
} }
private void radioDecision_CheckedChanged(object sender, EventArgs e){ private void radioDecision_CheckedChanged(object sender, EventArgs e){
btnContinue.Enabled = true; btnContinue.Enabled = true;
} }
private void cbConfig_CheckedChanged(object sender, EventArgs e){ private void checkBoxSelection_CheckedChanged(object sender, EventArgs e){
SetFlag(ProfileManager.Items.UserConfig, cbConfig.Checked); CheckBox cb = (CheckBox)sender;
} SetFlag(checkBoxMap[cb], cb.Checked);
private void cbSession_CheckedChanged(object sender, EventArgs e){
SetFlag(ProfileManager.Items.Session, cbSession.Checked);
}
private void cbPluginData_CheckedChanged(object sender, EventArgs e){
SetFlag(ProfileManager.Items.PluginData, cbPluginData.Checked);
} }
private void btnContinue_Click(object sender, EventArgs e){ private void btnContinue_Click(object sender, EventArgs e){
@ -89,9 +89,9 @@ private void btnContinue_Click(object sender, EventArgs e){
Text = "Import Profile"; Text = "Import Profile";
SelectedItems = importManager.FindImportItems(); SelectedItems = importManager.FindImportItems();
cbConfig.Enabled = cbConfig.Checked; foreach(CheckBox cb in checkBoxMap.Keys){
cbSession.Enabled = cbSession.Checked; cb.Enabled = cb.Checked;
cbPluginData.Enabled = cbPluginData.Checked; }
} }
// Export // Export
@ -100,12 +100,13 @@ private void btnContinue_Click(object sender, EventArgs e){
Text = "Export Profile"; Text = "Export Profile";
btnContinue.Text = "Export Profile"; btnContinue.Text = "Export Profile";
SelectedItems = ProfileManager.Items.All & ~ProfileManager.Items.Session; SelectedItems = ProfileManager.Items.UserConfig | ProfileManager.Items.PluginData;
} }
// Continue... // Continue...
panelDecision.Visible = false; panelDecision.Visible = false;
panelExport.Visible = true; panelSelection.Visible = true;
Height += panelSelection.Height-panelDecision.Height;
break; break;
case State.Reset: case State.Reset: