예제 #1
0
        private void HandleChooseWidget(ApiRequest request)
        {
            if (!View.Model.CanChangeImages())
            {
                // Enhance: more widget-specific message?
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked",
                                                  "Sorry, this book is locked down so that images cannot be changed."));
                request.ReplyWithText("");
                return;
            }

            var fileType = ".wdgt";
            var dlg      = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect     = false,
                CheckFileExists = true,
                Filter          = $"{fileType} files|*{fileType}"
            };
            var result = dlg.ShowDialog();

            if (result != DialogResult.OK)
            {
                request.ReplyWithText("");
                return;
            }

            var    fullWidgetPath = dlg.FileName;
            string activityName   = View.Model.MakeActivity(fullWidgetPath);
            var    url            = UrlPathString.CreateFromUnencodedString(activityName);

            request.ReplyWithText(url.UrlEncodedForHttpPath);
        }
예제 #2
0
 private void _fileChooserButton_Click(object sender, System.EventArgs e)
 {
     try
     {
         using (var dlg = new DialogAdapters.OpenFileDialogAdapter
         {
             Multiselect = false,
             CheckFileExists = true
         })
         {
             var result = dlg.ShowDialog();
             if (result == DialogResult.OK)
             {
                 _fileChosenLabel.Text = @"SELECTED FILE = " + dlg.FileName.Replace("\\", "/");
             }
             else
             {
                 _fileChosenLabel.Text = @"NO FILE SELECTED";
             }
         }
     }
     catch (Exception ex)
     {
         _fileChosenLabel.Text = @"CRASH! " + ex.Message;
         Console.WriteLine("CRASH: {0}", ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
예제 #3
0
        // Request from sign language tool to import a video.
        private void HandleImportVideoRequest(ApiRequest request)
        {
            string path = null;

            View.Invoke((Action)(() => {
                var videoFiles = LocalizationManager.GetString("EditTab.Toolbox.SignLanguage.FileDialogVideoFiles", "Video files");
                var dlg = new DialogAdapters.OpenFileDialogAdapter
                {
                    Multiselect = false,
                    CheckFileExists = true,
                    Filter = $"{videoFiles} (*.mp4)|*.mp4"
                };
                var result = dlg.ShowDialog();
                if (result == DialogResult.OK)
                {
                    path = dlg.FileName;
                }
            }));
            if (!string.IsNullOrEmpty(path))
            {
                _importedVideoIntoBloom = true;
                var newVideoPath = Path.Combine(BookStorage.GetVideoDirectoryAndEnsureExistence(CurrentBook.FolderPath), GetNewVideoFileName());                 // Use a new name to defeat caching.
                RobustFile.Copy(path, newVideoPath);
                var relativePath = BookStorage.GetVideoFolderName + Path.GetFileName(newVideoPath);
                request.ReplyWithText(UrlPathString.CreateFromUnencodedString(relativePath).UrlEncodedForHttpPath);
            }
            else
            {
                // If the user canceled, we didn't exactly succeed, but having the user cancel is such a normal
                // event that posting a failure, which is a nuisance to ignore, is not warranted.
                request.ReplyWithText("");
            }
        }
예제 #4
0
        private string ShowSelectAllowedWordsFileDialog()
        {
            var returnVal = "";

            var destPath = Path.Combine(Path.GetDirectoryName(CurrentBook.CollectionSettings.SettingsFilePath), "Allowed Words");

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            var textFiles = LocalizationManager.GetString("EditTab.Toolbox.DecodableReaderTool.FileDialogTextFiles", "Text files");
            var dlg       = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect     = false,
                CheckFileExists = true,
                Filter          = String.Format("{0} (*.txt;*.csv;*.tab)|*.txt;*.csv;*.tab", textFiles)
            };
            var result = dlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                var srcFile  = dlg.FileName;
                var destFile = Path.GetFileName(srcFile);
                if (destFile != null)
                {
                    // if file is in the "Allowed Words" directory, do not try to copy it again.
                    if (Path.GetFullPath(srcFile) != Path.Combine(destPath, destFile))
                    {
                        var i = 0;

                        // get a unique destination file name
                        while (RobustFile.Exists(Path.Combine(destPath, destFile)))
                        {
                            destFile = Path.GetFileName(srcFile);
                            var fileExt = Path.GetExtension(srcFile);
                            destFile = destFile.Substring(0, destFile.Length - fileExt.Length) + " - Copy";
                            if (++i > 1)
                            {
                                destFile += " " + i;
                            }
                            destFile += fileExt;
                        }

                        RobustFile.Copy(srcFile, Path.Combine(destPath, destFile));
                    }

                    returnVal = destFile;
                }
            }

            return(returnVal);
        }
예제 #5
0
        private string SelectFileUsingDialog()
        {
            var fileType = ".mp3";
            var dlg      = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect     = false,
                CheckFileExists = true,
                Filter          = $"{fileType} files|*{fileType}"
            };
            var result = dlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                return(dlg.FileName.Replace("\\", "/"));
            }

            return(String.Empty);
        }
