allow edit

This commit is contained in:
2024-09-08 17:04:13 +02:00
parent a02f275577
commit 27879f15c3
7 changed files with 182 additions and 20 deletions

View File

@@ -0,0 +1,11 @@
namespace ModpackUpdater.Apps.Manager;
internal static class Extensions
{
public static string? Nullify(this string? @this)
{
if (string.IsNullOrEmpty(@this))
return null;
return @this;
}
}

View File

@@ -7,6 +7,9 @@ namespace ModpackUpdater.Apps.Manager.Features.Workspaces.GitLabRepo;
internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspace internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspace
{ {
private string? rawInstallInfos = null;
private string? rawUpdateInfos = null;
public WorkspaceConfig Config => ConfigX; public WorkspaceConfig Config => ConfigX;
public GitLabRepoWorkspaceConfig ConfigX { get; } = config; public GitLabRepoWorkspaceConfig ConfigX { get; } = config;
@@ -19,19 +22,38 @@ internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspac
public async Task<bool> Load() public async Task<bool> Load()
{ {
InstallInfos = InstallInfos.Parse(await GetContent(ConfigX.FileLocationInstallJson)); rawInstallInfos = await GetContent(ConfigX.FileLocationInstallJson);
UpdateInfos = UpdateInfos.Parse(await GetContent(ConfigX.FileLocationUpdateJson)); InstallInfos = InstallInfos.Parse(rawInstallInfos);
rawUpdateInfos = await GetContent(ConfigX.FileLocationUpdateJson);
UpdateInfos = UpdateInfos.Parse(rawUpdateInfos);
ConfigX.RepoName = (await Gitlab.Projects.GetByIdAsync((int)ConfigX.RepoId, new())).Name; ConfigX.RepoName = (await Gitlab.Projects.GetByIdAsync((int)ConfigX.RepoId, new())).Name;
return InstallInfos != null && UpdateInfos != null; return InstallInfos != null && UpdateInfos != null;
} }
public async Task<bool> Save() public async Task<bool> Save()
{ {
if (InstallInfos != null) if (InstallInfos != null)
await SaveContent(ConfigX.FileLocationInstallJson, InstallInfos.ToString()); {
var newInstallInfos = InstallInfos.ToString();
if (newInstallInfos != rawInstallInfos)
{
await SaveContent(ConfigX.FileLocationInstallJson, newInstallInfos);
rawInstallInfos = newInstallInfos;
}
}
if (UpdateInfos != null) if (UpdateInfos != null)
await SaveContent(ConfigX.FileLocationUpdateJson, UpdateInfos.ToString()); {
var newUpdateInfos = UpdateInfos.ToString();
if (newUpdateInfos != rawUpdateInfos)
{
await SaveContent(ConfigX.FileLocationUpdateJson, newUpdateInfos);
rawUpdateInfos = newUpdateInfos;
}
}
return true; return true;
} }

View File

@@ -169,6 +169,7 @@ partial class Form1
radGridView_Actions.Size = new Size(590, 416); radGridView_Actions.Size = new Size(590, 416);
radGridView_Actions.TabIndex = 0; radGridView_Actions.TabIndex = 0;
radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting; radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting;
radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged;
// //
// radMenuItem_Workspace // radMenuItem_Workspace
// //

View File

@@ -6,6 +6,7 @@ using ModpackUpdater.Apps.Manager.Settings;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
using Pilz.Plugins.Advanced.UI.Telerik; using Pilz.Plugins.Advanced.UI.Telerik;
using Pilz.UI.Symbols; using Pilz.UI.Symbols;
using Pilz.UI.Telerik.Extensions;
using Telerik.WinControls; using Telerik.WinControls;
using Telerik.WinControls.UI; using Telerik.WinControls.UI;
@@ -138,11 +139,20 @@ public partial class Form1 : RadForm, IMainApi
// Add columns // Add columns
radGridView_Actions.Columns.AddRange([ radGridView_Actions.Columns.AddRange([
new GridViewTextBoxColumn
{
Name = "id",
HeaderText = ActionsListLangRes.Col_Id,
Width = 150,
IsVisible = infos is not UpdateInfo,
IsPinned = true,
},
new GridViewTextBoxColumn new GridViewTextBoxColumn
{ {
Name = "name", Name = "name",
HeaderText = ActionsListLangRes.Col_Name, HeaderText = ActionsListLangRes.Col_Name,
Width = 150, Width = 150,
IsVisible = infos is not UpdateInfo,
}, },
new GridViewTextBoxColumn new GridViewTextBoxColumn
{ {
@@ -150,6 +160,7 @@ public partial class Form1 : RadForm, IMainApi
HeaderText = ActionsListLangRes.Col_InheritFrom, HeaderText = ActionsListLangRes.Col_InheritFrom,
Width = 150, Width = 150,
IsVisible = infos is UpdateInfo, IsVisible = infos is UpdateInfo,
IsPinned = true,
}, },
new GridViewComboBoxColumn new GridViewComboBoxColumn
{ {
@@ -159,6 +170,19 @@ public partial class Form1 : RadForm, IMainApi
DataSource = Enum.GetValues<UpdateActionType>(), DataSource = Enum.GetValues<UpdateActionType>(),
IsVisible = infos is UpdateInfo, IsVisible = infos is UpdateInfo,
}, },
new GridViewComboBoxColumn
{
Name = "side",
HeaderText = ActionsListLangRes.Col_Side,
Width = 150,
DataSource = Enum.GetValues<Side>(),
},
new GridViewCheckBoxColumn
{
Name = "isextra",
HeaderText = ActionsListLangRes.Col_IsExtra,
Width = 50,
},
new GridViewCheckBoxColumn new GridViewCheckBoxColumn
{ {
Name = "iszip", Name = "iszip",
@@ -191,18 +215,12 @@ public partial class Form1 : RadForm, IMainApi
HeaderText = ActionsListLangRes.Col_DestPath, HeaderText = ActionsListLangRes.Col_DestPath,
Width = 250, Width = 250,
}, },
new GridViewTextBoxColumn
{
Name = "srcurl",
HeaderText = ActionsListLangRes.Col_SrcUrl,
Width = 350,
},
new GridViewComboBoxColumn new GridViewComboBoxColumn
{ {
Name = "srctype", Name = "srctype",
HeaderText = ActionsListLangRes.Col_SrcType, HeaderText = ActionsListLangRes.Col_SrcType,
DataSource = Enum.GetValues<SourceType>(),
Width = 150, Width = 150,
DataSource = Enum.GetValues<SourceType>(),
}, },
new GridViewTextBoxColumn new GridViewTextBoxColumn
{ {
@@ -228,18 +246,17 @@ public partial class Form1 : RadForm, IMainApi
HeaderText = ActionsListLangRes.Col_SrcTag, HeaderText = ActionsListLangRes.Col_SrcTag,
Width = 150, Width = 150,
}, },
new GridViewComboBoxColumn new GridViewTextBoxColumn
{ {
Name = "side", Name = "srcurl",
HeaderText = ActionsListLangRes.Col_Side, HeaderText = ActionsListLangRes.Col_SrcUrl,
DataSource = Enum.GetValues<Side>(), Width = 350,
Width = 150,
}, },
new GridViewCheckBoxColumn new GridViewTextBoxColumn
{ {
Name = "isextra", Name = "website",
HeaderText = ActionsListLangRes.Col_IsExtra, HeaderText = ActionsListLangRes.Col_Website,
Width = 50, Width = 350,
}, },
]); ]);
@@ -248,6 +265,7 @@ public partial class Form1 : RadForm, IMainApi
{ {
var row = radGridView_Actions.Rows.AddNew(); var row = radGridView_Actions.Rows.AddNew();
row.Tag = action; row.Tag = action;
row.Cells["id"].Value = action.Id;
row.Cells["name"].Value = action.Name; row.Cells["name"].Value = action.Name;
row.Cells["iszip"].Value = action.IsZip; row.Cells["iszip"].Value = action.IsZip;
row.Cells["zippath"].Value = action.ZipPath; row.Cells["zippath"].Value = action.ZipPath;
@@ -327,4 +345,84 @@ public partial class Form1 : RadForm, IMainApi
// cellElement.ResetValue(LightVisualElement.ImageAlignmentProperty, ValueResetFlags.Local); // cellElement.ResetValue(LightVisualElement.ImageAlignmentProperty, ValueResetFlags.Local);
//} //}
} }
private void RadGridView_Actions_CellValueChanged(object sender, GridViewCellEventArgs e)
{
if (e.Row?.Tag is not InstallAction action)
return;
var uaction = action as UpdateAction;
var newValue = e.Row.Cells[e.Column.Name].Value;
var colName = e.Column.Name;
if (newValue is string valueStr)
{
var valueNullStr = valueStr.Nullify();
switch (colName)
{
case "id":
action.Id = valueNullStr;
break;
case "name":
action.Name = valueNullStr;
break;
case "zippath":
action.ZipPath = valueNullStr;
break;
case "destpath":
action.DestPath = valueNullStr;
break;
case "srcurl":
action.SourceUrl = valueNullStr;
break;
case "srctype":
action.SourceType = Enum.Parse<SourceType>(valueStr);
break;
case "srcowner":
action.SourceOwner = valueNullStr;
break;
case "srcname":
action.SourceName = valueNullStr;
break;
case "srcregex":
action.SourceTag = valueNullStr;
break;
case "srctag":
action.SourceTag = valueNullStr;
break;
case "side":
action.Side = Enum.Parse<Side>(valueStr);
break;
case "inherit":
if (uaction is not null)
uaction.InheritFrom = valueNullStr;
break;
case "utype":
if (uaction is not null)
uaction.Type = Enum.Parse<UpdateActionType>(valueStr);
break;
case "srcpath":
if (uaction is not null)
uaction.SrcPath = valueNullStr;
break;
}
}
else if (newValue is bool valueBool)
{
switch (colName)
{
case "iszip":
action.IsZip = valueBool;
break;
case "isextra":
action.IsExtra = valueBool;
break;
case "isdir":
if (uaction is not null)
uaction.IsDirectory = valueBool;
break;
}
}
}
} }

