Move the plugin examples to subdir of pluginhowto.

This commit is contained in:
con
2010-06-21 16:12:49 +02:00
parent abcb9358c2
commit 08c8ce32e9
87 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<plugin name="DirModelPlugin" version="0.0.1">
<vendor>FooCompany</vendor>
<copyright>(C) 2009-2010 FooCompanyInc Pvt. Ltd.</copyright>
<license>GPL</license>
<description>Dir Model</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,35 @@
#include "dirmodelpluginplugin.h"
#include <QtPlugin>
#include <QStringList>
#include "DirNavigationFactory.h"
DirModelPluginPlugin::DirModelPluginPlugin()
{
// Do nothing
}
DirModelPluginPlugin::~DirModelPluginPlugin()
{
// Do notning
}
void DirModelPluginPlugin::extensionsInitialized()
{
// Do nothing
}
bool DirModelPluginPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject(new DirNavigationFactory);
return true;
}
void DirModelPluginPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(DirModelPluginPlugin)

View File

@@ -0,0 +1,18 @@
#ifndef DIRMODELPLUGIN_PLUGIN_H
#define DIRMODELPLUGIN_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DirModelPluginPlugin : public ExtensionSystem::IPlugin
{
public:
DirModelPluginPlugin();
~DirModelPluginPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // DIRMODELPLUGIN_PLUGIN_H

View File

@@ -0,0 +1,25 @@
# Uncomment the lines below and set the path
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DirModelPlugin
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = dirmodelpluginplugin.h \
dirnavigationfactory.h \
filesystemmodel.h
SOURCES = dirmodelpluginplugin.cpp \
dirnavigationfactory.cpp \
filesystemmodel.cpp
OTHER_FILES = DirModelPlugin.pluginspec

View File

@@ -0,0 +1,35 @@
#include "dirnavigationfactory.h"
#include "filesystemmodel.h"
#include <QTreeView>
#include <QDir>
#include <coreplugin/navigationwidget.h>
/**
\todo
*/
Core::NavigationView DirNavigationFactory::createWidget()
{
Core::NavigationView view;
// Create FileSystemModel and set the defauls path as home path
FileSystemModel* model = new FileSystemModel;
model->setRootPath(QDir::homePath());
// Create TreeView and set model
QTreeView* tree = new QTreeView;
tree->setModel(model);
view.widget = tree;
return view;
}
/**
\todo
*/
QString DirNavigationFactory::displayName()
{
return "Dir View";
}

View File

@@ -0,0 +1,15 @@
#ifndef DIRNAVIGATIONFACTORY_H
#define DIRNAVIGATIONFACTORY_H
#include <coreplugin/inavigationwidgetfactory.h>
class DirNavigationFactory : public Core::INavigationWidgetFactory
{
public:
DirNavigationFactory(){ }
~DirNavigationFactory() { }
Core::NavigationView createWidget();
QString displayName();
};
#endif // DIRNAVIGATIONFACTORY_H

View File

@@ -0,0 +1,20 @@
#include "filesystemmodel.h"
FileSystemModel::FileSystemModel(QObject* parent)
:QFileSystemModel(parent)
{
}
FileSystemModel::~FileSystemModel()
{
}
int FileSystemModel::columnCount(const QModelIndex &parent ) const
{
Q_UNUSED(parent)
return 1;
}

View File

@@ -0,0 +1,17 @@
#ifndef FILESYSTEMMODEL_H
#define FILESYSTEMMODEL_H
#include <QFileSystemModel>
/**
This FileSystemModel is subcalss of QFileSystemModel which just returns only 1 column.
*/
class FileSystemModel : public QFileSystemModel
{
public:
FileSystemModel(QObject* parent=0);
~FileSystemModel();
int columnCount(const QModelIndex &parent = QModelIndex()) const;
};
#endif // FILESYSTEMMODEL_H

View File

@@ -0,0 +1,10 @@
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license></license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,35 @@
#include "donothingplugin.h"
#include <QtPlugin>
#include <QStringList>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(DoNothingPlugin)

View File

@@ -0,0 +1,19 @@
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // DONOTHING_PLUGIN_H

View File

@@ -0,0 +1,21 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec

View File

@@ -0,0 +1,11 @@
<plugin name="HeaderFilter" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.foocompany.com</url>
<dependencyList>
<dependency name="Core"/>
<dependency name="Find"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,142 @@
#include "headerfilter.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/iprojectmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/filesearch.h>
#include<QFutureWatcher>
#include<QLabel>
#include <find/searchresultwindow.h>
#include <texteditor/basetexteditor.h>
using namespace Core;
using namespace Utils;
struct HeaderFilterData
{
HeaderFilterData() : m_projectPlugin(0), m_searchResultWindow(0){}
QFutureWatcher<FileSearchResult> watcher;
ProjectExplorer::ProjectExplorerPlugin* projectExplorer()
{
if(m_projectPlugin)
return m_projectPlugin;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
m_projectPlugin = pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
return m_projectPlugin;
}
// Method to search and return the search window
Find::SearchResultWindow* searchResultWindow()
{
if(m_searchResultWindow)
return m_searchResultWindow;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
m_searchResultWindow = pm->getObject<Find::SearchResultWindow>();
return m_searchResultWindow;
}
private:
ProjectExplorer::ProjectExplorerPlugin* m_projectPlugin;
Find::SearchResultWindow *m_searchResultWindow;
};
HeaderFilter::HeaderFilter()
{
d = new HeaderFilterData;
d->watcher.setPendingResultsLimit(1);
// displayResult(int) is called when every a new
// search result is generated
connect(&d->watcher, SIGNAL(resultReadyAt(int)),this, SLOT(displayResult(int)));
}
HeaderFilter::~HeaderFilter()
{
delete d;
}
QString HeaderFilter::id() const
{
return "HeaderFilter";
}
QString HeaderFilter::name() const
{
return tr("Header Filter");
}
bool HeaderFilter::isEnabled() const
{
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
if(projects.count())
return true;
return false;
}
QKeySequence HeaderFilter::defaultShortcut() const
{
return QKeySequence();
}
QWidget *HeaderFilter::createConfigWidget()
{
return (new QLabel("This is a header filter"));
}
void HeaderFilter::findAll(const QString &text,QTextDocument::FindFlags findFlags)
{
// Fetch a list of all open projects
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
// Make a list of files in each project
QStringList files;
Q_FOREACH(ProjectExplorer::Project* project, projects)
files += project->files(ProjectExplorer::Project::AllFiles);
// Remove duplicates
files.removeDuplicates();
//------------------------------------------------------------
// Begin searching
QString includeline = "#include <" + text + ">";
Find::SearchResult *result = d->searchResultWindow()->startNewSearch();
d->watcher.setFuture(QFuture<FileSearchResult>());
//When result gets activated it invokes the openEditor function
connect(result, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
d->searchResultWindow()->popup(true);
// Let the watcher monitor the search results
d->watcher.setFuture(Utils::findInFiles(includeline, files, findFlags));
}
void HeaderFilter::displayResult(int index)
{
FileSearchResult result = d->watcher.future().resultAt(index);
d->searchResultWindow()->addResult(result.fileName,
result.lineNumber,
result.matchingLine,
result.matchStart,
result.matchLength);
}
void HeaderFilter::openEditor(const Find::SearchResultItem &item)
{
TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.index);
}

View File

@@ -0,0 +1,42 @@
#ifndef HEADERFILTER_H
#define HEADERFILTER_H
#include <find/ifindfilter.h>
#include <utils/filesearch.h>
namespace Find {
class SearchResultWindow;
struct SearchResultItem;
}
class QKeySequence;
class QWidget;
struct HeaderFilterData;
class HeaderFilter : public Find::IFindFilter
{
Q_OBJECT
public:
HeaderFilter();
~HeaderFilter();
QString id() const;
QString name() const;
bool isEnabled() const;
QKeySequence defaultShortcut() const;
void findAll(const QString &txt,QTextDocument::FindFlags findFlags);
QWidget *createConfigWidget();
protected slots:
void displayResult(int index);
void openEditor(const Find::SearchResultItem &item);
private:
HeaderFilterData *d;
};
#endif // HEADERFILTER_H

View File

@@ -0,0 +1,36 @@
#include "headerfilterplugin.h"
#include "headerfilter.h"
#include <QtPlugin>
#include <QStringList>
HeaderFilterPlugin::HeaderFilterPlugin()
{
// Do nothing
}
HeaderFilterPlugin::~HeaderFilterPlugin()
{
// Do notning
}
void HeaderFilterPlugin::extensionsInitialized()
{
// Do nothing
}
bool HeaderFilterPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject( new HeaderFilter);
return true;
}
void HeaderFilterPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(HeaderFilterPlugin)

