Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("LibraryCatalogOverviewControl::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.InvokeInUIThread(() =>
            {
                WPFDoEvents.SafeExec(() =>
                {
                    if (dispose_count == 0)
                    {
                        // Get rid of managed resources / get rid of cyclic references:
                        library_index_hover_popup?.Dispose();
                    }
                });

                WPFDoEvents.SafeExec(() =>
                {
                    WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();
                    if (dispose_count == 0)
                    {
                        WizardDPs.ClearPointOfInterest(PanelSearchScore);
                    }
                });

                WPFDoEvents.SafeExec(() =>
                {
                    if (dispose_count == 0)
                    {
                        WizardDPs.ClearPointOfInterest(ObjLookInsidePanel);
                    }
                });

                WPFDoEvents.SafeExec(() =>
                {
                    TextTitle.MouseLeftButtonUp -= TextTitle_MouseLeftButtonUp;

                    ButtonOpen.ToolTipOpening -= HyperlinkPreview_ToolTipOpening;
                    ButtonOpen.ToolTipClosing -= HyperlinkPreview_ToolTipClosing;

                    ListSearchDetails.SearchClicked -= ListSearchDetails_SearchSelectionChanged;

                    DataContextChanged -= LibraryCatalogOverviewControl_DataContextChanged;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    DataContext = null;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    // Clear the references for sanity's sake
                    library_index_hover_popup = null;
                    drag_drop_helper          = null;
                });

                ++dispose_count;
            });
        }
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFAnnotationLayer::Dispose({0}) @{1}", disposing, dispose_count);

            try
            {
                if (null != drag_area_tracker)
                {
                    WPFDoEvents.InvokeInUIThread(() =>
                    {
                        try
                        {
                            foreach (var el in Children)
                            {
                                IDisposable node = el as IDisposable;
                                if (null != node)
                                {
                                    node.Dispose();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex);
                        }

                        try
                        {
                            Children.Clear();
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex);
                        }

                        WizardDPs.ClearPointOfInterest(this);

                        drag_area_tracker.OnDragComplete -= drag_area_tracker_OnDragComplete;
                    }, Dispatcher);
                }

                // Clear the references for sanity's sake
                pdf_renderer_control_stats = null;
                drag_area_tracker          = null;

                DataContext = null;
            }
            catch (Exception ex)
            {
                Logging.Error(ex);
            }

            ++dispose_count;

            //base.Dispose(disposing);     // parent only throws an exception (intentionally), so depart from best practices and don't call base.Dispose(bool)
        }
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFAnnotationLayer::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.InvokeInUIThread(() =>
            {
                WPFDoEvents.SafeExec(() =>
                {
                    foreach (var el in Children)
                    {
                        IDisposable node = el as IDisposable;
                        if (null != node)
                        {
                            node.Dispose();
                        }
                    }
                });

                WPFDoEvents.SafeExec(() =>
                {
                    Children.Clear();
                });

                WPFDoEvents.SafeExec(() =>
                {
                    WizardDPs.ClearPointOfInterest(this);
                });

                WPFDoEvents.SafeExec(() =>
                {
                    if (drag_area_tracker != null)
                    {
                        drag_area_tracker.OnDragComplete -= drag_area_tracker_OnDragComplete;
                    }

                    Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    // Clear the references for sanity's sake
                    pdf_document      = null;
                    drag_area_tracker = null;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    DataContext = null;
                });

                ++dispose_count;

                //base.Dispose(disposing);     // parent only throws an exception (intentionally), so depart from best practices and don't call base.Dispose(bool)
            });
        }
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            // base.OnClosed() invokes this class' Closed() code, so we flipped the order of exec to reduce the number of surprises for yours truly.
            // This NULLing stuff is really the last rites of Dispose()-like so we stick it at the end here.

            WizardDPs.ClearPointOfInterest(this);
            WizardDPs.ClearPointOfInterest(CmdGenerate);

            library = null;
            pdf_documents.Clear();
            pdf_documents = null;

            ListTags.Items.Clear();
            ListTags.ItemsSource = null;
        }
