From 7e5acd413ed598754aae6d07dfaf91ab5bb2f1fe Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 9 Sep 2024 09:20:24 +0200 Subject: [PATCH] add/remove action rows --- .../Api/Model/IMainApi.cs | 3 +- .../LangRes/GeneralLangRes.Designer.cs | 4 +-- .../LangRes/GeneralLangRes.resx | 4 +-- .../Ui/MainForm.Designer.cs | 8 +++-- ModpackUpdater.Apps.Manager/Ui/MainForm.cs | 32 ++++++++++++++++++- ModpackUpdater.Manager/ModpackInstaller.cs | 14 ++++++-- 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/ModpackUpdater.Apps.Manager/Api/Model/IMainApi.cs b/ModpackUpdater.Apps.Manager/Api/Model/IMainApi.cs index 73fb9a9..4d6fd50 100644 --- a/ModpackUpdater.Apps.Manager/Api/Model/IMainApi.cs +++ b/ModpackUpdater.Apps.Manager/Api/Model/IMainApi.cs @@ -2,5 +2,6 @@ public interface IMainApi { - public IWorkspace? Workspace { get; } + public IWorkspace? CurWorkspace { get; } + public IActionSetInfos? CurActionSet { get; } } diff --git a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs index 16c3286..618b66c 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.Designer.cs @@ -61,7 +61,7 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Install to {0} ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Installation: {0} ähnelt. /// internal static string Node_Install { get { @@ -70,7 +70,7 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Update to {0} ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Update: {0} ähnelt. /// internal static string Node_Update { get { diff --git a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx index 76ad5de..edc348b 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/GeneralLangRes.resx @@ -118,9 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Install to {0} + Installation: {0} - Update to {0} + Update: {0} \ No newline at end of file diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs index 6aec863..193b1d4 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.Designer.cs @@ -161,9 +161,8 @@ partial class MainForm // // // - radGridView_Actions.MasterTemplate.AllowAddNewRow = false; + radGridView_Actions.MasterTemplate.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom; radGridView_Actions.MasterTemplate.AllowColumnChooser = false; - radGridView_Actions.MasterTemplate.AllowDeleteRow = false; radGridView_Actions.MasterTemplate.AllowDragToGroup = false; radGridView_Actions.MasterTemplate.AllowRowResize = false; radGridView_Actions.MasterTemplate.AllowSearchRow = true; @@ -173,6 +172,9 @@ partial class MainForm radGridView_Actions.Size = new Size(590, 416); radGridView_Actions.TabIndex = 0; radGridView_Actions.CellFormatting += RadGridView_Actions_CellFormatting; + radGridView_Actions.UserAddingRow += RadGridView_Actions_UserAddingRow; + radGridView_Actions.UserAddedRow += RadGridView_Actions_UserAddedRow; + radGridView_Actions.UserDeletedRow += RadGridView_Actions_UserDeletedRow; radGridView_Actions.CellValueChanged += RadGridView_Actions_CellValueChanged; // // radMenuItem_Workspace @@ -185,7 +187,7 @@ partial class MainForm // radMenuItem_WorkspacePreferences.Name = "radMenuItem_WorkspacePreferences"; radMenuItem_WorkspacePreferences.Text = "Preferences"; - radMenuItem_WorkspacePreferences.Click += this.RadMenuItem_WorkspacePreferences_Click; + radMenuItem_WorkspacePreferences.Click += RadMenuItem_WorkspacePreferences_Click; // // radMenuItem_SaveWorkspace // diff --git a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs index d5dbcc4..1a0eba2 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainForm.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainForm.cs @@ -18,7 +18,9 @@ public partial class MainForm : RadForm, IMainApi { private WorkspaceTag? wsInfo; - IWorkspace? IMainApi.Workspace => wsInfo?.Workspace; + IWorkspace? IMainApi.CurWorkspace => wsInfo?.Workspace; + + public IActionSetInfos? CurActionSet => CurActionSet as IActionSetInfos; private record RecentFilesItemTag(WorkspaceConfig Config, WorkspaceFeature Feature); @@ -510,4 +512,32 @@ public partial class MainForm : RadForm, IMainApi radListControl_Updates.Items.Remove(radListControl_Updates.SelectedItem); } } + + private void RadGridView_Actions_UserAddingRow(object sender, GridViewRowCancelEventArgs e) + { + foreach (var row in e.Rows) + row.Tag = CurActionSet is UpdateInfo ? new UpdateAction() : new InstallAction(); + } + + private void RadGridView_Actions_UserAddedRow(object sender, GridViewRowEventArgs e) + { + foreach (var row in e.Rows) + { + if (row.Tag is UpdateAction uaction && CurActionSet is UpdateInfo uinfo && !uinfo.Actions.Contains(uaction)) + uinfo.Actions.Add(uaction); + else if (row.Tag is InstallAction iaction && CurActionSet is InstallInfos iinfo && !iinfo.Actions.Contains(iaction)) + iinfo.Actions.Add(iaction); + } + } + + private void RadGridView_Actions_UserDeletedRow(object sender, GridViewRowEventArgs e) + { + foreach (var row in e.Rows) + { + if (row.Tag is UpdateAction uaction && CurActionSet is UpdateInfo uinfo) + uinfo.Actions.Remove(uaction); + else if (row.Tag is InstallAction iaction && CurActionSet is InstallInfos iinfo) + iinfo.Actions.Remove(iaction); + } + } } diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 1f1744f..7bfb0d6 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -104,8 +104,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf foreach (var action in checkingVersion.Actions) { // Resolve inherits - if (!string.IsNullOrWhiteSpace(action.InheritFrom) && installInfos.Actions.FirstOrDefault(a => a.Id == action.InheritFrom) is InstallAction iaction) - JsonConvert.PopulateObject(JsonConvert.SerializeObject(iaction), action); + ResolveInherit(action, installInfos); // Check & add if (action.Side.IsSide(options.Side) && (!action.IsExtra || options.IncludeExtras) && !result.Actions.Any(n => n.DestPath == action.DestPath)) @@ -125,6 +124,17 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf return result; } + public static void ResolveInherit(UpdateAction action, InstallInfos installInfos) + { + if (!string.IsNullOrWhiteSpace(action.InheritFrom) && installInfos.Actions.FirstOrDefault(a => a.Id == action.InheritFrom) is InstallAction iaction) + DuplicateTo(iaction, action); + } + + public static void DuplicateTo(InstallAction source, InstallAction destination) + { + JsonConvert.PopulateObject(JsonConvert.SerializeObject(source), destination); + } + public async Task Install(UpdateCheckResult checkResult) { var processed = 0;