Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a root form component above the component list #355

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Celbridge/BaseLibrary/Entities/ComponentEditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public abstract class ComponentEditorBase : IComponentEditor
{
private IComponentEditorHelper? _helper;

public Guid EditorId { get; } = Guid.NewGuid();

public event Action<string>? FormPropertyChanged;

private IComponentProxy? _component;
Expand All @@ -26,11 +28,23 @@ public virtual Result Initialize(IComponentProxy component)

public abstract string GetComponentForm();

public virtual string GetComponentRootForm()
{
return string.Empty;
}

public abstract ComponentSummary GetComponentSummary();

public virtual void OnFormLoaded()
{
Guard.IsNull(_helper);
if (_helper is not null)
{
// If the _helper is already created then just return.
// OnFormLoaded() may be called multiple times. For example a root component
// may have botth a root form and a detail form, which will both call
// OnFormLoaded(). Both forms use the same component editor and helper instances.
return;
}

_helper = ServiceLocator.AcquireService<IComponentEditorHelper>();
_helper.Initialize(Component);
Expand All @@ -41,7 +55,7 @@ public virtual void OnFormUnloaded()
{
if (_helper is null)
{
// Unload can be called multiple times, noop if already unloaded
// OnFormUnloaded() can be called multiple times. Noop if already unloaded.
return;
}

Expand Down
25 changes: 0 additions & 25 deletions Celbridge/BaseLibrary/Entities/ComponentStatus.cs

This file was deleted.

18 changes: 14 additions & 4 deletions Celbridge/BaseLibrary/Entities/IComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Celbridge.Entities;
/// </summary>
public interface IComponentEditor : IFormDataProvider
{
/// <summary>
/// Unique identifier for a component editor instance.
/// </summary>
Guid EditorId { get; }

/// <summary>
/// Returns the component that the editor instance edits.
/// </summary>
Expand All @@ -19,14 +24,19 @@ public interface IComponentEditor : IFormDataProvider
Result Initialize(IComponentProxy component);

/// <summary>
/// Gets the form configuration data for the component.
/// Gets the component configuration JSON data.
/// </summary>
string GetComponentConfig();

/// <summary>
/// Gets the component form configuration JSON data.
/// </summary>
public abstract string GetComponentForm();
string GetComponentForm();

/// <summary>
/// Gets the configuration data for the component.
/// Gets the component root form configuration JSON data.
/// </summary>
string GetComponentConfig();
string GetComponentRootForm();

/// <summary>
/// Gets summary information for the edited component.
Expand Down
22 changes: 7 additions & 15 deletions Celbridge/BaseLibrary/Entities/IComponentProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public interface IComponentProxy
/// </summary>
bool IsValid { get; }

/// <summary>
/// Returns true if the component is a root component.
/// A root component is always the first component in an entity and is typically used to
/// configure the entity's general behaviour.
/// </summary>
bool IsRootComponent { get; }

/// <summary>
/// Returns the component key used to identify the component.
/// </summary>
Expand All @@ -27,21 +34,6 @@ public interface IComponentProxy
/// </summary>
event Action<string>? ComponentPropertyChanged;

/// <summary>
/// The validation status of the component.
/// </summary>
ComponentStatus Status { get; }

/// <summary>
/// The description of the component displayed in the editor UI.
/// </summary>
string Description { get; }

/// <summary>
/// The tooltip displayed in the editor UI.
/// </summary>
string Tooltip { get; }

/// <summary>
/// Returns the value of a string property as a JSON string.
/// propertyPath is a JSON Pointer (RFC 6901).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ private Result ApplyCheckSpellingConfig(JsonElement config, TextBox textBox)
if (config.TryGetProperty("checkSpelling", out var jsonValue))
{
// Check the type
if (jsonValue.ValueKind != JsonValueKind.String)
if (jsonValue.ValueKind == JsonValueKind.True)
{
return Result.Fail("'checkSpelling' property must be a string");
textBox.IsSpellCheckEnabled = true;
}

// Apply the property
var jsonText = jsonValue.GetString();
if (!bool.TryParse(jsonText, out var checkSpelling))
else if (jsonValue.ValueKind == JsonValueKind.False)
{
return Result.Fail("Failed to parse 'checkSpelling' property as a boolean");
textBox.IsSpellCheckEnabled = false;
}
else
{
return Result.Fail($"'checkSpelling' config is not valid");
}

textBox.IsSpellCheckEnabled = checkSpelling;

return Result.Ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Celbridge.Core.Components;
public class EmptyEditor : ComponentEditorBase
{
private const string _configPath = "Celbridge.Core.Assets.Components.EmptyComponent.json";
private const string _formPath = "Celbridge.Core.Assets.Forms.EmptyForm.json";
private const string _componentFormPath = "Celbridge.Core.Assets.Forms.EmptyForm.json";

public const string Comment = "/comment";

Expand All @@ -16,7 +16,7 @@ public override string GetComponentConfig()

public override string GetComponentForm()
{
return LoadEmbeddedResource(_formPath);
return LoadEmbeddedResource(_componentFormPath);
}

public override ComponentSummary GetComponentSummary()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
[
{
"element": "TextBox",
"header": "Editor Mode",
"text": "/editorMode"
},
{
"element": "TextBlock",
"text": "/editorMode"
"text": "The edit mode is currently:"
},
{
"element": "TextBlock",
"text": "Some text"
},
{
"element": "StackPanel",
"orientation": "Horizontal",
"horizontalAlignment": "Center",
"children": [
{
"element": "Button",
"tooltip": "Open document",
"icon": "OpenFile",
"buttonId": "OpenDocument"
},
{
"element": "Button",
"isEnabled": "/editorEnabled",
"tooltip": "Editor view",
"icon": "DockLeft",
"buttonId": "Editor"
},
{
"element": "Button",
"isEnabled": "/editorAndPreviewEnabled",
"tooltip": "Split view",
"icon": "DockBottom",
"buttonId": "EditorAndPreview"
},
{
"element": "Button",
"isEnabled": "/previewEnabled",
"tooltip": "Preview view",
"icon": "DockRight",
"buttonId": "Preview"
}
]
"text": "/editorMode"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"element": "StackPanel",
"orientation": "Horizontal",
"horizontalAlignment": "Center",
"children": [
{
"element": "Button",
"tooltip": "Open document",
"icon": "OpenFile",
"buttonId": "OpenDocument"
},
{
"element": "Button",
"isEnabled": "/editorEnabled",
"tooltip": "Editor view",
"icon": "DockLeft",
"buttonId": "Editor"
},
{
"element": "Button",
"isEnabled": "/editorAndPreviewEnabled",
"tooltip": "Split view",
"icon": "DockBottom",
"buttonId": "EditorAndPreview"
},
{
"element": "Button",
"isEnabled": "/previewEnabled",
"tooltip": "Preview view",
"icon": "DockRight",
"buttonId": "Preview"
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class MarkdownEditor : ComponentEditorBase
private readonly ICommandService _commandService;

private const string _configPath = "Celbridge.Markdown.Assets.Components.MarkdownComponent.json";
private const string _formPath = "Celbridge.Markdown.Assets.Forms.MarkdownForm.json";
private const string _componentFormPath = "Celbridge.Markdown.Assets.Forms.MarkdownForm.json";
private const string _componentRootFormPath = "Celbridge.Markdown.Assets.Forms.MarkdownRootForm.json";

private const string _openDocumentButtonId = "OpenDocument";
private const string _editorButtonId = "Editor";
Expand All @@ -36,7 +37,12 @@ public override string GetComponentConfig()

public override string GetComponentForm()
{
return LoadEmbeddedResource(_formPath);
return LoadEmbeddedResource(_componentFormPath);
}

public override string GetComponentRootForm()
{
return LoadEmbeddedResource(_componentRootFormPath);
}

public override ComponentSummary GetComponentSummary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"element": "TextBox",
"header": "Source Text",
"text": "/sourceText",
"checkSpelling": "true"
"checkSpelling": true
},
{
"element": "TextBox",
Expand Down
15 changes: 9 additions & 6 deletions Celbridge/Workspace/Celbridge.Entities/Models/ComponentProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ public class ComponentProxy : IComponentProxy

public bool IsValid { get; private set; } = true;

public bool IsRootComponent
{
get
{
var rootActivity = Schema.GetStringAttribute("rootActivity");
return !string.IsNullOrEmpty(rootActivity);
}
}

public ComponentKey Key { get; }

public ComponentSchema Schema { get; }

public event Action<string>? ComponentPropertyChanged;

public ComponentStatus Status { get; private set; }

public string Description { get; private set; } = string.Empty;

public string Tooltip { get; private set; } = string.Empty;

public ComponentProxy(IServiceProvider serviceProvider, ComponentKey componentKey, ComponentSchema schema)
{
_logger = serviceProvider.GetRequiredService<ILogger<ComponentProxy>>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Celbridge.Modules;
using Celbridge.Inspector.Services;
using Celbridge.Inspector.ViewModels;
using Celbridge.Inspector.Views;
Expand Down Expand Up @@ -31,7 +30,6 @@ public static void ConfigureServices(IServiceCollection services)
services.AddTransient<InspectorPanelViewModel>();
services.AddTransient<ResourceNameInspectorViewModel>();
services.AddTransient<WebInspectorViewModel>();
services.AddTransient<MarkdownInspectorViewModel>();
services.AddTransient<ComponentListViewModel>();
services.AddTransient<EntityEditorViewModel>();
services.AddTransient<ComponentValueEditorViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ private Result<IInspector> CreateFileInspector(ResourceKey resource)
{
inspector = CreateInspector<WebInspector, WebInspectorViewModel>(resource);
}
else if (extension == ".md")
{
inspector = CreateInspector<MarkdownInspector, MarkdownInspectorViewModel>(resource);
}

if (inspector is not null)
{
Expand Down
Loading