Skip to content

Commit

Permalink
some additional defensive coding following jimmejardine#304
Browse files Browse the repository at this point in the history
  • Loading branch information
GerHobbelt committed Feb 26, 2021
1 parent 0444bb5 commit d26d2d4
Show file tree
Hide file tree
Showing 72 changed files with 1,736 additions and 1,323 deletions.
59 changes: 31 additions & 28 deletions Qiqqa/Brainstorm/SceneManager/BrainstormControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,40 +240,43 @@ public SceneRenderingControl SceneRenderingControl

private void ObjSceneRenderingControl_SelectedNodeControlChanged(NodeControl node_control)
{
// The first time they select something, select the edit tab...
if (is_first_selection)
WPFDoEvents.SafeExec(() =>
{
is_first_selection = false;
DualTabControlArea.MakeActive("Edit");
SceneRenderingControl.Focus();
}

// Clear out the old selected node editor
if (0 < ObjStackEditor.Children.Count)
{
FrameworkElement fe = ObjStackEditor.Children[0] as FrameworkElement;
if (null != fe)
// The first time they select something, select the edit tab...
if (is_first_selection)
{
fe.DataContext = null;
is_first_selection = false;
DualTabControlArea.MakeActive("Edit");
SceneRenderingControl.Focus();
}
else

// Clear out the old selected node editor
if (0 < ObjStackEditor.Children.Count)
{
Logging.Warn("It is strange that there was a non-FrameworkElement child of the brainstorm node editor");
FrameworkElement fe = ObjStackEditor.Children[0] as FrameworkElement;
if (null != fe)
{
fe.DataContext = null;
}
else
{
Logging.Warn("It is strange that there was a non-FrameworkElement child of the brainstorm node editor");
}
ObjStackEditor.Children.Clear();
}
ObjStackEditor.Children.Clear();
}

// Create a new selected node editor (if we have one)
FrameworkElement fe_to_load = null;
if (null != node_control)
{
fe_to_load = NodeContentControlRegistry.Instance.GetContentEditor(node_control, node_control.scene_data.node_content);
}
if (null == fe_to_load)
{
fe_to_load = ObjStackEditorHelpWhenEmpty;
}
LoadEditorFrameworkElement(fe_to_load);
// Create a new selected node editor (if we have one)
FrameworkElement fe_to_load = null;
if (null != node_control)
{
fe_to_load = NodeContentControlRegistry.Instance.GetContentEditor(node_control, node_control.scene_data.node_content);
}
if (null == fe_to_load)
{
fe_to_load = ObjStackEditorHelpWhenEmpty;
}
LoadEditorFrameworkElement(fe_to_load);
});
}

private void LoadEditorFrameworkElement(FrameworkElement fe)
Expand Down
15 changes: 9 additions & 6 deletions Qiqqa/Brainstorm/SceneManager/SceneRenderingControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,17 @@ private NodeControl AddNewNodeControlSceneData(NodeControlSceneData node_control

private void SceneRenderingControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
double delta_x = (e.PreviousSize.Width - e.NewSize.Width);
double delta_y = (e.PreviousSize.Height - e.NewSize.Height);
WPFDoEvents.SafeExec(() =>
{
double delta_x = (e.PreviousSize.Width - e.NewSize.Width);
double delta_y = (e.PreviousSize.Height - e.NewSize.Height);

current_viewport_topleft.X += delta_x / 2.0 / CurrentPowerScale;
current_viewport_topleft.Y += delta_y / 2.0 / CurrentPowerScale;
ViewportHasChanged();
current_viewport_topleft.X += delta_x / 2.0 / CurrentPowerScale;
current_viewport_topleft.Y += delta_y / 2.0 / CurrentPowerScale;
ViewportHasChanged();

RecalculateAllNodeControlDimensions();
RecalculateAllNodeControlDimensions();
});
}

