some work for loading a workspace
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
namespace ModpackUpdater.Apps.Manager.Api.Model;
|
namespace ModpackUpdater.Apps.Manager.Api.Model;
|
||||||
|
|
||||||
public class WorkspaceConfig
|
public abstract class WorkspaceConfig
|
||||||
{
|
{
|
||||||
public string ProviderId { get; internal set; } = "origin.unknown";
|
public string ProviderId { get; internal set; } = "origin.unknown";
|
||||||
|
public abstract string DisplayText { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public abstract class WorkspaceFeature(string identifier, string name) : PluginF
|
|||||||
return workspace?.Config == null || workspace.Config.ProviderId == Identifier;
|
return workspace?.Config == null || workspace.Config.ProviderId == Identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool Configure(ref IWorkspace workspace)
|
public virtual bool Configure(ref IWorkspace? workspace)
|
||||||
{
|
{
|
||||||
OnConfigure(ref workspace);
|
OnConfigure(ref workspace);
|
||||||
|
|
||||||
@@ -22,5 +22,13 @@ public abstract class WorkspaceFeature(string identifier, string name) : PluginF
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract bool OnConfigure(ref IWorkspace workspace);
|
public virtual IWorkspace CreateFromSettings(WorkspaceConfig config)
|
||||||
|
{
|
||||||
|
OnCreate(out var workspace, config);
|
||||||
|
return workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void OnCreate(out IWorkspace workspace, WorkspaceConfig config);
|
||||||
|
|
||||||
|
protected abstract bool OnConfigure(ref IWorkspace? workspace);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ internal class GitLabRepoWorkspace(GitLabRepoWorkspaceConfig config) : IWorkspac
|
|||||||
{
|
{
|
||||||
InstallInfos = InstallInfos.Parse(await GetContent(ConfigX.FileLocationInstallJson));
|
InstallInfos = InstallInfos.Parse(await GetContent(ConfigX.FileLocationInstallJson));
|
||||||
UpdateInfos = UpdateInfos.Parse(await GetContent(ConfigX.FileLocationUpdateJson));
|
UpdateInfos = UpdateInfos.Parse(await GetContent(ConfigX.FileLocationUpdateJson));
|
||||||
|
ConfigX.InstanceUrl = (await Gitlab.Projects.GetByIdAsync((int)ConfigX.RepoId, new())).NameWithNamespace;
|
||||||
return InstallInfos != null && UpdateInfos != null;
|
return InstallInfos != null && UpdateInfos != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,19 @@ namespace ModpackUpdater.Apps.Manager.Features.Workspaces.GitLabRepo;
|
|||||||
|
|
||||||
internal class GitLabRepoWorkspaceConfig : WorkspaceConfig
|
internal class GitLabRepoWorkspaceConfig : WorkspaceConfig
|
||||||
{
|
{
|
||||||
|
public override string DisplayText => $"{RepoName ?? "?"} at {RepoBranche} on {InstanceUrl}";
|
||||||
|
|
||||||
|
public string? RepoName { get; set; }
|
||||||
|
|
||||||
public string InstanceUrl { get; set; } = "https://gitlab.com";
|
public string InstanceUrl { get; set; } = "https://gitlab.com";
|
||||||
|
|
||||||
public string? ApiToken { get; set; }
|
public string? ApiToken { get; set; }
|
||||||
|
|
||||||
public long RepoId { get; set; } = -1L;
|
public long RepoId { get; set; } = -1L;
|
||||||
|
|
||||||
public string RepoBranche { get; set; } = "master";
|
public string RepoBranche { get; set; } = "master";
|
||||||
|
|
||||||
public string FileLocationInstallJson { get; set; } = "install.json";
|
public string FileLocationInstallJson { get; set; } = "install.json";
|
||||||
|
|
||||||
public string FileLocationUpdateJson { get; set; } = "update.json";
|
public string FileLocationUpdateJson { get; set; } = "update.json";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ internal class GitLabRepoWorkspaceFeature : WorkspaceFeature, IPluginFeatureProv
|
|||||||
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.gitlab, SymbolSize.Small);
|
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.gitlab, SymbolSize.Small);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnConfigure(ref IWorkspace workspace)
|
protected override bool OnConfigure(ref IWorkspace? workspace)
|
||||||
{
|
{
|
||||||
var settings = workspace?.Config as GitLabRepoWorkspaceConfig ?? new();
|
var settings = workspace?.Config as GitLabRepoWorkspaceConfig ?? new();
|
||||||
|
|
||||||
@@ -25,6 +25,15 @@ internal class GitLabRepoWorkspaceFeature : WorkspaceFeature, IPluginFeatureProv
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
workspace = new GitLabRepoWorkspace(settings);
|
workspace = new GitLabRepoWorkspace(settings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnCreate(out IWorkspace workspace, WorkspaceConfig config)
|
||||||
|
{
|
||||||
|
if (config is not GitLabRepoWorkspaceConfig gitlabConfig)
|
||||||
|
throw new NotImplementedException($"Only configs of type {typeof(GitLabRepoWorkspaceConfig).Name} are allowed.");
|
||||||
|
|
||||||
|
workspace = new GitLabRepoWorkspace(gitlabConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
ModpackUpdater.Apps.Manager/Form1.Designer.cs
generated
14
ModpackUpdater.Apps.Manager/Form1.Designer.cs
generated
@@ -28,7 +28,7 @@ partial class Form1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
var tableViewDefinition2 = new Telerik.WinControls.UI.TableViewDefinition();
|
var tableViewDefinition1 = new Telerik.WinControls.UI.TableViewDefinition();
|
||||||
radSplitContainer1 = new Telerik.WinControls.UI.RadSplitContainer();
|
radSplitContainer1 = new Telerik.WinControls.UI.RadSplitContainer();
|
||||||
splitPanel1 = new Telerik.WinControls.UI.SplitPanel();
|
splitPanel1 = new Telerik.WinControls.UI.SplitPanel();
|
||||||
tableLayoutPanel2 = new TableLayoutPanel();
|
tableLayoutPanel2 = new TableLayoutPanel();
|
||||||
@@ -43,6 +43,7 @@ partial class Form1
|
|||||||
radMenuItem_RecentWorkspaces = new Telerik.WinControls.UI.RadMenuItem();
|
radMenuItem_RecentWorkspaces = new Telerik.WinControls.UI.RadMenuItem();
|
||||||
radMenuItem_Tools = new Telerik.WinControls.UI.RadMenuItem();
|
radMenuItem_Tools = new Telerik.WinControls.UI.RadMenuItem();
|
||||||
radMenu1 = new Telerik.WinControls.UI.RadMenu();
|
radMenu1 = new Telerik.WinControls.UI.RadMenu();
|
||||||
|
radMenuItem_SaveWorkspace = new Telerik.WinControls.UI.RadMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)radSplitContainer1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)radSplitContainer1).BeginInit();
|
||||||
radSplitContainer1.SuspendLayout();
|
radSplitContainer1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)splitPanel1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)splitPanel1).BeginInit();
|
||||||
@@ -147,14 +148,14 @@ partial class Form1
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
radGridView_Actions.MasterTemplate.ViewDefinition = tableViewDefinition2;
|
radGridView_Actions.MasterTemplate.ViewDefinition = tableViewDefinition1;
|
||||||
radGridView_Actions.Name = "radGridView_Actions";
|
radGridView_Actions.Name = "radGridView_Actions";
|
||||||
radGridView_Actions.Size = new Size(544, 416);
|
radGridView_Actions.Size = new Size(544, 416);
|
||||||
radGridView_Actions.TabIndex = 0;
|
radGridView_Actions.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// radMenuItem_Workspace
|
// radMenuItem_Workspace
|
||||||
//
|
//
|
||||||
radMenuItem_Workspace.Items.AddRange(new Telerik.WinControls.RadItem[] { radMenuItem_WorkspacePreferences, radMenuSeparatorItem1, radMenuItem_OpenNewWorkspace, radMenuItem_RecentWorkspaces });
|
radMenuItem_Workspace.Items.AddRange(new Telerik.WinControls.RadItem[] { radMenuItem_WorkspacePreferences, radMenuItem_SaveWorkspace, radMenuSeparatorItem1, radMenuItem_OpenNewWorkspace, radMenuItem_RecentWorkspaces });
|
||||||
radMenuItem_Workspace.Name = "radMenuItem_Workspace";
|
radMenuItem_Workspace.Name = "radMenuItem_Workspace";
|
||||||
radMenuItem_Workspace.Text = "Workspace";
|
radMenuItem_Workspace.Text = "Workspace";
|
||||||
//
|
//
|
||||||
@@ -192,6 +193,11 @@ partial class Form1
|
|||||||
radMenu1.Size = new Size(800, 28);
|
radMenu1.Size = new Size(800, 28);
|
||||||
radMenu1.TabIndex = 1;
|
radMenu1.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// radMenuItem_SaveWorkspace
|
||||||
|
//
|
||||||
|
radMenuItem_SaveWorkspace.Name = "radMenuItem_SaveWorkspace";
|
||||||
|
radMenuItem_SaveWorkspace.Text = "Save";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleBaseSize = new Size(7, 15);
|
AutoScaleBaseSize = new Size(7, 15);
|
||||||
@@ -203,6 +209,7 @@ partial class Form1
|
|||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Minecraft Modpack Updates Manager";
|
Text = "Minecraft Modpack Updates Manager";
|
||||||
|
Load += Form1_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)radSplitContainer1).EndInit();
|
((System.ComponentModel.ISupportInitialize)radSplitContainer1).EndInit();
|
||||||
radSplitContainer1.ResumeLayout(false);
|
radSplitContainer1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)splitPanel1).EndInit();
|
((System.ComponentModel.ISupportInitialize)splitPanel1).EndInit();
|
||||||
@@ -236,4 +243,5 @@ partial class Form1
|
|||||||
private Telerik.WinControls.UI.RadMenuSeparatorItem radMenuSeparatorItem1;
|
private Telerik.WinControls.UI.RadMenuSeparatorItem radMenuSeparatorItem1;
|
||||||
private Telerik.WinControls.UI.RadMenuItem radMenuItem_OpenNewWorkspace;
|
private Telerik.WinControls.UI.RadMenuItem radMenuItem_OpenNewWorkspace;
|
||||||
private Telerik.WinControls.UI.RadMenuItem radMenuItem_RecentWorkspaces;
|
private Telerik.WinControls.UI.RadMenuItem radMenuItem_RecentWorkspaces;
|
||||||
|
private Telerik.WinControls.UI.RadMenuItem radMenuItem_SaveWorkspace;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||||
|
using ModpackUpdater.Apps.Manager.Api.Plugins.Features;
|
||||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||||
|
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;
|
||||||
@@ -9,7 +11,9 @@ namespace ModpackUpdater.Apps.Manager;
|
|||||||
|
|
||||||
public partial class Form1 : RadForm, IMainApi
|
public partial class Form1 : RadForm, IMainApi
|
||||||
{
|
{
|
||||||
public IWorkspace? Workspace { get; set; }
|
private IWorkspace? workspace;
|
||||||
|
|
||||||
|
public IWorkspace? Workspace => workspace;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@@ -17,17 +21,68 @@ public partial class Form1 : RadForm, IMainApi
|
|||||||
|
|
||||||
radMenuItem_Workspace.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.workspace, SymbolSize.Small);
|
radMenuItem_Workspace.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.workspace, SymbolSize.Small);
|
||||||
radMenuItem_WorkspacePreferences.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.settings, SymbolSize.Small);
|
radMenuItem_WorkspacePreferences.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.settings, SymbolSize.Small);
|
||||||
|
radMenuItem_SaveWorkspace.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.save, SymbolSize.Small);
|
||||||
radMenuItem_OpenNewWorkspace.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.new_window, SymbolSize.Small);
|
radMenuItem_OpenNewWorkspace.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.new_window, SymbolSize.Small);
|
||||||
radMenuItem_RecentWorkspaces.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.time_machine, SymbolSize.Small);
|
radMenuItem_RecentWorkspaces.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.time_machine, SymbolSize.Small);
|
||||||
radMenuItem_Tools.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.tools, SymbolSize.Small);
|
radMenuItem_Tools.SvgImage = AppGlobals.Symbols.GetSvgImage(AppSymbols.tools, SymbolSize.Small);
|
||||||
|
|
||||||
PluginFeatureController.Instance.Functions.Get(FeatureTypes.Workspace).InsertItemsTo(radMenuItem_OpenNewWorkspace.Items, customClickHandler: RadMenuItem_OpenNewWorkspace_Click);
|
radMenuItem_SaveWorkspace.Shortcuts.Add(new(Keys.Control, Keys.S));
|
||||||
|
|
||||||
|
PluginFeatureController.Instance.Features.Get(FeatureTypes.Workspace).InsertItemsTo(radMenuItem_OpenNewWorkspace.Items, customClickHandler: RadMenuItem_OpenNewWorkspace_Click);
|
||||||
PluginFeatureController.Instance.Functions.Get(FeatureTypes.Tools).InsertItemsTo(radMenuItem_OpenNewWorkspace.Items, customClickHandler: RadMenuItem_ToolsItem_Click);
|
PluginFeatureController.Instance.Functions.Get(FeatureTypes.Tools).InsertItemsTo(radMenuItem_OpenNewWorkspace.Items, customClickHandler: RadMenuItem_ToolsItem_Click);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadRecentWorkspaces()
|
private void LoadRecentWorkspaces()
|
||||||
{
|
{
|
||||||
// ...
|
var settings = Program.Settings.Get<WorkspaceSettings>();
|
||||||
|
|
||||||
|
radMenuItem_RecentWorkspaces.Items.Clear();
|
||||||
|
|
||||||
|
foreach (var config in settings.Workspaces)
|
||||||
|
{
|
||||||
|
var item = new RadMenuItem
|
||||||
|
{
|
||||||
|
Text = config.DisplayText,
|
||||||
|
Tag = config,
|
||||||
|
};
|
||||||
|
|
||||||
|
item.Click += RadMenuItem_OpenRecentWorkspace_Click;
|
||||||
|
|
||||||
|
radMenuItem_RecentWorkspaces.Items.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (radMenuItem_RecentWorkspaces.Items.Any())
|
||||||
|
radMenuItem_RecentWorkspaces.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
||||||
|
else
|
||||||
|
radMenuItem_RecentWorkspaces.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddToRecentFiles(IWorkspace workspace)
|
||||||
|
{
|
||||||
|
var settings = Program.Settings.Get<WorkspaceSettings>();
|
||||||
|
|
||||||
|
settings.Workspaces.Remove(workspace.Config);
|
||||||
|
settings.Workspaces.Insert(0, workspace.Config);
|
||||||
|
|
||||||
|
while (settings.Workspaces.Count > 20)
|
||||||
|
settings.Workspaces.RemoveAt(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadNewWorkspace(IWorkspace? workspace)
|
||||||
|
{
|
||||||
|
if (workspace is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (workspace != this.workspace)
|
||||||
|
this.workspace = workspace;
|
||||||
|
|
||||||
|
AddToRecentFiles(workspace);
|
||||||
|
Invoke(LoadRecentWorkspaces);
|
||||||
|
|
||||||
|
if (!await workspace.Load())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Invoke(LoadWorkspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadWorkspace()
|
private void LoadWorkspace()
|
||||||
@@ -40,14 +95,23 @@ public partial class Form1 : RadForm, IMainApi
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RadMenuItem_OpenNewWorkspace_Click(object? sender, EventArgs e)
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// ...
|
LoadRecentWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RadMenuItem_OpenRecentWorkspace_Click(object? sender, EventArgs e)
|
private async void RadMenuItem_OpenNewWorkspace_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// ...
|
if (sender is RadMenuItem item && item.Tag is WorkspaceFeature feature && feature.Configure(ref workspace))
|
||||||
|
await LoadNewWorkspace(workspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void RadMenuItem_OpenRecentWorkspace_Click(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is RadMenuItem item && item.Tag is WorkspaceConfig config
|
||||||
|
&& PluginFeatureController.Instance.Features.Get(FeatureTypes.Workspace).OfType<WorkspaceFeature>().FirstOrDefault(n => n.Identifier == config.ProviderId) is WorkspaceFeature feature
|
||||||
|
&& feature.CreateFromSettings(config) is IWorkspace workspace)
|
||||||
|
await LoadNewWorkspace(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RadMenuItem_ToolsItem_Click(object? sender, EventArgs e)
|
private void RadMenuItem_ToolsItem_Click(object? sender, EventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user