Skip to content

Commit

Permalink
Parse multiple properties in a single winget() (#1656)
Browse files Browse the repository at this point in the history
Co-authored-by: wixoa <[email protected]>
  • Loading branch information
amylizzle and wixoaGit authored Feb 12, 2024
1 parent 6e250f8 commit e38ea14
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
10 changes: 10 additions & 0 deletions OpenDreamClient/Interface/Controls/ControlChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,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

0 comments on commit e38ea14

Please sign in to comment.