View File

@@ -69,6 +69,15 @@ namespace ModpackUpdater.Apps.Manager.LangRes {
} }
} }
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Id ähnelt.
/// </summary>
internal static string Col_Id {
get {
return ResourceManager.GetString("Col_Id", resourceCulture);
}
}
/// <summary> /// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Inherit from ähnelt. /// Sucht eine lokalisierte Zeichenfolge, die Inherit from ähnelt.
/// </summary> /// </summary>
@@ -195,6 +204,15 @@ namespace ModpackUpdater.Apps.Manager.LangRes {
} }
} }
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Website ähnelt.
/// </summary>
internal static string Col_Website {
get {
return ResourceManager.GetString("Col_Website", resourceCulture);
}
}
/// <summary> /// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die ZIP archive path ähnelt. /// Sucht eine lokalisierte Zeichenfolge, die ZIP archive path ähnelt.
/// </summary> /// </summary>

View File

@@ -120,6 +120,9 @@
<data name="Col_DestPath" xml:space="preserve"> <data name="Col_DestPath" xml:space="preserve">
<value>Destination path</value> <value>Destination path</value>
</data> </data>
<data name="Col_Id" xml:space="preserve">
<value>Id</value>
</data>
<data name="Col_InheritFrom" xml:space="preserve"> <data name="Col_InheritFrom" xml:space="preserve">
<value>Inherit from</value> <value>Inherit from</value>
</data> </data>
@@ -162,6 +165,9 @@
<data name="Col_UpdateType" xml:space="preserve"> <data name="Col_UpdateType" xml:space="preserve">
<value>Update type</value> <value>Update type</value>
</data> </data>
<data name="Col_Website" xml:space="preserve">
<value>Website</value>
</data>
<data name="Col_ZipPath" xml:space="preserve"> <data name="Col_ZipPath" xml:space="preserve">
<value>ZIP archive path</value> <value>ZIP archive path</value>
</data> </data>

View File

@@ -5,9 +5,15 @@ namespace ModpackUpdater;
public class InstallAction public class InstallAction
{ {
[DefaultValue(null)]
public string Id { get; set; }
[DefaultValue(null)] [DefaultValue(null)]
public string Name { get; set; } public string Name { get; set; }
[DefaultValue(null)]
public string Website { get; set; }
[DefaultValue(false)] [DefaultValue(false)]
public bool IsZip { get; set; } public bool IsZip { get; set; }