Exemplo n.º 5
0
        private void LibraryCatalogOverviewControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // Make the button semi-transparent if our new document is not actually on the harddrive
            PanelSearchScore.Visibility   = Visibility.Collapsed;
            ListSearchDetails.DataContext = null;
            ObjLookInsidePanel.Visibility = Visibility.Collapsed;
            ButtonThemeSwatch.Visibility  = Visibility.Collapsed;
            ObjFavouriteImage.Visibility  = Visibility.Collapsed;
            ButtonOpen.Background         = Brushes.Transparent;
            TextTitle.Foreground          = Brushes.Black;
            TextTitle.FontSize            = TextAuthors.FontSize;

            // No more work if our context is null
            if (null == PDFDocumentBindable)
            {
                return;
            }

            // The wizard
            if ("The Qiqqa Manual" == PDFDocumentBindable.Underlying.TitleCombined)
            {
                WizardDPs.SetPointOfInterest(TextTitle, "GuestLibraryQiqqaManualTitle");
                WizardDPs.SetPointOfInterest(ButtonOpen, "GuestLibraryQiqqaManualOpenButton");
            }
            else
            {
                WizardDPs.ClearPointOfInterest(TextTitle);
                WizardDPs.ClearPointOfInterest(ButtonOpen);
            }

            // Choose the icon depending on the reference type
            if (PDFDocumentBindable.Underlying.IsVanillaReference)
            {
                ButtonOpen.Icon    = Icons.GetAppIcon(Icons.LibraryCatalogOpenVanillaReference);
                ButtonOpen.Opacity = 1.0;
            }
            else
            {
                ButtonOpen.Icon    = Icons.GetAppIcon(Icons.LibraryCatalogOpen);
                ButtonOpen.Opacity = PDFDocumentBindable.Underlying.DocumentExists ? 1.0 : 0.5;
            }

            // Favourite?
            if (PDFDocumentBindable.Underlying.IsFavourite ?? false)
            {
                ObjFavouriteImage.Visibility = Visibility.Visible;
            }

            // Colour
            if (Colors.Transparent != PDFDocumentBindable.Underlying.Color)
            {
                ButtonOpen.Background = new SolidColorBrush(ColorTools.MakeTransparentColor(PDFDocumentBindable.Underlying.Color, 64));
            }

            // Rating
            if (!String.IsNullOrEmpty(PDFDocumentBindable.Underlying.Rating))
            {
                double rating;
                if (Double.TryParse(PDFDocumentBindable.Underlying.Rating, out rating))
                {
                    TextTitle.FontSize = TextAuthors.FontSize + rating;
                }
            }

            // Reading stage
            switch (PDFDocumentBindable.Underlying.ReadingStage)
            {
            case Choices.ReadingStages_TOP_PRIORITY:
                TextTitle.Foreground = Brushes.DarkRed;
                break;

            case Choices.ReadingStages_READ_AGAIN:
            case Choices.ReadingStages_INTERRUPTED:
            case Choices.ReadingStages_STARTED_READING:
                TextTitle.Foreground = Brushes.DarkGreen;
                break;

            case Choices.ReadingStages_SKIM_READ:
            case Choices.ReadingStages_BROWSED:
            case Choices.ReadingStages_INTEREST_ONLY:
                TextTitle.Foreground = Brushes.DarkBlue;
                break;

            case Choices.ReadingStages_FINISHED_READING:
            case Choices.ReadingStages_DUPLICATE:
                TextTitle.Foreground = Brushes.DarkGray;
                break;

            case Choices.ReadingStages_UNREAD:
                TextTitle.Foreground = Brushes.Black;
                break;

            default:
                TextTitle.Foreground = Brushes.Black;
                break;
            }

            // Populate the score if we have them
            if (null != LibraryCatalogControl)
            {
                Dictionary <string, double> search_scores = LibraryCatalogControl.SearchScores;
                if (null != search_scores)
                {
                    PanelSearchScore.Visibility = Visibility.Visible;

                    double score;
                    search_scores.TryGetValue(PDFDocumentBindable.Underlying.Fingerprint, out score);

                    string score_string = String.Format("{0:0}%", score * 100);
                    ButtonSearchInside.Caption  = "" + score_string + "";
                    ButtonSearchInside.ToolTip  = String.Format("Search score is {0}. Click here to see why...", score_string);
                    ButtonSearchInside.Cursor   = Cursors.Hand;
                    ButtonSearchInside.MinWidth = 0;
                    Color color = Color.FromRgb(255, (byte)(255 - 150 * score), 100);
                    ButtonSearchInside.Background = new SolidColorBrush(color);
                }
            }

            // Populate the theme swatch
            ButtonThemeSwatch.Visibility = Visibility.Visible;
            ButtonThemeSwatch.Background = ThemeBrushes.GetBrushForDocument(PDFDocumentBindable.Underlying);

            // Populate the linked documents
            PDFDocument pdf_document = PDFDocumentBindable.Underlying;

            SafeThreadPool.QueueUserWorkItem(o =>
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

                var links = pdf_document.PDFDocumentCitationManager.GetLinkedDocuments();

                WPFDoEvents.InvokeAsyncInUIThread(() =>
                {
                    WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

                    CitationsUserControl.PopulatePanelWithCitations(DocsPanel_Linked, pdf_document, links, Features.LinkedDocument_Library_OpenDoc, " » ", false);
                });
            });
        }