internal void UpdateMouseTracking(MouseEventArgs e, bool update_initial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using Qiqqa.Brainstorm.Nodes;
using Utilities.GUI;
using Utilities.Misc;

namespace Qiqqa.Brainstorm.SceneManager
Expand All @@ -23,8 +24,11 @@ public SceneRenderingControlScrollWrapper()

private void ObjSceneRenderingControl_ScrollInfoChanged()
{
DoHorizontal();
DoVertical();
WPFDoEvents.SafeExec(() =>
{
DoHorizontal();
DoVertical();
});
}

private bool horizonal_changing = false;
Expand Down Expand Up @@ -94,20 +98,26 @@ private void DoVertical()

private void ScrollHorizonal_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!horizonal_changing)
WPFDoEvents.SafeExec(() =>
{
ObjSceneRenderingControl.current_viewport_topleft.X = e.NewValue - ObjSceneRenderingControl.ActualWidth / ObjSceneRenderingControl.CurrentPowerScale / 2;
ObjSceneRenderingControl.ViewportHasChanged();
}
if (!horizonal_changing)
{
ObjSceneRenderingControl.current_viewport_topleft.X = e.NewValue - ObjSceneRenderingControl.ActualWidth / ObjSceneRenderingControl.CurrentPowerScale / 2;
ObjSceneRenderingControl.ViewportHasChanged();
}
});
}

private void ScrollVertical_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!vertical_changing)
WPFDoEvents.SafeExec(() =>
{
ObjSceneRenderingControl.current_viewport_topleft.Y = e.NewValue - ObjSceneRenderingControl.ActualHeight / ObjSceneRenderingControl.CurrentPowerScale / 2;
ObjSceneRenderingControl.ViewportHasChanged();
}
if (!vertical_changing)
{
ObjSceneRenderingControl.current_viewport_topleft.Y = e.NewValue - ObjSceneRenderingControl.ActualHeight / ObjSceneRenderingControl.CurrentPowerScale / 2;
ObjSceneRenderingControl.ViewportHasChanged();
}
});
}
}
}
15 changes: 9 additions & 6 deletions Qiqqa/Common/Configuration/ConfigurationControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,17 @@ private void CmdResetDevCfgToFactoryDefaults_Click(object sender, RoutedEventArg

private void ObjListEZProxy_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Proxy proxy = ObjListEZProxy.SelectedItem as Proxy;
if (null != proxy && !String.IsNullOrEmpty(proxy.url))
WPFDoEvents.SafeExec(() =>
{
ConfigurationManager.Instance.ConfigurationRecord.Proxy_EZProxy = proxy.url;
ConfigurationManager.Instance.ConfigurationRecord_Bindable.NotifyPropertyChanged(nameof(ConfigurationManager.Instance.ConfigurationRecord.Proxy_EZProxy));
}
Proxy proxy = ObjListEZProxy.SelectedItem as Proxy;
if (null != proxy && !String.IsNullOrEmpty(proxy.url))
{
ConfigurationManager.Instance.ConfigurationRecord.Proxy_EZProxy = proxy.url;
ConfigurationManager.Instance.ConfigurationRecord_Bindable.NotifyPropertyChanged(nameof(ConfigurationManager.Instance.ConfigurationRecord.Proxy_EZProxy));
}

e.Handled = true;
e.Handled = true;
});
}

private void ObjUserAgent_XXX_Click(object sender, RoutedEventArgs e)
Expand Down
50 changes: 27 additions & 23 deletions Qiqqa/Common/DocumentPickerStuff/DocumentPickerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Qiqqa.Documents.PDF;
using Qiqqa.UtilisationTracking;
using Utilities;
using Utilities.GUI;

