# Path: sunflower/operation.py
# class RenameOperation(Operation):
# 	"""Thread used for rename of large number of files"""
# 
# 	def __init__(self, application, provider, path, file_list):
# 		Operation.__init__(self, application, provider)
# 
# 		self._destination = provider
# 		self._destination_path = path
# 		self._source_path = path
# 		self._file_list = file_list
# 
# 	def _create_dialog(self):
# 		"""Create operation dialog"""
# 		self._dialog = RenameDialog(self._application, self)
# 
# 	def _rename_path(self, old_name, new_name, index):
# 		"""Rename specified path"""
# 		can_procede = True
# 
# 		try:
# 			# check if specified path already exists
# 			if self._destination.exists(new_name, relative_to=self._source_path):
# 				can_procede, options = self._get_overwrite_input(new_name)
# 
# 				# get new name if user specified
# 				if options[OverwriteOption.RENAME]:
# 					new_name = os.path.join(
# 					                    os.path.dirname(new_name),
# 					                    options[OverwriteOption.NEW_NAME]
# 					                )
# 
# 			if not can_procede:
# 				# user canceled overwrite, skip the file
# 				self._file_list.pop(index)
# 				return
# 
# 			else:
# 				# rename path
# 				self._source.rename_path(old_name, new_name, relative_to=self._source_path)
# 
# 				# push event to the queue
# 				if self._source_queue is not None:
# 					delete_event = (MonitorSignals.DELETE, old_name, None)
# 					create_event = (MonitorSignals.CREATED, new_name, None)
# 
# 					self._source_queue.put(delete_event, False)
# 					self._source_queue.put(create_event, False)
# 
# 		except Exception as error:
# 			# problem renaming path, ask user what to do
# 			if Skip.RENAME in self._response_cache:
# 				response = self._response_cache[Skip.RENAME]
# 			else:
# 				response = self._get_rename_error_input(error)
# 
# 			# try renaming path again
# 			if response == OperationError.RESPONSE_RETRY:
# 				self._remove_path(old_name, new_name, index)
# 
# 			else:
# 				# user didn't want to retry, remove path from list
# 				self._file_list.pop(index)
# 
# 	def run(self):
# 		"""Main thread method, this is where all the stuff is happening"""
# 		# wait for operation queue if needed
# 		if self._operation_queue is not None:
# 			self._operation_queue.wait()
# 
# 		for index, item in enumerate(self._file_list, 1):
# 			if self._abort.is_set(): break  # abort operation if requested
# 			self._can_continue.wait()  # pause lock
# 
# 			GObject.idle_add(self._dialog.set_current_file, item[0])
# 			self._rename_path(item[0], item[1], index-1)
# 
# 			# update current count
# 			if len(self._file_list) > 0:
# 				GObject.idle_add(
# 							self._dialog.set_current_file_fraction,
# 							float(index) / len(self._file_list)
# 						)
# 
# 			else:
# 				# prevent division by zero
# 				GObject.idle_add(self._dialog.set_current_file_fraction, 1)
# 
# 		# notify user if window is not focused
# 		def notify_is_not_focused():
# 			if not self._dialog.is_active() and not self._application.is_active() and not self._abort.is_set():
# 				notify_manager = self._application.notification_manager
# 
# 				title = _('Rename Operation')
# 				message = ngettext(
# 								'Rename of {0} item from "{1}" is completed!',
# 								'Rename of {0} items from "{1}" is completed!',
# 								len(self._file_list)
# 							).format(
# 				        len(self._file_list),
# 				        os.path.basename(self._source_path)
# 				    )
# 
# 				# queue notification
# 				notify_manager.notify(title, message)
# 
# 		GObject.idle_add(notify_is_not_focused)
# 
# 		# destroy dialog
# 		self._destroy_ui()
# 
# 		# start next operation
# 		if self._operation_queue is not None:
# 			OperationQueue.start_next(self._operation_queue_name)


import os
from gi.repository import Gtk, Gdk
from sunflower.operation import RenameOperation

			# store new name to list
			row[Column.NEW_NAME] = new_name

	def rename_files(self, widget=None, data=None):
		"""Rename selected files"""
		dialog = Gtk.MessageDialog(
								self.window,
								Gtk.DialogFlags.DESTROY_WITH_PARENT,
								Gtk.MessageType.QUESTION,
								Gtk.ButtonsType.YES_NO,
								ngettext(
									"You are about to rename {0} item.\n"
									"Are you sure about this?",
									"You are about to rename {0} items.\n"
									"Are you sure about this?",
									len(self._list)
								).format(len(self._list))
							)
		dialog.set_default_response(Gtk.ResponseType.YES)
		result = dialog.run()
		dialog.destroy()

		if result == Gtk.ResponseType.YES:
			# user confirmed rename
			item_list = []
			for item in self._list:
				item_list.append((item[Column.OLD_NAME], item[Column.NEW_NAME]))

			# create thread and start operation

