import c4d
from ssp_utils_dialog import *


####################################################################################################
# Class DialogAskSessionName #######################################################################
####################################################################################################
class DialogAskSessionName(c4d.gui.GeDialog):
    ID_EDITTEXT_NAME     = 50001

    _title = ''
    _nameDefault = ''
    _name = ''
    _result = False


    def __init__(self, title='Add Session...', nameDefault='New Session', nameGroup='Session Name'):
        self._name = 'New Session'
        self._title = title
        self._nameDefault = nameDefault
        self._nameGroup = nameGroup
        self._result = False

        c4d.gui.GeDialog.__init__(self)


    def CreateLayout(self):
        self.SetTitle(self._title)

        if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1): # Dialog main group
            self.GroupBorderSpace(7, 5, 7, 3)
            self.GroupSpace(0, 15)

            if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_TOP, cols=1): # Entry name
                CreateLayoutAddGroupBar(self, self._nameGroup)
                self.AddEditText(self.ID_EDITTEXT_NAME, c4d.BFH_SCALEFIT, initw=200)

            self.GroupEnd() # Entry name

            if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM, cols=1): # Dialog finish
                self.AddDlgGroup(c4d.DLG_OK | c4d.DLG_CANCEL)

            self.GroupEnd() # Dialog finish

        self.GroupEnd() # Dialog main group

        return True


    def InitValues(self):
        self.SetString(self.ID_EDITTEXT_NAME, self._nameDefault)
        return True


    def Command(self, id, msg):
        if id == c4d.DLG_OK:
            self._name = self.GetString(self.ID_EDITTEXT_NAME)

            if len(self._name) <= 0:
                c4d.gui.MessageDialog('Please enter a session name.')
                return True

            self._result = True
            self.Close()

        elif id == c4d.DLG_CANCEL:
            self._result = False
            self.Close()

        return True


    def GetResult(self):
        return self._result, self._name