View File

@@ -0,0 +1,20 @@
#ifndef HEADERFILTER_PLUGIN_H
#define HEADERFILTER_PLUGIN_H
#include <extensionsystem/iplugin.h>
class HeaderFilterPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
HeaderFilterPlugin();
~HeaderFilterPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // HEADERFILTER_PLUGIN_H

View File

@@ -0,0 +1,26 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
DEFINES += FIND_LIBRARY
TEMPLATE = lib
TARGET = HeaderFilter
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/libs/extensionsystem/extensionsystem.pri)
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
include($$QTC_SOURCE/src/libs/utils/utils.pri)
include($$QTC_SOURCE/src/plugins/projectexplorer/projectexplorer.pri)
include($$QTC_SOURCE/src/plugins/find/find.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = headerfilterplugin.h \
headerfilter.h
SOURCES = headerfilterplugin.cpp \
headerfilter.cpp
OTHER_FILES = HeaderFilter.pluginspec

View File

@@ -0,0 +1,11 @@
<plugin name="HTMLEditor" version="0.0.1">
<vendor>FooCompanyInc Pvt. Ltd</vendor>
<copyright>(C) 2009-2010 FooCompanyInc Pvt. Ltd.</copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,129 @@
#include "htmlfile.h"
#include "htmleditor.h"
#include "htmleditorwidget.h"
#include "coreplugin/uniqueidmanager.h"
struct HTMLEditorData
{
HTMLEditorData() : editorWidget(0), file(0) { }
HTMLEditorWidget* editorWidget;
QString displayName;
HTMLFile* file;
QList<int> context;
};
namespace HTMLEditorConstants
{
const char* const C_HTMLEDITOR_MIMETYPE = "text/html";
const char* const C_HTMLEDITOR = "HTML Editor";
}
HTMLEditor::HTMLEditor(HTMLEditorWidget* editorWidget)
:Core::IEditor(editorWidget)
{
d = new HTMLEditorData;
d->editorWidget = editorWidget;
d->file = new HTMLFile(this, editorWidget);
Core::UniqueIDManager* uidm = Core::UniqueIDManager::instance();
d->context << uidm->uniqueIdentifier(HTMLEditorConstants::C_HTMLEDITOR);
connect(d->editorWidget, SIGNAL(contentModified()),
d->file, SLOT(modified()));
connect(d->editorWidget, SIGNAL(titleChanged(QString)),
this, SLOT(slotTitleChanged(QString)));
connect(d->editorWidget, SIGNAL(contentModified()),
this, SIGNAL(changed()));
}
HTMLEditor::~HTMLEditor()
{
delete d;
}
QWidget* HTMLEditor::widget()
{
return d->editorWidget;
}
QList<int> HTMLEditor::context() const
{
return d->context;
}
Core::IFile* HTMLEditor::file()
{
return d->file;
}
bool HTMLEditor::createNew(const QString& contents)
{
Q_UNUSED(contents);
d->editorWidget->setContent(QByteArray());
d->file->setFilename(QString());
return true;
}
bool HTMLEditor::open(const QString &fileName)
{
return d->file->open(fileName);
}
const char* HTMLEditor::kind() const
{
return HTMLEditorConstants::C_HTMLEDITOR;
}
QString HTMLEditor::displayName() const
{
return d->displayName;
}
void HTMLEditor::setDisplayName(const QString& title)
{
if(d->displayName == title)
return;
d->displayName = title;
emit changed();
}
bool HTMLEditor::duplicateSupported() const
{
return false;
}
Core::IEditor* HTMLEditor::duplicate(QWidget* parent)
{
Q_UNUSED(parent);
return 0;
}
QByteArray HTMLEditor::saveState() const
{
return QByteArray();
}
bool HTMLEditor::restoreState(const QByteArray& state)
{
Q_UNUSED(state);
return false;
}
QToolBar* HTMLEditor::toolBar()
{
return 0;
}
bool HTMLEditor::isTemporary() const
{
return false;
}

View File

@@ -0,0 +1,44 @@
#ifndef HTMLEDITOR_H
#define HTMLEDITOR_H
#include "coreplugin/editormanager/ieditor.h"
#include <QToolBar>
class HTMLEditorWidget;
struct HTMLEditorData;
class HTMLEditor : public Core::IEditor
{
Q_OBJECT
public:
HTMLEditor(HTMLEditorWidget* editorWidget);
~HTMLEditor();
bool createNew(const QString& contents = QString());
QString displayName() const;
IEditor* duplicate(QWidget* parent);
bool duplicateSupported() const;
Core::IFile* file();
bool isTemporary() const;
const char* kind() const;
bool open(const QString& fileName = QString()) ;
bool restoreState(const QByteArray& state);
QByteArray saveState() const;
void setDisplayName(const QString &title);
QToolBar* toolBar();
// From Core::IContext
QWidget* widget();
QList<int> context() const;
protected slots:
void slotTitleChanged(const QString& title)
{ setDisplayName(title); }
private:
HTMLEditorData* d;
};
#endif // HTMLEDITOR_H

View File

@@ -0,0 +1,61 @@
#include "coreplugin/editormanager/editormanager.h"
#include "htmleditorfactory.h"
#include "htmleditorwidget.h"
#include "htmleditorplugin.h"
#include "htmleditor.h"
namespace HTMLEditorConstants
{
const char* const C_HTMLEDITOR_MIMETYPE = "text/html";
const char* const C_HTMLEDITOR = "HTML Editor";
}
struct HTMLEditorFactoryData
{
HTMLEditorFactoryData() : kind(HTMLEditorConstants::C_HTMLEDITOR)
{
mimeTypes << QString(HTMLEditorConstants::C_HTMLEDITOR_MIMETYPE);
}
QString kind;
QStringList mimeTypes;
};
HTMLEditorFactory::HTMLEditorFactory(HTMLEditorPlugin* owner)
:Core::IEditorFactory(owner)
{
d = new HTMLEditorFactoryData;
}
HTMLEditorFactory::~HTMLEditorFactory()
{
delete d;
}
QStringList HTMLEditorFactory::mimeTypes() const
{
return d->mimeTypes;
}
QString HTMLEditorFactory::kind() const
{
return d->kind;
}
Core::IFile* HTMLEditorFactory::open(const QString& fileName)
{
Core::EditorManager* em = Core::EditorManager::instance();
Core::IEditor* iface = em->openEditor(fileName, d->kind);
return iface ? iface->file() : 0;
}
Core::IEditor* HTMLEditorFactory::createEditor(QWidget* parent)
{
HTMLEditorWidget* editorWidget = new HTMLEditorWidget(parent);
return new HTMLEditor(editorWidget);
}

View File

@@ -0,0 +1,27 @@
#ifndef HTMLEDITORFACTORY_H
#define HTMLEDITORFACTORY_H
#include "coreplugin/editormanager/ieditorfactory.h"
class HTMLEditorPlugin;
struct HTMLEditorFactoryData;
class HTMLEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
HTMLEditorFactory(HTMLEditorPlugin* owner);
~HTMLEditorFactory();
QStringList mimeTypes() const;
QString kind() const;
Core::IEditor* createEditor(QWidget* parent);
Core::IFile* open(const QString &fileName);
private:
HTMLEditorFactoryData* d;
};
#endif // HTMLEDITORFACTORY_H

View File

@@ -0,0 +1,57 @@
#include "htmleditorplugin.h"
#include "htmleditorfactory.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/icore.h>
#include <QtPlugin>
#include <QString>
#include <QMessageBox>
#include <QFontDialog>
HTMLEditorPlugin::HTMLEditorPlugin()
{
// Do nothing
}
HTMLEditorPlugin::~HTMLEditorPlugin()
{
// Do notning
}
void HTMLEditorPlugin::extensionsInitialized()
{
// Do nothing
}
bool HTMLEditorPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Core::ActionManager* am = Core::ICore::instance()->actionManager();
Core::ActionContainer* ac = am->actionContainer(Core::Constants::M_EDIT);
QAction* Font = ac->menu()->addAction("Font");
// Create a command for "Font".
Core::Command* cmd = am->registerAction(new QAction(this),"HTMLEditorPlugin.Font",QList<int>() << 0);
cmd->action()->setText("Font");
Core::ICore* core = Core::ICore::instance();
Core::MimeDatabase* mdb = core->mimeDatabase();
if(!mdb->addMimeTypes("text-html-mimetype.xml", errMsg))
return false;
QMessageBox::information(0, "Msg", *errMsg);
addAutoReleasedObject(new HTMLEditorFactory(this));
return true;
}
void HTMLEditorPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(HTMLEditorPlugin)

View File

@@ -0,0 +1,21 @@
#ifndef HTMLEDITOR_PLUGIN_H
#define HTMLEDITOR_PLUGIN_H
#include "extensionsystem/iplugin.h"
#include "coreplugin/uniqueidmanager.h"
class HTMLEditorPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
HTMLEditorPlugin();
~HTMLEditorPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // HTMLEDITOR_PLUGIN_H

View File

@@ -0,0 +1,31 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = HTMLEditor
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
QT += webkit
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = htmleditorplugin.h \
htmleditorwidget.h \
htmlfile.h \
htmleditor.h \
htmleditorfactory.h
SOURCES = htmleditorplugin.cpp \
htmleditorwidget.cpp \
htmlfile.cpp \
htmleditor.cpp \
htmleditorfactory.cpp
OTHER_FILES = HTMLEditor.pluginspec \
text-html-mimetype.xml

View File

@@ -0,0 +1,82 @@
#include "htmleditorwidget.h"
#include <QTextEdit>
#include <QPlainTextEdit>
#include <QtWebKit>
#include <QDebug>
struct HTMLEditorWidgetData
{
QWebView* webView;
QPlainTextEdit* textEdit;
bool modified;
QString path;
};
HTMLEditorWidget::HTMLEditorWidget(QWidget* parent):QTabWidget(parent)
{
d = new HTMLEditorWidgetData;
d->webView = new QWebView;
d->textEdit = new QPlainTextEdit;
addTab(d->webView, "Preview");
addTab(d->textEdit, "Source");
setTabPosition(QTabWidget::South);
setTabShape(QTabWidget::Triangular);
d->textEdit->setFont( QFont("Courier", 12) );
connect(this, SIGNAL(currentChanged(int)),
this, SLOT(slotCurrentTabChanged(int)));
connect(d->textEdit, SIGNAL(textChanged()),
this, SLOT(slotContentModified()));
connect(d->webView, SIGNAL(titleChanged(QString)),
this, SIGNAL(titleChanged(QString)));
d->modified = false;
}
HTMLEditorWidget::~HTMLEditorWidget()
{
delete d;
}
void HTMLEditorWidget::setContent(const QByteArray& ba, const QString& path)
{
if(path.isEmpty())
d->webView->setHtml(ba);
else
d->webView->setHtml(ba, "file:///" + path);
d->textEdit->setPlainText(ba);
d->modified = false;
d->path = path;
}
QByteArray HTMLEditorWidget::content() const
{
QString HTMLText = d->textEdit->toPlainText();
return HTMLText.toAscii();
}
QString HTMLEditorWidget::title() const
{
return d->webView->title();
}
void HTMLEditorWidget::slotCurrentTabChanged(int tab)
{
if(tab == 0 && d->modified)
setContent( content(), d->path );
}
void HTMLEditorWidget::slotContentModified()
{
d->modified = true;
emit contentModified();
}

View File

@@ -0,0 +1,32 @@
#ifndef RTEDITORWIDGET_H
#define RTEDITORWIDGET_H
#include<QTabWidget>
struct HTMLEditorWidgetData;
class HTMLEditorWidget:public QTabWidget
{
Q_OBJECT
public:
HTMLEditorWidget(QWidget* parent = 0);
~HTMLEditorWidget();
void setContent(const QByteArray& ba, const QString& path=QString());
QByteArray content() const;
QString title() const;
protected slots:
void slotCurrentTabChanged(int tab);
void slotContentModified();
signals:
void contentModified();
void titleChanged(const QString&);
private:
HTMLEditorWidgetData* d;
};
#endif // RTEDITORWIDGET_H

View File

@@ -0,0 +1,130 @@
#include "htmlfile.h"
#include<QFile>
#include<QFileInfo>
namespace HTMLEditorConstants
{
const char* const C_HTMLEDITOR_MIMETYPE = "text/html";
const char* const C_HTMLEDITOR = "HTML Editor";
}
struct HTMLFileData
{
HTMLFileData(): mimeType(HTMLEditorConstants::C_HTMLEDITOR),
editorWidget(0), editor(0), modified(false) { }
const QString mimeType;
HTMLEditorWidget* editorWidget;
HTMLEditor* editor;
QString fileName;
bool modified;
};
HTMLFile::HTMLFile(HTMLEditor* editor, HTMLEditorWidget* editorWidget)
: Core::IFile(editor)
{
d = new HTMLFileData;
d->editor = editor;
d->editorWidget = editorWidget;
}
HTMLFile::~HTMLFile()
{
delete d;
}
void HTMLFile::setModified(bool val)
{
if(d->modified == val)
return;
d->modified = val;
emit changed();
}
bool HTMLFile::isModified() const
{
return d->modified;
}
QString HTMLFile::mimeType() const
{
return d->mimeType;
}
bool HTMLFile::save(const QString &fileName)
{
QFile file(fileName);
if(file.open(QFile::WriteOnly))
{
d->fileName = fileName;
QByteArray content = d->editorWidget->content();
file.write(content);
setModified(false);
return true;
}
return false;
}
bool HTMLFile::open(const QString &fileName)
{
QFile file(fileName);
if(file.open(QFile::ReadOnly))
{
d->fileName = fileName;
QString path = QFileInfo(fileName).absolutePath();
d->editorWidget->setContent(file.readAll(), path);
d->editor->setDisplayName(d->editorWidget->title());
return true;
}
return false;
}
void HTMLFile::setFilename(const QString& filename)
{
d->fileName = filename;
}
QString HTMLFile::fileName() const
{
return d->fileName;
}
QString HTMLFile::defaultPath() const
{
return QString();
}
QString HTMLFile::suggestedFileName() const
{
return QString();
}
QString HTMLFile::fileFilter() const
{
return QString();
}
QString HTMLFile::fileExtension() const
{
return QString();
}
bool HTMLFile::isReadOnly() const
{
return false;
}
bool HTMLFile::isSaveAsAllowed() const
{
return true;
}
void HTMLFile::modified(ReloadBehavior* behavior)
{
Q_UNUSED(behavior);
}

View File

@@ -0,0 +1,38 @@
#ifndef HTMLFILE_H
#define HTMLFILE_H
#include "coreplugin/ifile.h"
#include "htmleditorwidget.h"
#include "htmleditor.h"
struct HTMLFileData;
class HTMLFile : public Core::IFile
{
Q_OBJECT
public:
HTMLFile(HTMLEditor* editor, HTMLEditorWidget* editorWidget);
~HTMLFile();
void setModified(bool val=true);
bool isModified() const ;
bool save(const QString &filename);
bool open(const QString &filename);
void setFilename(const QString &filename);
QString mimiType(void) const ;
QString fileName() const;
QString defaultPath() const ;
QString mimeType() const;
QString suggestedFileName() const;
QString fileFilter() const;
QString fileExtension() const;
bool isReadOnly() const;
bool isSaveAsAllowed() const;
void modified(ReloadBehavior* behavior);
protected slots:
void modified() { setModified(true); }
private:
HTMLFileData* d;
};
#endif // HTMLFILE_H

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/html">
<sub-class-of type="text/plain"/>
<comment>HTML File</comment>
<glob pattern="*.html"/>
</mime-type>
</mime-info>

View File

@@ -0,0 +1,10 @@
<plugin name="loggermode" version="0.0.1">
<vendor>FoocompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,139 @@
#include "loggermode.h"
#include "loggermodewidget.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <utils/styledbar.h>
#include <utils/iwelcomepage.h>
#include <coreplugin/uniqueidmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <QtCore/QSettings>
#include <QStackedWidget>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QPushbutton>
#include <QMessageBox>
struct LoggerModeData
{
QWidget *m_widget;
QLabel *currentProjectsLabel;
QLabel *addProjectLabel;
QComboBox *currentProjectsCombobox;
QComboBox *addProjectComboBox;
QPushButton *addToProjectButton;
QStackedWidget *stackedWidget;
};
LoggerMode::LoggerMode()
{
d = new LoggerModeData;
d->m_widget = new QWidget;
d->currentProjectsLabel = new QLabel("Current projects :");
d->currentProjectsLabel->setFixedWidth(90);
d->currentProjectsCombobox = new QComboBox;
d->currentProjectsCombobox->setSizePolicy(QSizePolicy::Preferred,
QSizePolicy::Preferred);
d->addProjectLabel = new QLabel("Add Project :");
d->addProjectLabel->setAlignment(Qt::AlignRight);
d->addProjectComboBox = new QComboBox;
d->addProjectComboBox->setSizePolicy(QSizePolicy::Preferred,
QSizePolicy::Preferred);
d->addProjectComboBox->setEditable(true);
d->addToProjectButton = new QPushButton(tr("Add Project"));
d->addToProjectButton->setFixedWidth(80);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(d->currentProjectsLabel);
hLayout->addWidget(d->currentProjectsCombobox);
hLayout->addWidget(d->addProjectLabel);
hLayout->addWidget(d->addProjectComboBox);
hLayout->addWidget(d->addToProjectButton);
d->stackedWidget = new QStackedWidget;
QVBoxLayout* layout = new QVBoxLayout;
layout->addLayout(hLayout);
layout->addWidget(d->stackedWidget);
d->m_widget->setLayout(layout);
d->addProjectComboBox->addItem("Project 1");
d->addProjectComboBox->addItem("Project 2");
d->addProjectComboBox->addItem("Project 3");
connect(d->addToProjectButton,SIGNAL(clicked()),
this,SLOT(addItem()));
connect(d->currentProjectsCombobox, SIGNAL(currentIndexChanged(int)),
d->stackedWidget, SLOT(setCurrentIndex(int)));
}
LoggerMode::~LoggerMode()
{
delete d->m_widget;
delete d;
}
void LoggerMode::addItem()
{
d->currentProjectsCombobox->addItem(d->addProjectComboBox->currentText());
addNewStackWidgetPage(d->currentProjectsCombobox->itemText(0));
d->addProjectComboBox->removeItem(d->addProjectComboBox->currentIndex());
}
QString LoggerMode::name() const
{
return tr("LoggerMode");
}
QIcon LoggerMode::icon() const
{
return QIcon(QLatin1String(":/core/images/qtcreator_logo_32.png"));
}
int LoggerMode::priority() const
{
return 0;
}
QWidget* LoggerMode::widget()
{
return d->m_widget;
}
const char* LoggerMode::uniqueModeName() const
{
return "LoggerMode" ;
}
QList<int> LoggerMode::context() const
{
return QList<int>();
}
void LoggerMode::addNewStackWidgetPage(const QString projectName)
{
d->stackedWidget->addWidget(new LoggerModeWidget(projectName));
}

View File

@@ -0,0 +1,35 @@
#ifndef LOGGERMODE_H
#define LOGGERMODE_H
#include <coreplugin/imode.h>
#include <projectexplorer/project.h>
class QWidget;
struct LoggerModeData;
class LoggerMode :public Core::IMode
{
Q_OBJECT
public:
LoggerMode();
~LoggerMode();
// IMode
QString name() const;
QIcon icon() const;
int priority() const;
QWidget *widget();
const char *uniqueModeName() const;
QList<int> context() const;
void activated();
QString contextHelpId() const { return QLatin1String("Qt Creator"); }
protected slots:
void addNewStackWidgetPage(const QString projectName);
void addItem();
private:
LoggerModeData *d;
};
#endif // NEWMODE_H

View File

@@ -0,0 +1,36 @@
#include "loggermodePlugin.h"
#include "loggermode.h"
#include <QtPlugin>
#include <QStringList>
LoggerModePlugin::LoggerModePlugin()
{
}
LoggerModePlugin::~LoggerModePlugin()
{
}
void LoggerModePlugin::extensionsInitialized()
{
}
bool LoggerModePlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
loggerMode = new LoggerMode;
addAutoReleasedObject(loggerMode);
return true;
}
void LoggerModePlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(LoggerModePlugin)

View File

@@ -0,0 +1,21 @@
#ifndef LOGGERMODE_PLUGIN_H
#define LOGGERMODE_PLUGIN_H
#include <extensionsystem/iplugin.h>
class LoggerMode;
class LoggerModePlugin : public ExtensionSystem::IPlugin
{
public:
LoggerModePlugin();
~LoggerModePlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
LoggerMode *loggerMode;
};
#endif // NEWMODE_PLUGIN_H

View File

@@ -0,0 +1,20 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = loggermode
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = loggermodePlugin.h \
loggermode.h \
loggermodewidget.h
SOURCES = loggermodePlugin.cpp \
loggermode.cpp \
loggermodewidget.cpp
OTHER_FILES = LoggerMode.pluginspec

View File

@@ -0,0 +1,192 @@
#include "loggermodewidget.h"
#include<QTableWidget>
#include <QFileDialog>
#include<QLabel>
#include<QGroupBox>
#include<QComboBox>
#include<QPushButton>
#include<QLineEdit>
#include<QTime>
#include<QTimer>
#include<QTextEdit>
#include<QCalendarWidget>
#include<QComboBox>
#include<QGridLayout>
#include<QMessageBox>
#include<QApplication>
#include<QTextStream>
#include<QCloseEvent>
struct LoggerModeWidgetData
{
QLabel *progressLabel;
QLabel *hoursWorkedLabel;
QLabel *dateLabel;
QLabel *descriptionLabel;
QCalendarWidget *calendar;
QComboBox *progressComboBox;
QLineEdit *hoursWorkedLineEdit;
QPushButton *startTimerButton;
QPushButton *stopTimerButton;
QPushButton *saveButton;
QTimer *timer;
QTextEdit *textEdit;
QString projectName;
int totalTime;
};
LoggerModeWidget::LoggerModeWidget(const QString projectName, QWidget* parent)
:QWidget(parent)
{
d = new LoggerModeWidgetData;
d->projectName = projectName;
d->totalTime = 0;
/*
// Catch hold of the plugin-manager
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
// Look for the ProjectExplorerPlugin object
ProjectExplorer::ProjectExplorerPlugin* projectExplorerPlugin
= pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
// Fetch a list of all open projects
QList<ProjectExplorer::Project*> projects =projectExplorerPlugin->session()->projects();
Q_FOREACH(ProjectExplorer::Project* project, projects)
d->projectExplorerCombo->addItem( project->name());
*/
QStringList percentList;
percentList <<"10%" <<"20%" <<"30%" <<"40%" <<"50%"
<<"60%" <<"70%" <<"80%" <<"90%" <<"100%" ;
d->progressLabel = new QLabel("Progress:");
d->hoursWorkedLabel = new QLabel("Hours Worked:");
d->dateLabel = new QLabel("Date:");
d->descriptionLabel = new QLabel("Description :");
d->hoursWorkedLineEdit = new QLineEdit;
d->hoursWorkedLineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->progressComboBox = new QComboBox;
d->progressComboBox->addItems(percentList);
d->progressComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->startTimerButton = new QPushButton(tr("Start Timer"));
d->startTimerButton->setFixedWidth(80);
d->stopTimerButton = new QPushButton(tr("Pause Timer"));
d->stopTimerButton->setFixedWidth(80);
d->stopTimerButton->setCheckable(true);
d->textEdit = new QTextEdit(this);
d->textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->calendar = new QCalendarWidget;
d->saveButton = new QPushButton(tr("Save To File"));
d->saveButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QGroupBox *timeLoggerBox = new QGroupBox(tr("Time Logger"));
QGridLayout *gLayout = new QGridLayout;
gLayout->addWidget(d->dateLabel, 0, 0, 1, 1);
gLayout->addWidget(d->calendar, 1, 0, 1, 3);
gLayout->addWidget(d->progressLabel, 2, 0, 1, 1);
gLayout->addWidget(d->progressComboBox, 2, 1, 1, 1);
gLayout->addWidget(d->hoursWorkedLabel, 3, 0, 1, 1);
gLayout->addWidget(d->hoursWorkedLineEdit, 3, 1, 1, 1);
gLayout->addWidget(d->startTimerButton, 4, 1, 1, 1);
gLayout->addWidget(d->stopTimerButton, 4, 2, 1, 1);
timeLoggerBox->setLayout(gLayout);
d->timer = new QTimer(this);
//d->time.setHMS(0,0,0);
// connection of SIGNALS and SLOTS
connect(d->timer, SIGNAL(timeout()), this, SLOT(updateTime()));
connect(d->startTimerButton,SIGNAL(clicked()),this,SLOT(startTimeLog()));
connect(d->stopTimerButton,SIGNAL(clicked()),this,SLOT(endTimeLog()));
connect(d->saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(d->descriptionLabel);
vLayout->addWidget(d->textEdit);
QHBoxLayout * hLayout = new QHBoxLayout;
hLayout->addWidget(timeLoggerBox);
hLayout->addLayout(vLayout);
QHBoxLayout *bLayout = new QHBoxLayout;
bLayout->addStretch(1);
bLayout->addWidget(d->saveButton);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(hLayout);
mainLayout->addLayout(bLayout);
mainLayout->addStretch(1);
}
LoggerModeWidget::~LoggerModeWidget()
{
delete d;
}
bool LoggerModeWidget::saveToFile()
{
QString fileName = QFileDialog::getSaveFileName(this);
if (fileName.isEmpty())
return false;
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::critical(this, tr("Application"),
tr("Unable to open file %1 for writing :\n%2.")
.arg(fileName)
.arg(file.errorString()));
return false;
}
QTextStream out(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
out << "Project name : " << d->projectName << "\n";
out << "Date : " << d->calendar->selectedDate().toString() << "\n";
out << "Progress : " << d->progressComboBox->currentText() << "\n";
out << "Duration : " << d->hoursWorkedLineEdit->text() << "\n\n";
out << "Description : " << d->textEdit->toPlainText();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
return true;
}
void LoggerModeWidget::startTimeLog()
{
d->totalTime = 0;
d->timer->start(1000);
}
void LoggerModeWidget::endTimeLog()
{
if(d->stopTimerButton->isChecked())
{
d->stopTimerButton->setText("Continue Timer");
d->timer->stop();
}
else
{
d->stopTimerButton->setText("Pause Timer");
d->timer->start(1000);
}
}
void LoggerModeWidget::updateTime()
{
d->totalTime++;
QTime time(0,0,0);
time = time.addSecs(d->totalTime);
d->hoursWorkedLineEdit->setText(time.toString());
}
/*
void LoggerModeWidget::setProjectName(QString name)
{
d->projectName = name;
}
*/

View File

@@ -0,0 +1,28 @@
#ifndef LOGGERMODEWIDGET_H
#define LOGGERMODEWIDGET_H
#include <QWidget>
struct LoggerModeWidgetData;
class LoggerModeWidget : public QWidget
{
Q_OBJECT
public:
LoggerModeWidget(const QString projectName, QWidget* parent = 0);
~LoggerModeWidget();
public slots:
//void setProjectName(QString name);
protected slots:
bool saveToFile();
void startTimeLog();
void endTimeLog();
void updateTime();
private:
LoggerModeWidgetData* d;
};
#endif // NEWMODEWIDGET_H

View File

@@ -0,0 +1,10 @@
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license></license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,64 @@
#include "donothingplugin.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include <QtPlugin>
#include <QStringList>
#include <QMessageBox>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
// Fetch the action manager
Core::ActionManager* am = Core::ICore::instance()->actionManager();
// Create a DoNothing menu
Core::ActionContainer* ac = am->createMenu("DoNothingPlugin.DoNothingMenu");
ac->menu()->setTitle("DoNothing");
// Create a command for "About DoNothing".
QAction *action = new QAction(tr("About DoNothing"),this);
Core::Command* cmd = am->registerAction(action,"DoNothingPlugin.AboutDoNothing",QList<int>() << 0);
// Add DoNothing menu to the menubar
am->actionContainer(Core::Constants::MENU_BAR)->addMenu(ac);
// Add the "About DoNothing" action to the DoNothing menu
ac->addAction(cmd);
// Connect the action
connect(action, SIGNAL(triggered(bool)), this, SLOT(about()));
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
void DoNothingPlugin::about()
{
QMessageBox::information(0, "About DoNothing Plugin",
"Seriously dude, this plugin does nothing");
}
Q_EXPORT_PLUGIN(DoNothingPlugin)

View File

@@ -0,0 +1,22 @@
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private slots:
void about();
};
#endif // DONOTHING_PLUGIN_H

View File

@@ -0,0 +1,20 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec

View File

@@ -0,0 +1,10 @@
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license></license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,66 @@
#include "donothingplugin.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include <QtPlugin>
#include <QStringList>
#include <QMessageBox>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
// Fetch the action manager
Core::ActionManager* am = Core::ICore::instance()->actionManager();
// Create a DoNothing menu
Core::ActionContainer* ac = am->createMenu("DoNothingPlugin.DoNothingMenu");
ac->menu()->setTitle("DoNothing");
// Create a command for "About DoNothing".
QAction *action = new QAction(tr("About DoNothing"),this);
Core::Command* cmd = am->registerAction(action,"DoNothingPlugin.AboutDoNothing",QList<int>() << 0);
// Insert the "DoNothing" menu between "Window" and "Help".
QMenu* windowMenu = am->actionContainer(Core::Constants::M_HELP)->menu();
QMenuBar* menuBar = am->actionContainer(Core::Constants::MENU_BAR)->menuBar();
menuBar->insertMenu(windowMenu->menuAction(), ac->menu());
// Add the "About DoNothing" action to the DoNothing menu
ac->addAction(cmd);
// Connect the action
connect(action, SIGNAL(triggered(bool)), this, SLOT(about()));
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
void DoNothingPlugin::about()
{
QMessageBox::information(0, "About DoNothing Plugin",
"Seriously dude, this plugin does nothing");
}
Q_EXPORT_PLUGIN(DoNothingPlugin)

View File

@@ -0,0 +1,22 @@
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private slots:
void about();
};
#endif // DONOTHING_PLUGIN_H

View File

@@ -0,0 +1,20 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec

View File

@@ -0,0 +1,10 @@
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license></license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,48 @@
#include "donothingplugin.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include <QtPlugin>
#include <QStringList>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
// Fetch the action manager
Core::ActionManager* am = Core::ICore::instance()->actionManager();
// Create a command for "About DoNothing".
Core::Command* cmd = am->registerAction(new QAction(tr("About DoNothing"),this),"DoNothingPlugin.AboutDoNothing",
QList<int>() <<Core::Constants::C_GLOBAL_ID);
// Add the command to Help menu
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd);
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(DoNothingPlugin)

View File

@@ -0,0 +1,19 @@
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // DONOTHING_PLUGIN_H

View File

@@ -0,0 +1,20 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec

View File

@@ -0,0 +1,11 @@
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license>
GPL</license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,57 @@
#include "donothingplugin.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <QKeySequence>
#include <QtPlugin>
#include <QStringList>
#include <QMessageBox>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
// Fetch the action manager
Core::ActionManager* am = Core::ICore::instance()->actionManager();
// Create a command for "About DoNothing".
QAction *action = new QAction(tr("About DoNothing"),this);
Core::Command* cmd = am->registerAction(action,"DoNothingPlugin.AboutDoNothing",QList<int>() << 0);
Core::ActionContainer* ac = am->createMenu("DoNothingPlugin.DoNothingMenu");
// Add the command to Help menu
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd);
connect(action, SIGNAL(triggered(bool)), this, SLOT(about()));
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
void DoNothingPlugin::about()
{
QMessageBox::information(0, "About DoNothing Plugin",
"Seriously dude, this plugin does nothing");
}
Q_EXPORT_PLUGIN(DoNothingPlugin)

View File

@@ -0,0 +1,22 @@
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private slots:
void about();
};
#endif // DONOTHING_PLUGIN_H

View File

@@ -0,0 +1,20 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec

View File

@@ -0,0 +1,10 @@
<plugin name="PreferencePane" version="0.0.1">
<vendor>FooCompanyInc Pvt. Ltd</vendor>
<copyright>(C) 2009-2010 FooCompanyInc Pvt. Ltd.</copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompany.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,47 @@
#include "modifiedfilelister.h"
#include "modifiedfilelistwidget.h"
ModifiedFileLister::ModifiedFileLister(QObject *parent): IOptionsPage(parent)
{
}
ModifiedFileLister::~ModifiedFileLister()
{
}
QString ModifiedFileLister::id() const
{
return "ModifiedFiles";
}
QString ModifiedFileLister::trName() const
{
return tr("Modified Files");
}
QString ModifiedFileLister::category() const
{
return "Help";
}
QString ModifiedFileLister::trCategory() const
{
return tr("Help");
}
QWidget *ModifiedFileLister::createPage(QWidget *parent)
{
return new ModifiedFileListWidget(parent);
}
void ModifiedFileLister::apply()
{
// Do nothing
}
void ModifiedFileLister::finish()
{
// Do nothing
}

View File

@@ -0,0 +1,21 @@
#ifndef MODIFIEDFILELISTER_H
#define MODIFIEDFILELISTER_H
#include <coreplugin/dialogs/ioptionspage.h>
class ModifiedFileLister : public Core::IOptionsPage
{
Q_OBJECT
public:
ModifiedFileLister(QObject *parent = 0);
~ModifiedFileLister();
// IOptionsPage implementation
QString id() const;
QString trName() const;
QString category() const;
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void apply();
void finish();
};
#endif // MODIFIEDFILELISTER_H

View File

@@ -0,0 +1,20 @@
#include "modifiedfilelistwidget.h"
#include <coreplugin/filemanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/ifile.h>
ModifiedFileListWidget::ModifiedFileListWidget(QWidget* parent):QListWidget(parent)
{
// Show the list of modified pages
Core::FileManager* fm = Core::ICore::instance()->fileManager();
QList<Core::IFile*> files = fm->modifiedFiles();
for(int i=0; i<files.count();i++)
this->addItem(files.at(i)->fileName());
}
ModifiedFileListWidget::~ModifiedFileListWidget()
{
//Do Nothing
}

View File

@@ -0,0 +1,14 @@
#ifndef MODIFIEDFILELISTWIDGET_H
#define MODIFIEDFILELISTWIDGET_H
#include <QListWidget>
class ModifiedFileListWidget: public QListWidget
{
Q_OBJECT
public:
ModifiedFileListWidget(QWidget* parent=0);
~ModifiedFileListWidget();
};
#endif // MODIFIEDFILELISTWIDGET_H

View File

@@ -0,0 +1,36 @@
#include "preferencepaneplugin.h"
#include "modifiedfilelister.h"
#include <QtPlugin>
#include <QStringList>
PreferencePanePlugin::PreferencePanePlugin()
{
// Do nothing
}
PreferencePanePlugin::~PreferencePanePlugin()
{
// Do notning
}
void PreferencePanePlugin::extensionsInitialized()
{
// Do nothing
}
bool PreferencePanePlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject(new ModifiedFileLister);
return true;
}
void PreferencePanePlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(PreferencePanePlugin)

View File

@@ -0,0 +1,18 @@
#ifndef PREFERENCEPANE_PLUGIN_H
#define PREFERENCEPANE_PLUGIN_H
#include <extensionsystem/iplugin.h>
class PreferencePanePlugin : public ExtensionSystem::IPlugin
{
public:
PreferencePanePlugin();
~PreferencePanePlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // PREFERENCEPANE_PLUGIN_H

View File

@@ -0,0 +1,21 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = PreferencePane
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = preferencepaneplugin.h \
modifiedfilelistwidget.h \
modifiedfilelister.h
SOURCES = preferencepaneplugin.cpp \
modifiedfilelistwidget.cpp \
modifiedfilelister.cpp
OTHER_FILES = PreferencePane.pluginspec

View File

@@ -0,0 +1,11 @@
<plugin name="ProgressBar" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.foocompany.com</url>
<dependencyList>
<dependency name="Core"/>
<dependency name="Find"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,188 @@
#include "headerfilterprogress.h"
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/iprojectmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/basetexteditor.h>
#include <find/searchresultwindow.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <find/textfindconstants.h>
#include <utils/stylehelper.h>
#include <utils/filesearch.h>
#include <coreplugin/icore.h>
#include <QtGui/QComboBox>
#include <QtGui/QCheckBox>
#include<QFutureWatcher>
#include<QStringListModel>
#include<QLabel>
#include<QFont>
#include<QMessageBox>
#include<QGridLayout>
using namespace Core;
using namespace Utils;
using namespace TextEditor;
struct HeaderFilterProgressData
{
HeaderFilterProgressData() : projectPlugin(0), m_searchResultWindow(0){}
QFutureWatcher<FileSearchResult> watcher;
QLabel* resultLabel;
ProjectExplorer::ProjectExplorerPlugin* projectExplorer()
{
if(projectPlugin)
return projectPlugin;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
projectPlugin = pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
return projectPlugin;
}
// Method to search and return the search window
Find::SearchResultWindow* searchResultWindow()
{
if(m_searchResultWindow)
return m_searchResultWindow;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
m_searchResultWindow = pm->getObject<Find::SearchResultWindow>();
return m_searchResultWindow;
}
private:
ProjectExplorer::ProjectExplorerPlugin* projectPlugin;
Find::SearchResultWindow* m_searchResultWindow;
};
HeaderFilterProgress::HeaderFilterProgress()
{
d = new HeaderFilterProgressData;
d->watcher.setPendingResultsLimit(1);
d->resultLabel = 0 ;
// displayResult(int) is called when every a new
// search result is generated
connect(&d->watcher, SIGNAL(resultReadyAt(int)),this, SLOT(displayResult(int)));
}
HeaderFilterProgress::~HeaderFilterProgress()
{
delete d;
}
QString HeaderFilterProgress::id() const
{
return "HeaderFilter";
}
QString HeaderFilterProgress::name() const
{
return tr("Header Filter");
}
bool HeaderFilterProgress::isEnabled() const
{
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
if(projects.count())
return true;
return false;
}
QKeySequence HeaderFilterProgress::defaultShortcut() const
{
return QKeySequence();
}
void HeaderFilterProgress::findAll(const QString &text,QTextDocument::FindFlags findFlags)
{
// Fetch a list of all open projects
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
// Make a list of files in each project
QStringList files;
Q_FOREACH(ProjectExplorer::Project* project, projects)
files += project->files(ProjectExplorer::Project::AllFiles);
// Remove duplicates
files.removeDuplicates();
//------------------------------------------------------------
// Begin searching
QString includeline = "#include <" + text + ">";
Find::SearchResult* result = d->searchResultWindow()->startNewSearch();
d->watcher.setFuture(QFuture<FileSearchResult>());
//When result gets activated it invokes the openEditor function
connect(result, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
d->searchResultWindow()->popup(true);
// Let the watcher monitor the search results
d->watcher.setFuture(Utils::findInFiles(includeline, files, findFlags));
//Creates the Progres bar
Core::FutureProgress* progress =
Core::ICore::instance()->progressManager()->addTask(d->watcher.future(),
"MySearch",
Find::Constants::TASK_SEARCH,
Core::ProgressManager::KeepOnFinish
);
progress->setWidget(createProgressWidget());
connect(progress, SIGNAL(clicked()), d->searchResultWindow(), SLOT(popup()));
}
QWidget* HeaderFilterProgress::createProgressWidget()
{
d->resultLabel = new QLabel;
d->resultLabel->setAlignment(Qt::AlignCenter);
QFont f = d->resultLabel->font();
f.setBold(true);
f.setPointSizeF(StyleHelper::sidebarFontSize());
d->resultLabel->setFont(f);
d->resultLabel->setPalette(StyleHelper::sidebarFontPalette(d->resultLabel->palette()));
d->resultLabel->setText(tr("%1 found").arg(d->searchResultWindow()->numberOfResults()));
return d->resultLabel;
}
QWidget* HeaderFilterProgress::createConfigWidget()
{
return (new QLabel("This is a header filter"));
}
void HeaderFilterProgress::displayResult(int index)
{
FileSearchResult result = d->watcher.future().resultAt(index);
d->searchResultWindow()->addResult(result.fileName,
result.lineNumber,
result.matchingLine,
result.matchStart,
result.matchLength);
if (d->resultLabel)
d->resultLabel->setText(tr("%1 found").arg(d->searchResultWindow()->numberOfResults()));
}
void HeaderFilterProgress::openEditor(const Find::SearchResultItem &item)
{
TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.index);
}

View File

@@ -0,0 +1,45 @@
#ifndef HEADERFILTERPROGRESS_H
#define HEADERFILTERPROGRESS_H
#include <find/ifindfilter.h>
#include <utils/filesearch.h>
#include <QtGui/QComboBox>
namespace Find {
class SearchResultWindow;
struct SearchResultItem;
}
class QKeySequence;
class QWidget;
struct HeaderFilterProgressData;
class HeaderFilterProgress : public Find::IFindFilter
{
Q_OBJECT
public:
HeaderFilterProgress();
~HeaderFilterProgress();
QString id() const;
QString name() const;
bool isEnabled() const;
QKeySequence defaultShortcut() const;
void findAll(const QString &txt,QTextDocument::FindFlags findFlags);
QWidget* createConfigWidget();
QWidget* createProgressWidget();
protected slots:
void displayResult(int index);
void openEditor(const Find::SearchResultItem &item);
private:
HeaderFilterProgressData* d;
};
#endif // HEADERFILTERPROGRESS_H

View File

@@ -0,0 +1,28 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
DEFINES += FIND_LIBRARY
TEMPLATE = lib
TARGET = ProgressBar
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/libs/extensionsystem/extensionsystem.pri)
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
include($$QTC_SOURCE/src/libs/utils/utils.pri)
include($$QTC_SOURCE/src/plugins/projectexplorer/projectexplorer.pri)
include($$QTC_SOURCE/src/plugins/find/find.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = progressbarplugin.h \
headerfilterprogress.h
SOURCES = progressbarplugin.cpp \
headerfilteprogress.cpp
OTHER_FILES = ProgressBar.pluginspec

View File

@@ -0,0 +1,36 @@
#include "progressbarplugin.h"
#include "headerfilterprogress.h"
#include <QtPlugin>
#include <QStringList>
ProgressBarPlugin::ProgressBarPlugin()
{
// Do nothing
}
ProgressBarPlugin::~ProgressBarPlugin()
{
// Do notning
}
void ProgressBarPlugin::extensionsInitialized()
{
// Do nothing
}
bool ProgressBarPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject( new HeaderFilterProgress);
return true;
}
void ProgressBarPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(ProgressBarPlugin)

