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

Refactor Settings tabs (replace IsReady, remove SelectTab with no parameters)

This commit is contained in:
chylex 2017-03-22 13:19:19 +01:00
parent 7548e2e202
commit f091b2526e
8 changed files with 55 additions and 80 deletions

View File

@ -32,10 +32,6 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateHandler up
hasFinishedLoading = true;
}
private void SelectTab<T>() where T : BaseTabSettings, new(){
SelectTab(() => new T());
}
private void SelectTab<T>(Func<T> constructor) where T : BaseTabSettings{
BaseTabSettings control;
@ -44,7 +40,7 @@ private void SelectTab<T>(Func<T> constructor) where T : BaseTabSettings{
}
else{
control = tabs[typeof(T)] = constructor();
control.Ready = true;
control.OnReady();
tabPanel.ReplaceContent(control);
}
}

View File

@ -9,12 +9,11 @@ protected static UserConfig Config{
}
}
public bool Ready { get; set; }
public BaseTabSettings(){
Padding = new Padding(6);
}
public virtual void OnReady(){}
public virtual void OnClosing(){}
protected static void PromptRestart(){

View File

@ -54,7 +54,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.btnClearCache, "Clearing cache will free up space taken by downloaded images and other resources." +
"");
this.btnClearCache.UseVisualStyleBackColor = true;
this.btnClearCache.Click += new System.EventHandler(this.btnClearCache_Click);
//
// checkHardwareAcceleration
//
@ -68,7 +67,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.checkHardwareAcceleration, "Uses your graphics card to improve performance.\r\nDisable if you experience issues" +
" with rendering.");
this.checkHardwareAcceleration.UseVisualStyleBackColor = true;
this.checkHardwareAcceleration.CheckedChanged += new System.EventHandler(this.checkHardwareAcceleration_CheckedChanged);
//
// btnEditCefArgs
//
@ -79,7 +77,6 @@ private void InitializeComponent() {
this.btnEditCefArgs.Text = "Edit CEF Arguments";
this.toolTip.SetToolTip(this.btnEditCefArgs, "Set custom command line arguments for Chromium Embedded Framework.");
this.btnEditCefArgs.UseVisualStyleBackColor = true;
this.btnEditCefArgs.Click += new System.EventHandler(this.btnEditCefArgs_Click);
//
// btnEditCSS
//
@ -90,7 +87,6 @@ private void InitializeComponent() {
this.btnEditCSS.Text = "Edit CSS";
this.toolTip.SetToolTip(this.btnEditCSS, "Set custom CSS for browser and notification windows.");
this.btnEditCSS.UseVisualStyleBackColor = true;
this.btnEditCSS.Click += new System.EventHandler(this.btnEditCSS_Click);
//
// btnRestartArgs
//
@ -101,7 +97,6 @@ private void InitializeComponent() {
this.btnRestartArgs.Text = "Restart with Arguments";
this.toolTip.SetToolTip(this.btnRestartArgs, "Restarts the program with customizable\r\ncommand line arguments.");
this.btnRestartArgs.UseVisualStyleBackColor = true;
this.btnRestartArgs.Click += new System.EventHandler(this.btnRestartArgs_Click);
//
// btnRestart
//
@ -113,7 +108,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.btnRestart, "Restarts the program using the same command\r\nline arguments that were used at lau" +
"nch.");
this.btnRestart.UseVisualStyleBackColor = true;
this.btnRestart.Click += new System.EventHandler(this.btnRestart_Click);
//
// btnOpenAppFolder
//
@ -124,7 +118,6 @@ private void InitializeComponent() {
this.btnOpenAppFolder.Text = "Open Program Folder";
this.toolTip.SetToolTip(this.btnOpenAppFolder, "Opens the folder where the app is located.");
this.btnOpenAppFolder.UseVisualStyleBackColor = true;
this.btnOpenAppFolder.Click += new System.EventHandler(this.btnOpenAppFolder_Click);
//
// btnOpenDataFolder
//
@ -135,7 +128,6 @@ private void InitializeComponent() {
this.btnOpenDataFolder.Text = "Open Data Folder";
this.toolTip.SetToolTip(this.btnOpenDataFolder, "Opens the folder where your profile data is located.");
this.btnOpenDataFolder.UseVisualStyleBackColor = true;
this.btnOpenDataFolder.Click += new System.EventHandler(this.btnOpenDataFolder_Click);
//
// btnReset
//
@ -148,7 +140,6 @@ private void InitializeComponent() {
this.btnReset.TabIndex = 17;
this.btnReset.Text = "Restore Defaults";
this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btnImport
//
@ -161,7 +152,6 @@ private void InitializeComponent() {
this.btnImport.TabIndex = 16;
this.btnImport.Text = "Import Profile";
this.btnImport.UseVisualStyleBackColor = true;
this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
//
// btnExport
//
@ -175,7 +165,6 @@ private void InitializeComponent() {
this.btnExport.TabIndex = 15;
this.btnExport.Text = "Export Profile";
this.btnExport.UseVisualStyleBackColor = true;
this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
//
// groupPerformance
//

View File

@ -31,9 +31,24 @@ public TabSettingsAdvanced(Action<string> reinjectBrowserCSS, PluginManager plug
}));
}
private void btnClearCache_Click(object sender, EventArgs e){
if (!Ready)return;
public override void OnReady(){
btnClearCache.Click += btnClearCache_Click;
checkHardwareAcceleration.CheckedChanged += checkHardwareAcceleration_CheckedChanged;
btnEditCefArgs.Click += btnEditCefArgs_Click;
btnEditCSS.Click += btnEditCSS_Click;
btnExport.Click += btnExport_Click;
btnImport.Click += btnImport_Click;
btnReset.Click += btnReset_Click;
btnOpenAppFolder.Click += btnOpenAppFolder_Click;
btnOpenDataFolder.Click += btnOpenDataFolder_Click;
btnRestart.Click += btnRestart_Click;
btnRestartArgs.Click += btnRestartArgs_Click;
}
private void btnClearCache_Click(object sender, EventArgs e){
btnClearCache.Enabled = false;
BrowserCache.SetClearOnExit();
@ -41,8 +56,6 @@ private void btnClearCache_Click(object sender, EventArgs e){
}
private void checkHardwareAcceleration_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
bool succeeded = false;
if (checkHardwareAcceleration.Checked){

View File

@ -53,7 +53,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.checkExpandLinks, "Expands links inside the tweets. If disabled,\r\nthe full links show up in a toolti" +
"p instead.");
this.checkExpandLinks.UseVisualStyleBackColor = true;
this.checkExpandLinks.CheckedChanged += new System.EventHandler(this.checkExpandLinks_CheckedChanged);
//
// comboBoxTrayType
//
@ -64,7 +63,6 @@ private void InitializeComponent() {
this.comboBoxTrayType.Size = new System.Drawing.Size(171, 21);
this.comboBoxTrayType.TabIndex = 13;
this.toolTip.SetToolTip(this.comboBoxTrayType, "Changes behavior of the Tray icon.\r\nRight-click the icon for an action menu.");
this.comboBoxTrayType.SelectedIndexChanged += new System.EventHandler(this.comboBoxTrayType_SelectedIndexChanged);
//
// checkTrayHighlight
//
@ -78,7 +76,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.checkTrayHighlight, "Highlights the tray icon if there are new tweets.\r\nOnly works for columns with po" +
"pup or audio notifications.\r\nThe icon resets when the main window is restored.");
this.checkTrayHighlight.UseVisualStyleBackColor = true;
this.checkTrayHighlight.CheckedChanged += new System.EventHandler(this.checkTrayHighlight_CheckedChanged);
//
// checkSpellCheck
//
@ -90,7 +87,6 @@ private void InitializeComponent() {
this.checkSpellCheck.Text = "Enable Spell Check";
this.toolTip.SetToolTip(this.checkSpellCheck, "Underlines words that are spelled incorrectly.");
this.checkSpellCheck.UseVisualStyleBackColor = true;
this.checkSpellCheck.CheckedChanged += new System.EventHandler(this.checkSpellCheck_CheckedChanged);
//
// checkScreenshotBorder
//
@ -102,7 +98,6 @@ private void InitializeComponent() {
this.checkScreenshotBorder.Text = "Include Border In Screenshots";
this.toolTip.SetToolTip(this.checkScreenshotBorder, "Shows the window border in tweet screenshots.");
this.checkScreenshotBorder.UseVisualStyleBackColor = true;
this.checkScreenshotBorder.CheckedChanged += new System.EventHandler(this.checkScreenshotBorder_CheckedChanged);
//
// groupTray
//
@ -161,7 +156,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.checkUpdateNotifications, "Checks for updates every hour.\r\nIf an update is dismissed, it will not appear aga" +
"in.");
this.checkUpdateNotifications.UseVisualStyleBackColor = true;
this.checkUpdateNotifications.CheckedChanged += new System.EventHandler(this.checkUpdateNotifications_CheckedChanged);
//
// btnCheckUpdates
//
@ -172,7 +166,6 @@ private void InitializeComponent() {
this.btnCheckUpdates.Text = "Check Updates Now";
this.toolTip.SetToolTip(this.btnCheckUpdates, "Forces an update check, even for updates that had been dismissed.");
this.btnCheckUpdates.UseVisualStyleBackColor = true;
this.btnCheckUpdates.Click += new System.EventHandler(this.btnCheckUpdates_Click);
//
// TabSettingsGeneral
//

View File

@ -30,46 +30,44 @@ public TabSettingsGeneral(UpdateHandler updates){
checkUpdateNotifications.Checked = Config.EnableUpdateCheck;
}
private void checkExpandLinks_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
public override void OnReady(){
checkExpandLinks.CheckedChanged += checkExpandLinks_CheckedChanged;
checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged;
checkScreenshotBorder.CheckedChanged += checkScreenshotBorder_CheckedChanged;
comboBoxTrayType.SelectedIndexChanged += comboBoxTrayType_SelectedIndexChanged;
checkTrayHighlight.CheckedChanged += checkTrayHighlight_CheckedChanged;
checkUpdateNotifications.CheckedChanged += checkUpdateNotifications_CheckedChanged;
btnCheckUpdates.Click += btnCheckUpdates_Click;
}
private void checkExpandLinks_CheckedChanged(object sender, EventArgs e){
Config.ExpandLinksOnHover = checkExpandLinks.Checked;
}
private void checkSpellCheck_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.EnableSpellCheck = checkSpellCheck.Checked;
PromptRestart();
}
private void checkScreenshotBorder_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.ShowScreenshotBorder = checkScreenshotBorder.Checked;
}
private void comboBoxTrayType_SelectedIndexChanged(object sender, EventArgs e){
if (!Ready)return;
Config.TrayBehavior = (TrayIcon.Behavior)comboBoxTrayType.SelectedIndex;
}
private void checkTrayHighlight_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.EnableTrayHighlight = checkTrayHighlight.Checked;
}
private void checkUpdateNotifications_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.EnableUpdateCheck = checkUpdateNotifications.Checked;
}
private void btnCheckUpdates_Click(object sender, EventArgs e){
if (!Ready)return;
updateCheckEventId = updates.Check(true);
if (updateCheckEventId == -1){

View File

@ -110,7 +110,6 @@ private void InitializeComponent() {
this.comboBoxDisplay.Name = "comboBoxDisplay";
this.comboBoxDisplay.Size = new System.Drawing.Size(171, 21);
this.comboBoxDisplay.TabIndex = 7;
this.comboBoxDisplay.SelectedValueChanged += new System.EventHandler(this.comboBoxDisplay_SelectedValueChanged);
//
// labelEdgeDistance
//
@ -133,7 +132,6 @@ private void InitializeComponent() {
this.radioLocCustom.Text = "Custom";
this.toolTip.SetToolTip(this.radioLocCustom, "Drag the notification window to the desired location.");
this.radioLocCustom.UseVisualStyleBackColor = true;
this.radioLocCustom.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
//
// radioLocBR
//
@ -145,7 +143,6 @@ private void InitializeComponent() {
this.radioLocBR.TabStop = true;
this.radioLocBR.Text = "Bottom Right";
this.radioLocBR.UseVisualStyleBackColor = true;
this.radioLocBR.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
//
// radioLocBL
//
@ -157,7 +154,6 @@ private void InitializeComponent() {
this.radioLocBL.TabStop = true;
this.radioLocBL.Text = "Bottom Left";
this.radioLocBL.UseVisualStyleBackColor = true;
this.radioLocBL.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
//
// radioLocTR
//
@ -169,7 +165,6 @@ private void InitializeComponent() {
this.radioLocTR.TabStop = true;
this.radioLocTR.Text = "Top Right";
this.radioLocTR.UseVisualStyleBackColor = true;
this.radioLocTR.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
//
// radioLocTL
//
@ -181,7 +176,6 @@ private void InitializeComponent() {
this.radioLocTL.TabStop = true;
this.radioLocTL.Text = "Top Left";
this.radioLocTL.UseVisualStyleBackColor = true;
this.radioLocTL.CheckedChanged += new System.EventHandler(this.radioLoc_CheckedChanged);
//
// trackBarEdgeDistance
//
@ -197,7 +191,6 @@ private void InitializeComponent() {
this.trackBarEdgeDistance.TabIndex = 5;
this.trackBarEdgeDistance.TickFrequency = 4;
this.trackBarEdgeDistance.Value = 8;
this.trackBarEdgeDistance.ValueChanged += new System.EventHandler(this.trackBarEdgeDistance_ValueChanged);
//
// groupNotificationDuration
//
@ -243,7 +236,6 @@ private void InitializeComponent() {
this.btnDurationMedium.TabIndex = 2;
this.btnDurationMedium.Text = "Medium";
this.btnDurationMedium.UseVisualStyleBackColor = true;
this.btnDurationMedium.Click += new System.EventHandler(this.btnDurationMedium_Click);
//
// btnDurationLong
//
@ -259,7 +251,6 @@ private void InitializeComponent() {
this.btnDurationLong.TabIndex = 1;
this.btnDurationLong.Text = "Long";
this.btnDurationLong.UseVisualStyleBackColor = true;
this.btnDurationLong.Click += new System.EventHandler(this.btnDurationLong_Click);
//
// btnDurationShort
//
@ -275,7 +266,6 @@ private void InitializeComponent() {
this.btnDurationShort.TabIndex = 0;
this.btnDurationShort.Text = "Short";
this.btnDurationShort.UseVisualStyleBackColor = true;
this.btnDurationShort.Click += new System.EventHandler(this.btnDurationShort_Click);
//
// labelDurationValue
//
@ -302,7 +292,6 @@ private void InitializeComponent() {
this.trackBarDuration.TabIndex = 12;
this.trackBarDuration.TickFrequency = 5;
this.trackBarDuration.Value = 25;
this.trackBarDuration.ValueChanged += new System.EventHandler(this.trackBarDuration_ValueChanged);
//
// groupUserInterface
//
@ -327,7 +316,6 @@ private void InitializeComponent() {
this.toolTip.SetToolTip(this.checkNonIntrusive, "When not idle and the cursor is within the notification window area,\r\nit will be " +
"delayed until the cursor moves away to prevent accidental clicks.");
this.checkNonIntrusive.UseVisualStyleBackColor = true;
this.checkNonIntrusive.CheckedChanged += new System.EventHandler(this.checkNonIntrusive_CheckedChanged);
//
// checkTimerCountDown
//
@ -339,7 +327,6 @@ private void InitializeComponent() {
this.checkTimerCountDown.Text = "Timer Counts Down";
this.toolTip.SetToolTip(this.checkTimerCountDown, "The notification timer counts down instead of up.");
this.checkTimerCountDown.UseVisualStyleBackColor = true;
this.checkTimerCountDown.CheckedChanged += new System.EventHandler(this.checkTimerCountDown_CheckedChanged);
//
// checkNotificationTimer
//
@ -352,7 +339,6 @@ private void InitializeComponent() {
this.checkNotificationTimer.Text = "Display Notification Timer";
this.toolTip.SetToolTip(this.checkNotificationTimer, "Shows how much time is left before the current notification disappears.");
this.checkNotificationTimer.UseVisualStyleBackColor = true;
this.checkNotificationTimer.CheckedChanged += new System.EventHandler(this.checkNotificationTimer_CheckedChanged);
//
// groupCustomSound
//
@ -376,7 +362,6 @@ private void InitializeComponent() {
this.btnResetSound.TabIndex = 2;
this.btnResetSound.Text = "Reset";
this.btnResetSound.UseVisualStyleBackColor = true;
this.btnResetSound.Click += new System.EventHandler(this.btnResetSound_Click);
//
// btnBrowseSound
//
@ -388,7 +373,6 @@ private void InitializeComponent() {
this.btnBrowseSound.TabIndex = 1;
this.btnBrowseSound.Text = "Browse...";
this.btnBrowseSound.UseVisualStyleBackColor = true;
this.btnBrowseSound.Click += new System.EventHandler(this.btnBrowseSound_Click);
//
// tbCustomSound
//
@ -396,7 +380,6 @@ private void InitializeComponent() {
this.tbCustomSound.Name = "tbCustomSound";
this.tbCustomSound.Size = new System.Drawing.Size(170, 20);
this.tbCustomSound.TabIndex = 0;
this.tbCustomSound.TextChanged += new System.EventHandler(this.tbCustomSound_TextChanged);
//
// TabSettingsNotifications
//

View File

@ -65,6 +65,30 @@ public TabSettingsNotifications(FormNotificationMain notification, bool ignoreAu
Disposed += (sender, args) => this.notification.Dispose();
}
public override void OnReady(){
radioLocTL.CheckedChanged += radioLoc_CheckedChanged;
radioLocTR.CheckedChanged += radioLoc_CheckedChanged;
radioLocBL.CheckedChanged += radioLoc_CheckedChanged;
radioLocBR.CheckedChanged += radioLoc_CheckedChanged;
radioLocCustom.CheckedChanged += radioLoc_CheckedChanged;
trackBarDuration.ValueChanged += trackBarDuration_ValueChanged;
btnDurationShort.Click += btnDurationShort_Click;
btnDurationMedium.Click += btnDurationMedium_Click;
btnDurationLong.Click += btnDurationLong_Click;
checkNotificationTimer.CheckedChanged += checkNotificationTimer_CheckedChanged;
checkTimerCountDown.CheckedChanged += checkTimerCountDown_CheckedChanged;
checkNonIntrusive.CheckedChanged += checkNonIntrusive_CheckedChanged;
comboBoxDisplay.SelectedValueChanged += comboBoxDisplay_SelectedValueChanged;
trackBarEdgeDistance.ValueChanged += trackBarEdgeDistance_ValueChanged;
tbCustomSound.TextChanged += tbCustomSound_TextChanged;
btnBrowseSound.Click += btnBrowseSound_Click;
btnResetSound.Click += btnResetSound_Click;
}
public override void OnClosing(){
Config.NotificationSoundPath = tbCustomSound.Text;
}
@ -94,8 +118,6 @@ private void notification_Activated(object sender, EventArgs e){
}
private void radioLoc_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
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;
@ -113,8 +135,6 @@ private void radioLoc_CheckedChanged(object sender, EventArgs e){
}
private void trackBarDuration_ValueChanged(object sender, EventArgs e){
if (!Ready)return;
Config.NotificationDurationValue = trackBarDuration.Value;
labelDurationValue.Text = Config.NotificationDurationValue+" ms/c";
@ -122,54 +142,38 @@ private void trackBarDuration_ValueChanged(object sender, EventArgs e){
}
private void btnDurationShort_Click(object sender, EventArgs e){
if (!Ready)return;
trackBarDuration.Value = 15;
}
private void btnDurationMedium_Click(object sender, EventArgs e){
if (!Ready)return;
trackBarDuration.Value = 25;
}
private void btnDurationLong_Click(object sender, EventArgs e){
if (!Ready)return;
trackBarDuration.Value = 35;
}
private void checkNotificationTimer_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.DisplayNotificationTimer = checkNotificationTimer.Checked;
checkTimerCountDown.Enabled = checkNotificationTimer.Checked;
notification.ShowNotificationForSettings(true);
}
private void checkTimerCountDown_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.NotificationTimerCountDown = checkTimerCountDown.Checked;
notification.ShowNotificationForSettings(true);
}
private void checkNonIntrusive_CheckedChanged(object sender, EventArgs e){
if (!Ready)return;
Config.NotificationNonIntrusiveMode = checkNonIntrusive.Checked;
}
private void comboBoxDisplay_SelectedValueChanged(object sender, EventArgs e){
if (!Ready)return;
Config.NotificationDisplay = comboBoxDisplay.SelectedIndex;
notification.ShowNotificationForSettings(false);
}
private void trackBarEdgeDistance_ValueChanged(object sender, EventArgs e){
if (!Ready)return;
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value.ToString(CultureInfo.InvariantCulture)+" px";
Config.NotificationEdgeDistance = trackBarEdgeDistance.Value;
notification.ShowNotificationForSettings(false);