1. Yuya Nishihara
  2. thg-qt-mq

Source

thg-qt-mq / import-history.patch

# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1343405897 -7200
# Node ID 5a17c2bcc4c0cf1e348fce457a563a5e77622a07
# Parent  7fd0c95d55c2516b76b0319cea4213a799f37646
thgimport: save source list when the import dialog is closed

New sources are added to the sources combobox when the "Browse" and "Browse Dir"
buttons are used. These are saved when the dialog is closed, and the last 8
are restored when the dialog is open again.

I had to change the behavior of the dialog when the user hits enter and the
focus is on the source combobox. It used to trigger an import, but now it will
trigger a preview first. Hitting it again will import.

Note that the sources are saved per repository.

diff --git a/tortoisehg/hgqt/thgimport.py b/tortoisehg/hgqt/thgimport.py
--- a/tortoisehg/hgqt/thgimport.py
+++ b/tortoisehg/hgqt/thgimport.py
@@ -51,6 +51,8 @@
         self.src_combo = QComboBox()
         self.src_combo.setEditable(True)
         self.src_combo.setMinimumWidth(310)
+        self.src_combo.setMaxVisibleItems(8)
+
         self.file_btn = QPushButton(_('Browse...'))
         self.file_btn.setAutoDefault(False)
         self.file_btn.clicked.connect(self.browsefiles)
@@ -123,9 +125,10 @@
         self.detail_btn.toggled.connect(self.detail_toggled)
         box.addWidget(buttons)
 
+        self.loadSettings()
+
         # signal handlers
-        self.src_combo.editTextChanged.connect(lambda *a: self.preview())
-        self.src_combo.lineEdit().returnPressed.connect(self.thgimport)
+        self.src_combo.lineEdit().returnPressed.connect(self.preview)
         self.p0chk.toggled.connect(lambda *a: self.preview())
 
         # dialog setting
@@ -181,8 +184,11 @@
         if filelist:
             # Qt file browser uses '/' in paths, even on Windows.
             nl = QStringList([QDir.toNativeSeparators(x) for x in filelist])
-            self.src_combo.setEditText(nl.join(os.pathsep))
+            qpath = nl.join(os.pathsep)
+            self.src_combo.insertItem(0, qpath)
+            self.src_combo.setEditText(qpath)
             self.src_combo.setFocus()
+            self.preview()
 
     def browsedir(self):
         caption = _("Select Directory containing patches")
@@ -190,8 +196,11 @@
                                                 directory=self.repo.root,
                                                 caption=caption)
         if path:
-            self.src_combo.setEditText(QDir.toNativeSeparators(path))
+            qpath = QDir.toNativeSeparators(path)
+            self.src_combo.insertItem(0, qpath)
+            self.src_combo.setEditText(qpath)
             self.src_combo.setFocus()
+            self.preview()
 
     def getcliptext(self):
         text = hglib.fromunicode(QApplication.clipboard().text())
@@ -203,6 +212,7 @@
             self.src_combo.setEditText(curtext + os.pathsep + filename)
         else:
             self.src_combo.setEditText(filename)
+        self.preview()
 
     def updatestatus(self):
         items = self.cslist.curitems
@@ -286,6 +296,37 @@
         for path in self.tempfiles:
             os.unlink(path)
 
+    def _getSources(self):
+        sources = []
+        for row in range(self.src_combo.count()):
+            sources.append(self.src_combo.model().item(row).text())
+        return sources
+
+    def _getSettingsName(self):
+        if not self.repo:
+            return None
+        return "import/sources/" + self.repo.root            
+
+    def loadSettings(self):
+        wb = self._getSettingsName()
+        if wb is None:
+            return  
+        s = QSettings()
+        sources = s.value(wb)
+        sources = sources.toStringList()
+        self.src_combo.addItems(QStringList(sources)) 
+        # make sure that the repo root is always on the source list
+        if self.repo.root not in sources:
+            self.src_combo.insertItem(0, QDir.toNativeSeparators(self.repo.root)) 
+        self.src_combo.setEditText('')
+
+    def saveSettings(self):
+        wb = self._getSettingsName()
+        if wb is None:
+            return
+        s = QSettings()
+        s.setValue(wb, self._getSources())
+
     ### Override Handlers ###
 
     def accept(self):
@@ -294,6 +335,7 @@
 
     def reject(self):
         self.unlinktempfiles()
+        self.saveSettings()
         super(ImportDialog, self).reject()
 
     ### Signal Handlers ###