예제 #1
0
        /// ------------------------------------------------------------------------------------
        public static bool MoveToRecycleBin(ComponentFile file, bool askForConfirmation)
        {
            var path = file.PathToAnnotatedFile;

            if (!File.Exists(path))
            {
                return(false);
            }

            var uiFileName = Path.GetFileName(path);

            if (file.HasSubordinateFiles)
            {
                uiFileName = String.Format(LocalizationManager.GetString(
                                               "CommonToMultipleViews.FileList.DeleteSubordinateFilesFormat",
                                               "{0} and subordinate files",
                                               "Used to format a string that will indicate that subordinate files (i.e., annotation files)" +
                                               " will also be moved to the recycle bin. Parameter is the name (without path) of the main file being deleted."), uiFileName);
            }
            if (askForConfirmation && !ConfirmRecycleDialog.JustConfirm(uiFileName, file.HasSubordinateFiles, ApplicationContainer.kSayMoreLocalizationId))
            {
                return(false);
            }

            return(file.Delete());
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        protected internal virtual bool Delete()
        {
            var annotationFile = GetAnnotationFile();

            if (PreDeleteAction != null)
            {
                PreDeleteAction();
            }

            var path = PathToAnnotatedFile;

            // Delete the underlying component file.
            if (!ConfirmRecycleDialog.Recycle(path))
            {
                return(false);
            }

            // Delete the file's metadata file.
            var metaPath = path + Settings.Default.MetadataFileExtension;

            if (File.Exists(metaPath))
            {
                ConfirmRecycleDialog.Recycle(metaPath);
            }

            if (annotationFile != null)
            {
                annotationFile.Delete();
            }

            return(true);
        }
예제 #3
0
        /// ------------------------------------------------------------------------------------
        protected bool RemoveItemFromFileSystem(T item)
        {
            if (item.FolderPath == "*mocked*")
            {
                return(true);
            }

            // Recycle only, since the user has already confirmed the delete by this time.
            return(ConfirmRecycleDialog.Recycle(item.FolderPath));
        }
예제 #4
0
        /// ------------------------------------------------------------------------------------
        protected virtual bool DoesUserConfirmDeletingSelectedElements()
        {
            int itemCount = _elementsGrid.SelectedRows.Count;

            var msg = LocalizationManager.GetString("MainWindow.DeleteOneItemMsg", "{0}", "For deleting sessions and people items");

            msg = (itemCount > 1 ? string.Format(msg, itemCount) :
                   string.Format(msg, _elementsGrid.GetCurrentElement().Id));

            return(ConfirmRecycleDialog.JustConfirm(msg, itemCount > 1, ApplicationContainer.kSayMoreLocalizationId));
        }
예제 #5
0
        public bool DeleteBook(Book.Book book, BookCollection collection = null)
        {
            if (collection == null)
            {
                collection = TheOneEditableCollection;
            }
            Debug.Assert(book.FolderPath == _bookSelection.CurrentSelection?.FolderPath);

            if (_bookSelection.CurrentSelection != null && _bookSelection.CurrentSelection.CanDelete)
            {
                if (IsCurrentBookInCollection())
                {
                    if (!_bookSelection.CurrentSelection.IsSaveable)
                    {
                        var msg = LocalizationManager.GetString("TeamCollection.CheckOutForDelete",
                                                                "Please check out the book before deleting it.");
                        ErrorReport.NotifyUserOfProblem(msg);
                        return(false);
                    }

                    if (_tcManager.CannotDeleteBecauseDisconnected(_bookSelection.CurrentSelection.FolderPath))
                    {
                        var msg = LocalizationManager.GetString("TeamCollection.ConnectForDelete",
                                                                "Please connect to the Team Collection before deleting books that are part of it.");
                        ErrorReport.NotifyUserOfProblem(msg);
                        return(false);
                    }
                }
                var bookName = _bookSelection.CurrentSelection.NameBestForUserDisplay;
                var confirmRecycleDescription = L10NSharp.LocalizationManager.GetString("CollectionTab.ConfirmRecycleDescription", "The book '{0}'");
                if (ConfirmRecycleDialog.JustConfirm(string.Format(confirmRecycleDescription, bookName), false, "Palaso"))
                {
                    // The sequence of these is a bit arbitrary. We'd like to delete the book in both places.
                    // Either could conceivably fail. If something goes wrong with removing the selection
                    // from it (very unlikely), we may as well leave nothing changed. If we delete it from
                    // the local collection but fail to delete it from the repo, it will come back at the
                    // next startup. If we delete it from the repo but fail to delete it locally,
                    // it will just stick around, and at least the desired team collection result has
                    // been achieved and the local result won't be a surprise later. So it seems marginally
                    // better to do them in this order.
                    _bookSelection.SelectBook(null);
                    if (collection == TheOneEditableCollection)
                    {
                        _tcManager.CurrentCollection?.DeleteBookFromRepo(book.FolderPath);
                    }
                    collection.DeleteBook(book.BookInfo);
                    return(true);
                }
            }
            return(false);
        }
예제 #6
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            HandleBookDeletedFromCollection(bookInfo.FolderPath);
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }
예제 #7
0
        public bool DeleteBook(Book.Book book)        //, BookCollection collection)
        {
            Debug.Assert(book == _bookSelection.CurrentSelection);

            if (_bookSelection.CurrentSelection != null && _bookSelection.CurrentSelection.CanDelete)
            {
                var title = _bookSelection.CurrentSelection.TitleBestForUserDisplay;
                var confirmRecycleDescription = L10NSharp.LocalizationManager.GetString("CollectionTab.ConfirmRecycleDescription", "The book '{0}'");
                if (ConfirmRecycleDialog.JustConfirm(string.Format(confirmRecycleDescription, title), false, "Palaso"))
                {
                    TheOneEditableCollection.DeleteBook(book.BookInfo);
                    _bookSelection.SelectBook(null);
                    _sendReceiver.CheckInNow(string.Format("Deleted '{0}'", title));
                    return(true);
                }
            }
            return(false);
        }