예제 #6
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);
            }
        }
예제 #7
0
        private void HandleChooseWidget(ApiRequest request)
        {
            if (!View.Model.CanChangeImages())
            {
                // Enhance: more widget-specific message?
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked",
                                                  "Sorry, this book is locked down so that images cannot be changed."));
                request.ReplyWithText("");
                return;
            }

            using (var dlg = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect = false,
                CheckFileExists = true,
                Filter = "Widget files|*.wdgt;*.html;*.htm"
            })
            {
                var result = dlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    request.ReplyWithText("");
                    return;
                }

                var fullWidgetPath = dlg.FileName;
                var ext            = Path.GetExtension(fullWidgetPath);
                if (ext.EndsWith("htm") || ext.EndsWith("html"))
                {
                    fullWidgetPath = EditingModel.CreateWidgetFromHtmlFolder(fullWidgetPath);
                }
                string activityName = View.Model.MakeWidget(fullWidgetPath);
                var    url          = UrlPathString.CreateFromUnencodedString(activityName);
                request.ReplyWithText(url.UrlEncodedForHttpPath);
                // clean up the temporary widget file we created.
                if (fullWidgetPath != dlg.FileName)
                {
                    RobustFile.Delete(fullWidgetPath);
                }
            }
        }
예제 #8
0
        private string SelectFileUsingDialog()
        {
            var fileType = ".mp3";
            var dlg      = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect     = false,
                CheckFileExists = true,
                Filter          = $"{fileType} files|*{fileType}"
            };
            var result = dlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                // We are not trying get a memory or time diff, just a point measure.
                PerformanceMeasurement.Global.Measure("Choose file", dlg.FileName)?.Dispose();

                return(dlg.FileName.Replace("\\", "/"));
            }


            return(String.Empty);
        }
예제 #9
0
        private void OnBrowseForExistingLibraryClick(object sender, EventArgs e)
        {
            if (!Directory.Exists(NewCollectionWizard.DefaultParentDirectoryForCollections))
            {
                Directory.CreateDirectory(NewCollectionWizard.DefaultParentDirectoryForCollections);
            }

            using (var dlg = new DialogAdapters.OpenFileDialogAdapter())
            {
                dlg.Title = "Open Collection";

                dlg.Filter           = _filterString;
                dlg.InitialDirectory = NewCollectionWizard.DefaultParentDirectoryForCollections;
                dlg.CheckFileExists  = true;
                dlg.CheckPathExists  = true;
                if (dlg.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                SelectCollectionAndClose(dlg.FileName);
            }
        }
예제 #10
0
        private string ShowSelectMusicFile()
        {
            var returnVal = "";

            var destPath = Path.Combine(CurrentBook.FolderPath, "audio");

            if (!Directory.Exists(destPath))
            {
                Directory.CreateDirectory(destPath);
            }

            var soundFiles = LocalizationManager.GetString("EditTab.Toolbox.Music.FileDialogSoundFiles", "Sound files");
            var dlg        = new DialogAdapters.OpenFileDialogAdapter
            {
                Multiselect     = false,
                CheckFileExists = true,
                Filter          = $"{soundFiles} {BuildFileFilter()}"
            };
            var result = dlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                var srcFile  = dlg.FileName;
                var destFile = Path.GetFileName(srcFile);
                if (destFile != null)
                {
                    if (IsInvalidMp3File(srcFile))
                    {
                        var badMp3File = LocalizationManager.GetString("EditTab.Toolbox.Music.InvalidMp3File",
                                                                       "The selected sound file \"{0}\" cannot be played by Bloom.  Please choose another sound file.",
                                                                       "The {0} is replaced by the filename.");
                        var badMp3Title = LocalizationManager.GetString("EditTab.Toolbox.Music.InvalidMp3FileTitle",
                                                                        "Choose Another Sound File", "Title for a message box");
                        MessageBox.Show(String.Format(badMp3File, destFile), badMp3Title,
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(String.Empty);
                    }
                    // if file is already in the desired directory, do not try to copy it again.
                    if (Path.GetFullPath(srcFile) != Path.Combine(destPath, destFile))
                    {
                        var i = 0;

                        // get a unique destination file name
                        while (RobustFile.Exists(Path.Combine(destPath, destFile)))
                        {
                            // Enhance: if the file in the destination directory already has the required contents,
                            // we can just return this name.
                            destFile = Path.GetFileName(srcFile);
                            var fileExt = Path.GetExtension(srcFile);
                            destFile = destFile.Substring(0, destFile.Length - fileExt.Length) + " - Copy";
                            if (++i > 1)
                            {
                                destFile += " " + i;
                            }
                            destFile += fileExt;
                        }

                        RobustFile.Copy(srcFile, Path.Combine(destPath, destFile));
                    }

                    returnVal = destFile;
                }
            }

            return(returnVal);
        }