# Path: sunflower/plugin_base/rename_extension.py
# class RenameExtension:
# 	"""Base class for extending advanced rename tool.
# 
# 	Use this class to provide advanced rename tool with additional
# 	options. Objects are created every time tool is created!
# 
# 	"""
# 
# 	def __init__(self, parent):
# 		self._parent = parent
# 
# 		# create and configure container
# 		self.vbox = Gtk.VBox(False, 5)
# 		self.vbox.set_border_width(7)
# 		self.vbox.extension = self
# 
# 		# create activity toggle
# 		self._active = False
# 		self._checkbox_active = Gtk.CheckButton(_('Use this extension'))
# 		self._checkbox_active.connect('toggled', self.__toggle_active)
# 		self._checkbox_active.show()
# 
# 		self.vbox.pack_start(self._checkbox_active, False, False, 0)
# 
# 	def __toggle_active(self, widget, data=None):
# 		"""Toggle extension active property"""
# 		self._active = widget.get_active()
# 		self._update_parent_list()
# 
# 	def _update_parent_list(self, widget=None, data=None):
# 		"""Update parent list"""
# 		self._parent.update_list()
# 
# 	def is_active(self):
# 		"""Return boolean representing extension state"""
# 		return self._active
# 
# 	def reset(self):
# 		"""Method called before iterating through parents list"""
# 		pass
# 
# 	def get_title(self):
# 		"""Return i18n title for extension"""
# 		return None
# 
# 	def get_container(self):
# 		"""Return widget container"""
# 		return self.vbox
# 
# 	def get_new_name(self, old_name, new_name):
# 		"""Generate and return new name for specified file.
# 
# 		If you don't make any modifications to the name make sure
# 		you return new_name instead. In cases where extension needs
# 		to file (or file contents) you can use self._parent._provider
# 		object.
# 
# 		Parameters:
# 		old_name - original (unchanged) file name
# 		new_name - name modified by previous extensions
# 
# 		"""
# 		return new_name
# 
# Path: sunflower/gui/input_dialog.py
# class InputRangeDialog(InputDialog):
# 	"""Dialog used for getting selection range"""
# 
# 	def __init__(self, application, text):
# 		InputDialog.__init__(self, application)
# 
# 		# set labels
# 		self.set_title(_('Select range'))
# 		self.set_label(_('Select part of the text:'))
# 
# 		# configure entry
# 		self._entry.set_editable(False)
# 		self._entry.set_text(text)
# 
# 	def get_response(self):
# 		"""Return selection selection_range and self-destruct"""
# 		code = self._dialog.run()
# 		selection_range = self._entry.get_selection_bounds()
# 
# 		self._dialog.destroy()
# 
# 		return code, selection_range
# 
# Path: sunflower/tools/advanced_rename.py
# class Column:
# 	ICON = 0
# 	OLD_NAME = 1
# 	NEW_NAME = 2


import re
import os
from gi.repository import Gtk, Gdk
from sunflower.plugin_base.rename_extension import RenameExtension
from sunflower.gui.input_dialog import InputRangeDialog
from sunflower.tools.advanced_rename import Column as RenameColumn
		self._counter_step = self._entry_step.get_value_as_int()
		self._counter_digits = self._entry_digits.get_value_as_int()

		self._update_parent_list()

	def __button_add_clicked(self, widget, data=None):
		"""Handle clicking on add button"""
		self._add_menu.popup_at_widget(widget, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, None)

	def __add_to_template(self, widget, type):
		"""Add variable to template"""
		position = self._entry_template.get_property('cursor-position')
		self._entry_template.insert_text('[{0}]'.format(type), position)

		# update parent list
		self._template = self._entry_template.get_text()
		self._update_parent_list()

	def __add_range_to_template(self, widget, type):
		"""Add variable range to template"""
		if len(self._parent._list) > 0:
			# get selection from parent list
			selection = self._parent._names.get_selection()
			list_, iter_ = selection.get_selected()

			# ensure we have something to select
			if iter_ is None:
				iter_ = list_.get_iter_first()

			# get text for range selection and position of cursor in template

