public override bool Equals(object obj) { if (obj != null && obj is OoAccessibilitySelection) { OoAccessibilitySelection objS = obj as OoAccessibilitySelection; if (objS.Source.Equals(this.Source)) { if (objS.Count == this.Count) { if (objS.Count > 0) { foreach (var item in objS.SelectedItems) { if (!this.SelectedItems.Contains(item)) { return(false); } } } return(true); } } } return(false); }
/// <summary> /// Tries to the get current selection. /// </summary> /// <param name="doc">The document window.</param> /// <param name="selectedShapesList">The list of currently selected shapes.</param> /// <returns><c>true</c> if the selection could be achieved; otherwise <c>false</c> (e.g. because it was aborted by time limit)</returns> /// <remarks>This request is time limited to 300 ms.</remarks> public bool TryGetSelection(OoAccessibleDocWnd doc, out OoAccessibilitySelection selection) { selection = null; List <OoShapeObserver> selectedShapesList2 = new List <OoShapeObserver>(); bool innerSuccess = false; bool success = false; if (doc != null) { try { if (_cachedSelection.ContainsKey(doc)) { int i = 0; while (!_cachedSelection.TryGetValue(doc, out selection) && i++ < 3) { Thread.Sleep(5); } if (i < 3) { if (selection != null && DateTime.Now - selection.SelectionCreationTime < new TimeSpan(0, 1, 0)) { //System.Diagnostics.Debug.WriteLine("******* GET Cached Selection for WND: " + doc + " result in " + selection.Count + " selected Items."); return(true); } } } success = TimeLimitExecutor.WaitForExecuteWithTimeLimit(300, () => { try { lock (doc.SynchLock) { innerSuccess = tryGetSelection(doc, out selectedShapesList2); } } catch { innerSuccess = false; } }, "HandleSelectionChanged"); var selection2 = new OoAccessibilitySelection(doc, selectedShapesList2); if (success & innerSuccess) { //System.Diagnostics.Debug.WriteLine("++++++ ADD to cached Selection for WND: " + doc + " result in " + selection2.Count + " selected Items."); _cachedSelection.AddOrUpdate(doc, selection2, (key, oldValue) => selection2); selection = selection2; } //else resetSelectionCache(); } catch (ThreadInterruptedException) { } catch (ThreadAbortException) { } } //System.Diagnostics.Debug.WriteLine(".... Selection Return: " + (selection != null ? selection.Count.ToString() : " invalid selection")); return(success & innerSuccess); }