Skip to content

Commit

Permalink
jimmejardine#82 : try to set up some decent min/max sizes for the var…
Browse files Browse the repository at this point in the history
…ious controls/wrappers so that huge BibTeX raw content doesn't produce unworkable UI layouts and thus bad UX. MinWidth limits are meant to restrict button scaling and thus ugly/damaged looking UI, while MaxHeight limits are intended to limit the height of the BibTeXEditorControl when it is fed huge BibTeX raw content, such as when loading a BibTeX from converted PubMed XML (the source XML is appended as a multiline comment which often is very large)
  • Loading branch information
GerHobbelt committed Oct 22, 2019
1 parent 868e549 commit b3fae39
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 27 deletions.
22 changes: 11 additions & 11 deletions Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<local_gui:NonScrollingFlowDocumentScrollViewer x:Name="ObjNoBibTeXInstructions" DockPanel.Dock="Bottom">
<commongui:StandardFlowDocument>
<Paragraph>
Qiqqa has not been able to automatically associate BibTeX with this document. BibTeX is useful when formatting your bibliography with InCite. Use the BibTeX Sniffer to quickly search the Internet for this document's BibTeX.
Qiqqa has not been able to automatically associate BibTeX with this document. BibTeX is useful when formatting your bibliography with InCite. Use the BibTeX Sniffer to quickly search the Internet for this document's BibTeX.
</Paragraph>
</commongui:StandardFlowDocument>
</local_gui:NonScrollingFlowDocumentScrollViewer>
Expand All @@ -40,10 +40,10 @@
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Grid.Column="0" FontWeight="Bold" Name="ComboRecordTypeHeader">Type</TextBlock>
<ComboBox Grid.Row="0" Grid.Column="2" Name="ComboRecordType" MinWidth="50" IsEditable="True" BorderThickness="0"/>
<TextBlock Grid.Row="1" Grid.Column="0" FontWeight="Bold" Name="TxtRecordKeyHeader" >Key</TextBlock>
<TextBox Grid.Row="1" Grid.Column="2" Name="TxtRecordKey" MinWidth="50" BorderThickness="0"/>
<TextBlock Grid.Row="0" Grid.Column="0" FontWeight="Bold" Name="ComboRecordTypeHeader">Type</TextBlock>
<ComboBox Grid.Row="0" Grid.Column="2" Name="ComboRecordType" MinWidth="50" IsEditable="True" BorderThickness="0"/>
<TextBlock Grid.Row="1" Grid.Column="0" FontWeight="Bold" Name="TxtRecordKeyHeader" >Key</TextBlock>
<TextBox Grid.Row="1" Grid.Column="2" Name="TxtRecordKey" MinWidth="50" BorderThickness="0"/>
</Grid>

<local_gui:AugmentedSpacer DockPanel.Dock="Top" />
Expand All @@ -57,14 +57,14 @@
</Grid>
</DockPanel>

<Grid Name="ObjTextPanel" Visibility="Hidden">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Name="ObjBibTeXTextScrollViewer">
<TextBox Name="ObjBibTeXText" TextWrapping="Wrap" AcceptsReturn="True" />
</ScrollViewer>
</Grid>
<Grid Name="ObjTextPanel" Visibility="Hidden">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top" Name="ObjBibTeXTextScrollViewer">
<TextBox Name="ObjBibTeXText" TextWrapping="Wrap" AcceptsReturn="True" DockPanel.Dock="Top" />
</ScrollViewer>
</Grid>

<Grid Name="ObjErrorPanel">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top" Name="ObjBibTeXErrorScrollViewer">
<TextBox Name="ObjBibTeXErrorText" IsReadOnly="True" TextWrapping="NoWrap" FontFamily="Lucida Console" />
</ScrollViewer>
</Grid>
Expand Down
76 changes: 67 additions & 9 deletions Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Utilities.Reflection;
using Qiqqa.Common.Configuration;
using Utilities.Strings;
using Utilities;

namespace Qiqqa.Documents.BibTeXEditor
{
Expand Down Expand Up @@ -67,6 +68,7 @@ public BibTeXEditorControl()
InitializeComponent();

this.Unloaded += BibTeXEditorControl_Unloaded;
this.SizeChanged += BibTeXEditorControl_SizeChanged;

// The error panel
//ObjErrorPanel.Background = ThemeColours.Background_Brush_Warning;
Expand Down Expand Up @@ -113,17 +115,73 @@ public BibTeXEditorControl()
RebuidTextAndGrid();
}

private void BibTeXEditorControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
double table_height1 = ObjGridPanel.ActualHeight;
//double table_height2 = ObjHeaderGrid.ActualHeight;
//double table_height3 = ObjBibTeXGrid.ActualHeight;

//double rawtxt_height1 = ObjTextPanel.ActualHeight;
//double rawtxt_height2 = ObjBibTeXTextScrollViewer.ActualHeight;
//double rawtxt_height3 = ObjBibTeXText.ActualHeight;

