예제 #1
0
        private void DoSelectAllText()
        {
            // Check if we have any text or can get it automatically
            if (!CanPerformTextOperation("No text to select", true))
            {
                return;
            }

            //if (!_documentViewer.Text.HasDocumentPageText(0) && !
            //message = Helper.AddTextNote(message);

            var isSlow = _documentViewer.Commands.IsSlow(DocumentViewerCommands.TextSelectAll, 0);

            if (isSlow)
            {
                this.BeginBusyOperation();
            }

            var thisOperation = new DocumentViewerAsyncOperation
            {
                Error = (DocumentViewerAsyncOperation operation, Exception error) =>
                {
                    UI.Helper.ShowError(this, error);
                },
                Always = (DocumentViewerAsyncOperation operation) =>
                {
                    if (isSlow)
                    {
                        this.EndBusyOperation();
                    }
                }
            };

            _documentViewer.Commands.RunAsync(thisOperation, DocumentViewerCommands.TextSelectAll, 0);
        }
예제 #2
0
        private void FindNextPrevious(bool findNext)
        {
            var commandName = findNext ? DocumentViewerCommands.TextFindNext : DocumentViewerCommands.TextFindPrevious;
            var isSlow      = _documentViewer.Commands.IsSlow(commandName, 0);

            if (isSlow)
            {
                this.BeginBusyOperation();
            }

            var thisOperation = new DocumentViewerAsyncOperation
            {
                Error = (DocumentViewerAsyncOperation operation, Exception error) =>
                {
                    UI.Helper.ShowError(this, error);
                },
                Always = (DocumentViewerAsyncOperation operation) =>
                {
                    if (isSlow)
                    {
                        this.EndBusyOperation();
                    }
                }
            };

            _documentViewer.Commands.RunAsync(thisOperation, commandName, null);
        }
예제 #3
0
        private void getTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var thisOperation = new DocumentViewerAsyncOperation
            {
                Error = (DocumentViewerAsyncOperation operation, Exception error) =>
                {
                    MessageBox.Show(error.Message);
                },
                Always = (DocumentViewerAsyncOperation operation) =>
                {
                    MessageBox.Show("DONE!");
                }
            };

            _documentViewer.Commands.RunAsync(thisOperation, DocumentViewerCommands.TextGet, _documentViewer.CurrentPageNumber);
        }
예제 #4
0
        private void GetPagesText(int pageNumber)
        {
            // This could take some time, so run it as a busy operation
            this.BeginBusyOperation();

            var thisOperation = new DocumentViewerAsyncOperation
            {
                Error = (DocumentViewerAsyncOperation operation, Exception error) =>
                {
                    UI.Helper.ShowError(this, error);
                },
                Always = (DocumentViewerAsyncOperation operation) =>
                {
                    this.EndBusyOperation();
                }
            };

            _documentViewer.Commands.RunAsync(thisOperation, DocumentViewerCommands.TextGet, pageNumber);
        }
예제 #5
0
        private void _exportTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Check if we have any text or can get it automatically
            if (!CanPerformTextOperation("No text to export", true))
            {
                return;
            }

            int pageNumber = 1;
            int pageCount  = _documentViewer.PageCount;

            if (pageNumber > pageCount)
            {
                pageNumber = pageCount;
            }

            if (pageCount > 1)
            {
                using (var dlg = new UI.PagesDialog())
                {
                    dlg.Operation       = "Export Text";
                    dlg.PageCount       = _documentViewer.PageCount;
                    dlg.FirstPageNumber = _documentViewer.CurrentPageNumber;
                    dlg.SinglePageMode  = true;
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }

                    // Single page mode, either .FirstPageNumber == .LastPageNumber meaning all pages or get it from .FirstPageNumber
                    if (dlg.FirstPageNumber == 1 && dlg.LastPageNumber == _documentViewer.PageCount)
                    {
                        pageNumber = 0; // 0 means all pages
                    }
                    else
                    {
                        pageNumber = dlg.FirstPageNumber;
                    }
                }
            }

            var isSlow = _documentViewer.Commands.IsSlow(DocumentViewerCommands.TextExport, pageNumber);

            if (isSlow)
            {
                this.BeginBusyOperation();
            }

            var thisOperation = new DocumentViewerAsyncOperation <object>
            {
                Done = (DocumentViewerAsyncOperation <object> operation) =>
                {
                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        var text = operation.Result as string;
                        if (text != null)
                        {
                            using (var dlg = new UI.ExportTextDialog(text))
                            {
                                dlg.ShowDialog(this);
                            }
                        }
                        else
                        {
                            UI.Helper.ShowInformation(this, "This document does not contain any text");
                        }
                    });
                },
                Error = (DocumentViewerAsyncOperation <object> operation, Exception error) =>
                {
                    UI.Helper.ShowError(this, error);
                },
                Always = (DocumentViewerAsyncOperation <object> operation) =>
                {
                    if (isSlow)
                    {
                        this.EndBusyOperation();
                    }
                }
            };

            _documentViewer.Commands.RunAsync(thisOperation, DocumentViewerCommands.TextExport, pageNumber);
        }