Sat, 11 Feb 2017 19:47:41 +0100
Enabled the action menu for the Mercurial log browser in 'incoming' mode.
--- a/Plugins/VcsPlugins/vcsMercurial/FetchExtension/HgFetchDialog.py Sat Feb 11 18:19:56 2017 +0100 +++ b/Plugins/VcsPlugins/vcsMercurial/FetchExtension/HgFetchDialog.py Sat Feb 11 19:47:41 2017 +0100 @@ -14,27 +14,33 @@ from .Ui_HgFetchDialog import Ui_HgFetchDialog -import Preferences - class HgFetchDialog(QDialog, Ui_HgFetchDialog): """ Class implementing a dialog to enter data to be used for a fetch operation. """ - def __init__(self, parent=None): + def __init__(self, vcs, parent=None): """ Constructor - @param parent reference to the parent widget (QWidget) + @param vcs reference to the Mercurial vcs object + @type Hg + @param parent reference to the parent widget + @type QWidget """ super(HgFetchDialog, self).__init__(parent) self.setupUi(self) - self.recentCommitMessages = Preferences.toList( - Preferences.Prefs.settings.value('Mercurial/Commits')) + self.__vcs = vcs + + commitMessages = self.__vcs.getPlugin().getPreferences('Commits') self.recentComboBox.clear() self.recentComboBox.addItem("") - self.recentComboBox.addItems(self.recentCommitMessages) + for message in commitMessages: + abbrMsg = message[:60] + if len(message) > 60: + abbrMsg += "..." + self.recentComboBox.addItem(abbrMsg, message) @pyqtSlot(str) def on_recentComboBox_activated(self, txt): @@ -44,7 +50,7 @@ @param txt text of the selected entry (string) """ if txt: - self.messageEdit.setPlainText(txt) + self.messageEdit.setPlainText(self.recentComboBox.currentData()) def getData(self): """ @@ -55,14 +61,13 @@ """ msg = self.messageEdit.toPlainText() if msg: - if msg in self.recentCommitMessages: - self.recentCommitMessages.remove(msg) - self.recentCommitMessages.insert(0, msg) - no = int(Preferences.Prefs.settings.value( - 'Mercurial/CommitMessages', 20)) - del self.recentCommitMessages[no:] - Preferences.Prefs.settings.setValue( - 'Mercurial/Commits', - self.recentCommitMessages) + commitMessages = self.__vcs.getPlugin().getPreferences('Commits') + if msg in commitMessages: + commitMessages.remove(msg) + commitMessages.insert(0, msg) + no = self.__vcs.getPlugin().getPreferences("CommitMessages") + del commitMessages[no:] + self.__vcs.getPlugin().setPreferences( + 'Commits', commitMessages) return msg, self.switchCheckBox.isChecked()
--- a/Plugins/VcsPlugins/vcsMercurial/FetchExtension/fetch.py Sat Feb 11 18:19:56 2017 +0100 +++ b/Plugins/VcsPlugins/vcsMercurial/FetchExtension/fetch.py Sat Feb 11 19:47:41 2017 +0100 @@ -28,13 +28,20 @@ @param vcs reference to the Mercurial vcs object """ super(Fetch, self).__init__(vcs) + + self.__vcs = vcs - def hgFetch(self, name): + def hgFetch(self, name, revisions=None): """ Public method to fetch changes from a remote repository. - @param name file/directory name (string) - @return flag indicating that the project should be reread (boolean) + @param name directory name of the project to be fetched to + @type str + @param revisions list of revisions to be pulled + @type list of str + @return flag indicating, that the update contained an add + or delete + @rtype bool """ # find the root of the repo repodir = self.vcs.splitPath(name)[0] @@ -45,7 +52,7 @@ from .HgFetchDialog import HgFetchDialog res = False - dlg = HgFetchDialog() + dlg = HgFetchDialog(self.__vcs) if dlg.exec_() == QDialog.Accepted: message, switchParent = dlg.getData() @@ -56,6 +63,10 @@ if switchParent: args.append("--switch-parent") args.append("-v") + if revisions: + for rev in revisions: + args.append("--rev") + args.append(rev) dia = HgDialog( self.tr('Fetching from a remote Mercurial repository'),
--- a/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Sat Feb 11 18:19:56 2017 +0100 +++ b/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Sat Feb 11 19:47:41 2017 +0100 @@ -1298,9 +1298,13 @@ if self.__started: if self.__selectedRevisions: - self.logTree.setCurrentItem(self.logTree.findItems( + foundItems = self.logTree.findItems( self.__selectedRevisions[0], Qt.MatchExactly, - self.RevisionColumn)[0]) + self.RevisionColumn) + if foundItems: + self.logTree.setCurrentItem(foundItems[0]) + else: + self.logTree.setCurrentItem(self.logTree.topLevelItem(0)) else: self.logTree.setCurrentItem(self.logTree.topLevelItem(0)) self.__started = False @@ -1443,39 +1447,39 @@ the tool menu button. """ if self.initialCommandMode == "log" and self.projectMode: - if self.__phaseAct is not None: - # step 1: count entries with changeable phases - secret = 0 - draft = 0 - public = 0 - for itm in self.logTree.selectedItems(): - phase = itm.text(self.PhaseColumn) - if phase == self.phases["draft"]: - draft += 1 - elif phase == self.phases["secret"]: - secret += 1 - else: - public += 1 - - # step 2: set the status of the phase action - if public == 0 and \ - ((secret > 0 and draft == 0) or - (secret == 0 and draft > 0)): - self.__phaseAct.setEnabled(True) + # do the phase action + # step 1: count entries with changeable phases + secret = 0 + draft = 0 + public = 0 + for itm in self.logTree.selectedItems(): + phase = itm.text(self.PhaseColumn) + if phase == self.phases["draft"]: + draft += 1 + elif phase == self.phases["secret"]: + secret += 1 else: - self.__phaseAct.setEnabled(False) + public += 1 + + # step 2: set the status of the phase action + if public == 0 and \ + ((secret > 0 and draft == 0) or + (secret == 0 and draft > 0)): + self.__phaseAct.setEnabled(True) + else: + self.__phaseAct.setEnabled(False) - if self.__graftAct is not None: - # step 1: count selected entries not belonging to the - # current branch - otherBranches = 0 - for itm in self.logTree.selectedItems(): - branch = itm.text(self.BranchColumn) - if branch != self.__projectBranch: - otherBranches += 1 - - # step 2: set the status of the graft action - self.__graftAct.setEnabled(otherBranches > 0) + # do the graft action + # step 1: count selected entries not belonging to the + # current branch + otherBranches = 0 + for itm in self.logTree.selectedItems(): + branch = itm.text(self.BranchColumn) + if branch != self.__projectBranch: + otherBranches += 1 + + # step 2: set the status of the graft action + self.__graftAct.setEnabled(otherBranches > 0) selectedItemsCount = len(self.logTree.selectedItems()) self.__mergeAct.setEnabled(selectedItemsCount == 1) @@ -1484,6 +1488,8 @@ self.__bookmarkAct.setEnabled(selectedItemsCount == 1) self.__bookmarkMoveAct.setEnabled(selectedItemsCount == 1) + self.__pullAct.setText(self.tr("Pull Changes")) + self.__fetchAct.setText(self.tr("Fetch Changes")) if self.vcs.canPull(): self.__pullAct.setEnabled(True) self.__lfPullAct.setEnabled( @@ -1520,6 +1526,37 @@ selectedItemsCount == 1) self.actionsButton.setEnabled(True) + elif self.initialCommandMode == "incoming" and self.projectMode: + for act in [self.__phaseAct, self.__graftAct, self.__mergeAct, + self.__tagAct, self.__switchAct, self.__bookmarkAct, + self.__bookmarkMoveAct, self.__pushAct, + self.__pushAllAct, self.__stripAct, self.__bundleAct, + self.__gpgSignAct, self.__gpgVerifyAct]: + act.setEnabled(False) + + self.__pullAct.setText(self.tr("Pull Selected Changes")) + self.__fetchAct.setText(self.tr("Fetch Selected Changes")) + if self.vcs.canPull(): + # step 1: determine number of selected draft changesets + # i.e. those that can be pulled + selectedDraftItemsCount = 0 + for itm in self.logTree.selectedItems(): + phase = itm.text(self.PhaseColumn) + if phase == self.phases["draft"]: + selectedDraftItemsCount += 1 + self.__pullAct.setEnabled(selectedDraftItemsCount > 0) + self.__lfPullAct.setEnabled( + self.vcs.isExtensionActive("largefiles") and + selectedItemsCount > 0) + self.__fetchAct.setEnabled( + self.vcs.isExtensionActive("fetch") and + selectedDraftItemsCount > 0) + else: + self.__pullAct.setEnabled(False) + self.__lfPullAct.setEnabled(False) + self.__fetchAct.setEnabled(False) + + self.actionsButton.setEnabled(True) else: self.actionsButton.setEnabled(False) # TODO: add code to enable menu in incoming / outgoing mode as well @@ -2110,8 +2147,24 @@ """ Private slot to fetch changes from a remote repository. """ - shouldReopen = self.vcs.getExtensionObject("fetch").hgFetch( - self.repodir) + shouldReopen = False + refresh = False + + if self.initialCommandMode == "log": + shouldReopen = self.vcs.getExtensionObject("fetch").hgFetch( + self.repodir) + refresh = True + elif self.initialCommandMode == "incoming": + revs = [] + for itm in self.logTree.selectedItems(): + rev = itm.text(self.RevisionColumn).split(":")[1].strip() + phase = itm.text(self.PhaseColumn).strip() + if rev and phase == self.phases["draft"]: + revs.append(rev) + if revs: + shouldReopen = self.vcs.getExtensionObject("fetch").hgFetch( + self.repodir, ) + refresh = True if shouldReopen: res = E5MessageBox.yesNo( None, @@ -2123,14 +2176,31 @@ e5App().getObject("Project").reopenProject() return - self.on_refreshButton_clicked() + if refresh: + self.on_refreshButton_clicked() @pyqtSlot() def __pullActTriggered(self): """ Private slot to pull changes from a remote repository. """ - shouldReopen = self.vcs.hgPull(self.repodir) + shouldReopen = False + refresh = False + + if self.initialCommandMode == "log": + shouldReopen = self.vcs.hgPull(self.repodir) + refresh = True + elif self.initialCommandMode == "incoming": + revs = [] + for itm in self.logTree.selectedItems(): + rev = itm.text(self.RevisionColumn).split(":")[1].strip() + phase = itm.text(self.PhaseColumn).strip() + if rev and phase == self.phases["draft"]: + revs.append(rev) + if revs: + shouldReopen = self.vcs.hgPull(self.repodir, revisions=revs) + refresh = True + if shouldReopen: res = E5MessageBox.yesNo( None, @@ -2142,7 +2212,8 @@ e5App().getObject("Project").reopenProject() return - self.on_refreshButton_clicked() + if refresh: + self.on_refreshButton_clicked() @pyqtSlot() def __pushActTriggered(self):
--- a/Plugins/VcsPlugins/vcsMercurial/hg.py Sat Feb 11 18:19:56 2017 +0100 +++ b/Plugins/VcsPlugins/vcsMercurial/hg.py Sat Feb 11 19:47:41 2017 +0100 @@ -1934,17 +1934,22 @@ self.logBrowserOutgoing.raise_() self.logBrowserOutgoing.start(name) - def hgPull(self, name): + def hgPull(self, name, revisions=None): """ Public method used to pull changes from a remote Mercurial repository. - @param name directory name of the project to be pulled to (string) + @param name directory name of the project to be pulled to + @type str + @param revisions list of revisions to be pulled + @type list of str @return flag indicating, that the update contained an add - or delete (boolean) + or delete + @rtype bool """ if self.getPlugin().getPreferences("PreferUnbundle") and \ self.bundleFile and \ - os.path.exists(self.bundleFile): + os.path.exists(self.bundleFile) and \ + revisions is None: command = "unbundle" title = self.tr('Apply changegroups') else: @@ -1957,6 +1962,10 @@ args.append('--update') if command == "unbundle": args.append(self.bundleFile) + if revisions: + for rev in revisions: + args.append("--rev") + args.append(rev) # find the root of the repo repodir = self.splitPath(name)[0]