Skip to content

Commit

Permalink
Merge pull request #23 from haruki-taka8/feature-welcome-on-startup
Browse files Browse the repository at this point in the history
New Configuration: Show Welcome on Startup
  • Loading branch information
haruki-taka8 authored Sep 15, 2023
2 parents 4d92804 + 63175c6 commit 7a18783
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 19 deletions.
4 changes: 2 additions & 2 deletions rowsSharp/Model/CommonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class CommonModel
/// <summary>
/// User settings. Currently read from a JSON file.
/// </summary>
public Preferences Preferences { get; }
public Preferences Preferences { get; internal set; }

/// <summary>
/// A WPF-friendly representation of the CSV file.
/// </summary>
public ObservableTable<string> Table { get; }
public ObservableTable<string> Table { get; internal set; }

// Constructors
public CommonModel()
Expand Down
6 changes: 6 additions & 0 deletions rowsSharp/Model/Preferences/UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public class UserInterface
/// Whether user-friendly text is displayed upon hovering an element, especially a button.
/// </summary>
public bool IsToolTipEnabled { get; set; } = true;

/// <summary>
/// Whether to show the home screen (new file, open file, preferences) upon starting RowsSharp.
/// Useful for users who don't intend to open the same file every time.
/// </summary>
public bool ShowWelcomeOnStartup { get; set; }
}
4 changes: 3 additions & 1 deletion rowsSharp/Userdata/Configurations/Configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

"ThemePath": "$baseDir/Configurations/Themes/Light.xaml",

"IsToolTipEnabled": true
"IsToolTipEnabled": true,

"ShowWelcomeOnStartup": false
},

"Filter": {
Expand Down
3 changes: 2 additions & 1 deletion rowsSharp/View/Editor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
</Button.RenderTransform>
</Button>
<Rectangle/>
<Button DockPanel.Dock="Right" Margin="0,0,8,0" Command="{Binding OpenHome, Mode=OneTime}" Content="&#xe88a;" ToolTip="Home"/>
<Button DockPanel.Dock="Right" Margin="0,0,8,0" Command="{Binding OpenPreferences, Mode=OneTime}" Content="&#xe8b8;" ToolTip="Preferences"/>
<Rectangle DockPanel.Dock="Right"/>

Expand Down Expand Up @@ -329,7 +330,7 @@
<Condition Binding="{Binding Table.Headers.Count, Mode=OneWay}" Value="0"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Text" Value="Empty File"/>
<Setter Property="Text" Value="Insert a row and a column using the top toolbar"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
Expand Down
11 changes: 9 additions & 2 deletions rowsSharp/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RowsSharp.ViewModel;
using RowsSharp.Domain;
using RowsSharp.ViewModel;
using System.Windows;

namespace RowsSharp.View;
Expand All @@ -10,7 +11,13 @@ public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new CommonViewModel();
CommonViewModel viewModel = new();
viewModel.InitializeAsync();
DataContext = viewModel;

ResourceDictionary theme = PreferencesReader.GetTheme(viewModel.Preferences.UserInterface.ThemePath);
Application.Current.Resources.MergedDictionaries.Add(theme);

InitializeComponent();
App.Logger.Info("Okay, it's happening! Everybody stay calm!");
}
Expand Down
37 changes: 25 additions & 12 deletions rowsSharp/ViewModel/CommonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ internal set
/// <summary>
/// Reference to the CommonModel
/// </summary>
private CommonModel model = new();
private readonly CommonModel model = new();

/// <summary>
/// Reference to the Preferences object
/// </summary>
public Preferences Preferences => model.Preferences;
public Preferences Preferences
{
get => model.Preferences;
private set => model.Preferences = value;
}

/// <summary>
/// Reference to the ObservableTable object
/// </summary>
public ObservableTable<string> Table => model.Table;
public ObservableTable<string> Table
{
get => model.Table;
private set => model.Table = value;
}

private bool isEditorDirty;
/// <summary>
Expand All @@ -71,23 +79,28 @@ public bool IsEditorDirty
private const string ConfigurationPath =
"./Userdata/Configurations/Configuration.json";

public CommonViewModel(Preferences? preferences = null)
public CommonViewModel()
{
preferences ??= PreferencesReader.Import(ConfigurationPath);
ResourceDictionary theme = PreferencesReader.GetTheme(preferences.UserInterface.ThemePath);
Application.Current.Resources.MergedDictionaries.Add(theme);
Preferences = PreferencesReader.Import(ConfigurationPath);
}

public async void InitializeAsync()
{
// Don't block the UI thread
Task.Run(() => CreateModel(preferences));
await Task.Run(() => Initialize());
}

private void CreateModel(Preferences preferences)
private void Initialize()
{
var table = CsvFile.Import(preferences.Csv.Path, preferences.Csv.HasHeader);
if (Preferences.UserInterface.ShowWelcomeOnStartup)
{
CurrentSection = Section.Welcome;
return;
}

model = new(preferences, table);
Table = CsvFile.Import(Preferences.Csv.Path, Preferences.Csv.HasHeader);

CurrentSection = File.Exists(preferences.Csv.Path)
CurrentSection = File.Exists(Preferences.Csv.Path)
? Section.Editor
: Section.Welcome;
}
Expand Down
10 changes: 10 additions & 0 deletions rowsSharp/ViewModel/EditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,14 @@ private void Clear_Private(Container container)
public DelegateCommand OpenPreferences => new(() =>
commonViewModel.CurrentSection = Section.Settings
);

public DelegateCommand OpenHome => new(() =>
{
CancelEventArgs e = new();
commonViewModel.Exit.Execute(e);
if (e.Cancel) { return; }
commonViewModel.CurrentSection = Section.Welcome;
});
}
3 changes: 2 additions & 1 deletion rowsSharp/ViewModel/WelcomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public WelcomeViewModel(CommonViewModel commonViewModel)
string path = FileDialogHelper.RequestReadPath();
CommonViewModel.Preferences.Csv.Path = path;
CommonViewModel = new(CommonViewModel.Preferences);
CommonViewModel.Preferences.UserInterface.ShowWelcomeOnStartup = false;
CommonViewModel.InitializeAsync();
});

public DelegateCommand NewFile => new(() =>
Expand Down
1 change: 1 addition & 0 deletions rowsSharp/rowsSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<StartupObject></StartupObject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit 7a18783

Please sign in to comment.