Commit 14839418 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Enable the standard actions (e.g undo, redo, ...)

parent acea5c55
......@@ -47,6 +47,7 @@
#include <texteditor/fontsettings.h>
#include <texteditor/textblockiterator.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <QtGui/QMenu>
#include <QtCore/QTimer>
......@@ -64,11 +65,9 @@ ScriptEditorEditable::ScriptEditorEditable(ScriptEditor *editor, const QList<int
}
ScriptEditor::ScriptEditor(const Context &context,
TextEditor::TextEditorActionHandler *ah,
QWidget *parent) :
TextEditor::BaseTextEditor(parent),
m_context(context),
m_ah(ah)
m_context(context)
{
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
......@@ -93,15 +92,10 @@ ScriptEditor::~ScriptEditor()
Core::IEditor *ScriptEditorEditable::duplicate(QWidget *parent)
{
return qobject_cast<ScriptEditor*>(editor())->duplicate(parent)->editableInterface();
}
ScriptEditor *ScriptEditor::duplicate(QWidget *parent)
{
ScriptEditor *editor = new ScriptEditor(m_context, m_ah, parent);
editor->duplicateFrom(this);
QtScriptEditorPlugin::initializeEditor(editor);
return editor;
ScriptEditor *newEditor = new ScriptEditor(m_context, parent);
newEditor->duplicateFrom(editor());
QtScriptEditorPlugin::instance()->initializeEditor(newEditor);
return newEditor->editableInterface();
}
const char *ScriptEditorEditable::kind() const
......
......@@ -68,12 +68,9 @@ public:
typedef QList<int> Context;
ScriptEditor(const Context &context,
TextEditor::TextEditorActionHandler *ah,
QWidget *parent = 0);
~ScriptEditor();
ScriptEditor *duplicate(QWidget *parent);
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
......@@ -90,7 +87,6 @@ private:
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
const Context m_context;
TextEditor::TextEditorActionHandler *m_ah;
QTimer *m_updateDocumentTimer;
};
......
......@@ -72,8 +72,8 @@ Core::IFile *QtScriptEditorFactory::open(const QString &fileName)
Core::IEditor *QtScriptEditorFactory::createEditor(QWidget *parent)
{
ScriptEditor *rc = new ScriptEditor(m_context, m_actionHandler, parent);
QtScriptEditorPlugin::initializeEditor(rc);
ScriptEditor *rc = new ScriptEditor(m_context, parent);
QtScriptEditorPlugin::instance()->initializeEditor(rc);
return rc->editableInterface();
}
......
......@@ -45,6 +45,7 @@
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/textfilewizard.h>
#include <texteditor/texteditoractionhandler.h>
#include <utils/qtcassert.h>
#include <QtCore/QtPlugin>
......@@ -58,7 +59,8 @@ QtScriptEditorPlugin *QtScriptEditorPlugin::m_instance = 0;
QtScriptEditorPlugin::QtScriptEditorPlugin() :
m_wizard(0),
m_editor(0)
m_editor(0),
m_actionHandler(0)
{
m_instance = this;
}
......@@ -67,6 +69,7 @@ QtScriptEditorPlugin::~QtScriptEditorPlugin()
{
removeObject(m_editor);
removeObject(m_wizard);
delete m_actionHandler;
m_instance = 0;
}
......@@ -97,18 +100,27 @@ bool QtScriptEditorPlugin::initialize(const QStringList & /*arguments*/, QString
wizardParameters, this);
addObject(m_wizard);
m_actionHandler = new TextEditor::TextEditorActionHandler(QtScriptEditor::Constants::C_QTSCRIPTEDITOR,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll);
error_message->clear();
return true;
}
void QtScriptEditorPlugin::extensionsInitialized()
{
m_actionHandler->initializeActions();
}
void QtScriptEditorPlugin::initializeEditor(QtScriptEditor::Internal::ScriptEditor *editor)
{
QTC_ASSERT(m_instance, /**/);
m_actionHandler->setupActions(editor);
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
}
......
......@@ -34,6 +34,7 @@
namespace TextEditor {
class TextFileWizard;
class TextEditorActionHandler;
} // namespace TextEditor
namespace QtScriptEditor {
......@@ -54,7 +55,10 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage = 0);
void extensionsInitialized();
static void initializeEditor(ScriptEditor *editor);
static QtScriptEditorPlugin *instance()
{ return m_instance; }
void initializeEditor(ScriptEditor *editor);
private:
void registerActions();
......@@ -67,6 +71,7 @@ private:
TextEditor::TextFileWizard *m_wizard;
QtScriptEditorFactory *m_editor;
TextEditor::TextEditorActionHandler *m_actionHandler;
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment