From b3fae39f781fc96373db3cf8eb8a5e1f57f23bf4 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 22 Oct 2019 17:53:00 +0200 Subject: [PATCH] https://github.com/jimmejardine/qiqqa-open-source/issues/82 : try to set up some decent min/max sizes for the various 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) --- .../BibTeXEditor/BibTeXEditorControl.xaml | 22 +++--- .../BibTeXEditor/BibTeXEditorControl.xaml.cs | 76 ++++++++++++++++--- .../MetadataBibTeXEditorControl.xaml | 4 +- .../PDF/PDFControls/PDFReadingControl.xaml | 8 +- Utilities/Reflection/AugmentedBindable.cs | 1 - 5 files changed, 84 insertions(+), 27 deletions(-) diff --git a/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml b/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml index 4cbefa9be..bc49a45b7 100644 --- a/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml +++ b/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml @@ -20,7 +20,7 @@ - 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. @@ -40,10 +40,10 @@ - Type - - Key - + Type + + Key + @@ -57,14 +57,14 @@ - - - - - + + + + + - + diff --git a/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml.cs b/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml.cs index 30544ceeb..9bc2ee20a 100644 --- a/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml.cs +++ b/Qiqqa/Documents/BibTeXEditor/BibTeXEditorControl.xaml.cs @@ -12,6 +12,7 @@ using Utilities.Reflection; using Qiqqa.Common.Configuration; using Utilities.Strings; +using Utilities; namespace Qiqqa.Documents.BibTeXEditor { @@ -67,6 +68,7 @@ public BibTeXEditorControl() InitializeComponent(); this.Unloaded += BibTeXEditorControl_Unloaded; + this.SizeChanged += BibTeXEditorControl_SizeChanged; // The error panel //ObjErrorPanel.Background = ThemeColours.Background_Brush_Warning; @@ -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) diff --git a/Qiqqa/Documents/PDF/PDFControls/MetadataControls/MetadataBibTeXEditorControl.xaml b/Qiqqa/Documents/PDF/PDFControls/MetadataControls/MetadataBibTeXEditorControl.xaml index 7f44daebf..cb6331b0f 100644 --- a/Qiqqa/Documents/PDF/PDFControls/MetadataControls/MetadataBibTeXEditorControl.xaml +++ b/Qiqqa/Documents/PDF/PDFControls/MetadataControls/MetadataBibTeXEditorControl.xaml @@ -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" > @@ -15,7 +16,6 @@ - Toggle @@ -27,7 +27,7 @@ Close - + diff --git a/Qiqqa/Documents/PDF/PDFControls/PDFReadingControl.xaml b/Qiqqa/Documents/PDF/PDFControls/PDFReadingControl.xaml index aa45306a6..38e13b328 100644 --- a/Qiqqa/Documents/PDF/PDFControls/PDFReadingControl.xaml +++ b/Qiqqa/Documents/PDF/PDFControls/PDFReadingControl.xaml @@ -131,14 +131,14 @@ - - + + - - + + diff --git a/Utilities/Reflection/AugmentedBindable.cs b/Utilities/Reflection/AugmentedBindable.cs index 4df13faf8..f9f26e900 100644 --- a/Utilities/Reflection/AugmentedBindable.cs +++ b/Utilities/Reflection/AugmentedBindable.cs @@ -335,6 +335,5 @@ public override string ToString() { return String.Format("AugmentedBindable[{0}]", underlying.ToString()); } - } }