# Path: sunflower/plugin_base/rename_extension.py
# class RenameExtension:
# 	"""Base class for extending advanced rename tool.
# 
# 	Use this class to provide advanced rename tool with additional
# 	options. Objects are created every time tool is created!
# 
# 	"""
# 
# 	def __init__(self, parent):
# 		self._parent = parent
# 
# 		# create and configure container
# 		self.vbox = Gtk.VBox(False, 5)
# 		self.vbox.set_border_width(7)
# 		self.vbox.extension = self
# 
# 		# create activity toggle
# 		self._active = False
# 		self._checkbox_active = Gtk.CheckButton(_('Use this extension'))
# 		self._checkbox_active.connect('toggled', self.__toggle_active)
# 		self._checkbox_active.show()
# 
# 		self.vbox.pack_start(self._checkbox_active, False, False, 0)
# 
# 	def __toggle_active(self, widget, data=None):
# 		"""Toggle extension active property"""
# 		self._active = widget.get_active()
# 		self._update_parent_list()
# 
# 	def _update_parent_list(self, widget=None, data=None):
# 		"""Update parent list"""
# 		self._parent.update_list()
# 
# 	def is_active(self):
# 		"""Return boolean representing extension state"""
# 		return self._active
# 
# 	def reset(self):
# 		"""Method called before iterating through parents list"""
# 		pass
# 
# 	def get_title(self):
# 		"""Return i18n title for extension"""
# 		return None
# 
# 	def get_container(self):
# 		"""Return widget container"""
# 		return self.vbox
# 
# 	def get_new_name(self, old_name, new_name):
# 		"""Generate and return new name for specified file.
# 
# 		If you don't make any modifications to the name make sure
# 		you return new_name instead. In cases where extension needs
# 		to file (or file contents) you can use self._parent._provider
# 		object.
# 
# 		Parameters:
# 		old_name - original (unchanged) file name
# 		new_name - name modified by previous extensions
# 
# 		"""
# 		return new_name
# 
# Path: sunflower/gui/input_dialog.py
# class InputRangeDialog(InputDialog):
# 	"""Dialog used for getting selection range"""
# 
# 	def __init__(self, application, text):
# 		InputDialog.__init__(self, application)
# 
# 		# set labels
# 		self.set_title(_('Select range'))
# 		self.set_label(_('Select part of the text:'))
# 
# 		# configure entry
# 		self._entry.set_editable(False)
# 		self._entry.set_text(text)
# 
# 	def get_response(self):
# 		"""Return selection selection_range and self-destruct"""
# 		code = self._dialog.run()
# 		selection_range = self._entry.get_selection_bounds()
# 
# 		self._dialog.destroy()
# 
# 		return code, selection_range
# 
# Path: sunflower/tools/advanced_rename.py
# class Column:
# 	ICON = 0
# 	OLD_NAME = 1
# 	NEW_NAME = 2


# Path: sunflower/plugins/rename_extensions/default.py
import re
import os
from gi.repository import Gtk, Gdk
from sunflower.plugin_base.rename_extension import RenameExtension
from sunflower.gui.input_dialog import InputRangeDialog
from sunflower.tools.advanced_rename import Column as RenameColumn

		self._counter_step = self._entry_step.get_value_as_int()
		self._counter_digits = self._entry_digits.get_value_as_int()

		self._update_parent_list()

	def __button_add_clicked(self, widget, data=None):
		"""Handle clicking on add button"""
		self._add_menu.popup_at_widget(widget, Gdk.Gravity.SOUTH_WEST, Gdk.Gravity.NORTH_WEST, None)

	def __add_to_template(self, widget, type):
		"""Add variable to template"""
		position = self._entry_template.get_property('cursor-position')
		self._entry_template.insert_text('[{0}]'.format(type), position)

		# update parent list
		self._template = self._entry_template.get_text()
		self._update_parent_list()

	def __add_range_to_template(self, widget, type):
		"""Add variable range to template"""
		if len(self._parent._list) > 0:
			# get selection from parent list
			selection = self._parent._names.get_selection()
			list_, iter_ = selection.get_selected()

			# ensure we have something to select
			if iter_ is None:
				iter_ = list_.get_iter_first()

			# get text for range selection and position of cursor in template

			name, extension = os.path.splitext(list_.get_value(iter_, RenameColumn.OLD_NAME))