# -*- coding: utf-8 -*-

# Copyright (c) 2003 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter the data for a merge operation.
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from Ui_CvsMergeDialog import Ui_CvsMergeDialog

class CvsMergeDialog(QDialog, Ui_CvsMergeDialog):
    """
    Class implementing a dialog to enter the data for a merge operation.
    """
    def __init__(self, taglist, parent = None):
        """
        Constructor
        
        @param taglist list of previously entered tags (QStringList)
        @param parent parent widget (QWidget)
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        
        self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.okButton.setEnabled(False)
        
        self.tag1Combo.clear()
        self.tag1Combo.addItems(taglist)
        self.tag2Combo.clear()
        self.tag2Combo.addItems(taglist)
        
        self.cvsTagValidator = QRegExpValidator(QRegExp(r"[a-zA-Z][a-zA-Z0-9_-]*"), self)
        self.tag1Combo.setValidator(self.cvsTagValidator)
        self.tag2Combo.setValidator(self.cvsTagValidator)
        
    def on_tag1Combo_editTextChanged(self, text):
        """
        Private method used to enable/disable the OK-button.
        
        @param text ignored
        """
        self.okButton.setDisabled(text.isEmpty())
    
    def getParameters(self):
        """
        Public method to retrieve the tag data.
        
        @return tuple naming two tag names or two revisions (QString, QString)
        """
        return (self.tag1Combo.currentText(), self.tag2Combo.currentText())
