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

Parse multiple properties in a single winget() #1656

Merged
merged 4 commits into from
Feb 12, 2024
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
10 changes: 10 additions & 0 deletions OpenDreamClient/Interface/Controls/ControlChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ private void UpdateGrid() {

_grid.SplitFraction = ChildDescriptor.Splitter / 100f;
}

public override bool TryGetProperty(string property, out string value) {
switch (property) {
case "splitter":
value = $"{_grid.SplitFraction * 100}";
return true;
default:
return base.TryGetProperty(property, out value);
}
}
}
43 changes: 43 additions & 0 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,47 @@ protected override Control CreateUIElement() {
private void CanvasOnResized() {
UpdateAnchors();
}

public override bool TryGetProperty(string property, out string value) {
switch (property) {
case "inner-size":
value = $"{_canvas.Width}x{_canvas.Height}";
return true;
case "outer-size":
if(_myWindow.osWindow is not null){
value = $"{_myWindow.osWindow.Width}x{_myWindow.osWindow.Height}";
return true;
} else if(_myWindow.clydeWindow is not null){
value = $"{_myWindow.clydeWindow.Size.X}x{_myWindow.clydeWindow.Size.Y}";
return true;
} else {
value = $"{UIElement.Size.X}x{UIElement.Size.Y}";
return true;
}
case "is-minimized":
if(_myWindow.osWindow?.ClydeWindow != null){
value = _myWindow.osWindow.ClydeWindow.IsMinimized ? "true" : "false";
return true;
} else if(_myWindow.clydeWindow is not null){
value = _myWindow.clydeWindow.IsMinimized ? "true" : "false";
return true;
} else {
value = "false";
return true;
}
case "is-maximized": //TODO this is current "not isMinimised" because RT doesn't expose a maximised check
if(_myWindow.osWindow?.ClydeWindow != null){
value = !_myWindow.osWindow.ClydeWindow.IsMinimized ? "true" : "false";
return true;
} else if(_myWindow.clydeWindow is not null){
value = !_myWindow.clydeWindow.IsMinimized ? "true" : "false";
return true;
} else {
value = "false";
return true;
}
default:
return base.TryGetProperty(property, out value);
}
}
}
3 changes: 3 additions & 0 deletions OpenDreamClient/Interface/Controls/InterfaceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public override bool TryGetProperty(string property, out string value) {
case "is-disabled":
value = ControlDescriptor.IsDisabled.ToString();
return true;
case "pos":
value = $"{UIElement.Position.X},{UIElement.Position.Y}";
return true;
default:
return base.TryGetProperty(property, out value);
}
Expand Down
16 changes: 13 additions & 3 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,20 @@ string GetProperty(string elementId) {
return string.Empty;
}

if (!element.TryGetProperty(queryValue, out var value))
_sawmill.Error($"Could not winget property {queryValue} on {element.Id}");
var multiQuery = queryValue.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if(multiQuery.Length > 1) {
var result = "";
foreach(var query in multiQuery) {
if (!element.TryGetProperty(query, out var queryResult))
_sawmill.Error($"Could not winget property {query} on {element.Id}");
result += query+"="+queryResult + ";";
}
return result.TrimEnd(';');
} else if (element.TryGetProperty(queryValue, out var value))
return value;

return value;
_sawmill.Error($"Could not winget property {queryValue} on {element.Id}");
return string.Empty;
}

var elementIds = controlId.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Expand Down
Loading