"""Subclass of NewDir, which is generated by wxFormBuilder."""

import os
import wx
import wxx
import model
from activity.files.ui import ui as ui


# Implementing NewDir
class NewDir(ui.NewDir):
    """
    This dialog allows to create a new directory inside any project.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """Initialize dialog"""
        """constructor"""
        self.container = container  # the receiver of the new element
        super(NewDir, self).__init__(parent)
        if type(container) is model.Project:
            self.m_dirPicker.SetPath(self.container.dir)
        else:
            self.m_dirPicker.SetPath(self.container._file)

    def Validate(self):
        """validate the dialog"""
        self._dir = self.m_dirPicker.GetPath()
        #check about dir existence
        if os.path.exists(self._dir):
            wx.MessageBox("Directory already exists", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        return True

    def CopyAttributes(self, fobj):
        """Copy dialog selections to object"""
        fobj._file = self._file

    def SetAttributes(self, fobj):
        """Copy object attributes to dialog"""
        self.m_dirPicker.SetPath(fobj.abs_file)

    def get_kwargs(self):
        """Returns suitable arguments for creating object"""
        kwargs = {'parent': self.container, 'file': self._dir}
        return kwargs

    def OnOK(self, event):
        """implement OnOK button"""
        if self.Validate():
            self.EndModal(wx.ID_OK)

    def OnCancel(self, event):
        """implement OnCancel button"""
        self.EndModal(wx.ID_CANCEL)
