mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-03 05:34:07 +02:00
Refactor UserConfig event invocations into a generic method
This commit is contained in:
parent
4f8c778ba0
commit
33d9ba3871
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using TweetDuck.Core.Controls;
|
||||
@ -95,7 +96,7 @@ static UserConfig(){
|
||||
public bool IsCustomNotificationSizeSet => CustomNotificationSize != Size.Empty;
|
||||
|
||||
public TwitterUtils.ImageQuality TwitterImageQuality => BestImageQuality ? TwitterUtils.ImageQuality.Orig : TwitterUtils.ImageQuality.Default;
|
||||
|
||||
|
||||
public string NotificationSoundPath{
|
||||
get => string.IsNullOrEmpty(_notificationSoundPath) ? string.Empty : _notificationSoundPath;
|
||||
set => _notificationSoundPath = value;
|
||||
@ -103,35 +104,17 @@ public string NotificationSoundPath{
|
||||
|
||||
public bool MuteNotifications{
|
||||
get => _muteNotifications;
|
||||
|
||||
set{
|
||||
if (_muteNotifications != value){
|
||||
_muteNotifications = value;
|
||||
MuteToggled?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
set => UpdatePropertyWithEvent(ref _muteNotifications, value, MuteToggled);
|
||||
}
|
||||
|
||||
public int ZoomLevel{
|
||||
get => _zoomLevel;
|
||||
|
||||
set{
|
||||
if (_zoomLevel != value){
|
||||
_zoomLevel = value;
|
||||
ZoomLevelChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
set => UpdatePropertyWithEvent(ref _zoomLevel, value, ZoomLevelChanged);
|
||||
}
|
||||
|
||||
public TrayIcon.Behavior TrayBehavior{
|
||||
get => _trayBehavior;
|
||||
|
||||
set{
|
||||
if (_trayBehavior != value){
|
||||
_trayBehavior = value;
|
||||
TrayBehaviorChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
set => UpdatePropertyWithEvent(ref _trayBehavior, value, TrayBehaviorChanged);
|
||||
}
|
||||
|
||||
// EVENTS
|
||||
@ -148,6 +131,13 @@ private UserConfig(string file){
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
private void UpdatePropertyWithEvent<T>(ref T field, T value, EventHandler eventHandler){
|
||||
if (!EqualityComparer<T>.Default.Equals(field, value)){
|
||||
field = value;
|
||||
eventHandler?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(){
|
||||
try{
|
||||
if (File.Exists(file)){
|
||||
|
Loading…
Reference in New Issue
Block a user