On Friday 11 September 2009 22:02:50 ext Nicolas Arnaud-Cormos wrote:
> Hi,
> 
> I'm playing with the code, and I find something strange. I'm trying to get
>  the type of the file in the current editor (header or source).
> If I'm on a header file, and call the function file()->mimetype() in
>  CPPEditor, it returns the string text/x-c++src.
> I would have expected text/x-c++hdr.
> 
> If I do something like this:
        
>     const QString typeName = mimeType.type();
>     if (typeName == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
>  || typeName == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
>  it's working.
> 
> Is it a bug?
Yes that's a bug. Though I'm not sure how to best fix that. Can you try the 
attached patch?


daniel
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 597a276..1788a0f 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -59,6 +59,7 @@
 #include <coreplugin/actionmanager/actionmanager.h>
 #include <coreplugin/editormanager/ieditor.h>
 #include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/mimedatabase.h>
 #include <utils/uncommentselection.h>
 #include <extensionsystem/pluginmanager.h>
 #include <projectexplorer/projectexplorerconstants.h>
@@ -1474,6 +1475,19 @@ void CPPEditor::setFontSettings(const TextEditor::FontSettings &fs)
     m_occurrenceRenameFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES_RENAME));
 }
 
+bool CPPEditor::open(const QString &fileName)
+{
+    if (BaseTextEditor::open(fileName)) {
+        Core::ICore *core = Core::ICore::instance();
+        QFileInfo fi(fileName);
+        const Core::MimeDatabase *mimeDatase = core->mimeDatabase();
+        setMimeType(mimeDatase->findByFile(fi).type());
+        return true;
+    } else {
+        return false;
+    }
+}
+
 void CPPEditor::unCommentSelection()
 {
     Core::Utils::unCommentSelection(this);
diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h
index 40e2e71..e571a93 100644
--- a/src/plugins/cppeditor/cppeditor.h
+++ b/src/plugins/cppeditor/cppeditor.h
@@ -185,10 +185,12 @@ public:
 
     CPPEditor(QWidget *parent);
     ~CPPEditor();
-    void unCommentSelection();
 
-    void indentInsertedText(const QTextCursor &tc);
+    bool open(const QString &fileName = QString());
+
+    void unCommentSelection();
 
+    void indentInsertedText(const QTextCursor &tc);    
     SemanticInfo semanticInfo() const;
 
 public Q_SLOTS:
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to