namespace Qiqqa.Common.DocumentPickerStuff
{
Expand Down Expand Up @@ -39,35 +40,38 @@ private void ObjLibraryPicker_OnWebLibraryPicked(WebLibraryDetail web_library_de

private void ApplyNewSearch()
{
ObjDocumentsPanel.Children.Clear();

WebLibraryDetail web_library_detail = ObjLibraryPicker.WebLibraryDetail;
if (null != web_library_detail)
WPFDoEvents.SafeExec(() =>
{
string query = ObjSearchFilter.Text;
if (!String.IsNullOrEmpty(query))
{
Library library = web_library_detail.Xlibrary;
HashSet<string> fingerprints = library.GetDocumentFingerprintsWithKeyword(query);
List<PDFDocument> pdf_documents = library.GetDocumentByFingerprints(fingerprints);
ObjDocumentsPanel.Children.Clear();

List<PDFDocument> pdf_documents_sorted = new List<PDFDocument>(pdf_documents.OrderBy(x => x.TitleCombined));
bool alternator = false;
foreach (PDFDocument pdf_document in pdf_documents_sorted)
WebLibraryDetail web_library_detail = ObjLibraryPicker.WebLibraryDetail;
if (null != web_library_detail)
{
string query = ObjSearchFilter.Text;
if (!String.IsNullOrEmpty(query))
{
TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Feature, OnDocumentClicked);
ObjDocumentsPanel.Children.Add(text_doc);
}
Library library = web_library_detail.Xlibrary;
HashSet<string> fingerprints = library.GetDocumentFingerprintsWithKeyword(query);
List<PDFDocument> pdf_documents = library.GetDocumentByFingerprints(fingerprints);

// If the panel is empty, put NONE
if (0 == ObjDocumentsPanel.Children.Count)
{
TextBlock text_doc = new TextBlock();
text_doc.Text = "(none)";
ObjDocumentsPanel.Children.Add(text_doc);
List<PDFDocument> pdf_documents_sorted = new List<PDFDocument>(pdf_documents.OrderBy(x => x.TitleCombined));
bool alternator = false;
foreach (PDFDocument pdf_document in pdf_documents_sorted)
{
TextBlock text_doc = ListFormattingTools.GetDocumentTextBlock(pdf_document, ref alternator, Feature, OnDocumentClicked);
ObjDocumentsPanel.Children.Add(text_doc);
}

// If the panel is empty, put NONE
if (0 == ObjDocumentsPanel.Children.Count)
{
TextBlock text_doc = new TextBlock();
text_doc.Text = "(none)";
ObjDocumentsPanel.Children.Add(text_doc);
}
}
}
}
});
}

private void OnDocumentClicked(object sender, MouseButtonEventArgs e)
Expand Down
25 changes: 14 additions & 11 deletions Qiqqa/Common/ReadOutLoud/ReadOutLoudManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ private void OnShutdown()

private void speech_synthesizer_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
// Add the current word to our list
last_words.Add(e.Text);
while (last_words.Count > 10)
WPFDoEvents.SafeExec(() =>
{
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
}
// Add the current word to our list
last_words.Add(e.Text);
while (last_words.Count > 10)
{
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
last_words.RemoveAt(0);
}

string textwindow = ArrayFormatter.ListElements(last_words, " ");
string textwindow = ArrayFormatter.ListElements(last_words, " ");

StatusManager.Instance.UpdateStatus("ReadOutAloud", textwindow, e.CharacterPosition, current_prompt_length);
StatusManager.Instance.UpdateStatus("ReadOutAloud", textwindow, e.CharacterPosition, current_prompt_length);
});
}

private void speech_synthesizer_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ private void ButtonCancel_Click(object sender, RoutedEventArgs e)

private void TxtPath_TextChanged(object sender, TextChangedEventArgs e)
{
ValidateFolder();
WPFDoEvents.SafeExec(() =>
{
ValidateFolder();
});
}

private void ValidateFolder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ private void ButtonCancel_Click(object sender, RoutedEventArgs e)

private void TxtPath_TextChanged(object sender, TextChangedEventArgs e)
{
ValidateFolder();
WPFDoEvents.SafeExec(() =>
{
ValidateFolder();
});
}

private void ValidateFolder()
Expand Down
16 changes: 11 additions & 5 deletions Qiqqa/DocumentLibrary/LibraryCatalog/LibraryCatalogControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ private void dispatcherTimer_Tick(object sender, EventArgs e)

private void ListPDFDocuments_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (ListPDFDocuments.IsVisible)
WPFDoEvents.SafeExec(() =>
{
ListPDFDocuments.UpdateLayout();
}
if (ListPDFDocuments.IsVisible)
{
ListPDFDocuments.UpdateLayout();
}
});
}

internal void OnFilterChanged(LibraryFilterControl library_filter_control, List<PDFDocument> pdf_documents, Span descriptive_span, string filter_terms, Dictionary<string, double> search_scores, PDFDocument pdf_document_to_focus_on)
Expand All @@ -83,9 +86,12 @@ internal void OnFilterChanged(LibraryFilterControl library_filter_control, List<

private void ListPDFDocuments_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ReconsiderPDFDocumentDetail();
WPFDoEvents.SafeExec(() =>
{
ReconsiderPDFDocumentDetail();

SelectionChanged?.Invoke(SelectedPDFDocuments);
SelectionChanged?.Invoke(SelectedPDFDocuments);
});
}

private void ReconsiderPDFDocumentDetail()
Expand Down
Loading

0 comments on commit d26d2d4

Please sign in to comment.