Commit 70d392d2 authored by hjk's avatar hjk

core: make context and widget IContext data members

parent cbfaea1e
......@@ -143,8 +143,12 @@ class AnalyzerMode : public Core::IMode
public:
AnalyzerMode(QObject *parent = 0)
: Core::IMode(parent)
, m_widget(0)
{}
{
setContext(Core::Context(
Core::Constants::C_EDITORMANAGER,
Constants::C_ANALYZEMODE,
Core::Constants::C_NAVIGATION_PANE));
}
~AnalyzerMode()
{
......@@ -159,19 +163,9 @@ public:
QString displayName() const { return tr("Analyze"); }
QIcon icon() const { return QIcon(":/images/analyzer_mode.png"); }
int priority() const { return Constants::P_MODE_ANALYZE; }
QWidget *widget() { return m_widget; }
QString id() const { return QLatin1String(Constants::MODE_ANALYZE); }
QString type() const { return Core::Constants::MODE_EDIT_TYPE; }
Core::Context context() const
{
return Core::Context(Core::Constants::C_EDITORMANAGER, Constants::C_ANALYZEMODE,
Core::Constants::C_NAVIGATION_PANE);
}
QString contextHelpId() const { return QString(); }
void setWidget(QWidget *widget) { m_widget = widget; }
private:
QWidget *m_widget;
};
} // namespace Internal
......
......@@ -318,6 +318,7 @@ class BinEditorInterface : public Core::IEditor
public:
BinEditorInterface(BinEditor *editor)
{
setWidget(editor);
m_editor = editor;
m_file = new BinEditorFile(m_editor);
m_context.add(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
......@@ -351,10 +352,6 @@ public:
delete m_editor;
}
QWidget *widget() { return m_editor; }
Core::Context context() const { return m_context; }
bool createNew(const QString & /* contents */ = QString()) {
m_editor->clear();
m_file->setFilename(QString());
......@@ -392,7 +389,6 @@ private:
BinEditor *m_editor;
QString m_displayName;
BinEditorFile *m_file;
Core::Context m_context;
QToolBar *m_toolBar;
QLineEdit *m_addressEdit;
};
......
......@@ -300,21 +300,11 @@ void BookmarkView::gotoBookmark(const QModelIndex &index)
// BookmarkContext
////
BookmarkContext::BookmarkContext(BookmarkView *widget)
: Core::IContext(widget),
m_bookmarkView(widget),
m_context(Constants::BOOKMARKS_CONTEXT)
BookmarkContext::BookmarkContext(QWidget *widget)
: Core::IContext(widget)
{
}
Context BookmarkContext::context() const
{
return m_context;
}
QWidget *BookmarkContext::widget()
{
return m_bookmarkView;
setWidget(widget);
setContext(Core::Context(Constants::BOOKMARKS_CONTEXT));
}
////
......
......@@ -164,12 +164,7 @@ private:
class BookmarkContext : public Core::IContext
{
public:
BookmarkContext(BookmarkView *widget);
virtual Core::Context context() const;
virtual QWidget *widget();
private:
BookmarkView *m_bookmarkView;
const Core::Context m_context;
BookmarkContext(QWidget *widget);
};
class BookmarkViewFactory : public Core::INavigationWidgetFactory
......
......@@ -55,17 +55,11 @@ using namespace CMakeProjectManager::Internal;
//
CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
: BaseTextEditor(editor),
m_context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)
: BaseTextEditor(editor)
{
connect (this, SIGNAL(changed()),
this, SLOT(markAsChanged()));
}
Core::Context CMakeEditor::context() const
{
return m_context;
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR));
connect(this, SIGNAL(changed()), this, SLOT(markAsChanged()));
}
Core::IEditor *CMakeEditor::duplicate(QWidget *parent)
......@@ -122,10 +116,6 @@ CMakeEditorWidget::CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factor
baseTextDocument()->setSyntaxHighlighter(new CMakeHighlighter);
}
CMakeEditorWidget::~CMakeEditorWidget()
{
}
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor()
{
return new CMakeEditor(this);
......
......@@ -54,19 +54,18 @@ class CMakeManager;
class CMakeEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
CMakeEditor(CMakeEditorWidget *);
Core::Context context() const;
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
QString id() const;
bool isTemporary() const { return false; }
private slots:
void markAsChanged();
void build();
private:
const Core::Context m_context;
};
class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
......@@ -75,7 +74,6 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
public:
CMakeEditorWidget(QWidget *parent, CMakeEditorFactory *factory, TextEditor::TextEditorActionHandler *ah);
~CMakeEditorWidget();
bool save(const QString &fileName = QString());
......
......@@ -120,6 +120,9 @@ DesignMode::DesignMode(EditorManager *editorManager) :
{
setObjectName(QLatin1String("DesignMode"));
setEnabled(false);
setContext(Context(Constants::C_DESIGN_MODE));
setWidget(d->m_stackWidget);
ExtensionSystem::PluginManager::instance()->addObject(d->m_coreListener);
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
......@@ -138,17 +141,6 @@ DesignMode::~DesignMode()
delete d;
}
Context DesignMode::context() const
{
static Context contexts(Constants::C_DESIGN_MODE);
return contexts;
}
QWidget *DesignMode::widget()
{
return d->m_stackWidget;
}
QString DesignMode::displayName() const
{
return tr("Design");
......
......@@ -68,10 +68,6 @@ public:
QStringList registeredMimeTypes() const;
// IContext
Context context() const;
QWidget *widget();
// IMode
QString displayName() const;
QIcon icon() const;
......
......@@ -88,6 +88,11 @@ EditMode::EditMode(EditorManager *editorManager) :
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(grabEditorManager(Core::IMode*)));
m_splitter->setFocusProxy(m_editorManager);
setWidget(m_splitter);
setContext(Context(Constants::C_EDIT_MODE,
Constants::C_EDITORMANAGER,
Constants::C_NAVIGATION_PANE));
}
EditMode::~EditMode()
......@@ -112,11 +117,6 @@ int EditMode::priority() const
return Constants::P_MODE_EDIT;
}
QWidget* EditMode::widget()
{
return m_splitter;
}
QString EditMode::id() const
{
return QLatin1String(Constants::MODE_EDIT);
......@@ -127,14 +127,6 @@ QString EditMode::type() const
return QLatin1String(Constants::MODE_EDIT_TYPE);
}
Context EditMode::context() const
{
static Context contexts(Constants::C_EDIT_MODE,
Constants::C_EDITORMANAGER,
Constants::C_NAVIGATION_PANE);
return contexts;
}
void EditMode::grabEditorManager(Core::IMode *mode)
{
if (mode != this)
......
......@@ -60,10 +60,8 @@ public:
QString displayName() const;
QIcon icon() const;
int priority() const;
QWidget* widget();
QString id() const;
QString type() const;
Context context() const;
private slots:
void grabEditorManager(Core::IMode *mode);
......
......@@ -38,10 +38,8 @@
#include <QtCore/QList>
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE
#include <QtCore/QPointer>
#include <QtGui/QWidget>
namespace Core {
......@@ -80,31 +78,28 @@ class CORE_EXPORT IContext : public QObject
{
Q_OBJECT
public:
IContext(QObject *parent = 0) : QObject(parent) {}
virtual ~IContext() {}
IContext(QObject *parent = 0) : QObject(parent), m_widget(0) {}
virtual Context context() const = 0;
virtual QWidget *widget() = 0;
virtual Context context() const { return m_context; }
virtual QWidget *widget() const { return m_widget; }
virtual QString contextHelpId() const { return QString(); }
virtual void setContext(const Context &context) { m_context = context; }
virtual void setWidget(QWidget *widget) { m_widget = widget; }
protected:
Context m_context;
QPointer<QWidget> m_widget;
};
class BaseContext : public Core::IContext
{
public:
BaseContext(QWidget *widget, const Context &context, QObject *parent = 0)
: Core::IContext(parent),
m_widget(widget),
m_context(context)
: Core::IContext(parent)
{
setWidget(widget);
setContext(context);
}
Context context() const { return m_context; }
QWidget *widget() { return m_widget; }
private:
QWidget *m_widget;
Context m_context;
};
} // namespace Core
......
......@@ -38,10 +38,7 @@
using namespace Core;
StatusBarWidget::StatusBarWidget(QObject *parent)
: IContext(parent),
m_widget(0),
m_context(),
m_defaultPosition(StatusBarWidget::First)
: IContext(parent), m_defaultPosition(StatusBarWidget::First)
{
}
......@@ -50,33 +47,11 @@ StatusBarWidget::~StatusBarWidget()
delete m_widget;
}
Context StatusBarWidget::context() const
{
return m_context;
}
QWidget *StatusBarWidget::widget()
{
return m_widget;
}
StatusBarWidget::StatusBarPosition StatusBarWidget::position() const
{
return m_defaultPosition;
}
QWidget *StatusBarWidget::setWidget(QWidget *widget)
{
QWidget *oldWidget = m_widget;
m_widget = widget;
return oldWidget;
}
void StatusBarWidget::setContext(const Context &context)
{
m_context = context;
}
void StatusBarWidget::setPosition(StatusBarWidget::StatusBarPosition position)
{
m_defaultPosition = position;
......
......@@ -50,17 +50,10 @@ public:
StatusBarWidget(QObject *parent = 0);
~StatusBarWidget();
Context context() const;
QWidget *widget();
StatusBarWidget::StatusBarPosition position() const;
QWidget *setWidget(QWidget *widget);
void setContext(const Context &context);
void setPosition(StatusBarWidget::StatusBarPosition position);
private:
QPointer<QWidget> m_widget;
Context m_context;
StatusBarWidget::StatusBarPosition m_defaultPosition;
};
......
......@@ -1775,11 +1775,6 @@ void CPPEditorWidget::keyPressEvent(QKeyEvent *e)
finishRename();
}
Core::Context CPPEditor::context() const
{
return m_context;
}
Core::IEditor *CPPEditor::duplicate(QWidget *parent)
{
CPPEditorWidget *newEditor = new CPPEditorWidget(parent);
......
......@@ -147,7 +147,6 @@ class CPPEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
CPPEditor(CPPEditorWidget *);
Core::Context context() const;
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
......@@ -155,9 +154,6 @@ public:
bool isTemporary() const { return false; }
virtual bool open(const QString & fileName);
private:
Core::Context m_context;
};
class CPPEditorWidget : public TextEditor::BaseTextEditorWidget
......
......@@ -495,7 +495,11 @@ public:
class DebugMode : public IMode
{
public:
DebugMode() : m_widget(0) { setObjectName(QLatin1String("DebugMode")); }
DebugMode()
{
setObjectName(QLatin1String("DebugMode"));
setContext(Context(CC::C_EDITORMANAGER, C_DEBUGMODE, CC::C_NAVIGATION_PANE));
}
~DebugMode()
{
......@@ -504,18 +508,18 @@ public:
delete m_widget;
}
void setWidget(QWidget *widget)
{
m_widget = widget;
}
// IMode
QString displayName() const { return DebuggerPlugin::tr("Debug"); }
QIcon icon() const { return QIcon(__(":/fancyactionbar/images/mode_Debug.png")); }
int priority() const { return P_MODE_DEBUG; }
QWidget *widget();
QString id() const { return MODE_DEBUG; }
QString type() const { return CC::MODE_EDIT_TYPE; }
Context context() const
{ return Context(CC::C_EDITORMANAGER, C_DEBUGMODE, CC::C_NAVIGATION_PANE); }
QString contextHelpId() const { return QString(); }
private:
QWidget *m_widget;
};
......@@ -2942,7 +2946,12 @@ void DebuggerPluginPrivate::extensionsInitialized()
// Debug mode setup
m_plugin->addAutoReleasedObject(new DebugMode);
DebugMode *debugMode = new DebugMode;
QWidget *widget = m_mainWindow->createContents(debugMode);
widget->setFocusProxy(EditorManager::instance());
debugMode->setWidget(widget);
m_plugin->addAutoReleasedObject(debugMode);
//
// Connections
......@@ -3157,16 +3166,6 @@ QAction *DebuggerPlugin::visibleDebugAction()
return theDebuggerCore->m_visibleDebugAction;
}
QWidget *DebugMode::widget()
{
if (!m_widget) {
//qDebug() << "CREATING DEBUG MODE WIDGET";
m_widget = theDebuggerCore->m_mainWindow->createContents(this);
m_widget->setFocusProxy(EditorManager::instance());
}
return m_widget;
}
} // namespace Debugger
#include "debuggerplugin.moc"
......
......@@ -47,23 +47,12 @@ enum { debug = 0 };
namespace Designer {
namespace Internal {
DesignerContext::DesignerContext(const Core::Context &contexts,
QWidget *widget,
QObject *parent) :
Core::IContext(parent),
m_context(contexts),
m_widget(widget)
DesignerContext::DesignerContext(const Core::Context &context,
QWidget *widget, QObject *parent)
: Core::IContext(parent)
{
}
Core::Context DesignerContext::context() const
{
return m_context;
}
QWidget *DesignerContext::widget()
{
return m_widget;
setContext(context);
setWidget(widget);
}
QString DesignerContext::contextHelpId() const
......
......@@ -53,13 +53,7 @@ public:
QWidget *widget,
QObject *parent = 0);
virtual Core::Context context() const;
virtual QWidget *widget();
virtual QString contextHelpId() const;
private:
const Core::Context m_context;
QWidget *m_widget;
};
} // namespace Internal
......
......@@ -59,28 +59,25 @@ namespace Designer {
struct FormWindowEditorPrivate
{
explicit FormWindowEditorPrivate(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form);
FormWindowEditorPrivate(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form)
: m_textEditor(editor), m_file(form)
{}
TextEditor::PlainTextEditor m_textEditor;
Internal::FormWindowFile m_file;
Core::Context m_context;
};
FormWindowEditorPrivate::FormWindowEditorPrivate(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form) :
m_textEditor(editor), m_file(form)
{
}
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form,
QObject *parent) :
Core::IEditor(parent),
d(new FormWindowEditorPrivate(editor, form))
{
d->m_context.add(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
d->m_context.add(Designer::Constants::C_DESIGNER_XML_EDITOR);
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
Designer::Constants::C_DESIGNER_XML_EDITOR));
setWidget(d->m_textEditor.widget());
connect(form, SIGNAL(changed()), this, SIGNAL(changed()));
// Revert to saved/load externally modified files.
connect(&d->m_file, SIGNAL(reload(QString)), this, SLOT(slotOpen(QString)));
......@@ -239,16 +236,6 @@ bool FormWindowEditor::restoreState(const QByteArray &state)
return d->m_textEditor.restoreState(state);
}
Core::Context FormWindowEditor::context() const
{
return d->m_context;
}
QWidget *FormWindowEditor::widget()
{
return d->m_textEditor.widget();
}
bool FormWindowEditor::isTemporary() const
{
return false;
......
......@@ -94,10 +94,6 @@ public:
virtual QString preferredModeType() const;
// IContext
virtual Core::Context context() const;
virtual QWidget *widget();
// For uic code model support
QString contents() const;
......
......@@ -59,10 +59,6 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager,
m_mimeTypes.append(QLatin1String(Constants::CONFIG_MIMETYPE));
}
ProjectFilesFactory::~ProjectFilesFactory()
{
}
Manager *ProjectFilesFactory::manager() const
{
return m_manager;
......@@ -105,16 +101,9 @@ Core::IFile *ProjectFilesFactory::open(const QString &fileName)
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
: TextEditor::BaseTextEditor(editor),
m_context(Constants::C_FILESEDITOR)
{ }
ProjectFilesEditor::~ProjectFilesEditor()
{ }
Core::Context ProjectFilesEditor::context() const
: TextEditor::BaseTextEditor(editor)
{
return m_context;
setContext(Core::Context(Constants::C_FILESEDITOR));
}
QString ProjectFilesEditor::id() const
......
......@@ -58,7 +58,6 @@ class ProjectFilesFactory: public Core::IEditorFactory
public:
ProjectFilesFactory(Manager *manager, TextEditor::TextEditorActionHandler *handler);
virtual ~ProjectFilesFactory();
Manager *manager() const;
......@@ -81,18 +80,11 @@ class ProjectFilesEditor : public TextEditor::BaseTextEditor
public:
ProjectFilesEditor(ProjectFilesEditorWidget *editorWidget);
virtual ~ProjectFilesEditor();
virtual Core::Context context() const;
virtual QString id() const;
virtual bool duplicateSupported() const;
virtual Core::IEditor *duplicate(QWidget *parent);
virtual bool isTemporary() const { return false; }
private:
Core::Context m_context;
};
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
......
......@@ -213,11 +213,6 @@ bool GLSLEditorEditable::open(const QString &fileName)
return b;
}
Core::Context GLSLEditorEditable::context() const
{
return m_context;
}
void GLSLTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
......
......@@ -121,8 +121,6 @@ private:
void setSelectedElements();
QString wordUnderCursor() const;