예제 #1
0
	def _trash_page(self, path):
		from zim.newfs.helpers import TrashHelper

		logger.debug('Trash page: %s', path)

		if self.config['Notebook']['disable_trash']:
			raise TrashNotSupportedError('disable_trash is set')

		self.emit('delete-page', path)

		file, folder = self.layout.map_page(path)
		helper = TrashHelper()

		re = False
		if folder.exists():
			re = helper.trash(folder)
			if isinstance(path, Page):
				path.haschildren = False

		if file.exists():
			re = helper.trash(file) or re

		self.index.update_file(file)
		self.index.update_file(folder)

		return re
예제 #2
0
    def on_delete(self, *a):
        # Only delete custom, may result in reset to default
        custom, default = self.view.get_selected()
        if custom is None or not custom.exists():
            return  # Should not have been sensitive

        try:
            TrashHelper().trash(LocalFile(custom.path))
        except TrashNotSupportedError:
            # TODO warnings
            custom.remove()

        self.view.refresh()
def delete_file(widget, file):
	'''Delete a file

	@param widget: parent for new dialogs, C{Gtk.Widget} or C{None}
	@param file: a L{File} object

	@raises FileNotFoundError: if C{file} does not exist
	'''
	logger.debug('delete_file(%s)', file)
	file = localFileOrFolder(file)
	assert isinstance(file, LocalFile) and not isinstance(file, LocalFolder)

	if not file.exists():
		raise FileNotFoundError(file)

	dialog = QuestionDialog(widget, _('Are you sure you want to delete the file \'%s\'?') % file.basename)
		# T: text in confirmation dialog on deleting a file
	if dialog.run():
		TrashHelper().trash(file)
예제 #4
0
    def runTest(self):
        root = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
        helper = TrashHelper()

        file = root.file('test.txt')
        file.touch()
        self.assertTrue(file.exists())
        self.assertTrue(helper.trash(file))
        self.assertFalse(file.exists())

        dir = root.folder('test')
        dir.touch()
        self.assertTrue(dir.exists())
        self.assertTrue(helper.trash(dir))
        self.assertFalse(dir.exists())

        # fails silent if file does not exist
        self.assertFalse(helper.trash(file))
        self.assertFalse(helper.trash(dir))
예제 #5
0
    def runTest(self):
        root = LocalFolder(self.create_tmp_dir())
        helper = TrashHelper()

        file = root.file('test.txt')
        file.touch()
        self.assertTrue(file.exists())
        self.assertTrue(helper.trash(file))
        self.assertFalse(file.exists())

        dir = root.folder('test')
        dir.touch()
        self.assertTrue(dir.exists())
        self.assertTrue(helper.trash(dir))
        self.assertFalse(dir.exists())

        # fails silent if file does not exist
        self.assertFalse(helper.trash(file))
        self.assertFalse(helper.trash(dir))