Exemplo n.º 6
0
        void LibraryCatalogOverviewControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // Make the button semi-transparent if our new document is not actually on the harddrive
            PanelSearchScore.Visibility   = Visibility.Collapsed;
            ListSearchDetails.DataContext = null;
            ObjLookInsidePanel.Visibility = Visibility.Collapsed;
            ButtonThemeSwatch.Visibility  = Visibility.Collapsed;
            ObjFavouriteImage.Visibility  = Visibility.Collapsed;
            ButtonOpen.Background         = Brushes.Transparent;
            TextTitle.Foreground          = Brushes.Black;
            TextTitle.FontSize            = TextAuthors.FontSize;

            // No more work if our context is null
            if (null == PDFDocumentBindable)
            {
                return;
            }

            // The wizard
            if ("The Qiqqa Manual" == PDFDocumentBindable.Underlying.TitleCombined)
            {
                WizardDPs.SetPointOfInterest(TextTitle, "GuestLibraryQiqqaManualTitle");
                WizardDPs.SetPointOfInterest(ButtonOpen, "GuestLibraryQiqqaManualOpenButton");
            }
            else
            {
                WizardDPs.ClearPointOfInterest(TextTitle);
                WizardDPs.ClearPointOfInterest(ButtonOpen);
            }

            // Choose the icon depending on the reference type
            if (false)
            {
            }
            else if (PDFDocumentBindable.Underlying.IsVanillaReference)
            {
                ButtonOpen.Icon    = Icons.GetAppIcon(Icons.LibraryCatalogOpenVanillaReference);
                ButtonOpen.Opacity = 1.0;
            }
            else
            {
                ButtonOpen.Icon    = Icons.GetAppIcon(Icons.LibraryCatalogOpen);
                ButtonOpen.Opacity = PDFDocumentBindable.Underlying.DocumentExists ? 1.0 : 0.5;
            }

            // Favourite?
            if (PDFDocumentBindable.Underlying.IsFavourite ?? false)
            {
                ObjFavouriteImage.Visibility = Visibility.Visible;
            }

            // Colour
            if (Colors.Transparent != PDFDocumentBindable.Underlying.Color)
            {
                ButtonOpen.Background = new SolidColorBrush(ColorTools.MakeTransparentColor(PDFDocumentBindable.Underlying.Color, 64));
            }

            // Rating
            if (!String.IsNullOrEmpty(PDFDocumentBindable.Underlying.Rating))
            {
                double rating;
                if (Double.TryParse(PDFDocumentBindable.Underlying.Rating, out rating))
                {
                    TextTitle.FontSize = TextAuthors.FontSize + rating;
                }
            }

            // Reading stage
            switch (PDFDocumentBindable.Underlying.ReadingStage)
            {
            case "Top priority":
                TextTitle.Foreground = Brushes.DarkRed;
                break;

            case "Read again":
            case "Interrupted":
            case "Started reading":
                TextTitle.Foreground = Brushes.DarkGreen;
                break;

            case "Skim read":
            case "Browsed":
                TextTitle.Foreground = Brushes.DarkBlue;
                break;

            case "Finished reading":
            case Choices.ReadingStages_DUPLICATE:
                TextTitle.Foreground = Brushes.DarkGray;
                break;

            case "Unread":
                TextTitle.Foreground = Brushes.Black;
                break;

            default:
                TextTitle.Foreground = Brushes.Black;
                break;
            }

            // Populate the score if we have them
            if (null != LibraryCatalogControl)
            {
                Dictionary <string, double> search_scores = LibraryCatalogControl.SearchScores;
                if (null != search_scores)
                {
                    PanelSearchScore.Visibility = Visibility.Visible;

                    double score;
                    search_scores.TryGetValue(PDFDocumentBindable.Underlying.Fingerprint, out score);

                    string score_string = String.Format("{0:0}%", score * 100);
                    ButtonSearchInside.Caption  = "" + score_string + "";
                    ButtonSearchInside.ToolTip  = String.Format("Search score is {0}. Click here to see why...", score_string);
                    ButtonSearchInside.Cursor   = Cursors.Hand;
                    ButtonSearchInside.MinWidth = 0;
                    Color color = Color.FromRgb(255, (byte)(255 - 150 * score), 100);
                    ButtonSearchInside.Background = new SolidColorBrush(color);
                }
            }

            // Populate the theme swatch
            {
                ButtonThemeSwatch.Visibility = Visibility.Visible;
                ButtonThemeSwatch.Background = ThemeBrushes.GetBrushForDocument(PDFDocumentBindable.Underlying);
            }

            // Populate the linked documents
            {
                CitationsUserControl.PopulatePanelWithCitations(DocsPanel_Linked, PDFDocumentBindable.Underlying.Library, PDFDocumentBindable.Underlying, PDFDocumentBindable.Underlying.PDFDocumentCitationManager.GetLinkedDocuments(), Features.LinkedDocument_Library_OpenDoc, " » ", false);
            }
        }