public delegate PublishView Factory(); //autofac uses this public PublishView(PublishModel model, SelectedTabChangedEvent selectedTabChangedEvent, LocalizationChangedEvent localizationChangedEvent, BookTransfer bookTransferrer, LoginDialog login, NavigationIsolator isolator, PublishToAndroidApi publishApi) { _bookTransferrer = bookTransferrer; _loginDialog = login; _isolator = isolator; _publishApi = publishApi; InitializeComponent(); if (this.DesignMode) { return; } _model = model; _model.View = this; _makePdfBackgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(_makePdfBackgroundWorker_RunWorkerCompleted); _pdfViewer.PrintProgress += new System.EventHandler <PdfPrintProgressEventArgs>(OnPrintProgress); // BL-625: With mono, if a RadioButton group has its AutoCheck properties set to true, the default RadioButton.OnEnter // event checks to make sure one of the RadioButtons is checked. If none are checked, the one the mouse pointer // is over is checked, causing the CheckChanged event to fire. if (SIL.PlatformUtilities.Platform.IsMono) { SetAutoCheck(false); } //NB: just triggering off "VisibilityChanged" was unreliable. So now we trigger //off the tab itself changing, either to us or away from us. selectedTabChangedEvent.Subscribe(c => { if (c.To == this) { Activate(); } else if (c.To != this) { Deactivate(); } }); //TODO: find a way to call this just once, at the right time: // DeskAnalytics.Track("Publish"); //#if DEBUG // var linkLabel = new LinkLabel() {Text = "DEBUG"}; // linkLabel.Click+=new EventHandler((x,y)=>_model.DebugCurrentPDFLayout()); // tableLayoutPanel1.Controls.Add(linkLabel); //#endif if (SIL.PlatformUtilities.Platform.IsMono) { BackgroundColorsForLinux(); } // Adding this renderer prevents a white line from showing up under the components. _menusToolStrip.Renderer = new EditingView.FixedToolStripRenderer(); // As far as I can tell, this is not needed anymore, and its presence, // at least in this place in the code, causes errors when running command-line tools // like UploadCommand which needs a PublishView but must not have something fully initialized. //GeckoPreferences.Default["pdfjs.disabled"] = false; SetupLocalization(); localizationChangedEvent.Subscribe(o => { SetupLocalization(); UpdateLayoutChoiceLabels(); UpdateSaveButton(); }); // Make this extra box available to show when wanted. _previewBox = new PictureBox(); _previewBox.Visible = false; Controls.Add(_previewBox); _previewBox.BringToFront(); _electronicPublishView = new ElectronicPublishView(_model); }
public void SetDisplayMode(PublishModel.DisplayModes displayMode) { // This is only supposed to be active in one mode of PublishView. Browser.SuppressJavaScriptErrors = false; if (displayMode != PublishModel.DisplayModes.Upload && _publishControl != null) { Controls.Remove(_publishControl); _publishControl = null; } if (displayMode != PublishModel.DisplayModes.EPUB && _epubPreviewControl != null && Controls.Contains(_epubPreviewControl)) { Controls.Remove(_epubPreviewControl); } if (displayMode != PublishModel.DisplayModes.Android && _androidControl != null && Controls.Contains(_androidControl)) { Controls.Remove(_androidControl); // disposal of the browser is good but it hides a multitude of sins that we'd rather catch and fix during development. E.g. BL-4901 if (!ApplicationUpdateSupport.IsDevOrAlpha) { _androidControl.Dispose(); _androidControl = null; } } if (displayMode != PublishModel.DisplayModes.Upload && displayMode != PublishModel.DisplayModes.EPUB && displayMode != PublishModel.DisplayModes.Android) { _pdfViewer.Visible = true; } switch (displayMode) { case PublishModel.DisplayModes.WaitForUserToChooseSomething: _printButton.Enabled = _saveButton.Enabled = false; Cursor = Cursors.Default; _workingIndicator.Visible = false; _pdfViewer.Visible = false; break; case PublishModel.DisplayModes.Working: _printButton.Enabled = _saveButton.Enabled = false; _workingIndicator.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor; _workingIndicator.Visible = true; _pdfViewer.Visible = false; break; case PublishModel.DisplayModes.ShowPdf: Logger.WriteEvent("Entering Publish PDF Screen"); if (RobustFile.Exists(_model.PdfFilePath)) { _pdfViewer.Visible = true; _workingIndicator.Visible = false; Cursor = Cursors.Default; _saveButton.Enabled = true; _printButton.Enabled = _pdfViewer.ShowPdf(_model.PdfFilePath); } break; case PublishModel.DisplayModes.Printing: _simpleAllPagesRadio.Enabled = false; _bookletCoverRadio.Enabled = false; _bookletBodyRadio.Enabled = false; _printButton.Enabled = _saveButton.Enabled = false; _workingIndicator.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor; _workingIndicator.Visible = true; break; case PublishModel.DisplayModes.ResumeAfterPrint: _simpleAllPagesRadio.Enabled = true; _pdfViewer.Visible = true; _workingIndicator.Visible = false; Cursor = Cursors.Default; _saveButton.Enabled = true; _printButton.Enabled = true; break; case PublishModel.DisplayModes.Upload: { Logger.WriteEvent("Entering Publish Upload Screen"); _workingIndicator.Visible = false; // If we haven't finished creating the PDF, we will indicate that in the progress window. _saveButton.Enabled = _printButton.Enabled = false; // Can't print or save in this mode...wouldn't be obvious what would be saved. _pdfViewer.Visible = false; Cursor = Cursors.Default; if (_publishControl == null) { SetupPublishControl(); } break; } case PublishModel.DisplayModes.EPUB: { Logger.WriteEvent("Entering Publish Epub Screen"); // We may reuse this for the process of generating the ePUB staging files. For now, skip it. _workingIndicator.Visible = false; _printButton.Enabled = false; // don't know how to print an ePUB _pdfViewer.Visible = false; Cursor = Cursors.WaitCursor; _epubPreviewControl = ElectronicPublishView.SetupEpubControl(_epubPreviewControl, _isolator, () => _saveButton.Enabled = _model.EpubMaker.ReadyToSave()); _epubPreviewControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top, _pdfViewer.Width, _pdfViewer.Height); _epubPreviewControl.Dock = _pdfViewer.Dock; _epubPreviewControl.Anchor = _pdfViewer.Anchor; var saveBackGround = _epubPreviewControl.BackColor; // changed to match parent during next statement Controls.Add(_epubPreviewControl); _epubPreviewControl.BackColor = saveBackGround; // keep own color. // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work. _epubPreviewControl.BringToFront(); Cursor = Cursors.Default; // We rather mangled the Readium code in the process of cutting away its own navigation // and other controls. It produces all kinds of JavaScript errors, but it seems to do // what we want. So just suppress the toasts for all of them. Browser.SuppressJavaScriptErrors = true; break; } case PublishModel.DisplayModes.Android: { Logger.WriteEvent("Entering Publish Android Screen"); _workingIndicator.Visible = false; _printButton.Enabled = false; _pdfViewer.Visible = false; Cursor = Cursors.WaitCursor; _androidControl = new AndroidView(_isolator); _androidControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top, _pdfViewer.Width, _pdfViewer.Height); _androidControl.Dock = _pdfViewer.Dock; _androidControl.Anchor = _pdfViewer.Anchor; var saveBackGround = _androidControl.BackColor; // changed to match parent during next statement Controls.Add(_androidControl); _androidControl.BackColor = saveBackGround; // keep own color. // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work. _androidControl.BringToFront(); Cursor = Cursors.Default; break; } } UpdateSaveButton(); }
public void SetDisplayMode(PublishModel.DisplayModes displayMode) { if (displayMode != PublishModel.DisplayModes.Upload && _publishControl != null) { Controls.Remove(_publishControl); _publishControl = null; } if (displayMode != PublishModel.DisplayModes.EPUB && _epubPreviewControl != null && Controls.Contains(_epubPreviewControl)) { Controls.Remove(_epubPreviewControl); } if (displayMode != PublishModel.DisplayModes.Upload && displayMode != PublishModel.DisplayModes.EPUB) { _pdfViewer.Visible = true; } switch (displayMode) { case PublishModel.DisplayModes.WaitForUserToChooseSomething: _printButton.Enabled = _saveButton.Enabled = false; Cursor = Cursors.Default; _workingIndicator.Visible = false; _pdfViewer.Visible = false; break; case PublishModel.DisplayModes.Working: _printButton.Enabled = _saveButton.Enabled = false; _workingIndicator.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor; _workingIndicator.Visible = true; _pdfViewer.Visible = false; break; case PublishModel.DisplayModes.ShowPdf: if (RobustFile.Exists(_model.PdfFilePath)) { _pdfViewer.Visible = true; _workingIndicator.Visible = false; Cursor = Cursors.Default; _saveButton.Enabled = true; _printButton.Enabled = _pdfViewer.ShowPdf(_model.PdfFilePath); } break; case PublishModel.DisplayModes.Printing: _simpleAllPagesRadio.Enabled = false; _bookletCoverRadio.Enabled = false; _bookletBodyRadio.Enabled = false; _printButton.Enabled = _saveButton.Enabled = false; _workingIndicator.Cursor = Cursors.WaitCursor; Cursor = Cursors.WaitCursor; _workingIndicator.Visible = true; break; case PublishModel.DisplayModes.ResumeAfterPrint: _simpleAllPagesRadio.Enabled = true; _pdfViewer.Visible = true; _workingIndicator.Visible = false; Cursor = Cursors.Default; _saveButton.Enabled = true; _printButton.Enabled = true; break; case PublishModel.DisplayModes.Upload: { _workingIndicator.Visible = false; // If we haven't finished creating the PDF, we will indicate that in the progress window. _saveButton.Enabled = _printButton.Enabled = false; // Can't print or save in this mode...wouldn't be obvious what would be saved. _pdfViewer.Visible = false; Cursor = Cursors.Default; if (_publishControl == null) { SetupPublishControl(); } break; } case PublishModel.DisplayModes.EPUB: { // We may reuse this for the process of generating the ePUB staging files. For now, skip it. _workingIndicator.Visible = false; _printButton.Enabled = false; // don't know how to print an ePUB _pdfViewer.Visible = false; Cursor = Cursors.WaitCursor; _epubPreviewControl = ElectronicPublishView.SetupEpubControl(_epubPreviewControl, _isolator, () => _saveButton.Enabled = _model.EpubMaker.ReadyToSave()); _saveButton.Enabled = _model.EpubMaker.ReadyToSave(); _epubPreviewControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top, _pdfViewer.Width, _pdfViewer.Height); _epubPreviewControl.Dock = _pdfViewer.Dock; _epubPreviewControl.Anchor = _pdfViewer.Anchor; var saveBackGround = _epubPreviewControl.BackColor; // changed to match parent during next statement Controls.Add(_epubPreviewControl); _epubPreviewControl.BackColor = saveBackGround; // keep own color. // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work. _epubPreviewControl.BringToFront(); Cursor = Cursors.Default; break; } } UpdateSaveButton(); }