//double errtxt_height1 = ObjErrorPanel.ActualHeight;
//double errtxt_height2 = ObjBibTeXErrorScrollViewer.ActualHeight;
//double errtxt_height3 = ObjBibTeXErrorText.ActualHeight;

const double THRESHOLD = 100;

if (table_height1 > THRESHOLD)
{
double maxh1 = ObjBibTeXTextScrollViewer.MaxHeight;
double maxh2 = ObjBibTeXErrorScrollViewer.MaxHeight;

// tweak the control so the Parsed View gives us the master MaxHeight:
ObjBibTeXTextScrollViewer.MaxHeight = THRESHOLD;
ObjBibTeXErrorScrollViewer.MaxHeight = THRESHOLD;
this.UpdateLayout();

table_height1 = ObjGridPanel.ActualHeight;

if (table_height1 > THRESHOLD)
{
ObjBibTeXTextScrollViewer.MaxHeight = table_height1;
ObjBibTeXErrorScrollViewer.MaxHeight = table_height1;
}
else
{
ObjBibTeXTextScrollViewer.MaxHeight = double.PositiveInfinity;
ObjBibTeXErrorScrollViewer.MaxHeight = double.PositiveInfinity;
}

if (Math.Abs(maxh1 - ObjBibTeXTextScrollViewer.MaxHeight) > 0.25)
{
this.UpdateLayout();
}
}
}

private void BibTeXEditorControl_Unloaded(object sender, RoutedEventArgs e)
{
// discard all references which might otherwise potentially cause memleaks due to (potential) references cycles:
BibTeXParseErrorButtonRef.SetTarget(null);
BibTeXModeToggleButtonRef.SetTarget(null);
BibTeXUndoEditButtonRef.SetTarget(null);

wdpcn.Dispose();
wdpcn = null;
BibTeX = "";
bindable = null;
try
{
// discard all references which might otherwise potentially cause memleaks due to (potential) references cycles:
BibTeXParseErrorButtonRef.SetTarget(null);
BibTeXModeToggleButtonRef.SetTarget(null);
BibTeXUndoEditButtonRef.SetTarget(null);

if (null != wdpcn)
{
wdpcn.Dispose();
}
wdpcn = null;
BibTeX = "";
bindable = null;
}
catch (Exception ex)
{
Logging.Error(ex);
}
}

public void RegisterOverlayButtons(FrameworkElement BibTeXParseErrorButton, FrameworkElement BibTeXModeToggleButton, FrameworkElement BibTeXUndoEditButton, double IconHeight = double.NaN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:local_gui="clr-namespace:Utilities.GUI;assembly=Utilities"
xmlns:local_bibtex="clr-namespace:Qiqqa.Documents.BibTeXEditor"
xmlns:commongui="clr-namespace:Qiqqa.Common.GUI"
MinWidth="250"
>
<DockPanel>
<Grid DockPanel.Dock="Bottom">
Expand All @@ -15,7 +16,6 @@
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="3" />
<ColumnDefinition Width="7*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<local_gui:AugmentedButton Name="ButtonToggleBibTeX" Grid.Column="0" >Toggle</local_gui:AugmentedButton>
Expand All @@ -27,7 +27,7 @@
<local_gui:AugmentedButton x:Name="ButtonCancel" Grid.Column="6" MinHeight="10" >Close</local_gui:AugmentedButton>
</Grid>

<ScrollViewer>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" >
<StackPanel>
<local_bibtex:BibTeXEditorControl x:Name="ObjBibTeXEditorControl" BibTeX="{Binding BibTex, Mode=TwoWay}" MinHeight="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ScrollViewer}},Path=ActualHeight}" />
Expand Down
8 changes: 4 additions & 4 deletions Qiqqa/Documents/PDF/PDFControls/PDFReadingControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@

<!-- PDFDocument metadata controls - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<local_gui:CollapsibleRegion Name="GridLEFT" DockPanel.Dock="Right" VisibleEdge="Left">
<local_metadata:DocumentMetadataControlsPanel x:Name="ObjDocumentMetadataControlsPanel" Width="220"/>
<local_gui:CollapsibleRegion Name="GridLEFT" DockPanel.Dock="Right" VisibleEdge="Left">
<local_metadata:DocumentMetadataControlsPanel x:Name="ObjDocumentMetadataControlsPanel" Width="220" MinWidth="220" />
</local_gui:CollapsibleRegion>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<local_gui:CollapsibleRegion Name="GridRIGHT" DockPanel.Dock="Left" VisibleEdge="Right">
<DockPanel Width="200">
<local_gui:CollapsibleRegion Name="GridRIGHT" DockPanel.Dock="Left" VisibleEdge="Right">
<DockPanel Width="200" MinWidth="186">

<ScrollViewer VerticalScrollBarVisibility="Auto" >
<StackPanel>
Expand Down
1 change: 0 additions & 1 deletion Utilities/Reflection/AugmentedBindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,5 @@ public override string ToString()
{
return String.Format("AugmentedBindable[{0}]", underlying.ToString());
}

}
}

0 comments on commit b3fae39

Please sign in to comment.