コード例 #1
0
 // Called when we cause the book's status to change, so things outside the HTML world, like visibility of the
 // "Edit this book" button, can change appropriately. Pretending the user chose a different book seems to
 // do all the necessary stuff for now.
 private void UpdateUiForBook(bool reloadFromDisk = false, string renamedTo = null)
 {
     // Todo: This is not how we want to do this. Probably the UI should listen for changes to the status of books,
     // whether selected or not, talking to the repo directly.
     if (Form.ActiveForm == null)
     {
         // On Linux (at least for Bionic), Form.ActiveForm can sometimes be null when
         // this executes.  The following loop seems to be as simple a fix as possible.
         foreach (var form in Application.OpenForms)
         {
             if (form is Shell shell)
             {
                 shell.Invoke((Action)(() => _bookSelection.InvokeSelectionChanged(false)));
                 return;
             }
         }
     }
     Form.ActiveForm.Invoke((Action)(() =>
     {
         if (reloadFromDisk)
         {
             _bookSelection.CurrentSelection.ReloadFromDisk(renamedTo);
         }
         _bookSelection.InvokeSelectionChanged(false);
     }));
 }
コード例 #2
0
        /// <summary>
        /// This is our primary entry point for importing from a spreadsheet. There is also a CLI command,
        /// but we shouldn't need that one much, now that we have this on our book thumb context menus.
        /// </summary>
        public void HandleImportContentFromSpreadsheet(Book.Book book)
        {
            if (!_collectionModel.CollectionSettings.HaveEnterpriseFeatures)
            {
                Enterprise.ShowRequiresEnterpriseNotice(Form.ActiveForm, "Import to Spreadsheet");
                return;
            }

            var bookPath = book.GetPathHtmlFile();

            try
            {
                string inputFilepath;
                using (var dlg = new DialogAdapters.OpenFileDialogAdapter())
                {
                    dlg.Filter           = "xlsx|*.xlsx";
                    dlg.RestoreDirectory = true;
                    dlg.InitialDirectory = GetSpreadsheetFolderFor(book, false);
                    if (DialogResult.Cancel == dlg.ShowDialog())
                    {
                        return;
                    }
                    inputFilepath = dlg.FileName;
                    var spreadsheetFolder = Path.GetDirectoryName(inputFilepath);
                    SetSpreadsheetFolder(book, spreadsheetFolder);
                }

                var importer = new SpreadsheetImporter(_webSocketServer, book, Path.GetDirectoryName(inputFilepath));
                importer.ImportWithProgress(inputFilepath);

                // The importer now does BringBookUpToDate() which accomplishes everything this did,
                // plus it may have actually changed the folder (and subsequent 'bookPath')
                // due to a newly imported title. That would cause this call to fail.
                //XmlHtmlConverter.SaveDOMAsHtml5(book.OurHtmlDom.RawDom, bookPath);
                book.ReloadFromDisk(null);
                BookHistory.AddEvent(book, TeamCollection.BookHistoryEventType.ImportSpreadsheet);
                _bookSelection.InvokeSelectionChanged(false);
            }
            catch (Exception ex)
            {
                var msg = LocalizationManager.GetString("Spreadsheet:ImportFailed", "Import failed: ");
                NonFatalProblem.Report(ModalIf.All, PassiveIf.None, msg + ex.Message, exception: ex, showSendReport: false);
            }
        }