1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 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{
None = 0,
UserConfig = 1,
SystemConfig = 2, // TODO implement later
SystemConfig = 2,
Session = 4,
PluginData = 8,
All = UserConfig|SystemConfig|Session|PluginData

View File

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

View File

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