예제 #8
0
        /// ------------------------------------------------------------------------------------
        protected internal override bool Delete()
        {
            // If the annotation file has an associated ELAN preference file, then delete it.
            var prefFilePath       = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");
            var oralAnnotationFile = OralAnnotationFile;

            if (!base.Delete())
            {
                return(false);
            }

            if (File.Exists(prefFilePath))
            {
                ConfirmRecycleDialog.Recycle(prefFilePath);
            }

            if (oralAnnotationFile != null)
            {
                oralAnnotationFile.Delete();
                _oralAnnotationFile = null;
            }

            var           segmentAnnotationFileFolder = SegmentAnnotationFileFolder;
            DirectoryInfo dirInfo = new DirectoryInfo(segmentAnnotationFileFolder);

            if (dirInfo.Exists)
            {
                try
                {
                    foreach (FileInfo file in dirInfo.EnumerateFiles())
                    {
                        ConfirmRecycleDialog.Recycle(file.FullName);
                    }
                    Directory.Delete(segmentAnnotationFileFolder, true);
                }
                catch (Exception e)
                {
                    Logger.WriteEvent("Handled Exception in AnnotationComponentFile.Delete:\r\n{0}", e.ToString());
                }
            }

            return(true);
        }
예제 #9
0
        // Request from sign language tool to delete the selected video.
        private void HandleDeleteVideoRequest(ApiRequest request)
        {
            lock (request)
            {
                string    videoPath;
                decimal[] dummy;
                if (!GetVideoDetailsFromRequest(request, true, out videoPath, out dummy))
                {
                    return;                     // request.Failed was called inside the above method
                }
                var label = LocalizationManager.GetString("EditTab.Toolbox.SignLanguage.SelectedVideo", "The selected video", "Appears in the context \"X will be moved to the recycle bin\"");
                if (!ConfirmRecycleDialog.JustConfirm(label))
                {
                    request.ReplyWithText("canceled");
                    return;
                }

                ConfirmRecycleDialog.Recycle(videoPath);
                request.ReplyWithText("deleted");
            }
        }
예제 #10
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            //Debug.Assert(_bookInfos.Contains(bookInfo)); this will occur if we delete a book from the BloomLibrary section
            _bookInfos.Remove(bookInfo);

            if (CollectionChanged != null)
            {
                CollectionChanged.Invoke(this, null);
            }
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }
예제 #11
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            //ListOfBooksIsOutOfDate();
            Debug.Assert(_bookInfos.Contains(bookInfo));
            _bookInfos.Remove(bookInfo);

            if (CollectionChanged != null)
            {
                CollectionChanged.Invoke(this, null);
            }
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }