forked from qt-creator/qt-creator
Register C++ header and source file icons by mime type
Makes sure that all files recognized by the CppEditorFactory get the proper icon.
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "fileiconprovider.h"
|
#include "fileiconprovider.h"
|
||||||
|
#include "mimedatabase.h"
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
@@ -88,7 +90,9 @@ QIcon FileIconProvider::icon(const QFileInfo &fileInfo)
|
|||||||
return icon;
|
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 FileIconProvider::overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const
|
||||||
{
|
{
|
||||||
QPixmap iconPixmap = qApp->style()->standardIcon(baseIcon).pixmap(size);
|
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)
|
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);
|
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.
|
Returns an icon for the given suffix, or an empty one if none registered.
|
||||||
*/
|
*/
|
||||||
QIcon FileIconProvider::iconForSuffix(const QString &suffix) const
|
QIcon FileIconProvider::iconForSuffix(const QString &suffix) const
|
||||||
{
|
{
|
||||||
QIcon icon;
|
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)
|
Q_UNUSED(suffix)
|
||||||
#else
|
#else
|
||||||
if (suffix.isEmpty())
|
if (suffix.isEmpty())
|
||||||
|
|||||||
@@ -40,13 +40,17 @@
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class CORE_EXPORT FileIconProvider {
|
class MimeType;
|
||||||
|
|
||||||
|
class CORE_EXPORT FileIconProvider
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
~FileIconProvider(); // used to clear the cache
|
~FileIconProvider(); // used to clear the cache
|
||||||
QIcon icon(const QFileInfo &fileInfo);
|
QIcon icon(const QFileInfo &fileInfo);
|
||||||
|
|
||||||
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const;
|
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size) const;
|
||||||
void registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix);
|
void registerIconOverlayForSuffix(const QIcon &icon, const QString &suffix);
|
||||||
|
void registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType);
|
||||||
|
|
||||||
static FileIconProvider *instance();
|
static FileIconProvider *instance();
|
||||||
|
|
||||||
|
|||||||
@@ -65,29 +65,19 @@ CppEditorFactory::CppEditorFactory(CppPlugin *owner) :
|
|||||||
m_owner(owner)
|
m_owner(owner)
|
||||||
{
|
{
|
||||||
m_mimeTypes << QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)
|
m_mimeTypes << QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)
|
||||||
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
|
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
|
||||||
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
|
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
|
||||||
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
|
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
|
||||||
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
|
||||||
#ifndef Q_WS_MAC
|
#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.
|
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
||||||
QIcon cppIcon(":/cppeditor/images/qt_cpp.png");
|
Core::MimeDatabase *mimeDatabase = Core::ICore::instance()->mimeDatabase();
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cpp"));
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_cpp.png"),
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cp"));
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)));
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cc"));
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_c.png"),
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("cxx"));
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)));
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("C"));
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_h.png"),
|
||||||
iconProvider->registerIconOverlayForSuffix(cppIcon, QLatin1String("c++"));
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE)));
|
||||||
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++"));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +112,6 @@ CppPlugin *CppPlugin::m_instance = 0;
|
|||||||
|
|
||||||
CppPlugin::CppPlugin() :
|
CppPlugin::CppPlugin() :
|
||||||
m_actionHandler(0),
|
m_actionHandler(0),
|
||||||
m_factory(0),
|
|
||||||
m_sortedMethodOverview(false)
|
m_sortedMethodOverview(false)
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
@@ -130,8 +119,6 @@ CppPlugin::CppPlugin() :
|
|||||||
|
|
||||||
CppPlugin::~CppPlugin()
|
CppPlugin::~CppPlugin()
|
||||||
{
|
{
|
||||||
removeObject(m_factory);
|
|
||||||
delete m_factory;
|
|
||||||
delete m_actionHandler;
|
delete m_actionHandler;
|
||||||
m_instance = 0;
|
m_instance = 0;
|
||||||
}
|
}
|
||||||
@@ -174,12 +161,11 @@ bool CppPlugin::sortedMethodOverview() const
|
|||||||
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
||||||
{
|
{
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
|
|
||||||
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
|
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_factory = new CppEditorFactory(this);
|
addAutoReleasedObject(new CppEditorFactory(this));
|
||||||
addObject(m_factory);
|
|
||||||
|
|
||||||
addAutoReleasedObject(new CppHoverHandler);
|
addAutoReleasedObject(new CppHoverHandler);
|
||||||
|
|
||||||
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
|
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ namespace CppEditor {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CPPEditor;
|
class CPPEditor;
|
||||||
class CppEditorFactory;
|
|
||||||
|
|
||||||
class CppPlugin : public ExtensionSystem::IPlugin
|
class CppPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -76,7 +75,6 @@ private slots:
|
|||||||
void jumpToDefinition();
|
void jumpToDefinition();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CppEditorFactory;
|
|
||||||
Core::IEditor *createEditor(QWidget *parent);
|
Core::IEditor *createEditor(QWidget *parent);
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
@@ -84,7 +82,6 @@ private:
|
|||||||
static CppPlugin *m_instance;
|
static CppPlugin *m_instance;
|
||||||
|
|
||||||
TextEditor::TextEditorActionHandler *m_actionHandler;
|
TextEditor::TextEditorActionHandler *m_actionHandler;
|
||||||
CppEditorFactory *m_factory;
|
|
||||||
bool m_sortedMethodOverview;
|
bool m_sortedMethodOverview;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user