Added Git Export Feature

- Added import algorithm
- Added FromJsonX() methods to data models
- Added possibility to work with temp. database file
- Added export processor to handle export process & triggers
- Added something changed event e.g. as export trigger
- Added possibility to import a JSON export
- Updated Git icon
This commit is contained in:
tsommer committed 2023-01-22 19:35:57 +01:00
1 parent 7a742a18e7
commit 0587af18f2
20 files changed
+411 -62

No files matched your search

@@ -62,6 +62,7 @@ public partial class LoaderStart : UserControl
#endregion
// Opens the recent projects dropdown menu.
private void buttonOpen_Click(object sender, EventArgs e)
{
if(this.DesignMode)
@@ -84,9 +85,19 @@ public partial class LoaderStart : UserControl
// Split the file's path into each folder's name:
var folderNames = fileInfo.DirectoryName!.Split(Path.DirectorySeparatorChar);
// Render this entry:
var item = this.contextMenuRecentProjects.Items.Add($"{folderNames.Last()}: {fileInfo.Name}", Resources.Icons.icons8_document_512, (innerSender, args) => this.OpenRecentProject(innerSender));
item.Tag = recentProject;
// Distinguish between I18N Commander projects and JSON imports:
if (fileInfo.Extension == ".i18nc")
{
// Render this entry:
var item = this.contextMenuRecentProjects.Items.Add($"{folderNames.Last()}: {fileInfo.Name}", Resources.Icons.icons8_document_512, (innerSender, args) => this.OpenRecentProject(innerSender, LoaderAction.LOAD_PROJECT));
item.Tag = recentProject;
}
else if (fileInfo.Extension == ".json")
{
// Render this entry:
var item = this.contextMenuRecentProjects.Items.Add($"{folderNames.Last()}: {fileInfo.Name}", Resources.Icons.icons8_git, (innerSender, args) => this.OpenRecentProject(innerSender, LoaderAction.IMPORT_JSON));
item.Tag = recentProject;
}
}
var button = (sender as Button)!;
@@ -125,7 +136,7 @@ public partial class LoaderStart : UserControl
File.Delete(destinationFilePath);
LoaderStart.UpdateRecentProjectsWithPruning(destinationFilePath);
this.OpenProject(destinationFilePath);
this.OpenProject(LoaderAction.CREATE_NEW_PROJECT, destinationFilePath);
}
private void BrowseForProject()
@@ -137,10 +148,12 @@ public partial class LoaderStart : UserControl
CheckFileExists = true,
DereferenceLinks = true,
DefaultExt = ".i18nc",
Filter = "I18N Commander Files (*.i18nc)|*.i18nc",
// I18N Commander files (*.i18nc) or JSON files (*.json):
Filter = "I18N Commander Files (*.i18nc)|*.i18nc|JSON Files (*.json)|*.json",
Multiselect = false,
RestoreDirectory = true,
Title = "Open an I18N Commander file",
Title = "Open an I18N Commander file or Import a JSON file",
};
var dialogResult = openDialog.ShowDialog(this);
if (dialogResult != DialogResult.OK)
@@ -148,23 +161,28 @@ public partial class LoaderStart : UserControl
var projectFilePath = openDialog.FileName;
LoaderStart.UpdateRecentProjectsWithPruning(projectFilePath);
this.OpenProject(projectFilePath);
// Check, if the user chose an I18N Commander file or a JSON file:
if (projectFilePath.ToLowerInvariant().EndsWith(".i18nc", StringComparison.InvariantCulture))
this.OpenProject(LoaderAction.LOAD_PROJECT, projectFilePath);
else if (projectFilePath.ToLowerInvariant().EndsWith(".json", StringComparison.InvariantCulture))
this.OpenProject(LoaderAction.IMPORT_JSON, projectFilePath);
}
private void OpenRecentProject(object? sender)
private void OpenRecentProject(object? sender, LoaderAction action)
{
if (sender is not ToolStripItem item)
return;
var path = (item.Tag as string)!;
LoaderStart.UpdateRecentProjectsWithPruning(path);
this.OpenProject(path);
this.OpenProject(action, path);
}
private void OpenProject(string path)
private void OpenProject(LoaderAction action, string path)
{
// Hint: the project file might or might not exist (new project vs. recent project)
this.LoadProject?.Invoke(this, path);
this.LoadProject?.Invoke(this, new LoaderResult(action, path));
}
private void contextMenuRecentProjects_Closing(object sender, ToolStripDropDownClosingEventArgs e)
@@ -173,5 +191,16 @@ public partial class LoaderStart : UserControl
}
[Category("Settings"), Description("When the user chooses a project to load.")]
public event EventHandler<string>? LoadProject;
public event EventHandler<LoaderResult>? LoadProject;
public readonly record struct LoaderResult(LoaderAction Action, string DataFile);
public enum LoaderAction
{
NONE,
LOAD_PROJECT,
CREATE_NEW_PROJECT,
IMPORT_JSON,
}
}
@@ -1,4 +1,6 @@
namespace UI_WinForms.Components;
using Processor;
namespace UI_WinForms.Components;
public partial class Main : UserControl
{
@@ -6,6 +8,9 @@ public partial class Main : UserControl
{
this.InitializeComponent();
Program.RestartMainApp = false;
// Register the something changed event to trigger the export:
AppEvents.WhenSomethingChanged += async (_, _) => await ExportProcessor.TriggerExport();
}
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
@@ -690,7 +690,7 @@ public sealed partial class Setting : UserControl
{
var currentSetting = await AppSettings.GetAutoExportEnabled();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
Icon: Icons.icons8_git,
SettingName: () => "Git (JSON) Auto-Export: Enabled",
ChangeNeedsRestart: true,
SettingExplanation: () => "When enabled, all changes are automatically exported into a Git repository as JSON file.",
@@ -700,9 +700,13 @@ public sealed partial class Setting : UserControl
// Set up an checkbox:
var checkbox = new CheckBox();
checkbox.Checked = currentSetting;
checkbox.CheckedChanged += async (sender, args) => await AppSettings.SetAutoExportEnabled(checkbox.Checked);
checkbox.CheckedChanged += (sender, args) => changeTrigger();
checkbox.Text = "Enable Git (JSON) Auto-Export";
checkbox.CheckedChanged += async (sender, args) =>
{
await AppSettings.SetAutoExportEnabled(checkbox.Checked);
await ExportProcessor.TriggerExport();
changeTrigger();
};
checkbox.Text = "Enable Auto-Export";
// Apply the desired layout:
checkbox.Dock = DockStyle.Fill;
@@ -717,7 +721,7 @@ public sealed partial class Setting : UserControl
{
var currentSetting = await AppSettings.GetAutoExportDestinationPath();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
Icon: Icons.icons8_git,
SettingName: () => "Git (JSON) Auto-Export: Destination Path",
ChangeNeedsRestart: true,
SettingExplanation: () => "The destination path for the Git repository. You might use environment variables like %USERPROFILE%.",
@@ -775,7 +779,7 @@ public sealed partial class Setting : UserControl
{
var currentSetting = await AppSettings.GetAutoExportFilename();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
Icon: Icons.icons8_git,
SettingName: () => "Git (JSON) Auto-Export: Filename",
ChangeNeedsRestart: true,
SettingExplanation: () => "The filename used for the Git export. You might use environment variables like %USERPROFILE%.",
@@ -800,7 +804,7 @@ public sealed partial class Setting : UserControl
{
var currentSetting = await AppSettings.GetAutoExportSensitiveData();
var settingData = new SettingUIData(
Icon: Icons.icons8_git_svg,
Icon: Icons.icons8_git,
SettingName: () => "Git (JSON) Auto-Export: Export Sensitive Data",
ChangeNeedsRestart: true,
SettingExplanation: () => "When enabled, sensitive data like API tokens are exported into the Git repository. This is not recommended!",