diff -r 72b6b0778e06 -r 919147f2b518 Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarkDialog.py --- a/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarkDialog.py Sat May 07 13:37:58 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarkDialog.py Sat May 07 17:56:31 2011 +0200 @@ -17,10 +17,14 @@ """ Class mplementing the bookmark dialog. """ - def __init__(self, tagsList, branchesList, bookmarksList, parent=None): + DEFINE_MODE = 0 + MOVE_MODE = 1 + + def __init__(self, mode, tagsList, branchesList, bookmarksList, parent=None): """ Constructor + @param mode of the dialog (integer) @param tagsList list of tags (list of strings) @param branchesList list of branches (list of strings) @param bookmarksList list of bookmarks (list of strings) @@ -30,11 +34,65 @@ self.setupUi(self) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) - + + self.__mode = mode + if mode == self.MOVE_MODE: + self.nameEdit.hide() + self.nameCombo.addItems([""] + sorted(bookmarksList)) + else: + self.nameCombo.hide() + + self.__bookmarksList = bookmarksList[:] + self.tagCombo.addItems(sorted(tagsList)) self.branchCombo.addItems(["default"] + sorted(branchesList)) self.bookmarkCombo.addItems(sorted(bookmarksList)) + def __updateOK(self): + """ + Private slot to update the OK button. + """ + if self.__mode == self.MOVE_MODE: + enabled = self.nameCombo.currentText() != "" + else: + enabled = self.nameEdit.text() != "" + if self.idButton.isChecked(): + enabled = enabled and self.idEdit.text() != "" + elif self.tagButton.isChecked(): + enabled = enabled and self.tagCombo.currentText() != "" + elif self.branchButton.isChecked(): + enabled = enabled and self.branchCombo.currentText() != "" + elif self.bookmarkButton.isChecked(): + enabled = enabled and self.bookmarkCombo.currentText() != "" + + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled) + + def __updateBookmarksCombo(self): + """ + Private slot to update the bookmarks combo. + """ + if self.__mode == self.MOVE_MODE: + bookmark = self.nameCombo.currentText() + selectedBookmark = self.bookmarkCombo.currentText() + self.bookmarkCombo.clearEditText() + self.bookmarkCombo.clear() + self.bookmarkCombo.addItems(sorted(self.__bookmarksList)) + index = self.bookmarkCombo.findText(bookmark) + if index > -1: + self.bookmarkCombo.removeItem(index) + if selectedBookmark: + index = self.bookmarkCombo.findText(selectedBookmark) + if index > -1: + self.bookmarkCombo.setCurrentIndex(index) + + @pyqtSlot(str) + def on_nameCombo_activated(self, txt): + """ + Private slot to handle changes of the selected bookmark name. + """ + self.__updateOK() + self.__updateBookmarksCombo() + @pyqtSlot(str) def on_nameEdit_textChanged(self, txt): """ @@ -42,7 +100,79 @@ @param txt text of the edit (string) """ - self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(txt != "") + self.__updateOK() + + @pyqtSlot(bool) + def on_idButton_toggled(self, checked): + """ + Private slot to handle changes of the ID select button. + + @param checked state of the button (boolean) + """ + self.__updateOK() + + @pyqtSlot(bool) + def on_tagButton_toggled(self, checked): + """ + Private slot to handle changes of the Tag select button. + + @param checked state of the button (boolean) + """ + self.__updateOK() + + @pyqtSlot(bool) + def on_branchButton_toggled(self, checked): + """ + Private slot to handle changes of the Branch select button. + + @param checked state of the button (boolean) + """ + self.__updateOK() + + @pyqtSlot(bool) + def on_bookmarkButton_toggled(self, checked): + """ + Private slot to handle changes of the Bookmark select button. + + @param checked state of the button (boolean) + """ + self.__updateOK() + + @pyqtSlot(str) + def on_idEdit_textChanged(self, txt): + """ + Private slot to handle changes of the ID edit. + + @param txt text of the edit (string) + """ + self.__updateOK() + + @pyqtSlot(str) + def on_tagCombo_editTextChanged(self, txt): + """ + Private slot to handle changes of the Tag combo. + + @param txt text of the combo (string) + """ + self.__updateOK() + + @pyqtSlot(str) + def on_branchCombo_editTextChanged(self, txt): + """ + Private slot to handle changes of the Branch combo. + + @param txt text of the combo (string) + """ + self.__updateOK() + + @pyqtSlot(str) + def on_bookmarkCombo_editTextChanged(self, txt): + """ + Private slot to handle changes of the Bookmark combo. + + @param txt text of the combo (string) + """ + self.__updateOK() def getData(self): """ @@ -64,4 +194,9 @@ else: rev = "" - return rev, self.nameEdit.text() + if self.__mode == self.MOVE_MODE: + name = self.nameCombo.currentText() + else: + name = self.nameEdit.text() + + return rev, name