Skip to content

Commit

Permalink
cluster: Fix grid-splitter move when textbox is resized by exceeding …
Browse files Browse the repository at this point in the history
…max length of actual-width
  • Loading branch information
rollrat committed Apr 10, 2020
1 parent 1711504 commit f3efcd9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
21 changes: 14 additions & 7 deletions CustomCrawler/CustomCrawlerCluster.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>

<Grid Margin="8">
<Grid Margin="8" x:Name="g1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -93,17 +93,23 @@
</Grid.ColumnDefinitions>

<TextBlock Text="Attr: " Grid.Column="0" Margin="0 4 0 0" FontSize="15" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<TextBox x:Name="Attributes" Grid.Row="1" Grid.Column="1" Margin="0 4 0 0" FontSize="15" AcceptsReturn="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto"/>

<!--<Grid VerticalAlignment="Stretch" Grid.Row="1" Grid.Column="1" AcceptsReturn="True" >
<DockPanel>-->
<RichTextBox x:Name="Attributes" Grid.Row="1" Grid.Column="1" Margin="0 4 0 0" FontSize="15" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" />
<!--</DockPanel>
</Grid>-->
</Grid>
</Border>

<TextBlock Grid.Column="0" Grid.Row="3" Text="FILTER: " FontSize="15" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0 4 0 0"/>
<TextBox x:Name="Filter" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="3" Margin="0 4 0 0" TextChanged="Filter_TextChanged"/>

</Grid>

<GridSplitter Grid.Column="1"
<GridSplitter Grid.Column="1" x:Name="gs1"
ShowsPreview="True"
Width="2"
Width="2" ResizeBehavior="BasedOnAlignment"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"/>

Expand Down Expand Up @@ -145,7 +151,8 @@
HorizontalAlignment="Center"
VerticalAlignment="Stretch"/>

<Grid Grid.Column="4" Width="500">
<Grid Grid.Column="4">
<!--Width="500"-->
<StackPanel>
<GroupBox Header="CaptureList" Height="300">
<Grid>
Expand Down Expand Up @@ -263,10 +270,10 @@
</Grid.ColumnDefinitions>

<TextBlock Text="XPath: " Grid.Row="0" Grid.Column="0" FontSize="15" VerticalAlignment="Center"/>
<TextBox x:Name="CurrentXPath" Grid.Row="0" Grid.Column="1" FontSize="15"/>
<RichTextBox x:Name="CurrentXPath" Grid.Row="0" Grid.Column="1" FontSize="15"/>

<TextBlock Text="Code: " Grid.Row="1" Grid.Column="0" Margin="0 4 0 0" FontSize="15" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<TextBox x:Name="CurrentCode" Grid.Row="1" Grid.Column="1" Margin="0 4 0 0" FontSize="15" AcceptsReturn="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto"/>
<RichTextBox x:Name="CurrentCode" Grid.Row="1" Grid.Column="1" Margin="0 4 0 0" FontSize="15" AcceptsReturn="True" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto"/>
</Grid>
</Border>
</StackPanel>
Expand Down
30 changes: 26 additions & 4 deletions CustomCrawler/CustomCrawlerCluster.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public CustomCrawlerCluster(string url, HtmlTree tree)
}

KeyDown += CustomCrawlerCluster_KeyDown;
Loaded += CustomCrawlerCluster_Loaded;
}

private void CustomCrawlerCluster_Loaded(object sender, RoutedEventArgs e)
{
Task.Run(() =>
{
Thread.Sleep(500);
Application.Current.Dispatcher.BeginInvoke(new Action(
delegate
{
Attributes.Document.PageWidth = Attributes.ActualWidth + 10000;
CurrentCode.Document.PageWidth = CurrentCode.ActualWidth + 10000;
CurrentXPath.Document.PageWidth = CurrentXPath.ActualWidth + 10000;
}));
});
}

private void Browser_IsBrowserInitializedChanged(object sender, DependencyPropertyChangedEventArgs e)
Expand Down Expand Up @@ -698,7 +714,8 @@ public void hoverelem(string elem, bool adjust = false)
before = $"ccw_tag=ccw_{i}_{j}";
before_border = instance.browser.EvaluateScriptAsync($"document.querySelector('[{before}]').style.border").Result.Result.ToString();
instance.browser.EvaluateScriptAsync($"document.querySelector('[{before}]').style.border = '0.2em solid red';").Wait();
instance.CurrentXPath.Text = selected_node.XPath;
instance.CurrentXPath.Document.Blocks.Clear();
instance.CurrentXPath.Document.Blocks.Add(new Paragraph(new Run(selected_node.XPath)));

var builder = new StringBuilder();
builder.Append("public HtmlNode Extract(string html)\r\n");
Expand All @@ -708,19 +725,24 @@ public void hoverelem(string elem, bool adjust = false)
builder.Append($" return document.DocumentNode.SelectSingleNode(\"{selected_node.XPath}\");\r\n");
builder.Append("}\r\n");

instance.CurrentCode.Text = builder.ToString();
instance.CurrentCode.Document.Blocks.Clear();
instance.CurrentCode.Document.Blocks.Add(new Paragraph(new Run(builder.ToString())));

builder.Clear();
var cf = new Func<string, string>((x) =>
{
if (x == "origin_onmouseenter") return "onmouseetner";
if (x == "origin_onmouseenter") return "onmouseenter";
if (x == "origin_onmouseleave") return "onmouseleave";
return x;
});
selected_node.Attributes.Where(x => !new [] { "onmouseenter", "onmouseleave", "ccw_tag" }.Contains(x.Name))
.ToList().ForEach(x => builder.Append($"{cf(x.Name)}=\"{x.Value}\"\r\n"));

instance.Attributes.Text = builder.ToString();
var xy = instance.gs1;

instance.Attributes.Document.Blocks.Clear();
instance.Attributes.Document.Blocks.Add(new Paragraph(new Run(builder.ToString())));
//instance.Attributes.Text = builder.ToString();
}
catch { }
}));
Expand Down

0 comments on commit f3efcd9

Please sign in to comment.