# Path: sunflower/operation.py
# class RenameOperation(Operation):
# 	"""Thread used for rename of large number of files"""
# 
# 	def __init__(self, application, provider, path, file_list):
# 		Operation.__init__(self, application, provider)
# 
# 		self._destination = provider
# 		self._destination_path = path
# 		self._source_path = path
# 		self._file_list = file_list
# 
# 	def _create_dialog(self):
# 		"""Create operation dialog"""
# 		self._dialog = RenameDialog(self._application, self)
# 
# 	def _rename_path(self, old_name, new_name, index):
# 		"""Rename specified path"""
# 		can_procede = True
# 
# 		try:
# 			# check if specified path already exists
# 			if self._destination.exists(new_name, relative_to=self._source_path):
# 				can_procede, options = self._get_overwrite_input(new_name)
# 
# 				# get new name if user specified
# 				if options[OverwriteOption.RENAME]:
# 					new_name = os.path.join(
# 					                    os.path.dirname(new_name),
# 					                    options[OverwriteOption.NEW_NAME]
# 					                )
# 
# 			if not can_procede:
# 				# user canceled overwrite, skip the file
# 				self._file_list.pop(index)
# 				return
# 
# 			else:
# 				# rename path
# 				self._source.rename_path(old_name, new_name, relative_to=self._source_path)
# 
# 				# push event to the queue
# 				if self._source_queue is not None:
# 					delete_event = (MonitorSignals.DELETE, old_name, None)
# 					create_event = (MonitorSignals.CREATED, new_name, None)
# 
# 					self._source_queue.put(delete_event, False)
# 					self._source_queue.put(create_event, False)
# 
# 		except Exception as error:
# 			# problem renaming path, ask user what to do
# 			if Skip.RENAME in self._response_cache:
# 				response = self._response_cache[Skip.RENAME]
# 			else:
# 				response = self._get_rename_error_input(error)
# 
# 			# try renaming path again
# 			if response == OperationError.RESPONSE_RETRY:
# 				self._remove_path(old_name, new_name, index)
# 
# 			else:
# 				# user didn't want to retry, remove path from list
# 				self._file_list.pop(index)
# 
# 	def run(self):
# 		"""Main thread method, this is where all the stuff is happening"""
# 		# wait for operation queue if needed
# 		if self._operation_queue is not None:
# 			self._operation_queue.wait()
# 
# 		for index, item in enumerate(self._file_list, 1):
# 			if self._abort.is_set(): break  # abort operation if requested
# 			self._can_continue.wait()  # pause lock
# 
# 			GObject.idle_add(self._dialog.set_current_file, item[0])
# 			self._rename_path(item[0], item[1], index-1)
# 
# 			# update current count
# 			if len(self._file_list) > 0:
# 				GObject.idle_add(
# 							self._dialog.set_current_file_fraction,
# 							float(index) / len(self._file_list)
# 						)
# 
# 			else:
# 				# prevent division by zero
# 				GObject.idle_add(self._dialog.set_current_file_fraction, 1)
# 
# 		# notify user if window is not focused
# 		def notify_is_not_focused():
# 			if not self._dialog.is_active() and not self._application.is_active() and not self._abort.is_set():
# 				notify_manager = self._application.notification_manager
# 
# 				title = _('Rename Operation')
# 				message = ngettext(
# 								'Rename of {0} item from "{1}" is completed!',
# 								'Rename of {0} items from "{1}" is completed!',
# 								len(self._file_list)
# 							).format(
# 				        len(self._file_list),
# 				        os.path.basename(self._source_path)
# 				    )
# 
# 				# queue notification
# 				notify_manager.notify(title, message)
# 
# 		GObject.idle_add(notify_is_not_focused)
# 
# 		# destroy dialog
# 		self._destroy_ui()
# 
# 		# start next operation
# 		if self._operation_queue is not None:
# 			OperationQueue.start_next(self._operation_queue_name)


# Path: sunflower/tools/advanced_rename.py
import os
from gi.repository import Gtk, Gdk
from sunflower.operation import RenameOperation


			# store new name to list
			row[Column.NEW_NAME] = new_name

	def rename_files(self, widget=None, data=None):
		"""Rename selected files"""
		dialog = Gtk.MessageDialog(
								self.window,
								Gtk.DialogFlags.DESTROY_WITH_PARENT,
								Gtk.MessageType.QUESTION,
								Gtk.ButtonsType.YES_NO,
								ngettext(
									"You are about to rename {0} item.\n"
									"Are you sure about this?",
									"You are about to rename {0} items.\n"
									"Are you sure about this?",
									len(self._list)
								).format(len(self._list))
							)
		dialog.set_default_response(Gtk.ResponseType.YES)
		result = dialog.run()
		dialog.destroy()

		if result == Gtk.ResponseType.YES:
			# user confirmed rename
			item_list = []
			for item in self._list:
				item_list.append((item[Column.OLD_NAME], item[Column.NEW_NAME]))

			# create thread and start operation

			operation = RenameOperation(