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

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


# Implementing CommitGit
class CommitGitDialog(ui.CommitGit):
    """
    This dialog allows to commit the git repository
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent):
        """Initialize the dialog"""
        super(CommitGitDialog, self).__init__(parent)

    def Validate(self):
        """Do dialog validation"""
        self._message = self.m_richText39.GetValue().strip()
        if len(self._message) == 0:
            wx.MessageBox("The commit message must be non empty", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        return True

    # Handlers for CommitGit events.
    def OnCancel(self, event):
        """Cancel the commit process"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        """Do the git process"""
        if self.Validate():
            self.EndModal(wx.ID_OK)