View File

@@ -0,0 +1,20 @@
#ifndef PROGRESSBAR_PLUGIN_H
#define PROGRESSBAR_PLUGIN_H
#include <extensionsystem/iplugin.h>
class ProgressBarPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
ProgressBarPlugin();
~ProgressBarPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString* errorString);
void shutdown();
};
#endif // PROGRESSBAR_PLUGIN_H

View File

@@ -0,0 +1,10 @@
<plugin name="CustomProject" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,37 @@
#include "customprojectplugin.h"
#include "customprojectwizard.h"
#include <QtPlugin>
#include <QStringList>
CustomProjectPlugin::CustomProjectPlugin()
{
// Do nothing
}
CustomProjectPlugin::~CustomProjectPlugin()
{
// Do notning
}
void CustomProjectPlugin::extensionsInitialized()
{
// Do nothing
}
bool CustomProjectPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject(new CustomProjectWizard);
return true;
}
void CustomProjectPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(CustomProjectPlugin)

View File

@@ -0,0 +1,18 @@
#ifndef CUSTOMPROJECT_PLUGIN_H
#define CUSTOMPROJECT_PLUGIN_H
#include <extensionsystem/iplugin.h>
class CustomProjectPlugin : public ExtensionSystem::IPlugin
{
public:
CustomProjectPlugin();
~CustomProjectPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // CUSTOMPROJECT_PLUGIN_H

View File

@@ -0,0 +1,18 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = CustomProject
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = customprojectplugin.h \
customprojectwizard.h
SOURCES = customprojectplugin.cpp \
customprojectwizard.cpp
OTHER_FILES = CustomProject.pluginspec

View File

@@ -0,0 +1,51 @@
#include "customprojectwizard.h"
#include <QMessageBox>
#include <QApplication>
#include <QIcon>
CustomProjectWizard::CustomProjectWizard()
{
}
CustomProjectWizard::~CustomProjectWizard()
{
}
Core::IWizard::Kind CustomProjectWizard::kind() const
{
return IWizard::ProjectWizard;
}
QIcon CustomProjectWizard::icon() const
{
return qApp->windowIcon();
}
QString CustomProjectWizard::description() const
{
return "A custom project";
}
QString CustomProjectWizard::name() const
{
return "CustomProject";
}
QString CustomProjectWizard::category() const
{
return "FooCompanyInc";
}
QString CustomProjectWizard::trCategory() const
{
return tr("FooCompanyInc");
}
QStringList CustomProjectWizard::runWizard(const QString &path, QWidget *parent)
{
Q_UNUSED(path);
Q_UNUSED(parent);
QMessageBox::information(parent, "Custom Wizard Dialog", "Hi there!");
return QStringList();
}

View File

@@ -0,0 +1,21 @@
#ifndef CUSTOMPROJECTWIZARD_H
#define CUSTOMPROJECTWIZARD_H
#include <coreplugin/dialogs/iwizard.h>
class CustomProjectWizard : public Core::IWizard
{
public:
CustomProjectWizard();
~CustomProjectWizard();
Core::IWizard::Kind kind() const;
QIcon icon() const;
QString description() const;
QString name() const;
QString category() const;
QString trCategory() const;
QStringList runWizard(const QString &path, QWidget *parent);
};
#endif // CUSTOMPROJECTWIZARD_H

View File

@@ -0,0 +1,22 @@
#ifndef {{UPPER_CLASS_NAME}}_H
#define {{UPPER_CLASS_NAME}}_H
#include <{{BASE_CLASS_NAME}}>
struct {{CLASS_NAME}}Data;
class {{CLASS_NAME}} : public {{BASE_CLASS_NAME}}
{
Q_OBJECT
public:
{{CLASS_NAME}}(QObject* parent=0);
~{{CLASS_NAME}}();
int rowCount(const QModelIndex& parent) const;
QVariant data(const QModelIndex& index, int role) const;
private:
{{CLASS_NAME}}Data* d;
};
#endif // {{UPPER_CLASS_NAME}}_H

View File

@@ -0,0 +1,23 @@
#include <{{CLASS_HEADER}}>
struct {{CLASS_NAME}}Data
{
};
{{CLASS_NAME}}::{{CLASS_NAME}}(QObject* parent)
:{{BASE_CLASS_NAME}}(parent)
{
d = {{CLASS_NAME}}Data;
}
{{CLASS_NAME}}::~{{CLASS_NAME}}()
{
}
int {{CLASS_NAME}}::rowCount(const QModelIndex& parent) const
{
}
QVariant {{CLASS_NAME}}::data(const QModelIndex& index, int role) const
{
}

View File

@@ -0,0 +1,10 @@
<plugin name="ItemModelWizard" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,43 @@
#include "itemmodelwizardplugin.h"
#include "modelclasswizard.h"
#include <QApplication>
#include <QtPlugin>
#include <QStringList>
ItemModelWizardPlugin::ItemModelWizardPlugin()
{
// Do nothing
}
ItemModelWizardPlugin::~ItemModelWizardPlugin()
{
// Do notning
}
void ItemModelWizardPlugin::extensionsInitialized()
{
// Do nothing
}
bool ItemModelWizardPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
Core::BaseFileWizardParameters params;
params.setKind(Core::IWizard::ClassWizard);
params.setIcon(qApp->windowIcon());
params.setDescription("Generates an item-model class");
params.setName("Item Model");
params.setCategory("FooCompany");
params.setTrCategory(tr("FooCompany"));
addAutoReleasedObject(new ModelClassWizard(params, this));
return true;
}
void ItemModelWizardPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(ItemModelWizardPlugin)

View File

@@ -0,0 +1,18 @@
#ifndef ITEMMODELWIZARD_PLUGIN_H
#define ITEMMODELWIZARD_PLUGIN_H
#include <extensionsystem/iplugin.h>
class ItemModelWizardPlugin : public ExtensionSystem::IPlugin
{
public:
ItemModelWizardPlugin();
~ItemModelWizardPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // ITEMMODELWIZARD_PLUGIN_H

View File

@@ -0,0 +1,25 @@
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = ItemModelWizard
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
include($$QTC_SOURCE/src/plugins/texteditor/texteditor.pri)
include($$QTC_SOURCE/src/plugins/cppeditor/cppeditor.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = itemmodelwizardplugin.h \
modelnamepage.h \
modelclasswizard.h
SOURCES = itemmodelwizardplugin.cpp \
modelnamepage.cpp \
modelclasswizard.cpp
OTHER_FILES = ItemModelWizard.pluginspec
FORMS += modelnamepage.ui
RESOURCES += template.qrc

View File

@@ -0,0 +1,101 @@
#include "modelclasswizard.h"
#include "modelnamepage.h"
#include <QFile>
#include <QFileInfo>
#include <cppeditor/cppeditor.h>
#include <cppeditor/cppeditorconstants.h>
#include <coreplugin/basefilewizard.h>
ModelClassWizard::ModelClassWizard(const Core::BaseFileWizardParameters &parameters,QObject *parent)
: Core::BaseFileWizard(parameters, parent)
{
}
ModelClassWizard::~ModelClassWizard()
{
}
QWizard * ModelClassWizard::createWizardDialog(
QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
{
// Create a wizard
QWizard* wizard = new QWizard(parent);
wizard->setWindowTitle("Model Class Wizard");
// Make our page as first page
ModelNamePage* page = new ModelNamePage(wizard);
int pageId = wizard->addPage(page);
wizard->setProperty("_PageId_", pageId);
page->setPath(defaultPath);
// Now add the remaining pages
foreach (QWizardPage *p, extensionPages)
wizard->addPage(p);
return wizard;
}
QString ModelClassWizard::readFile(const QString& fileName, const QMap<QString,QString>&
replacementMap) const
{
QFile file(fileName);
file.open(QFile::ReadOnly);
QString retStr = file.readAll();
QMap<QString,QString>::const_iterator it = replacementMap.begin();
QMap<QString,QString>::const_iterator end = replacementMap.end();
while(it != end)
{
retStr.replace(it.key(), it.value());
++it;
}
return retStr;
}
Core::GeneratedFiles ModelClassWizard::generateFiles(
const QWizard *w,QString *errorMessage) const
{
Q_UNUSED(errorMessage);
Core::GeneratedFiles ret;
int pageId = w->property("_PageId_").toInt();
ModelNamePage* page = qobject_cast<ModelNamePage*>(w->page(pageId));
if(!page)
return ret;
ModelClassParameters params = page->parameters();
QMap<QString,QString> replacementMap;
replacementMap["{{UPPER_CLASS_NAME}}"] = params.className.toUpper();
replacementMap["{{BASE_CLASS_NAME}}"] = params.baseClass;
replacementMap["{{CLASS_NAME}}"] = params.className;
replacementMap["{{CLASS_HEADER}}"] = QFileInfo(params.headerFile).fileName();
Core::GeneratedFile headerFile(params.path + "/" + params.headerFile);
headerFile.setEditorKind(CppEditor::Constants::CPPEDITOR_KIND);
Core::GeneratedFile sourceFile(params.path + "/" + params.sourceFile);
sourceFile.setEditorKind(CppEditor::Constants::CPPEDITOR_KIND);
if(params.baseClass == "QAbstractItemModel")
{
headerFile.setContents(readFile(":/CustomProject/ItemModelHeader", replacementMap) );
sourceFile.setContents(readFile(":/CustomProject/ItemModelSource", replacementMap) );
}
else if(params.baseClass == "QAbstractTableModel")
{
headerFile.setContents(readFile(":/CustomProject/TableModelHeader", replacementMap) );
sourceFile.setContents(readFile(":/CustomProject/TableModelSource", replacementMap) );
}
else if(params.baseClass == "QAbstractListModel")
{
headerFile.setContents(readFile(":/CustomProject/ListModelHeader", replacementMap) );
sourceFile.setContents(readFile(":/CustomProject/ListModelSource", replacementMap) );
}
ret << headerFile << sourceFile;
return ret;
}

View File

@@ -0,0 +1,26 @@
#ifndef MODELCLASSWIZARD_H
#define MODELCLASSWIZARD_H
#include <coreplugin/basefilewizard.h>
class ModelClassWizard : public Core::BaseFileWizard
{
Q_OBJECT
public:
ModelClassWizard(const Core::BaseFileWizardParameters &parameters, QObject *parent = 0);
~ModelClassWizard();
QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const;
Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
private:
QString readFile(const QString& fileName,
const QMap<QString,QString>& replacementMap) const;
};
#endif // MODELCLASSWIZARD_H

View File

@@ -0,0 +1,38 @@
#include "modelnamepage.h"
#include "ui_modelnamepage.h"
ModelNamePage::ModelNamePage(QWidget *parent) :
QWizardPage(parent)
{
setTitle("Enter model class information");
setSubTitle("The header and source file names will be derived from the class name");
ui.setupUi(this);
}
ModelNamePage::~ModelNamePage()
{
}
void ModelNamePage::setPath(const QString& path)
{
this->path = path;
}
void ModelNamePage::on_txtModelClass_textEdited(const QString& txt)
{
ui.txtHeaderFile->setText(txt + ".h");
ui.txtImplFile->setText(txt + ".cpp");
}
ModelClassParameters ModelNamePage::parameters() const
{
ModelClassParameters params;
params.className = ui.txtModelClass->text();
params.headerFile = ui.txtHeaderFile->text();
params.sourceFile = ui.txtImplFile->text();
params.baseClass = ui.cmbBaseClass->currentText();
params.path = path;
return params;
}

View File

@@ -0,0 +1,34 @@
#ifndef MODELNAMEPAGE_H
#define MODELNAMEPAGE_H
#include <QWizardPage>
#include "ui_ModelNamePage.h"
struct ModelClassParameters
{
QString className;
QString headerFile;
QString sourceFile;
QString baseClass;
QString path;
};
class ModelNamePage : public QWizardPage
{
Q_OBJECT
public:
ModelNamePage(QWidget *parent = 0);
~ModelNamePage();
void setPath(const QString& path);
ModelClassParameters parameters() const;
private slots:
void on_txtModelClass_textEdited(const QString& txt);
private:
Ui::ModelNamePage ui;
QString path;
};
#endif // MODELNAMEPAGE_H

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ModelNamePage</class>
<widget class="QWidget" name="ModelNamePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>346</width>
<height>257</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Model Class Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtModelClass"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Base Class Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbBaseClass">
<item>
<property name="text">
<string>QAbstractItemModel</string>
</property>
</item>
<item>
<property name="text">
<string>QAbstractListModel</string>
</property>
</item>
<item>
<property name="text">
<string>QAbstractTableModel</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Header:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtHeaderFile"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Implementation:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtImplFile"/>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>61</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/CustomProject">
<file alias="ItemModelSource">ItemModelSource.txt</file>
<file alias="ItemModelHeader">ItemModelHeader.txt</file>
</qresource>
</RCC>