Commit 8234858b authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Register C++ header and source file icons by mime type

Makes sure that all files recognized by the CppEditorFactory get the
proper icon.
parent c13f8326
......@@ -28,6 +28,8 @@
**************************************************************************/
#include "fileiconprovider.h"
#include "mimedatabase.h"
#include <QtGui/QApplication>
#include <QtGui/QStyle>
#include <QtGui/QPainter>
......@@ -88,7 +90,9 @@ QIcon FileIconProvider::icon(const QFileInfo &fileInfo)
return icon;
}
// Creates a pixmap with baseicon at size and overlayous overlayIcon over it.
/*!
Creates a pixmap with baseicon at size and overlays overlayIcon over it.
*/
QPixmap FileIconProvider::overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const
{
QPixmap iconPixmap = qApp->style()->standardIcon(baseIcon).pixmap(size);
......@@ -99,7 +103,7 @@ QPixmap FileIconProvider::overlayIcon(QStyle::StandardPixmap baseIcon, const QIc
}
/*!
Registers an icon for a given suffix, overlaying the system file icon
Registers an icon for a given suffix, overlaying the system file icon.
*/
void FileIconProvider::registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix)
{
......@@ -117,13 +121,22 @@ void FileIconProvider::registerIconOverlayForSuffix(const QIcon &icon, const QSt
m_cache.append(newEntry);
}
/*!
Registers an icon for all the suffixes of a given mime type, overlaying the system file icon.
*/
void FileIconProvider::registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType)
{
foreach (const QString &suffix, mimeType.suffixes())
registerIconOverlayForSuffix(icon, suffix);
}
/*!
Returns an icon for the given suffix, or an empty one if none registered.
*/
QIcon FileIconProvider::iconForSuffix(const QString &suffix) const
{
QIcon icon;
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) // On windows we use the file system icons
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) // On Windows and Mac we use the file system icons
Q_UNUSED(suffix)
#else
if (suffix.isEmpty())
......
......@@ -40,13 +40,17 @@
namespace Core {
class CORE_EXPORT FileIconProvider {
class MimeType;
class CORE_EXPORT FileIconProvider
{
public:
~FileIconProvider(); // used to clear the cache
QIcon icon(const QFileInfo &fileInfo);
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const;
void registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix);
void registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType);
static FileIconProvider *instance();
......
......@@ -65,29 +65,19 @@ CppEditorFactory::CppEditorFactory(CppPlugin *owner) :
m_owner(owner)
{
m_mimeTypes << QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
#ifndef Q_WS_MAC
// ### It would be really cool if we could get the stuff from the XML file here and not play "catch up" all the time.
QIcon cppIcon(":/cppeditor/images/qt_cpp.png");
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cpp"));
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cp"));
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cc"));
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cxx"));
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("C"));
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("c++"));
iconProvider->registerIconOverlayForSuffix(QIcon(":/cppeditor/images/qt_c.png"),
QLatin1String("c"));
QIcon headerIcon(":/cppeditor/images/qt_h.png");
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("hpp"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("hh"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("h"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("hxx"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("H"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("hp"));
iconProvider->registerIconOverlayForSuffix(headerIcon, QLatin1String("h++"));
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
Core::MimeDatabase *mimeDatabase = Core::ICore::instance()->mimeDatabase();
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_cpp.png"),
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)));
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_c.png"),
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)));
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_h.png"),
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE)));
#endif
}
......@@ -122,7 +112,6 @@ CppPlugin *CppPlugin::m_instance = 0;
CppPlugin::CppPlugin() :
m_actionHandler(0),
m_factory(0),
m_sortedMethodOverview(false)
{
m_instance = this;
......@@ -130,8 +119,6 @@ CppPlugin::CppPlugin() :
CppPlugin::~CppPlugin()
{
removeObject(m_factory);
delete m_factory;
delete m_actionHandler;
m_instance = 0;
}
......@@ -174,12 +161,11 @@ bool CppPlugin::sortedMethodOverview() const
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
Core::ICore *core = Core::ICore::instance();
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
return false;
m_factory = new CppEditorFactory(this);
addObject(m_factory);
addAutoReleasedObject(new CppEditorFactory(this));
addAutoReleasedObject(new CppHoverHandler);
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
......
......@@ -44,7 +44,6 @@ namespace CppEditor {
namespace Internal {
class CPPEditor;
class CppEditorFactory;
class CppPlugin : public ExtensionSystem::IPlugin
{
......@@ -76,7 +75,6 @@ private slots:
void jumpToDefinition();
private:
friend class CppEditorFactory;
Core::IEditor *createEditor(QWidget *parent);
void writeSettings();
void readSettings();
......@@ -84,7 +82,6 @@ private:
static CppPlugin *m_instance;
TextEditor::TextEditorActionHandler *m_actionHandler;
CppEditorFactory *m_factory;
bool m_sortedMethodOverview;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment