private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (CmdImage == sender)
            {
                Clipboard.SetImage(image);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "An image snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdRawText == sender)
            {
                ClipboardTools.SetText(raw_text);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "A text snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdTabulatedText == sender)
            {
                ClipboardTools.SetText(tabled_text);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "A tabulated snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdTabulatedCharts == sender)
            {
                string data = Uri.EscapeDataString(tabled_text);
                string url  = String.Format(WebsiteAccess.Url_DatacopiaSearch, data);
                MainWindowServiceDispatcher.Instance.OpenUrlInBrowser(url, true);
            }

            Close();
        }
        void Button_Click(object sender, RoutedEventArgs e)
        {
            if (false)
            {
            }

            else if (CmdImage == sender)
            {
                Clipboard.SetImage(this.image);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "An image snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdRawText == sender)
            {
                ClipboardTools.SetText(raw_text);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "A text snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdTabulatedText == sender)
            {
                ClipboardTools.SetText(tabled_text);
                StatusManager.Instance.UpdateStatus("RegionSnapshot", "A tabulated snapshot of the PDF region has been copied to the clipboard.");
            }

            else if (CmdTabulatedCharts == sender)
            {
                string data = Uri.EscapeDataString(tabled_text);
                string url  = "https://datacopia.com?data=" + data;
                MainWindowServiceDispatcher.Instance.OpenUrlInBrowser(url, true);
            }

            this.Close();
        }
Пример #3
0
        void MenuCopyBibTeXKey_Click(object sender, RoutedEventArgs e)
        {
            popup.Close();

            FeatureTrackingManager.Instance.UseFeature(Features.Library_CopyBibTeXKey);

            StringBuilder sb = new StringBuilder();

            foreach (var pdf_document in pdf_documents)
            {
                string key = pdf_document.BibTexKey;
                if (!String.IsNullOrEmpty(key))
                {
                    sb.Append(key);
                    sb.Append(",");
                }
                else
                {
                    MessageBoxes.Warn("'{0}' does not have a BibTeX key.", pdf_document.TitleCombined);
                }
            }


            // To clipboard
            string result = sb.ToString().Trim(',');

            if (!String.IsNullOrEmpty(result))
            {
                result = @"\cite{" + result + @"}";

                ClipboardTools.SetText(result);
                StatusManager.Instance.UpdateStatus("CopyBibTeXKey", String.Format("Copied '{0}' to clipboard.", result));
            }
        }
        private void ButtonInCite_BibTeXKey_Click(object sender, RoutedEventArgs e)
        {
            ButtonInCitePopup.Close();
            {
                if (!String.IsNullOrEmpty(pdf_renderer_control_stats.pdf_document.BibTexKey))
                {
                    string result = @"\cite{" + pdf_renderer_control_stats.pdf_document.BibTexKey + @"}";
                    ClipboardTools.SetText(result);
                    StatusManager.Instance.UpdateStatus("CopyBibTeXKey", String.Format("Copied '{0}' to clipboard.", result));
                }

                e.Handled = true;
            }
        }
        private void HyperlinkLocateSyncPoint_OnClick(object sender, MouseButtonEventArgs e)
        {
            WebLibraryDetail web_library_detail = DataContext as WebLibraryDetail;

            if (null != web_library_detail)
            {
                if (!String.IsNullOrEmpty(web_library_detail.IntranetPath))
                {
                    MessageBoxes.Warn("The Intranet Library Sync Point directory name is now on your Clipboard so you can paste it into an email to your colleagues so that they can join the Intranet Library.\n\nPlease note that this Sync Point is used to synchronize your Intranet Library with others in your organisation.  Please do not modify its contents in any way.\n\n" + web_library_detail.IntranetPath);
                    ClipboardTools.SetText(web_library_detail.IntranetPath);
                }
            }
            e.Handled = true;
        }
Пример #6
0
        void MenuItemCopy_Click(object sender, RoutedEventArgs e)
        {
            using (var c = popup.AutoCloser)
            {
                FeatureTrackingManager.Instance.UseFeature(Features.Document_CopyText);

                try
                {
                    ClipboardTools.SetText(selected_text);
                }

                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem copying text to the clipboard.");
                }
            }
        }
        private void PDFTextLayer_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.C && KeyboardTools.IsCTRLDown())
            {
                Logging.Info("Copying text");

                FeatureTrackingManager.Instance.UseFeature(Features.Document_CopyText);

                try
                {
                    string selected_text = text_selection_manager.GetLastSelectedWordsString();
                    ClipboardTools.SetText(selected_text);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem copying text to the clipboard.");
                }

                e.Handled = true;
            }
        }
Пример #8
0
        internal void RepopulateFromCSLProcessor_SUCCESS(CSLProcessorOutputConsumer ip, CSLProcessor.BrowserThreadPassThru passthru)
        {
            int MAX_DODGY_PASTE_RETRY_COUNT     = 5;
            int DODGY_PASTE_RETRY_SLEEP_TIME_MS = 200;
            int dodgy_paste_retry_count         = 0;

            try
            {
                // Suppress screen updates (for performance reasons)
                repopulating_clusters           = true;
                word_application.ScreenUpdating = false;

                Document document = word_application.Selection.Document;

                // Get all the fields out there
                Logging.Info("+Enumerating all fields");
                List <Field> fields = GetDocumentFields(document);
                Logging.Info("-Enumerating all fields");

                StatusManager.Instance.ClearCancelled("InCite");
                for (int f = 0; f < fields.Count; ++f)
                {
                    if (StatusManager.Instance.IsCancelled("InCite"))
                    {
                        Logging.Info("Updating of citations in Word has been cancelled by the user.");
                        break;
                    }

                    Field field = fields[f];

                    StatusManager.Instance.UpdateStatus("InCite", "Updating InCite fields in Word", f, fields.Count, true);
                    word_application.StatusBar = String.Format("Updating InCite field {0} of {1}...", f, fields.Count);

                    try
                    {
                        // Do we have a citation that we can fill?
                        CitationCluster citation_cluster = GenerateCitationClusterFromField(field);
                        if (null != citation_cluster)
                        {
                            string text_for_cluster = ip.GetTextForCluster(citation_cluster.cluster_id);
                            string rtf_hash         = GenerateRTFHash(passthru.is_note_format, text_for_cluster);

                            // Update this citation cluster only if it needs updating (if it has changed from what is currently stored in it)
                            if (!String.IsNullOrEmpty(text_for_cluster))
                            {
                                bool needs_update = false;

                                if (!needs_update)
                                {
                                    if (rtf_hash != citation_cluster.rtf_hash)
                                    {
                                        needs_update = true;
                                    }
                                }

                                if (!needs_update)
                                {
                                    string current_field_contents = field.Result.Text;
                                    if (current_field_contents.Contains("QIQQA"))
                                    {
                                        needs_update = true;
                                    }
                                }

                                if (needs_update)
                                {
                                    // Update the field with the new hash
                                    citation_cluster.rtf_hash = rtf_hash;
                                    PopulateFieldWithRawCitationCluster(field, citation_cluster);

                                    // Remember the font
                                    string font_name = field.Result.Font.Name;
                                    float  font_size = field.Result.Font.Size;

                                    string rtf = RTF_START + text_for_cluster + RTF_END;
                                    ClipboardTools.SetText(rtf, TextDataFormat.Rtf);

                                    if (passthru.is_note_format)
                                    {
                                        field.Result.Text = "";
                                        Footnote footnote = field.Result.Footnotes.Add(field.Result);
                                        footnote.Range.Text = " ";
                                        Range range = footnote.Range;
                                        range.Collapse(WdCollapseDirection.wdCollapseStart);
                                        range.PasteSpecial(DataType: WdPasteDataType.wdPasteRTF);
                                        footnote.Range.Font.Name = font_name;
                                        footnote.Range.Font.Size = font_size;
                                    }
                                    else
                                    {
                                        field.Result.Text = " ";
                                        Range range = field.Result;
                                        range.Collapse(WdCollapseDirection.wdCollapseStart);
                                        range.PasteSpecial(DataType: WdPasteDataType.wdPasteRTF);
                                        field.Result.Text      = field.Result.Text.Trim();
                                        field.Result.Font.Name = font_name;
                                        field.Result.Font.Size = font_size;
                                    }
                                }
                            }
                            else
                            {
                                citation_cluster.rtf_hash = rtf_hash;
                                PopulateFieldWithRawCitationCluster(field, citation_cluster);
                                field.Result.Text = String.Format("ERROR: Unable to find key {0} in the CSL output.", citation_cluster.cluster_id);
                            }

                            // If we get here, it must have worked!
                            dodgy_paste_retry_count = 0;

                            continue;
                        }

                        // Do we have a bibliography that we can fill?
                        if (IsFieldBibliography(field))
                        {
                            // Remember the font
                            string font_name = field.Result.Font.Name;
                            float  font_size = field.Result.Font.Size;

                            string formatted_bibliography_section = ip.GetFormattedBibliographySection();
                            if (String.IsNullOrEmpty(formatted_bibliography_section))
                            {
                                formatted_bibliography_section = "Either this CSL citation style does not produce a bibliography section or you have not yet added any citations to this document, so this bibliography is empty.";
                            }

                            string formatted_bibliography_section_wrapped = CSLProcessorOutputConsumer.RTF_START + formatted_bibliography_section + CSLProcessorOutputConsumer.RTF_END;

                            ClipboardTools.SetText(formatted_bibliography_section_wrapped, TextDataFormat.Rtf);

                            field.Result.Text = " ";
                            Range range = field.Result;
                            range.Collapse(WdCollapseDirection.wdCollapseStart);
                            range.PasteSpecial(DataType: WdPasteDataType.wdPasteRTF);
                            field.Result.Font.Name = font_name;
                            field.Result.Font.Size = font_size;

                            // If we get here, it must have worked!
                            dodgy_paste_retry_count = 0;

                            continue;
                        }

                        // Do we have a CSL stats region?
                        if (IsFieldCSLStats(field))
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(RTF_START);
                            {
                                sb.AppendFormat("maxoffset={0}\\line\n", ip.max_offset);
                                sb.AppendFormat("entryspacing={0}\\line\n", ip.entry_spacing);
                                sb.AppendFormat("linespacing={0}\\line\n", ip.line_spacing);
                                sb.AppendFormat("hangingindent={0}\\line\n", ip.hanging_indent);
                                sb.AppendFormat("second_field_align={0}\\line\n", ip.second_field_align);
                            }
                            sb.Append(RTF_END);

                            Clipboard.SetText(sb.ToString(), TextDataFormat.Rtf);

                            field.Result.Text = " ";
                            Range range = field.Result;
                            range.Collapse(WdCollapseDirection.wdCollapseStart);
                            range.PasteSpecial(DataType: WdPasteDataType.wdPasteRTF);

                            // If we get here, it must have worked!
                            dodgy_paste_retry_count = 0;

                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        ++dodgy_paste_retry_count;
                        if (dodgy_paste_retry_count < MAX_DODGY_PASTE_RETRY_COUNT)
                        {
                            Logging.Warn(ex, "Will try again (try {0}) because there was a problem updating a citation field: {1}", dodgy_paste_retry_count, field.Result.Text);

                            // Back up one field so we can try again
                            Thread.Sleep(DODGY_PASTE_RETRY_SLEEP_TIME_MS);
                            --f;
                            continue;
                        }
                        else
                        {
                            Logging.Error(ex, "Giving up because there was a problem updating a citation field: {0}", field.Result.Text);
                            dodgy_paste_retry_count = 0;
                            continue;
                        }
                    }
                }
            }
            finally
            {
                // Restore the screen updates
                repopulating_clusters           = false;
                word_application.ScreenUpdating = true;
                word_application.StatusBar      = "Updated InCite fields.";
            }
        }