This commit is contained in:
Trevi Awater
2024-03-02 21:46:37 +01:00
parent cd30e482dd
commit b009222333
10 changed files with 27 additions and 30 deletions

View File

@@ -125,8 +125,8 @@ namespace Xamarin.Neo4j.iOS.CustomRenderers
// Apply text color formatting for text inside double quotes. // Apply text color formatting for text inside double quotes.
ApplyQuoteTextColorFormatting(text, attributedText, "\"(.*?)\"", Color.FromHex("#ae8b2d").ToUIColor()); ApplyQuoteTextColorFormatting(text, attributedText, "\"(.*?)\"", Color.FromHex("#ae8b2d").ToUIColor());
attributedText.AddAttribute(UIStringAttributeKey.Font, UIFont.SystemFontOfSize((nfloat) Element.FontSize), new NSRange(0, attributedText.Length)); attributedText.AddAttribute(UIStringAttributeKey.Font, UIFont.FromName("Roboto Mono", (nfloat) Element.FontSize), new NSRange(0, attributedText.Length));
Control.AttributedText = attributedText; Control.AttributedText = attributedText;
} }

View File

@@ -41,6 +41,8 @@
<string>iconize-fontawesome-regular.ttf</string> <string>iconize-fontawesome-regular.ttf</string>
<string>iconize-fontawesome-solid.ttf</string> <string>iconize-fontawesome-solid.ttf</string>
<string>iconize-fontawesome-brands.ttf</string> <string>iconize-fontawesome-brands.ttf</string>
<string>iconize-fontawesome-brands.ttf</string>
<string>roboto-mono-regular.ttf</string>
</array> </array>
</dict> </dict>
</plist> </plist>

View File

@@ -28,5 +28,3 @@ using Xamarin.Forms;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ExportFont("RobotoMono-Regular.ttf", Alias = "RobotoMonoRegular")]

View File

@@ -151,5 +151,8 @@
<BundleResource Include="Resources\logo.png" /> <BundleResource Include="Resources\logo.png" />
<BundleResource Include="Resources\resoftware.png" /> <BundleResource Include="Resources\resoftware.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\roboto-mono-regular.ttf" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project> </Project>

View File

@@ -17,11 +17,6 @@ namespace Xamarin.Neo4j.Controls
public double MaxHeight { get; set; } public double MaxHeight { get; set; }
public event EventHandler ExecuteClicked; public event EventHandler ExecuteClicked;
public QueryEditor()
{
FontFamily = "RobotoMonoRegular";
}
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
{ {

View File

@@ -43,7 +43,7 @@
<pancakeView:Border Thickness="2" Color="#d8e5f1" /> <pancakeView:Border Thickness="2" Color="#d8e5f1" />
</pancakeView:PancakeView.Border> </pancakeView:PancakeView.Border>
<controls:QueryEditor Text="{Binding Query}" ExecuteClicked="ExecuteQuery" MaxHeight="200" HorizontalOptions="FillAndExpand" AutoSize="TextChanges" /> <controls:QueryEditor Text="{Binding Query}" ExecuteClicked="ExecuteQuery" FontSize="14" MaxHeight="200" HorizontalOptions="FillAndExpand" AutoSize="TextChanges" />
</pancakeView:PancakeView> </pancakeView:PancakeView>
</pancakeView:PancakeView> </pancakeView:PancakeView>

View File

@@ -153,7 +153,7 @@ namespace Xamarin.Neo4j.Services
Success = true, Success = true,
CanDisplayGraph = canDisplayGraph, CanDisplayGraph = canDisplayGraph,
Query = query, Query = query,
DisplayQuery = QueryHelper.TransformQuery(query), DisplayQuery = QueryHelper.ToDisplayQuery(query),
ConnectionString = connectionString, ConnectionString = connectionString,
Results = results Results = results
}; };

View File

