Skip to content

Commit

Permalink
Added the possibility to set the default tab (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Jun 19, 2022
1 parent e487a68 commit 7cb84c3
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Datalya/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ private void CheckSettings()
Global.Settings.DisplayDeleteBlockMessage = true;
}

if (!Global.Settings.DefaultMenuTab.HasValue)
{
Global.Settings.DefaultMenuTab = 0;
}

SettingsManager.Save(); // Save changes
}
}
8 changes: 7 additions & 1 deletion Datalya/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public class Settings
/// True if Datalya should display a warning message when deleting a Block.
/// </summary>
public bool? DisplayDeleteBlockMessage { get; set; }

/// <summary>
/// The efault tab that sould be selected when opening Datalya.
/// </summary>
public DatabaseMenuTabs? DefaultMenuTab { get; set; }
}

public static class SettingsManager
Expand Down Expand Up @@ -105,7 +110,8 @@ public static void Load()
NotifyUpdates = true,
IsMaximized = false,
IsFirstRun = true,
DisplayDeleteBlockMessage = true
DisplayDeleteBlockMessage = true,
DefaultMenuTab = DatabaseMenuTabs.File
}; // Create a new settings file

Save(); // Save the changes
Expand Down
33 changes: 33 additions & 0 deletions Datalya/Enums/DatabaseMenuTabs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
namespace Datalya.Enums
{
public enum DatabaseMenuTabs
{
File,
Edit,
Export,
Help
}
}
16 changes: 14 additions & 2 deletions Datalya/Pages/DatabasePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MIT License
*/
using ClosedXML.Excel;
using Datalya.Classes;
using Datalya.Enums;
using Datalya.Windows;
using LeoCorpLibrary;
using Microsoft.Win32;
Expand Down Expand Up @@ -51,8 +52,19 @@ public DatabasePage()

internal void InitUI()
{
CheckButton(FileRibBtn); // Check
FileTab.Visibility = Visibility.Visible; // Show
CheckButton(Global.Settings.DefaultMenuTab switch
{
DatabaseMenuTabs.File => FileRibBtn,
DatabaseMenuTabs.Edit => EditRibBtn,
DatabaseMenuTabs.Export => ExportRibBtn,
DatabaseMenuTabs.Help => HelpRibBtn,
_ => FileRibBtn
}); // Check

FileTab.Visibility = Global.Settings.DefaultMenuTab == DatabaseMenuTabs.File ? Visibility.Visible : Visibility.Collapsed; // Show
EditTab.Visibility = Global.Settings.DefaultMenuTab == DatabaseMenuTabs.Edit ? Visibility.Visible : Visibility.Collapsed; // Show
ExportTab.Visibility = Global.Settings.DefaultMenuTab == DatabaseMenuTabs.Export ? Visibility.Visible : Visibility.Collapsed; // Show
HelpTab.Visibility = Global.Settings.DefaultMenuTab == DatabaseMenuTabs.Help ? Visibility.Visible : Visibility.Collapsed; // Show

InitDataBaseUI(); // Init database UI
}
Expand Down
18 changes: 18 additions & 0 deletions Datalya/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Datalya/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,4 +1232,10 @@ Europe</value>
<data name="UseDefaultDate" xml:space="preserve">
<value>Use default date</value>
</data>
<data name="DefaultTab" xml:space="preserve">
<value>Default tab</value>
</data>
<data name="DefaultTabDesc" xml:space="preserve">
<value>Default tab in "Database" mode.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Datalya/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1285,4 +1285,10 @@ Europe</value>
<data name="UseDefaultDate" xml:space="preserve">
<value>Utiliser la date par défaut</value>
</data>
<data name="DefaultTab" xml:space="preserve">
<value>Onglet par défaut</value>
</data>
<data name="DefaultTabDesc" xml:space="preserve">
<value>Onglet par défaut en mode « Base de données ».</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Datalya/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1212,4 +1212,10 @@ Europe</value>
<data name="UseDefaultDate" xml:space="preserve">
<value>Use default date</value>
</data>
<data name="DefaultTab" xml:space="preserve">
<value>Default tab</value>
</data>
<data name="DefaultTabDesc" xml:space="preserve">
<value>Default tab in "Database" mode.</value>
</data>
</root>
14 changes: 13 additions & 1 deletion Datalya/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,19 @@
</Button>
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.Messages}" FontWeight="Bold" FontSize="16" Margin="0 5"/>
<TextBlock Text="{x:Static lang:Resources.DefaultTab}" FontWeight="Bold" FontSize="16"/>
<TextBlock Text="{x:Static lang:Resources.DefaultTabDesc}" FontSize="14"/>
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="DefaultTabComboBox" SelectionChanged="DefaultTabComboBox_SelectionChanged" Style="{DynamicResource ComboBoxStyle1}" BorderThickness="3" Margin="2" HorizontalAlignment="Left" VerticalContentAlignment="Center" Foreground="{Binding Source={StaticResource Foreground1}}" Padding="5 6">
<ComboBoxItem Content="{x:Static lang:Resources.File}"/>
<ComboBoxItem Content="{x:Static lang:Resources.Edit}"/>
<ComboBoxItem Content="{x:Static lang:Resources.Export}"/>
<ComboBoxItem Content="{x:Static lang:Resources.Help}"/>
</ComboBox>

</StackPanel>

<TextBlock Text="{x:Static lang:Resources.Messages}" FontWeight="Bold" FontSize="16" Margin="0 5"/>
<CheckBox Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background1}}" x:Name="DeleteBlockMessageConfirmChk" Checked="DeleteBlockMessageConfirmChk_Checked" Unchecked="DeleteBlockMessageConfirmChk_Checked" BorderThickness="3" Content="{x:Static lang:Resources.ShowDeleteBlockConfirmMessage}" FontWeight="Bold" Margin="5 2" Style="{DynamicResource CheckBoxStyle1}" VerticalContentAlignment="Center"/>

<TextBlock Text="{x:Static lang:Resources.Data}" FontWeight="Bold" FontSize="16" Margin="0,5,0,2"/>
Expand Down
12 changes: 11 additions & 1 deletion Datalya/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ private void InitUI()

LangComboBox.SelectedIndex = (Global.Settings.Language == "_default") ? 0 : Global.LanguageCodeList.IndexOf(Global.Settings.Language) + 1;

// Default tab ComboBox
DefaultTabComboBox.SelectedIndex = (int)Global.Settings.DefaultMenuTab; // Select the correct item

// Apply buttons
LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
Expand Down Expand Up @@ -236,7 +239,8 @@ private void ResetSettingsLink_Click(object sender, RoutedEventArgs e)
RecentFiles = new(),
IsMaximized = false,
IsFirstRun = false, // Default is true but would be useless
DisplayDeleteBlockMessage = true
DisplayDeleteBlockMessage = true,
DefaultMenuTab = DatabaseMenuTabs.File
}; // Create default settings

SettingsManager.Save(); // Save the changes
Expand Down Expand Up @@ -264,4 +268,10 @@ private void SeeLicensesLink_Click(object sender, RoutedEventArgs e)
"LeoCorpLibrary - MIT License - © 2020-2022 Léo Corporation\n" +
"Datalya - MIT License - © 2021-2022 Léo Corporation", Properties.Resources.Datalya, MessageBoxButton.OK, MessageBoxImage.Information);
}

private void DefaultTabComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Global.Settings.DefaultMenuTab = (DatabaseMenuTabs)DefaultTabComboBox.SelectedIndex; // Set
SettingsManager.Save(); // Save changes
}
}

0 comments on commit 7cb84c3

Please sign in to comment.