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

import wx
import wxx
import app.resources as rc
from activity.git.ui import ui as ui


# Implementing NewGitRemote
class GitRemoteDialog(ui.NewGitRemote):
    """
    This dialog allows to create a new git remote.

    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """Init"""
        self.container = container
        super(GitRemoteDialog, self).__init__(parent)
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(rc.GetBitmap("git_remote"))
        self.SetIcon(icon)

    def Validate(self):
        """Validate dialog"""
        self._name = self.m_name.GetValue().strip()
        self._url = self.m_url.GetValue().strip()
        self._pass = self.m_password.GetValue()
        if not self._name:
            wx.MessageBox("Remote repository name is mandatory.", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        return True

    def get_kwargs(self):
        """Returns kwargs dictionary suitable for object creation"""
        kwargs = {}
        kwargs['parent'] = self.container
        kwargs['name'] = self._name
        kwargs['url'] = self._url
        kwargs['pass'] = self._pass
        kwargs['new'] = True  # This arg indicates that the remote must be added to the repo
        return kwargs

    # Handlers for NewGitRemote events.
    def OnCancel(self, event):
        """Handle cancel event"""
        """cancel event handler"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        """Handle OnOk"""
        if self.Validate():
            self.EndModal(wx.ID_OK)