@@ -15,51 +15,51 @@ namespace Xamarin.Neo4j.Utilities
{ {
public static class QueryHelper public static class QueryHelper
{ {
public static string TransformQuery(string query) public static string ToDisplayQuery(string query)
{ {
// Check if there is a return statement, if not return the original query // Check if there is a return statement, if not return the original query
if (query.IndexOf("RETURN ", StringComparison.OrdinalIgnoreCase) <= 0) if (query.IndexOf("RETURN ", StringComparison.OrdinalIgnoreCase) <= 0)
return query; return query;
// This pattern is designed to match relationships with and without labels.
// It captures the relationship direction and type, but not the existing label (if any).
const string pattern = @"-\[:?(\w+)?\]->";
var matches = Regex.Matches(query, pattern);
// Keep track of unique relationships to ensure they are returned // Adjusted pattern to match relationships with and without labels/types.
const string pattern = @"-\[(\w*:?(\w+)?)\]->";
var matches = Regex.Matches(query, pattern);
var relationships = new List<string>(); var relationships = new List<string>();
var relationshipCounter = 1; var relationshipCounter = 1;
var transformedQuery = query; var transformedQuery = query;
foreach (Match match in matches) foreach (Match match in matches)
{ {
var newLabel = $"display_variable_{relationshipCounter++}"; // Generate a unique label for the relationship var newLabel = $"display_variable_{relationshipCounter++}"; // Generate a unique label for the relationship
// Replace the first occurrence of this match in the query with the new labeled version // Determine the correct new pattern based on whether the original had a type/label
var oldPattern = match.Value; var oldPattern = match.Value;
var newPattern = oldPattern.Replace("[:", $"[{newLabel}:").Replace("]->", "]->"); var newPattern = !string.IsNullOrEmpty(match.Groups[1].Value) ?
oldPattern.Replace("[:", $"[{newLabel}:").Replace("]->", "]->") : // For labeled/types
oldPattern.Replace("[]", $"[{newLabel}]"); // For unlabeled
var idx = transformedQuery.IndexOf(oldPattern); var idx = transformedQuery.IndexOf(oldPattern);
if (idx != -1) if (idx != -1)
{ {
transformedQuery = transformedQuery.Substring(0, idx) + newPattern + transformedQuery.Substring(idx + oldPattern.Length); transformedQuery = transformedQuery.Substring(0, idx) + newPattern + transformedQuery.Substring(idx + oldPattern.Length);
} }
relationships.Add(newLabel); relationships.Add(newLabel);
} }
// Construct the new RETURN clause with the added relationships. // Construct the new RETURN clause with the added relationships.
if (relationships.Count > 0) if (relationships.Count > 0)
{ {
// Assuming there's always a RETURN statement to append to.
var returnIndex = transformedQuery.LastIndexOf("RETURN ", StringComparison.OrdinalIgnoreCase); var returnIndex = transformedQuery.LastIndexOf("RETURN ", StringComparison.OrdinalIgnoreCase);
var returnClause = transformedQuery.Substring(returnIndex + "RETURN ".Length); var returnClause = transformedQuery.Substring(returnIndex + "RETURN ".Length);
var newReturnClause = string.Join(", ", relationships) + ", " + returnClause; var newReturnClause = string.Join(", ", relationships) + ", " + returnClause;
transformedQuery = transformedQuery.Substring(0, returnIndex) + "RETURN " + newReturnClause; transformedQuery = transformedQuery.Substring(0, returnIndex) + "RETURN " + newReturnClause;
} }
return transformedQuery; return transformedQuery;
} }
} }

View File

@@ -24,6 +24,5 @@
<None Remove="Resources\licenses.json" /> <None Remove="Resources\licenses.json" />
<EmbeddedResource Include="Resources\licenses.json" /> <EmbeddedResource Include="Resources\licenses.json" />
<None Remove="Assets\Fonts\RobotoMono-Regular.ttf" /> <None Remove="Assets\Fonts\RobotoMono-Regular.ttf" />
<EmbeddedResource Include="Assets\Fonts\RobotoMono-Regular.ttf" />
</ItemGroup> </ItemGroup>
</Project> </Project>