Browse Source

bugfix in VFileList and VEditArea

1. Clear selection before setting current item in VFileList;
2. Status change of non-active tabs shoud not be propagated upwards;
Le Tan 8 years ago
parent
commit
f4708e427f
4 changed files with 25 additions and 5 deletions
  1. 11 1
      src/veditarea.cpp
  2. 3 0
      src/veditarea.h
  3. 8 1
      src/veditwindow.cpp
  4. 3 3
      src/vfilelist.cpp

+ 11 - 1
src/veditarea.cpp

@@ -68,7 +68,7 @@ void VEditArea::insertSplitWindow(int idx)
     VEditWindow *win = new VEditWindow(vnote, this);
     splitter->insertWidget(idx, win);
     connect(win, &VEditWindow::tabStatusChanged,
-            this, &VEditArea::curTabStatusChanged);
+            this, &VEditArea::handleEditWindowStatusChanged);
     connect(win, &VEditWindow::requestSplitWindow,
             this, &VEditArea::handleSplitWindowRequest);
     connect(win, &VEditWindow::requestRemoveSplit,
@@ -81,6 +81,15 @@ void VEditArea::insertSplitWindow(int idx)
             this, &VEditArea::handleCurHeaderChanged);
 }
 
+void VEditArea::handleEditWindowStatusChanged(const VFile *p_file,
+                                              const VEditTab *p_editTab,
+                                              bool p_editMode)
+{
+    if (splitter->widget(curWindowIndex) == sender()) {
+        emit curTabStatusChanged(p_file, p_editTab, p_editMode);
+    }
+}
+
 void VEditArea::removeSplitWindow(VEditWindow *win)
 {
     if (!win) {
@@ -194,6 +203,7 @@ void VEditArea::updateWindowStatus()
         emit curHeaderChanged(VAnchor());
         return;
     }
+
     VEditWindow *win = getWindow(curWindowIndex);
     win->requestUpdateTabStatus();
     win->requestUpdateOutline();

+ 3 - 0
src/veditarea.h

@@ -90,6 +90,9 @@ private slots:
     void handleReplaceAll(const QString &p_text, uint p_options,
                           const QString &p_replaceText);
     void handleFindDialogClosed();
+    void handleEditWindowStatusChanged(const VFile *p_file,
+                                       const VEditTab *p_editTab,
+                                       bool p_editMode);
 
 private:
     void setupUI();

+ 8 - 1
src/veditwindow.cpp

@@ -550,7 +550,14 @@ void VEditWindow::noticeStatus(int index)
 
 void VEditWindow::handleTabStatusChanged()
 {
-    noticeTabStatus(currentIndex());
+    int idx = indexOf(dynamic_cast<QWidget *>(sender()));
+    if (idx == currentIndex()) {
+        noticeTabStatus(idx);
+    } else {
+        // Only update the tab status. Do no propagate upwards.
+        updateTabInfo(idx);
+        updateAllTabsSequence();
+    }
 }
 
 void VEditWindow::updateFileInfo(const VFile *p_file)

+ 3 - 3
src/vfilelist.cpp

@@ -201,7 +201,7 @@ void VFileList::newFile()
             }
             QVector<QListWidgetItem *> items = updateFileListAdded();
             Q_ASSERT(items.size() == 1);
-            fileList->setCurrentItem(items[0]);
+            fileList->setCurrentItem(items[0], QItemSelectionModel::ClearAndSelect);
             // Qt seems not to update the QListWidget correctly. Manually force it to repaint.
             fileList->update();
 
@@ -529,7 +529,7 @@ bool VFileList::locateFile(const VFile *p_file)
         }
         QListWidgetItem *item = findItem(p_file);
         if (item) {
-            fileList->setCurrentItem(item);
+            fileList->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
         }
     }
     return false;
@@ -615,7 +615,7 @@ bool VFileList::handleKeyNavigation(int p_key, bool &p_succeed)
         ret = true;
         auto it = m_keyMap.find(keyChar);
         if (it != m_keyMap.end()) {
-            fileList->setCurrentItem(it.value());
+            fileList->setCurrentItem(it.value(), QItemSelectionModel::ClearAndSelect);
             fileList->setFocus();
         }
     } else if (keyChar == m_majorKey) {