From a841c0583b071a0c46138925466ecc92fd610e90 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Tue, 25 Aug 2009 12:30:47 +0200
Subject: [PATCH] Correctly update the status of the current file find filter.

---
 src/plugins/texteditor/findincurrentfile.cpp | 32 +++++++++++++++-----
 src/plugins/texteditor/findincurrentfile.h   |  6 ++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp
index 3a397094c1d..1cdf9fce174 100644
--- a/src/plugins/texteditor/findincurrentfile.cpp
+++ b/src/plugins/texteditor/findincurrentfile.cpp
@@ -43,8 +43,12 @@ using namespace TextEditor::Internal;
 
 FindInCurrentFile::FindInCurrentFile(SearchResultWindow *resultWindow)
   : BaseFileFind(resultWindow),
-    m_configWidget(0)
+    m_configWidget(0),
+    m_currentFile(0)
 {
+    connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
+            this, SLOT(handleFileChange(Core::IEditor*)));
+    handleFileChange(Core::ICore::instance()->editorManager()->currentEditor());
 }
 
 QString FindInCurrentFile::id() const
@@ -65,19 +69,33 @@ QKeySequence FindInCurrentFile::defaultShortcut() const
 QStringList FindInCurrentFile::files()
 {
     QStringList fileList;
-    if (Core::IEditor *editor = Core::ICore::instance()->editorManager()->currentEditor()) {
-        if (editor->file() && !editor->file()->fileName().isEmpty())
-            fileList << editor->file()->fileName();
-    }
+    if (isEnabled())
+        fileList << m_currentFile->fileName();
     return fileList;
 }
 
 bool FindInCurrentFile::isEnabled() const
 {
-    Core::IEditor *editor = Core::ICore::instance()->editorManager()->currentEditor();
-    return editor && editor->file() && !editor->file()->fileName().isEmpty();
+    return m_currentFile && !m_currentFile->fileName().isEmpty();
+}
+
+void FindInCurrentFile::handleFileChange(Core::IEditor *editor)
+{
+    if (!editor) {
+        if (m_currentFile) {
+            m_currentFile = 0;
+            emit changed();
+        }
+    } else {
+        Core::IFile *file = editor->file();
+        if (file != m_currentFile) {
+            m_currentFile = file;
+            emit changed();
+        }
+    }
 }
 
+
 QWidget *FindInCurrentFile::createConfigWidget()
 {
     if (!m_configWidget) {
diff --git a/src/plugins/texteditor/findincurrentfile.h b/src/plugins/texteditor/findincurrentfile.h
index cb3eecb428a..0785f54cc75 100644
--- a/src/plugins/texteditor/findincurrentfile.h
+++ b/src/plugins/texteditor/findincurrentfile.h
@@ -32,6 +32,8 @@
 
 #include "basefilefind.h"
 
+#include <coreplugin/ifile.h>
+#include <coreplugin/editormanager/ieditor.h>
 #include <find/ifindfilter.h>
 #include <find/searchresultwindow.h>
 
@@ -62,8 +64,12 @@ public:
 protected:
     QStringList files();
 
+private slots:
+    void handleFileChange(Core::IEditor *editor);
+
 private:
     QPointer<QWidget> m_configWidget;
+    Core::IFile *m_currentFile;
 };
 
 } // namespace Internal
-- 
GitLab