def showAlreadyExistsDialog(self): """ Show a warning dialog if the item already exists on save. :rtype: None """ if not self.libraryWindow(): raise ItemSaveError("Item already exists!") path = self.path() title = "Item already exists" text = 'Would you like to move the existing item "{}" to the trash?' text = text.format(self.name()) buttons = QtWidgets.QMessageBox.Yes | \ QtWidgets.QMessageBox.Cancel try: QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.ArrowCursor) button = self.libraryWindow().showQuestionDialog( title, text, buttons) finally: QtWidgets.QApplication.restoreOverrideCursor() if button == QtWidgets.QMessageBox.Yes: library = self.library() item = studiolibrary.LibraryItem(path, library=library) self.libraryWindow().moveItemsToTrash([item]) self.setPath(path) else: raise ItemSaveError("You cannot save over an existing item.") return button
def showAlreadyExistsDialog(self): """ Show a warning dialog if the item already exists on save. :rtype: None """ if not self.libraryWidget(): raise ItemSaveError("Item already exists!") path = self.path() title = "Item already exists" text = 'Would you like to move the existing item "{}" to the trash?' text = text.format(self.name()) button = self.libraryWidget().showQuestionDialog(title, text) if button == QtWidgets.QMessageBox.Yes: self.libraryWidget().moveItemsToTrash( [studiolibrary.LibraryItem(path)]) elif button == QtWidgets.QMessageBox.Cancel: raise ItemSaveError("Saving was canceled.") elif button != QtWidgets.QMessageBox.Yes: raise ItemSaveError("You cannot save over an existing item.") self.setPath(path)
def _moveToTrash(self): """ Move the current item to the trash. This method should only be used when saving. """ path = self.path() library = self.library() item = studiolibrary.LibraryItem(path, library=library) self.libraryWindow().moveItemsToTrash([item])