Skip to content

Commit

Permalink
Merge pull request nicehash#2512 from nicehash/master_NL-1504
Browse files Browse the repository at this point in the history
Theme change reverts when "x" is clicked
  • Loading branch information
S74nk0 authored Oct 6, 2021
2 parents a10a8a8 + 0720c6c commit f25722f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/NHMCore/Configs/GUISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,42 @@ public bool AutoScaleBTCValues
// }
//}

public void RevertTheme()
{
DisplayTheme = LastDisplayTheme;
}


private string _lastDisplayTheme = "Light";
public string LastDisplayTheme
{
get => _lastDisplayTheme;
set
{
_lastDisplayTheme = value;
OnPropertyChanged(nameof(LastDisplayTheme));
}
}

private string _nextDisplayTheme = "Light";
public string NextDisplayTheme
{
get => _nextDisplayTheme;
set
{
_nextDisplayTheme = value;
OnPropertyChanged(nameof(NextDisplayTheme));
}
}


private string _displayTheme = "Light";
public string DisplayTheme
{
get => _displayTheme;
set
{
LastDisplayTheme = _displayTheme;
_displayTheme = value;
OnPropertyChanged(nameof(DisplayTheme));
}
Expand Down
1 change: 1 addition & 0 deletions src/NiceHashMiner/Views/Common/CustomDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void CloseDialog(object sender, RoutedEventArgs e)
public event EventHandler<RoutedEventArgs> CancelClick;



public string Title
{
get => (string)GetValue(TitleProperty);
Expand Down
2 changes: 1 addition & 1 deletion src/NiceHashMiner/Views/Settings/SettingsGeneral.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<Label Content="Theme" Style="{StaticResource FontsTypography.SmallRegular/Active}"/>
<TextBlock HorizontalAlignment="Right" FontFamily="{StaticResource FontAwesome}" FontSize="12" Foreground="#cecdcd" FontStyle="Normal" FontStretch="Normal" FontWeight="Normal" Margin="0,5,12,0">&#xF05A;</TextBlock>
</StackPanel>
<ComboBox Margin="0,0,24,0" Style="{StaticResource smallComboBox}" ItemContainerStyle="{StaticResource ItemStyle}" ItemsSource="{Binding ThemeOptions}" SelectedItem="{Binding GUISettings.DisplayTheme, Mode=TwoWay}" SelectionChanged="ThemeComboBox_SelectionChanged" />
<ComboBox x:Name="ThemeSelect" Margin="0,0,24,0" Style="{StaticResource smallComboBox}" ItemContainerStyle="{StaticResource ItemStyle}" ItemsSource="{Binding ThemeOptions}" SelectedItem="{Binding GUISettings.DisplayTheme, Mode=OneWay}" SelectionChanged="ThemeComboBox_SelectionChanged" />
</StackPanel>
</WrapPanel>
<!--NHM and PLUGINS UPDATE-->
Expand Down
19 changes: 18 additions & 1 deletion src/NiceHashMiner/Views/Settings/SettingsGeneral.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,19 @@ private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEv

private void CommitGeneralAndRestart()
{
GUISettings.Instance.DisplayTheme = GUISettings.Instance.NextDisplayTheme;
ConfigManager.GeneralConfigFileCommit();
Task.Run(() => ApplicationStateManager.RestartProgram());
}

private void RevertTheme()
{
this.ThemeSelect.SelectionChanged -= new System.Windows.Controls.SelectionChangedEventHandler(this.ThemeComboBox_SelectionChanged);
GUISettings.Instance.RevertTheme();
ConfigManager.GeneralConfigFileCommit();
this.ThemeSelect.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.ThemeComboBox_SelectionChanged);
}

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if(sender is TextBox tb)
Expand Down Expand Up @@ -254,6 +263,13 @@ private void CopyLogReportIdButton_Click(object sender, RoutedEventArgs e)
Clipboard.SetText(_reportId);
}

private void SelectTheme()
{
GUISettings.Instance.NextDisplayTheme = ThemeSelect.SelectedItem.ToString();//so we can commit on restart
GUISettings.Instance.DisplayTheme = ThemeSelect.SelectedItem.ToString();//for current show of theme
ConfigManager.GeneralConfigFileCommit();
}

private void ThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var nhmConfirmDialog = new CustomDialog()
Expand All @@ -264,8 +280,9 @@ private void ThemeComboBox_SelectionChanged(object sender, SelectionChangedEvent
CancelVisible = Visibility.Collapsed,
AnimationVisible = Visibility.Collapsed
};
SelectTheme();
nhmConfirmDialog.OKClick += (s, e1) => CommitGeneralAndRestart();
nhmConfirmDialog.OnExit += (s, e1) => CommitGeneralAndRestart();
nhmConfirmDialog.OnExit += (s, e1) => RevertTheme();//reverts even when click ok because it exits...

CustomDialogManager.ShowModalDialog(nhmConfirmDialog);
}
Expand Down

0 comments on commit f25722f

Please sign in to comment.