Commits

Philip Allgaier committed 376f8bf

- first steps with the GenericTextEditor codecs
- many parts still missing
- first parts of MaterialTextEditor ported
- ScriptTextEditor still to be done

Comments (0)

Files changed (20)

Dependencies/GenericTextEditor/CMakeLists.txt

 
 	set(HEADER_FILES
 		./include/generictexteditor.hxx
+		./include/itexteditorcodec.hxx
+		./include/generictexteditorcodec.hxx
 	)
 
 	set(SOURCE_FILES
 		./src/generictexteditor.cpp	
+		./src/generictexteditorcodec.cpp
 	)
 
 	SET(MOC_SRCS2 
 		./include/generictexteditor.hxx
+		./include/itexteditorcodec.hxx
+		./include/generictexteditorcodec.hxx
 	)
 
 	qt4_wrap_cpp(MOC_SRCS ${MOC_SRCS2})
 	include_directories(include)
 
 	include_directories(.)
-
+	include_directories(${OGITOR_INCLUDES})
         include_directories(../OFS/include)
 
 
-	link_libraries(${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES} OFS)
+	link_libraries(${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES} OFS Ogitor)
 	add_library(GenericTextEditor SHARED ${SRCS})
 	set(LIBRARY_OUTPUT_PATH ../lib)
 

Dependencies/GenericTextEditor/include/generictexteditor.hxx

 #include <QtGui/QMdiSubWindow>
 #include <QtGui/QSyntaxHighlighter>
 
+#include "OgreSingleton.h"
+
+#include "generictexteditorcodec.hxx"
 #include "ofs.h"
 
 class QPaintEvent;
    #define GTEExport
 #endif
 
+typedef std::map<QString, ITextEditorCodecFactory*> CodecExtensionFactoryMap;
 
 //-----------------------------------------------------------------------------------------
 
-class GTEExport GenericTextEditor : public QMdiArea
+class GTEExport GenericTextEditor : public QMdiArea, public Ogre::Singleton<GenericTextEditor>
 {
     Q_OBJECT
 
 public:
-    GenericTextEditor(QString editorName, QString documentIcon, QWidget *parent = 0);
+    GenericTextEditor(QString editorName, QWidget *parent = 0);
 
-    void    displayTextFromFile(QString fileName);
-    void    displayText(QString docName, QString text);
+    bool                            displayTextFromFile(QString filePath);
+    bool                            displayText(QString docName, QString text, QString extension);
+    void                            moveToForeground();
+    void                            saveAll();
 
-    inline void    setAllowDoubleDisplay(bool allow) {mAllowDoubleDisplay = allow;}
-    inline bool    isAllowDoubleDisplay() {return mAllowDoubleDisplay;}
+    static void                     registerCodecFactory(QString extension, ITextEditorCodecFactory* codec);
+    static void                     unregisterCodecFactory(QString extension);
+    static ITextEditorCodecFactory* findMatchingCodecFactory(QString extensionOrFileName);
+
+    static QStringListModel*        modelFromFile(const QString& fileName);
+
+    inline void                     setAllowDoubleDisplay(bool allow) {mAllowDoubleDisplay = allow;}
+    inline bool                     isAllowDoubleDisplay() {return mAllowDoubleDisplay;}
 
 signals:
     void    currentChanged(int);
 protected:
     bool    isPathAlreadyShowing(QString filePath, GenericTextEditorDocument*& document);
     bool    isDocAlreadyShowing(QString docName, GenericTextEditorDocument*& document);
-    void    closeEvent(QCloseEvent *event);
+    void    closeEvent(QCloseEvent *event);    
 
 private slots:
     void    closeTab(int index);
-    void    tabChanged(int index);
 
-protected:
-    QString mDocumentIcon;
-    bool    mAllowDoubleDisplay;
+private:
+     static CodecExtensionFactoryMap    mRegisteredCodecFactories;
+     QTabWidget*                        mParentTabWidget;
+     bool                               mAllowDoubleDisplay;
 };
 
 //-----------------------------------------------------------------------------------------
     void lineNumberAreaPaintEvent(QPaintEvent *event);
     int  lineNumberAreaWidth();
 
-    bool saveFile();
     void displayTextFromFile(QString docName, QString filePath);
     void displayText(QString docName, QString text);
     void releaseFile();
     void addCompleter(const QString keywordListFilePath);
 
     inline QString getDocName(){return mDocName;}
-    inline QString getFilePath() {return mFilePath;}
+    inline QString getFilePath(){return mFilePath;}
+    inline ITextEditorCodec* getCodec(){return mCodec;}
     inline bool isTextModified(){return mTextModified;}
-    inline void setTextModified(bool modified) {mTextModified = modified;}
+    inline void setTextModified(bool modified){mTextModified = modified;}
+    inline void setCodec(ITextEditorCodec* codec){mCodec = codec;}
 
 protected:
     void resizeEvent(QResizeEvent *event);
     void contextMenuEvent(QContextMenuEvent *event);
     void mousePressEvent(QMouseEvent *event);
     QString textUnderCursor() const;
-    QStringListModel* modelFromFile(const QString& fileName);
     int  calculateIndentation(const QString& str);
 
 protected slots:
     void documentWasModified();
 
 protected:
-    bool                    mIsOfsFile;
-    QString            mDocName;
-    QString            mFilePath;
-    QFile              mFile;
-    OFS::OfsPtr             mOfsPtr;
-    OFS::OFSHANDLE          mOfsFileHandle;
-    QWidget*           mLineNumberArea;
-    QCompleter*        mCompleter;
-    bool               mTextModified;
+    ITextEditorCodec*   mCodec;
+    bool                mIsOfsFile;
+    QString             mDocName;
+    QString             mFilePath;
+    QFile               mFile;
+    OFS::OfsPtr         mOfsPtr;
+    OFS::OFSHANDLE      mOfsFileHandle;
+    QWidget*            mLineNumberArea;
+    QCompleter*         mCompleter;
+    bool                mTextModified;
 };
 
 //-----------------------------------------------------------------------------------------

Dependencies/GenericTextEditor/include/generictexteditorcodec.hxx

+/*/////////////////////////////////////////////////////////////////////////////////
+/// An
+///    ___   ____ ___ _____ ___  ____
+///   / _ \ / ___|_ _|_   _/ _ \|  _ \
+///  | | | | |  _ | |  | || | | | |_) |
+///  | |_| | |_| || |  | || |_| |  _ <
+///   \___/ \____|___| |_| \___/|_| \_\
+///                              File
+///
+/// Copyright (c) 2008-2011 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
+//
+/// The MIT License
+///
+/// Permission is hereby granted, free of charge, to any person obtaining a copy
+/// of this software and associated documentation files (the "Software"), to deal
+/// in the Software without restriction, including without limitation the rights
+/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+/// copies of the Software, and to permit persons to whom the Software is
+/// furnished to do so, subject to the following conditions:
+///
+/// The above copyright notice and this permission notice shall be included in
+/// all copies or substantial portions of the Software.
+///
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+/// THE SOFTWARE.
+////////////////////////////////////////////////////////////////////////////////*/
+
+#ifndef GENERIC_TEXT_EDITOR_CODEC_HXX
+#define GENERIC_TEXT_EDITOR_CODEC_HXX
+
+#include "itexteditorcodec.hxx"
+
+//----------------------------------------------------------------------------------------
+
+class GenericTextEditorCodec : public ITextEditorCodec
+{
+public:
+    GenericTextEditorCodec(QPlainTextEdit* textEdit, QString docName, QString documentIcon);
+
+    QString prepareForDisplay(QString docName, QString text);
+    bool    save();
+    void    contextMenu(QContextMenuEvent* event){};    
+    void    keyPressEvent(QKeyEvent *event){};
+    void    addHighlighter(GenericTextEditorDocument* document){};
+    void    addCompleter(GenericTextEditorDocument* document){};
+};
+
+//----------------------------------------------------------------------------------------
+
+class GenericTextEditorCodecFactory : public ITextEditorCodecFactory
+{
+public:
+    ITextEditorCodec* create(QPlainTextEdit* textEdit, QString docName);
+};
+
+//----------------------------------------------------------------------------------------
+
+#endif
+
+//----------------------------------------------------------------------------------------

Dependencies/GenericTextEditor/include/itexteditorcodec.hxx

+/*/////////////////////////////////////////////////////////////////////////////////
+/// An
+///    ___   ____ ___ _____ ___  ____
+///   / _ \ / ___|_ _|_   _/ _ \|  _ \
+///  | | | | |  _ | |  | || | | | |_) |
+///  | |_| | |_| || |  | || |_| |  _ <
+///   \___/ \____|___| |_| \___/|_| \_\
+///                              File
+///
+/// Copyright (c) 2008-2011 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
+//
+/// The MIT License
+///
+/// Permission is hereby granted, free of charge, to any person obtaining a copy
+/// of this software and associated documentation files (the "Software"), to deal
+/// in the Software without restriction, including without limitation the rights
+/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+/// copies of the Software, and to permit persons to whom the Software is
+/// furnished to do so, subject to the following conditions:
+///
+/// The above copyright notice and this permission notice shall be included in
+/// all copies or substantial portions of the Software.
+///
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+/// THE SOFTWARE.
+////////////////////////////////////////////////////////////////////////////////*/
+
+#ifndef I_TEXT_EDITOR_CODEC_HXX
+#define I_TEXT_EDITOR_CODEC_HXX
+
+#include <QtCore/QString>
+#include <QtGui/QContextMenuEvent>
+#include <QtGui/QKeyEvent>
+#include <QtGui/QPlainTextEdit>
+
+//----------------------------------------------------------------------------------------
+
+class GenericTextEditorDocument;
+
+//----------------------------------------------------------------------------------------
+
+class ITextEditorCodec
+{
+public:
+    ITextEditorCodec(QPlainTextEdit* textEdit, QString docName, QString documentIcon)
+    {
+        mTextEdit           = textEdit;
+        mDocName            = docName;
+        mDocumentIcon       = documentIcon;
+    }
+
+    virtual QString prepareForDisplay(QString docName, QString text) = 0;
+    virtual bool    save() = 0;
+    virtual void    contextMenu(QContextMenuEvent* event) = 0;
+    virtual void    keyPressEvent(QKeyEvent* event) = 0;
+    virtual void    addHighlighter(GenericTextEditorDocument* document) = 0;
+    virtual void    addCompleter(GenericTextEditorDocument* document) = 0;
+
+    QString         getDocumentIcon() {return mDocumentIcon;}
+
+protected:
+    QPlainTextEdit* mTextEdit;
+    QString         mDocName;
+    QString         mDocumentIcon;
+};
+
+//----------------------------------------------------------------------------------------
+
+class ITextEditorCodecFactory
+{
+public:
+    virtual ITextEditorCodec* create(QPlainTextEdit* textEdit, QString docName) = 0;
+};
+
+//----------------------------------------------------------------------------------------
+
+#endif
+
+//----------------------------------------------------------------------------------------

Dependencies/GenericTextEditor/src/generictexteditor.cpp

 #include "generictexteditor.hxx"
 
 //-----------------------------------------------------------------------------------------
-GenericTextEditor::GenericTextEditor(QString editorName, QString documentIcon, QWidget *parent) : QMdiArea(parent)
+
+template<> GenericTextEditor* Ogre::Singleton<GenericTextEditor>::ms_Singleton = 0;
+CodecExtensionFactoryMap GenericTextEditor::mRegisteredCodecFactories = CodecExtensionFactoryMap();
+
+//-----------------------------------------------------------------------------------------
+GenericTextEditor::GenericTextEditor(QString editorName, QWidget *parent) : QMdiArea(parent)
 {
-    mDocumentIcon = documentIcon;
-    mAllowDoubleDisplay = false;
-
+    mParentTabWidget = static_cast<QTabWidget*>(parent);
     setObjectName(editorName);
     setViewMode(QMdiArea::TabbedView);
 
     connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
     connect(tabBar, SIGNAL(currentChanged(int)),    this, SLOT(tabChanged(int)));
     connect(this,   SIGNAL(currentChanged(int)),    this, SLOT(tabChanged(int)));
+
+    // Register the standard generic text editor codec extensions
+    GenericTextEditorCodecFactory* genCodecFactory = new GenericTextEditorCodecFactory();
+    GenericTextEditor::registerCodecFactory("txt",         genCodecFactory);
+    GenericTextEditor::registerCodecFactory("xml",         genCodecFactory);
+    GenericTextEditor::registerCodecFactory("ogscene",     genCodecFactory);
+    GenericTextEditor::registerCodecFactory("html",        genCodecFactory);
+    GenericTextEditor::registerCodecFactory("htm",         genCodecFactory);
+    GenericTextEditor::registerCodecFactory("scene",       genCodecFactory);
+    GenericTextEditor::registerCodecFactory("cfg",         genCodecFactory);
+    GenericTextEditor::registerCodecFactory("log",         genCodecFactory);
 }
 //-----------------------------------------------------------------------------------------
-void GenericTextEditor::displayTextFromFile(QString filePath)
+void GenericTextEditor::registerCodecFactory(QString extension, ITextEditorCodecFactory* codec)
 {
+    mRegisteredCodecFactories.insert(CodecExtensionFactoryMap::value_type(extension, codec));
+}
+//-----------------------------------------------------------------------------------------
+void GenericTextEditor::unregisterCodecFactory(QString extension)
+{
+    CodecExtensionFactoryMap::const_iterator it = mRegisteredCodecFactories.end();
+    it = mRegisteredCodecFactories.find(extension);
+
+    if(it != mRegisteredCodecFactories.end())
+        mRegisteredCodecFactories.erase(it);
+}
+//-----------------------------------------------------------------------------------------
+bool GenericTextEditor::displayTextFromFile(QString filePath)
+{
+    ITextEditorCodecFactory* codecFactory = GenericTextEditor::findMatchingCodecFactory(filePath);
+
+    if(codecFactory == 0)
+       return false;    
+    
     GenericTextEditorDocument* document = 0;
-    if(!isPathAlreadyShowing(filePath, document) || mAllowDoubleDisplay)
+    if(!isPathAlreadyShowing(filePath, document) || isAllowDoubleDisplay())
     {
         document = new GenericTextEditorDocument(this);
+        ITextEditorCodec* codec = codecFactory->create(document, filePath);
+        document->setCodec(codec);
         document->displayTextFromFile(QFile(filePath).fileName(), filePath);
         QMdiSubWindow *window = addSubWindow(document);
-        window->setWindowIcon(QIcon(mDocumentIcon));
+        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
         document->showMaximized();
         QTabBar* tabBar = findChildren<QTabBar*>().at(0);
         tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, QFile(filePath).fileName());
         setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
         document->setFocus(Qt::ActiveWindowFocusReason);
     }
+
+    moveToForeground();
+
+    return true;
 }
 //-----------------------------------------------------------------------------------------
-void GenericTextEditor::displayText(QString docName, QString text)
+bool GenericTextEditor::displayText(QString docName, QString text, QString extension = "")
 {
+    // If there is no extra extension passed, then try to find the matching one based on the doc name
+    ITextEditorCodecFactory* codecFactory;
+    if(extension == "")    
+        codecFactory = GenericTextEditor::findMatchingCodecFactory(docName);
+    else
+        codecFactory = GenericTextEditor::findMatchingCodecFactory(extension);
+
+    if(codecFactory == 0)
+        return false;
+
     GenericTextEditorDocument* document = 0;
-    if(!isDocAlreadyShowing(docName, document) || mAllowDoubleDisplay)
+    if(!isDocAlreadyShowing(docName, document) || isAllowDoubleDisplay())
     {
         document = new GenericTextEditorDocument(this);
+        ITextEditorCodec* codec = codecFactory->create(document, docName);
+        document->setCodec(codec);
         document->displayText(docName, text);
         QMdiSubWindow *window = addSubWindow(document);
-        window->setWindowIcon(QIcon(mDocumentIcon));
+        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
         document->showMaximized();
         QTabBar* tabBar = findChildren<QTabBar*>().at(0);
         tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, docName);
         setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
         document->setFocus(Qt::ActiveWindowFocusReason);
     }
+
+    moveToForeground();
+
+    return true;
 }
 //-----------------------------------------------------------------------------------------
 bool GenericTextEditor::isPathAlreadyShowing(QString filePath, GenericTextEditorDocument*& document)
         int result = QMessageBox::information(QApplication::activeWindow(), "qtOgitor", "Document has been modified. Should the changes be saved?", QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
         switch(result)
         {
-        case QMessageBox::Yes: document->saveFile(); break;
+        case QMessageBox::Yes: document->getCodec()->save(); break;
         case QMessageBox::No: break;
         case QMessageBox::Cancel: return;
         }
     emit currentChanged(subWindowList().indexOf(activeSubWindow()));
 }
 //-----------------------------------------------------------------------------------------
-void GenericTextEditor::tabChanged(int index)
-{
-}
-//-----------------------------------------------------------------------------------------
 void GenericTextEditor::closeEvent(QCloseEvent *event)
 {
     QList<QMdiSubWindow*> list = subWindowList();
         closeTab(i);
 }
 //-----------------------------------------------------------------------------------------
-GenericTextEditorDocument::GenericTextEditorDocument(QWidget *parent) : QPlainTextEdit(parent), 
-mCompleter(0), mDocName(""), mFilePath(""), mTextModified(false), mFile(0), mIsOfsFile(false)
+ITextEditorCodecFactory* GenericTextEditor::findMatchingCodecFactory(QString extensionOrFileName)
+{
+    int pos = extensionOrFileName.lastIndexOf(".");
+    QString extension;
+
+    if(pos != -1)
+        extension = extensionOrFileName.right(extensionOrFileName.size() - pos - 1);
+    else
+        extension = extensionOrFileName;
+    
+    CodecExtensionFactoryMap::const_iterator it = mRegisteredCodecFactories.end();
+    it = mRegisteredCodecFactories.find(extension);
+
+    if(it != mRegisteredCodecFactories.end())
+        return it->second;
+    else 
+        return 0;
+}
+//-----------------------------------------------------------------------------------------
+QStringListModel* GenericTextEditor::modelFromFile(const QString& filePath)
+{
+    QFile file(filePath);
+    if(!file.open(QFile::ReadOnly))
+        return new QStringListModel();
+
+    QStringList words;
+    while (!file.atEnd()) 
+    {
+        QByteArray line = file.readLine();
+        if(!line.isEmpty())
+            words << line.trimmed();
+    }
+    QMap<QString, QString> strMap;
+    foreach(QString str, words) 
+        strMap.insert(str.toLower(), str);
+
+    file.close();
+    return new QStringListModel(strMap.values());
+}
+//-----------------------------------------------------------------------------------------
+void GenericTextEditor::moveToForeground()
+{
+    mParentTabWidget->setCurrentIndex(mParentTabWidget->indexOf(this));
+}
+//-----------------------------------------------------------------------------------------
+void GenericTextEditor::saveAll()
+{
+    GenericTextEditorDocument* document;
+    QList<QMdiSubWindow*> list = subWindowList();
+    for(int i = 0; i < list.size(); i++)
+    { 
+        document = static_cast<GenericTextEditorDocument*>(subWindowList()[i]->widget());
+    
+        if(document->isTextModified())
+            document->getCodec()->save();
+    }
+}
+//-----------------------------------------------------------------------------------------
+GenericTextEditorDocument::GenericTextEditorDocument( QWidget *parent) : QPlainTextEdit(parent), 
+mCodec(0), mCompleter(0), mDocName(""), mFilePath(""), mTextModified(false), mFile(0), mIsOfsFile(false)
 {
     QFont fnt = font();
     fnt.setFamily("Courier New");
         unsigned int cont_len = 0;
         mOfsPtr->getFileSize(mOfsFileHandle, cont_len);
 
-        char  * buf = new char[cont_len + 1];
+        char* buf = new char[cont_len + 1];
         buf[cont_len] = 0;
 
         mOfsPtr->read(mOfsFileHandle, buf, cont_len);
         mOfsPtr->closeFile(mOfsFileHandle);
         
         displayText(filePath, buf);
-        delete [] buf;
+        delete[] buf;
     }
     else
     {
 
         mFile.setFileName(filePath);
         mFile.open(QIODevice::ReadOnly);
-        displayText(docName, mFile.fileName());
+        displayText(docName, mFile.readAll());
     }
    
 }
 void GenericTextEditorDocument::displayText(QString docName, QString text)
 {
     mDocName = docName;
-    setPlainText(text);
+
+    setPlainText(mCodec->prepareForDisplay(docName, text));
 
     QString tabTitle = docName;
     if(tabTitle.length() > 25)
         tabTitle = tabTitle.left(12) + "..." + tabTitle.right(10);
     setWindowTitle(tabTitle + QString("[*]"));
 
+    mCodec->addCompleter(this);
+    mCodec->addHighlighter(this);
+
     connect(this, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
+
+    setWindowModified(false);
 }
 //-----------------------------------------------------------------------------------------
 int GenericTextEditorDocument::lineNumberAreaWidth()
     QPlainTextEdit::focusInEvent(event);
 }
 //-----------------------------------------------------------------------------------------
-QStringListModel* GenericTextEditorDocument::modelFromFile(const QString& filePath)
-{
-    QFile file(filePath);
-    if(!file.open(QFile::ReadOnly))
-        return new QStringListModel(mCompleter);
-
-    QStringList words;
-    while (!file.atEnd()) 
-    {
-        QByteArray line = file.readLine();
-        if(!line.isEmpty())
-            words << line.trimmed();
-    }
-    QMap<QString, QString> strMap;
-    foreach(QString str, words) 
-        strMap.insert(str.toLower(), str);
-
-    file.close();
-    return new QStringListModel(strMap.values(), mCompleter);
-}
-//-----------------------------------------------------------------------------------------
 void GenericTextEditorDocument::keyPressEvent(QKeyEvent *event)
 {
     QPlainTextEdit::keyPressEvent(event);
 //-----------------------------------------------------------------------------------------
 void GenericTextEditorDocument::contextMenuEvent(QContextMenuEvent *event)
 {
-    QPlainTextEdit::contextMenuEvent(event);
+    mCodec->contextMenu(event);
 }
 //-----------------------------------------------------------------------------------------
 void GenericTextEditorDocument::mousePressEvent(QMouseEvent *event)
 {
-    // Rewrite the mouse event to a left button event so the cursor is moved to the location of the pointer
+    // Rewrite the right clcick mouse event to a left button event so the cursor is moved to the location of the click
     if(event->button() == Qt::RightButton)
         event = new QMouseEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
     QPlainTextEdit::mousePressEvent(event);
 {
     setTextModified(true);
     setWindowModified(isTextModified());
-}
-//-----------------------------------------------------------------------------------------
-bool GenericTextEditorDocument::saveFile()
-{
-    return true;
+    // TODO!!!
+    //OgitorsRoot::getSingletonPtr()->SetSceneModified(true);
 }
 //-----------------------------------------------------------------------------------------
 void GenericTextEditorDocument::releaseFile()
 //-----------------------------------------------------------------------------------------
 void GenericTextEditorDocument::addCompleter(const QString keywordListFilePath)
 {
-    mCompleter = new QCompleter(modelFromFile(keywordListFilePath)->stringList(), this);
+    mCompleter = new QCompleter(GenericTextEditor::getSingletonPtr()->modelFromFile(keywordListFilePath)->stringList(), this);
     mCompleter->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
     mCompleter->setCaseSensitivity(Qt::CaseInsensitive);
     mCompleter->setCompletionMode(QCompleter::PopupCompletion);

Dependencies/GenericTextEditor/src/generictexteditorcodec.cpp

+/*/////////////////////////////////////////////////////////////////////////////////
+/// An
+///    ___   ____ ___ _____ ___  ____
+///   / _ \ / ___|_ _|_   _/ _ \|  _ \
+///  | | | | |  _ | |  | || | | | |_) |
+///  | |_| | |_| || |  | || |_| |  _ <
+///   \___/ \____|___| |_| \___/|_| \_\
+///                              File
+///
+/// Copyright (c) 2008-2011 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
+//
+/// The MIT License
+///
+/// Permission is hereby granted, free of charge, to any person obtaining a copy
+/// of this software and associated documentation files (the "Software"), to deal
+/// in the Software without restriction, including without limitation the rights
+/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+/// copies of the Software, and to permit persons to whom the Software is
+/// furnished to do so, subject to the following conditions:
+///
+/// The above copyright notice and this permission notice shall be included in
+/// all copies or substantial portions of the Software.
+///
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+/// THE SOFTWARE.
+////////////////////////////////////////////////////////////////////////////////*/
+
+#include "generictexteditorcodec.hxx"
+
+//-----------------------------------------------------------------------------------------
+GenericTextEditorCodec::GenericTextEditorCodec(QPlainTextEdit* textEdit, QString docName, QString documentIcon) : 
+ITextEditorCodec(textEdit, docName, documentIcon)
+{
+}
+//-----------------------------------------------------------------------------------------
+QString GenericTextEditorCodec::prepareForDisplay(QString docName, QString text)
+{
+    return text;
+}
+//-----------------------------------------------------------------------------------------
+bool GenericTextEditorCodec::save()
+{
+    return true;
+}
+//-----------------------------------------------------------------------------------------
+ITextEditorCodec* GenericTextEditorCodecFactory::create(QPlainTextEdit* textEdit, QString docName)
+{
+    return new GenericTextEditorCodec(textEdit, ":/icons/files.svg", docName);
+}
+//-----------------------------------------------------------------------------------------

Ogitor/include/OgitorsRoot.h

 /// THE SOFTWARE.
 ////////////////////////////////////////////////////////////////////////////////*/
 
-#pragma once
+#ifndef OGITORS_ROOT_H
+#define OGITORS_ROOT_H
 
 #include "OgitorsSingleton.h"
 
         void resourceStreamOpened(const Ogre::String &name, const Ogre::String &group, Ogre::Resource *resource, Ogre::DataStreamPtr& dataStream){};
     };
 }
+
+#endif

Ogitor/src/OgitorsRoot.cpp

     }
 }
 //-----------------------------------------------------------------------------------------
-typedef bool (*DLL_START_PLUGIN)(void *, Ogre::String&);
+typedef bool (*DLL_START_PLUGIN)(void*, Ogre::String&);
 typedef bool (*DLL_GET_PLUGIN_NAME)(Ogre::String&);
 typedef bool (*DLL_STOP_PLUGIN)(void);
 //-----------------------------------------------------------------------------------------

Plugins/OgMaterialEditor/CMakeLists.txt

 		TechniqueEditor.h
 		Plugin.h
 		materialeditorprefseditor.hxx
+		materialtexteditorcodec.hxx
 	)
 
 	set(SOURCE_FILES
 		TechniqueEditor.cpp
 		Plugin.cpp
 		materialeditorprefseditor.cpp
+		materialtexteditorcodec.cpp
 	)
 
 	set(MOC_SRCS2 
 		materialtexteditor.hxx
 		materialhighlighter.hxx
 		materialeditorprefseditor.hxx
+		materialtexteditorcodec.hxx
 	)
 
 	qt4_wrap_cpp(MOC_SRCS ${MOC_SRCS2} OPTIONS ${OGITOR_QT_PREPROCESSOR})
 	set(OgMaterialEditor_VERSION 0)
 	set(OgMaterialEditor_VERSION_MAJOR 1)
 
-	include_directories (include)
+	include_directories(include)
 	include_directories(${DEPENDENCIES_INCLUDES})
 	include_directories(${OGITOR_INCLUDES})
 	message(STATUS "${OGITOR_INCLUDES}")

Plugins/OgMaterialEditor/Plugin.cpp

 #include "Plugin.h"
 #include "MaterialEditor.h"
 #include "TechniqueEditor.h"
-#include "materialtexteditor.hxx"
+#include "materialtexteditorcodec.hxx"
 #include "materialview.hxx"
 #include "materialeditorprefseditor.hxx"
 
 bool dllStartPlugin(void *identifier, Ogre::String& name)
 {
     name = "Material Editor Plugin";
-	
-    mMaterialTextEditor = new MaterialTextEditor();
+
 	mMaterialViewWidget = new MaterialViewWidget();
     mMaterialPrefsEditor = new MaterialEditorPrefsEditor();
 
     dockWidgetData.mIcon = ":/icons/material.svg";
     dockWidgetData.mParent = DOCK_RESOURCES;
 	   
-	Ogitors::TabWidgetData tabWidgetData;
-	tabWidgetData.mCaption = "Material Editor";
-    tabWidgetData.mHandle = mMaterialTextEditor;
-
     Ogitors::PreferencesEditorData preferencesEditorData;
     preferencesEditorData.mCaption = "Material Editor";
     preferencesEditorData.mIcon = ":/icons/material.svg";
     preferencesEditorData.mSectionName = "materialEditor";
     preferencesEditorData.mHandle = mMaterialPrefsEditor;
 
+    MaterialTextEditorCodecFactory* matCodecFactory = new MaterialTextEditorCodecFactory();
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("material",     matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("cg",           matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("hlsl",         matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("glsl",         matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("frag",         matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("vert",         matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("program",      matCodecFactory);
+    GenericTextEditor::getSingletonPtr()->registerCodecFactory("compositor",   matCodecFactory);
+
     OgitorsRoot::getSingletonPtr()->RegisterEditorFactory(identifier, OGRE_NEW CMaterialEditorFactory());
     OgitorsRoot::getSingletonPtr()->RegisterEditorFactory(identifier, OGRE_NEW CTechniqueEditorFactory());
 	OgitorsRoot::getSingletonPtr()->RegisterDockWidget(identifier, dockWidgetData);
-	OgitorsRoot::getSingletonPtr()->RegisterTabWidget(identifier, tabWidgetData);
     OgitorsRoot::getSingletonPtr()->RegisterPreferenceEditor(identifier, preferencesEditorData);
 
     return true;
 //----------------------------------------------------------------------------
 bool dllStopPlugin(void)
 {
-    //delete mMaterialTextEditor;
-    //delete mMaterialViewWidget;
-    //delete mMaterialPrefsEditor;
     return true;
 }
 //----------------------------------------------------------------------------

Plugins/OgMaterialEditor/materialeditorprefseditor.cpp

 //----------------------------------------------------------------------------------------
 bool MaterialEditorPrefsEditor::applyPreferences()
 {
-    if(mMaterialTextEditor->findChildren<QPlainTextEdit*>().size() != 0)
-    {
-        // Change font size
-        QFont font = static_cast<QPlainTextEdit*>(mMaterialTextEditor->findChildren<QPlainTextEdit*>().at(0))->font();
-        font.setPointSize(fontSizeSpinBox->value());
-        foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
-            pEdit->setFont(font);
+    //if(mMaterialTextEditor->findChildren<QPlainTextEdit*>().size() != 0)
+    //{
+    //    // Change font size
+    //    QFont font = static_cast<QPlainTextEdit*>(mMaterialTextEditor->findChildren<QPlainTextEdit*>().at(0))->font();
+    //    font.setPointSize(fontSizeSpinBox->value());
+    //    foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
+    //        pEdit->setFont(font);
 
-        // Change line wrapping
-        if(lineBreakCheckBox->isChecked())
-            foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
-                pEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth);
-        else
-            foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
-                pEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
-    }
+    //    // Change line wrapping
+    //    if(lineBreakCheckBox->isChecked())
+    //        foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
+    //            pEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth);
+    //    else
+    //        foreach(QPlainTextEdit* pEdit, mMaterialTextEditor->findChildren<QPlainTextEdit*>())
+    //            pEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
+    //}
 
+    //return true;
     return true;
 }
 //----------------------------------------------------------------------------------------

Plugins/OgMaterialEditor/materialtexteditor.cpp

-/*/////////////////////////////////////////////////////////////////////////////////
-/// An
-///    ___   ____ ___ _____ ___  ____
-///   / _ \ / ___|_ _|_   _/ _ \|  _ \
-///  | | | | |  _ | |  | || | | | |_) |
-///  | |_| | |_| || |  | || |_| |  _ <
-///   \___/ \____|___| |_| \___/|_| \_\
-///                              File
-///
-/// Copyright (mCompleter) 2008-2011 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
+///*/////////////////////////////////////////////////////////////////////////////////
+///// An
+/////    ___   ____ ___ _____ ___  ____
+/////   / _ \ / ___|_ _|_   _/ _ \|  _ \
+/////  | | | | |  _ | |  | || | | | |_) |
+/////  | |_| | |_| || |  | || |_| |  _ <
+/////   \___/ \____|___| |_| \___/|_| \_\
+/////                              File
+/////
+///// Copyright (mCompleter) 2008-2011 Ismail TARIM <ismail@royalspor.com> and the Ogitor Team
+////
+///// The MIT License
+/////
+///// Permission is hereby granted, free of charge, to any person obtaining a copy
+///// of this software and associated documentation files (the "Software"), to deal
+///// in the Software without restriction, including without limitation the rights
+///// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+///// copies of the Software, and to permit persons to whom the Software is
+///// furnished to do so, subject to the following conditions:
+/////
+///// The above copyright notice and this permission notice shall be included in
+///// all copies or substantial portions of the Software.
+/////
+///// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+///// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+///// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+///// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+///// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+///// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+///// THE SOFTWARE.
+//////////////////////////////////////////////////////////////////////////////////*/
 //
-/// The MIT License
-///
-/// Permission is hereby granted, free of charge, to any person obtaining a copy
-/// of this software and associated documentation files (the "Software"), to deal
-/// in the Software without restriction, including without limitation the rights
-/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-/// copies of the Software, and to permit persons to whom the Software is
-/// furnished to do so, subject to the following conditions:
-///
-/// The above copyright notice and this permission notice shall be included in
-/// all copies or substantial portions of the Software.
-///
-/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-/// THE SOFTWARE.
-////////////////////////////////////////////////////////////////////////////////*/
-
-#include <QtGui/QtGui>
-#include <QtGui/QColorDialog>
-#include <QtGui/QMessageBox>
-
-#include "OgitorsPrerequisites.h"
-
-#include "materialtexteditor.hxx"
-#include "materialview.hxx"
-#include "materialeditorprefseditor.hxx"
-
-using namespace Ogitors;
-
-MaterialTextEditor *mMaterialTextEditor = 0;
-//-----------------------------------------------------------------------------------------
-enum ColorType
-{
-    NONE = 0,
-    AMBIENT,
-    DIFFUSE,
-    SPECULAR,
-    EMISSIVE
-};
-//-----------------------------------------------------------------------------------------
-QString getMaterialText(const Ogre::String& input, const Ogre::String& find)
-{
-    Ogre::String buffer = input;
-
-    char *curpos = const_cast<char *>(buffer.c_str());
-    char *start = curpos;
-    char *end = curpos;
-
-    const char *curposend = curpos + buffer.size();
-
-    // Fill all comment lines with SPACE so they don't interfere with our search, example: //material X
-    while(curpos < curposend)
-    {
-        if(curpos[0] == '/' && (curpos + 1) < curposend && curpos[1] == '/')
-        {
-            while(curpos < curposend && curpos[0] != '\n')
-            {
-                *curpos = ' ';
-                curpos++;
-            }
-        }
-        curpos++;
-    }
-
-    int ps = buffer.find("material " + find);
-    if(ps != -1)
-    {
-        start += ps;
-        end += ps;
-
-        curpos = start;
-
-        while(curpos < curposend && curpos[0] != '{')
-            curpos++;
-
-        if((curpos + 1) >= curposend)
-            return "";
-
-        curpos++;
-
-        int brackets = 1;
-
-        while(brackets && (curpos < curposend))
-        {
-            if(curpos[0] == '{')
-                ++brackets;
-            else if(curpos[0] == '}')
-                --brackets;
-            curpos++;
-        }
-
-        if(curpos > curposend)
-            return "";
-
-        end = curpos;
-
-        Ogre::String res = input.substr(start - buffer.c_str(), end - start);
-        return res.c_str();
-    }
-    else
-        return "";
-}
-//-----------------------------------------------------------------------------------------
-MaterialTextEditor::MaterialTextEditor(QWidget *parent) : 
-GenericTextEditor("MaterialEditor", ":/icons/material.svg", parent)
-{
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditor::displayMaterial(QString materialName, QString resourceGroup, QString materialFileName)
-{
-    GenericTextEditorDocument* document = 0;
-    if(!isDocAlreadyShowing(materialName, document) || mAllowDoubleDisplay)
-    {
-        MaterialTextEditorDocument* document = new MaterialTextEditorDocument(this);
-        document->displayMaterial(materialName, resourceGroup, materialFileName);
-        QMdiSubWindow *window = addSubWindow(document);
-        window->setWindowIcon(QIcon(mDocumentIcon));
-        document->showMaximized();
-        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
-        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, materialName);
-    }
-    else
-    {
-        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
-        document->setFocus(Qt::ActiveWindowFocusReason);
-    }
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditor::tabChanged(int index)
-{
-    QTreeWidget *tree = mMaterialViewWidget->getTreeWidget();
-    
-    if(index == -1)
-        tree->selectionModel()->clearSelection();
-    else
-    {
-        QMdiSubWindow *wnd = subWindowList()[index];
-        MaterialTextEditorDocument *document = static_cast<MaterialTextEditorDocument*>(wnd->widget());
-        if(document)
-        {
-            QList<QTreeWidgetItem*> list = tree->findItems(document->getDocName(), Qt::MatchRecursive | Qt::MatchCaseSensitive);
-            if(list.size())
-                tree->setCurrentItem(list[0]);
-        }
-    }
-}
-//-----------------------------------------------------------------------------------------
-MaterialTextEditorDocument::MaterialTextEditorDocument(QWidget *parent) : GenericTextEditorDocument(parent), 
-mLastMaterialSource(""), mResourceGroup("")
-{
-    QSettings settings;
-    settings.beginGroup(mMaterialPrefsEditor->getPrefsSectionName().c_str());
-
-    if(settings.value("lineWrapping", false).toBool() == false)
-        setLineWrapMode(QPlainTextEdit::NoWrap);
-    else
-        setLineWrapMode(QPlainTextEdit::WidgetWidth);
-
-    settings.endGroup();
-
-    mHighlighter = new MaterialHighlighter(modelFromFile(":/syntax_highlighting/material.txt"), document());
-
-    Ogre::ScriptCompilerManager::getSingletonPtr()->setListener(this);
-
-    addCompleter(":/syntax_highlighting/material.txt");
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditorDocument::displayMaterial(QString materialName, QString resourceGroup, QString materialFilePath)
-{
-    mResourceGroup = resourceGroup;
-    mDocName = materialName;
-    mFilePath = materialFilePath;
-
-    Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mFilePath.toStdString(), resourceGroup.toStdString());                
-    mLastMaterialSource = getMaterialText(stream->getAsString().c_str(), materialName.toStdString());
-    
-    displayText(materialName, mLastMaterialSource);
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditorDocument::keyPressEvent(QKeyEvent *event)
-{
-    if((event->key() == Qt::Key_F5 || event->key() == Qt::Key_F6) && event->modifiers() == Qt::AltModifier)
-    {
-        //QString newMaterialName = saveMaterial();
-
-        //if(event->key() == Qt::Key_F5)
-            //OgitorsRoot::getSingletonPtr()->UpdateMaterialInScene(newMaterialName);
-    }
-
-    if(mCompleter && mCompleter->popup()->isVisible()) 
-    {
-        switch (event->key()) 
-        {
-        case Qt::Key_Enter:
-        case Qt::Key_Return:
-        case Qt::Key_Escape:
-        case Qt::Key_Tab:
-        case Qt::Key_Backtab:
-            event->ignore();
-            return;
-        default:
-            break;
-        }
-    }
-
-    // Auto start next line with the indentation of previous line...
-    if(event->key() == Qt::Key_Return)
-    {
-        QTextCursor tc = textCursor();
-        int savePos = tc.position();
-        //Get Previous bracket position
-        tc.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
-        QString tmpStr = tc.selectedText();
-
-        int count = calculateIndentation(tmpStr);
-
-        tc.setPosition(savePos);
-        QString txt = "\n";
-        for(int z = 0;z < count;z++)
-            txt += " ";
-        tc.insertText(txt);
-        tc.setPosition(savePos + count + 1);
-        setTextCursor(tc);
-        event->accept();
-        return;
-    }
-
-    //Insert 4 spaces instead of tab
-    if(event->key() == Qt::Key_Tab)
-    {
-        QTextCursor tc = textCursor();
-        int savePos = tc.position();
-        QString txt = "    ";
-        tc.insertText(txt);
-        tc.setPosition(savePos + 4);
-        setTextCursor(tc);
-        event->accept();
-        return;
-    }
-
-    bool isShortcut = ((event->modifiers() & Qt::ControlModifier) && event->key() == Qt::Key_Space); 
-    if(!mCompleter || !isShortcut) 
-        QPlainTextEdit::keyPressEvent(event);
-
-    const bool ctrlOrShift = event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
-    if(!mCompleter || (ctrlOrShift && event->text().isEmpty()))
-        return;
-
-    static QString eow("~!@#$%^&*()+{}|:\"<>?,./;'[]\\-= "); // end of word
-    bool hasModifier = (event->modifiers() != Qt::NoModifier) && !ctrlOrShift;
-    QString completionPrefix = textUnderCursor();
-
-    if(!isShortcut && (hasModifier || event->text().isEmpty() || completionPrefix.length() < 1
-        || eow.contains(event->text().right(1))))
-    {
-        mCompleter->popup()->hide();
-        return;
-    }
-
-    if(completionPrefix != mCompleter->completionPrefix()) 
-    {
-        mCompleter->setCompletionPrefix(completionPrefix);
-        mCompleter->popup()->setCurrentIndex(mCompleter->completionModel()->index(0, 0));
-    }
-    QRect cr = cursorRect();
-    cr.setWidth(mCompleter->popup()->sizeHintForColumn(0) + mCompleter->popup()->verticalScrollBar()->sizeHint().width());
-    mCompleter->complete(cr);
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditorDocument::contextMenuEvent(QContextMenuEvent *event)
-{
-    QTextCursor cursor = textCursor();
-    cursor.select(QTextCursor::LineUnderCursor);
-    setTextCursor(cursor);
-
-    if(textCursor().hasSelection())
-    {
-        QString lineText = textCursor().selectedText();
-        int lineNumber = textCursor().blockNumber();
-
-        cursor = textCursor();
-        cursor.setPosition(0);
-        cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, lineNumber);
-        int startPos = cursor.position();
-
-        // Offer color dialog help for the light terms
-        int colourType = NONE;
-        int index;
-        QRegExp expression;
-        expression.setPattern("ambient[^_](.+)$");
-        index = lineText.indexOf(expression);
-        if(index >= 0)
-            colourType = AMBIENT;
-        else
-        {
-            expression.setPattern("diffuse[^_](.+)$");
-            index = lineText.indexOf(expression);
-            if(index >= 0)
-                colourType = DIFFUSE;
-            else
-            {
-                expression.setPattern("specular[^_](.+)$");
-                index = lineText.indexOf(expression);
-                if(index >= 0)
-                    colourType = SPECULAR;
-                else
-                {
-                    expression.setPattern("emissive[^_](.+)$");
-                    index = lineText.indexOf(expression);
-                    if(index >= 0)
-                        colourType = EMISSIVE;
-                }
-            }
-        }
-            
-        if(colourType != NONE)
-        {         
-            int length = expression.matchedLength();
-            cursor = textCursor();
-            cursor.setPosition(startPos + index + length - expression.cap(1).length());
-            cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, expression.cap(1).length());
-            setTextCursor(cursor);
-
-            Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingletonPtr()->getByName(mDocName.toStdString());
-            
-            Ogre::ColourValue colour;
-            if(colourType == AMBIENT)
-                colour = mat->getBestTechnique(0)->getPass(0)->getAmbient();
-            else if(colourType == DIFFUSE)
-                colour = mat->getBestTechnique(0)->getPass(0)->getDiffuse();
-            else if(colourType == SPECULAR)
-                colour = mat->getBestTechnique(0)->getPass(0)->getSpecular();
-            else if(colourType == EMISSIVE)
-                colour = mat->getBestTechnique(0)->getPass(0)->getSelfIllumination();
-
-            QColor oldColour = QColor(255 * colour.r, 255 * colour.g, 255 * colour.b, 255 * colour.a);
-            QColor newColour = QColorDialog::getColor(oldColour, this);
-
-            // If the user pressed cancel, use our previous colour
-            if(!newColour.isValid())
-                return;
-
-            cursor.removeSelectedText();
-            char temp[128];
-            sprintf(temp, "%.4f %.4f %.4f %.4f", newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF());
-            cursor.insertText(QString(temp));
-            if(colourType == AMBIENT)
-                mat->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
-            else if(colourType == DIFFUSE)
-                mat->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
-            else if(colourType == SPECULAR)
-                mat->getTechnique(0)->getPass(0)->setSpecular(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
-            else if(colourType == EMISSIVE)
-                mat->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
-
-            return;
-        }
-
-        expression = QRegExp("texture[^_]([a-zA-Z0-9\\.\\-\\_]+)\\s*([a-zA-Z0-9-]*)");
-        index = lineText.indexOf(expression);
-        if(index >= 0)
-        {
-            int length = expression.matchedLength();
-            cursor = textCursor();
-            cursor.setPosition(startPos + index + length - expression.cap(1).length());
-            cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, expression.cap(1).length());
-            setTextCursor(cursor);
-            return;
-        }
-    }
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditorDocument::mousePressEvent(QMouseEvent *event)
-{
-    // Rewrite the mouse event to a left button event so the cursor is moved to the location of the pointer
-    if(event->button() == Qt::RightButton)
-        event = new QMouseEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
-    QPlainTextEdit::mousePressEvent(event);
-}
-//-----------------------------------------------------------------------------------------
-bool MaterialTextEditorDocument::saveFile()
-{
-    //bool reLoad = false;
-
-    //Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mFilePath.toStdString(), mResourceGroup.toStdString());				
-    //QString contents = stream->getAsString().c_str();
-    //stream.setNull();
-
-    //int pos = contents.indexOf(mLastMaterialSource);
-    //contents.erase(pos, mLastMaterialSource.size());
-    //contents.insert(pos, document()->toPlainText().toAscii());
-
-    //Ogre::Material* material = static_cast<Ogre::Material*>(mMaterialViewWidget->getMaterialEditor()->getHandle());
-
-    //Ogre::FileInfoListPtr fileInfoList;
-    //QString matOrigin = material->getOrigin();
-
-    //try
-    //{
-    //    fileInfoList = Ogre::ResourceGroupManager::getSingletonPtr()->findResourceFileInfo(material->getGroup(), material->getOrigin());
-
-    //    stream = fileInfoList.getPointer()->at(0).archive->create(matOrigin);
-
-    //    if(!stream.isNull())
-    //    {
-    //        int content_size = contents.length();
-    //        stream->write(contents.c_str(), content_size);
-    //        stream->close();
-    //        reLoad = true;
-    //    }
-    //}
-    //catch(...)
-    //{
-    //}
-
-
-    //if(reLoad)
-    //{
-    //    QString matName = material->getName();
-    //    material->unload();
-    //    Ogre::MaterialManager::getSingletonPtr()->remove(matName);
-
-    //    stream = fileInfoList.getPointer()->at(0).archive->open(matOrigin);
-
-    //    if(!stream.isNull())
-    //    {	
-    //        mScriptError = false;
-    //        Ogre::MaterialManager::getSingleton().parseScript(stream, material->getGroup());
-
-    //        if(!mScriptError)
-    //        {
-    //            Ogre::MaterialPtr reloadedMaterial = Ogre::MaterialManager::getSingleton().getByName(matName);
-    //            if (!reloadedMaterial.isNull())
-    //            {
-    //                reloadedMaterial->compile();
-    //                reloadedMaterial->load();
-    //                mMaterialViewWidget->getMaterialEditor()->setHandle(reloadedMaterial);
-    //            }
-
-    //            stream->close();
-    //            setTextModified(false);
-    //            setWindowModified(false);
-    //            //return matName;
-    //        }
-    //    }
-    //}
-    //else
-    //{
-    //    QMessageBox::information(QApplication::activeWindow(),"qtOgitor", tr("Error saving material script"));
-    //}
-
-    ////return QString("");
-
-    return true;
-}
-//-----------------------------------------------------------------------------------------
-void MaterialTextEditorDocument::handleError(Ogre::ScriptCompiler *compiler, Ogre::uint32 code, const QString &file, int line, const QString &msg)
-{
-    mScriptError = true;
-    QList<QTextEdit::ExtraSelection> extraSelections;
-    QTextEdit::ExtraSelection selection;
-    int currentLine = textCursor().blockNumber() + 1;
-    QTextCursor cursor = textCursor();
-    int lineDiff = line - currentLine;
-    if(lineDiff > 0)
-        cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, lineDiff);
-    else if(lineDiff < 0)
-        cursor.movePosition(QTextCursor::Up, QTextCursor::MoveAnchor, lineDiff);
-    setTextCursor(cursor);
-
-    QColor lineColor = QColor(Qt::red).lighter(160);
-    selection.format.setBackground(lineColor);
-    selection.format.setProperty(QTextFormat::FullWidthSelection, true);
-    selection.cursor = textCursor();
-    selection.cursor.clearSelection();
-    extraSelections.append(selection);
-    setExtraSelections(extraSelections);
-
-    QString message = QString("Script Compiler error: %1\nLine: %2").arg(msg).arg(line);
-    QMessageBox::information(QApplication::activeWindow(), "qtOgitor", tr(message.toAscii()));
-}
-//-----------------------------------------------------------------------------------------
+//#include <QtGui/QtGui>
+//#include <QtGui/QColorDialog>
+//#include <QtGui/QMessageBox>
+//
+//#include "OgitorsPrerequisites.h"
+//
+//#include "materialtexteditor.hxx"
+//#include "materialview.hxx"
+//#include "materialeditorprefseditor.hxx"
+//
+//using namespace Ogitors;
+//
+//MaterialTextEditor *mMaterialTextEditor = 0;
+////-----------------------------------------------------------------------------------------
+//enum ColorType
+//{
+//    NONE = 0,
+//    AMBIENT,
+//    DIFFUSE,
+//    SPECULAR,
+//    EMISSIVE
+//};
+////-----------------------------------------------------------------------------------------
+//QString getMaterialText(const Ogre::String& input, const Ogre::String& find)
+//{
+//    Ogre::String buffer = input;
+//
+//    char *curpos = const_cast<char *>(buffer.c_str());
+//    char *start = curpos;
+//    char *end = curpos;
+//
+//    const char *curposend = curpos + buffer.size();
+//
+//    // Fill all comment lines with SPACE so they don't interfere with our search, example: //material X
+//    while(curpos < curposend)
+//    {
+//        if(curpos[0] == '/' && (curpos + 1) < curposend && curpos[1] == '/')
+//        {
+//            while(curpos < curposend && curpos[0] != '\n')
+//            {
+//                *curpos = ' ';
+//                curpos++;
+//            }
+//        }
+//        curpos++;
+//    }
+//
+//    int ps = buffer.find("material " + find);
+//    if(ps != -1)
+//    {
+//        start += ps;
+//        end += ps;
+//
+//        curpos = start;
+//
+//        while(curpos < curposend && curpos[0] != '{')
+//            curpos++;
+//
+//        if((curpos + 1) >= curposend)
+//            return "";
+//
+//        curpos++;
+//
+//        int brackets = 1;
+//
+//        while(brackets && (curpos < curposend))
+//        {
+//            if(curpos[0] == '{')
+//                ++brackets;
+//            else if(curpos[0] == '}')
+//                --brackets;
+//            curpos++;
+//        }
+//
+//        if(curpos > curposend)
+//            return "";
+//
+//        end = curpos;
+//
+//        Ogre::String res = input.substr(start - buffer.c_str(), end - start);
+//        return res.c_str();
+//    }
+//    else
+//        return "";
+//}
+////-----------------------------------------------------------------------------------------
+//MaterialTextEditor::MaterialTextEditor(QWidget *parent) : 
+//GenericTextEditor("MaterialEditor", ":/icons/material.svg", parent)
+//{
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditor::displayMaterial(QString materialName, QString resourceGroup, QString materialFileName)
+//{
+//    GenericTextEditorDocument* document = 0;
+//    if(!isDocAlreadyShowing(materialName, document) || mAllowDoubleDisplay)
+//    {
+//        MaterialTextEditorDocument* document = new MaterialTextEditorDocument(this);
+//        document->displayMaterial(materialName, resourceGroup, materialFileName);
+//        QMdiSubWindow *window = addSubWindow(document);
+//        window->setWindowIcon(QIcon(mDocumentIcon));
+//        document->showMaximized();
+//        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
+//        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, materialName);
+//    }
+//    else
+//    {
+//        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
+//        document->setFocus(Qt::ActiveWindowFocusReason);
+//    }
+//}
+////-----------------------------------------------------------------------------------------
+//MaterialTextEditorDocument::MaterialTextEditorDocument(QWidget *parent) : GenericTextEditorDocument(parent), 
+//mLastMaterialSource(""), mResourceGroup("")
+//{
+//    QSettings settings;
+//    settings.beginGroup(mMaterialPrefsEditor->getPrefsSectionName().c_str());
+//
+//    if(settings.value("lineWrapping", false).toBool() == false)
+//        setLineWrapMode(QPlainTextEdit::NoWrap);
+//    else
+//        setLineWrapMode(QPlainTextEdit::WidgetWidth);
+//
+//    settings.endGroup();
+//
+//    mHighlighter = new MaterialHighlighter(modelFromFile(":/syntax_highlighting/material.txt"), document());
+//
+//    Ogre::ScriptCompilerManager::getSingletonPtr()->setListener(this);
+//
+//    addCompleter(":/syntax_highlighting/material.txt");
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditorDocument::displayMaterial(QString materialName, QString resourceGroup, QString materialFilePath)
+//{
+//    mResourceGroup = resourceGroup;
+//    mDocName = materialName;
+//    mFilePath = materialFilePath;
+//
+//    Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mFilePath.toStdString(), resourceGroup.toStdString());                
+//    mLastMaterialSource = getMaterialText(stream->getAsString().c_str(), materialName.toStdString());
+//    
+//    displayText(materialName, mLastMaterialSource);
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditorDocument::keyPressEvent(QKeyEvent *event)
+//{
+//    if((event->key() == Qt::Key_F5 || event->key() == Qt::Key_F6) && event->modifiers() == Qt::AltModifier)
+//    {
+//        //QString newMaterialName = saveMaterial();
+//
+//        //if(event->key() == Qt::Key_F5)
+//            //OgitorsRoot::getSingletonPtr()->UpdateMaterialInScene(newMaterialName);
+//    }
+//
+//    if(mCompleter && mCompleter->popup()->isVisible()) 
+//    {
+//        switch (event->key()) 
+//        {
+//        case Qt::Key_Enter:
+//        case Qt::Key_Return:
+//        case Qt::Key_Escape:
+//        case Qt::Key_Tab:
+//        case Qt::Key_Backtab:
+//            event->ignore();
+//            return;
+//        default:
+//            break;
+//        }
+//    }
+//
+//    // Auto start next line with the indentation of previous line...
+//    if(event->key() == Qt::Key_Return)
+//    {
+//        QTextCursor tc = textCursor();
+//        int savePos = tc.position();
+//        //Get Previous bracket position
+//        tc.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
+//        QString tmpStr = tc.selectedText();
+//
+//        int count = calculateIndentation(tmpStr);
+//
+//        tc.setPosition(savePos);
+//        QString txt = "\n";
+//        for(int z = 0;z < count;z++)
+//            txt += " ";
+//        tc.insertText(txt);
+//        tc.setPosition(savePos + count + 1);
+//        setTextCursor(tc);
+//        event->accept();
+//        return;
+//    }
+//
+//    //Insert 4 spaces instead of tab
+//    if(event->key() == Qt::Key_Tab)
+//    {
+//        QTextCursor tc = textCursor();
+//        int savePos = tc.position();
+//        QString txt = "    ";
+//        tc.insertText(txt);
+//        tc.setPosition(savePos + 4);
+//        setTextCursor(tc);
+//        event->accept();
+//        return;
+//    }
+//
+//    bool isShortcut = ((event->modifiers() & Qt::ControlModifier) && event->key() == Qt::Key_Space); 
+//    if(!mCompleter || !isShortcut) 
+//        QPlainTextEdit::keyPressEvent(event);
+//
+//    const bool ctrlOrShift = event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
+//    if(!mCompleter || (ctrlOrShift && event->text().isEmpty()))
+//        return;
+//
+//    static QString eow("~!@#$%^&*()+{}|:\"<>?,./;'[]\\-= "); // end of word
+//    bool hasModifier = (event->modifiers() != Qt::NoModifier) && !ctrlOrShift;
+//    QString completionPrefix = textUnderCursor();
+//
+//    if(!isShortcut && (hasModifier || event->text().isEmpty() || completionPrefix.length() < 1
+//        || eow.contains(event->text().right(1))))
+//    {
+//        mCompleter->popup()->hide();
+//        return;
+//    }
+//
+//    if(completionPrefix != mCompleter->completionPrefix()) 
+//    {
+//        mCompleter->setCompletionPrefix(completionPrefix);
+//        mCompleter->popup()->setCurrentIndex(mCompleter->completionModel()->index(0, 0));
+//    }
+//    QRect cr = cursorRect();
+//    cr.setWidth(mCompleter->popup()->sizeHintForColumn(0) + mCompleter->popup()->verticalScrollBar()->sizeHint().width());
+//    mCompleter->complete(cr);
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditorDocument::contextMenuEvent(QContextMenuEvent *event)
+//{
+//    QTextCursor cursor = textCursor();
+//    cursor.select(QTextCursor::LineUnderCursor);
+//    setTextCursor(cursor);
+//
+//    if(textCursor().hasSelection())
+//    {
+//        QString lineText = textCursor().selectedText();
+//        int lineNumber = textCursor().blockNumber();
+//
+//        cursor = textCursor();
+//        cursor.setPosition(0);
+//        cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, lineNumber);
+//        int startPos = cursor.position();
+//
+//        // Offer color dialog help for the light terms
+//        int colourType = NONE;
+//        int index;
+//        QRegExp expression;
+//        expression.setPattern("ambient[^_](.+)$");
+//        index = lineText.indexOf(expression);
+//        if(index >= 0)
+//            colourType = AMBIENT;
+//        else
+//        {
+//            expression.setPattern("diffuse[^_](.+)$");
+//            index = lineText.indexOf(expression);
+//            if(index >= 0)
+//                colourType = DIFFUSE;
+//            else
+//            {
+//                expression.setPattern("specular[^_](.+)$");
+//                index = lineText.indexOf(expression);
+//                if(index >= 0)
+//                    colourType = SPECULAR;
+//                else
+//                {
+//                    expression.setPattern("emissive[^_](.+)$");
+//                    index = lineText.indexOf(expression);
+//                    if(index >= 0)
+//                        colourType = EMISSIVE;
+//                }
+//            }
+//        }
+//            
+//        if(colourType != NONE)
+//        {         
+//            int length = expression.matchedLength();
+//            cursor = textCursor();
+//            cursor.setPosition(startPos + index + length - expression.cap(1).length());
+//            cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, expression.cap(1).length());
+//            setTextCursor(cursor);
+//
+//            Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingletonPtr()->getByName(mDocName.toStdString());
+//            
+//            Ogre::ColourValue colour;
+//            if(colourType == AMBIENT)
+//                colour = mat->getBestTechnique(0)->getPass(0)->getAmbient();
+//            else if(colourType == DIFFUSE)
+//                colour = mat->getBestTechnique(0)->getPass(0)->getDiffuse();
+//            else if(colourType == SPECULAR)
+//                colour = mat->getBestTechnique(0)->getPass(0)->getSpecular();
+//            else if(colourType == EMISSIVE)
+//                colour = mat->getBestTechnique(0)->getPass(0)->getSelfIllumination();
+//
+//            QColor oldColour = QColor(255 * colour.r, 255 * colour.g, 255 * colour.b, 255 * colour.a);
+//            QColor newColour = QColorDialog::getColor(oldColour, this);
+//
+//            // If the user pressed cancel, use our previous colour
+//            if(!newColour.isValid())
+//                return;
+//
+//            cursor.removeSelectedText();
+//            char temp[128];
+//            sprintf(temp, "%.4f %.4f %.4f %.4f", newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF());
+//            cursor.insertText(QString(temp));
+//            if(colourType == AMBIENT)
+//                mat->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
+//            else if(colourType == DIFFUSE)
+//                mat->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
+//            else if(colourType == SPECULAR)
+//                mat->getTechnique(0)->getPass(0)->setSpecular(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
+//            else if(colourType == EMISSIVE)
+//                mat->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue(newColour.redF(), newColour.greenF(), newColour.blueF(), newColour.alphaF()));
+//
+//            return;
+//        }
+//
+//        expression = QRegExp("texture[^_]([a-zA-Z0-9\\.\\-\\_]+)\\s*([a-zA-Z0-9-]*)");
+//        index = lineText.indexOf(expression);
+//        if(index >= 0)
+//        {
+//            int length = expression.matchedLength();
+//            cursor = textCursor();
+//            cursor.setPosition(startPos + index + length - expression.cap(1).length());
+//            cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, expression.cap(1).length());
+//            setTextCursor(cursor);
+//            return;
+//        }
+//    }
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditorDocument::mousePressEvent(QMouseEvent *event)
+//{
+//    // Rewrite the mouse event to a left button event so the cursor is moved to the location of the pointer
+//    if(event->button() == Qt::RightButton)
+//        event = new QMouseEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+//    QPlainTextEdit::mousePressEvent(event);
+//}
+////-----------------------------------------------------------------------------------------
+//bool MaterialTextEditorDocument::saveFile()
+//{
+//    //bool reLoad = false;
+//
+//    //Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(mFilePath.toStdString(), mResourceGroup.toStdString());				
+//    //QString contents = stream->getAsString().c_str();
+//    //stream.setNull();
+//
+//    //int pos = contents.indexOf(mLastMaterialSource);
+//    //contents.erase(pos, mLastMaterialSource.size());
+//    //contents.insert(pos, document()->toPlainText().toAscii());
+//
+//    //Ogre::Material* material = static_cast<Ogre::Material*>(mMaterialViewWidget->getMaterialEditor()->getHandle());
+//
+//    //Ogre::FileInfoListPtr fileInfoList;
+//    //QString matOrigin = material->getOrigin();
+//
+//    //try
+//    //{
+//    //    fileInfoList = Ogre::ResourceGroupManager::getSingletonPtr()->findResourceFileInfo(material->getGroup(), material->getOrigin());
+//
+//    //    stream = fileInfoList.getPointer()->at(0).archive->create(matOrigin);
+//
+//    //    if(!stream.isNull())
+//    //    {
+//    //        int content_size = contents.length();
+//    //        stream->write(contents.c_str(), content_size);
+//    //        stream->close();
+//    //        reLoad = true;
+//    //    }
+//    //}
+//    //catch(...)
+//    //{
+//    //}
+//
+//
+//    //if(reLoad)
+//    //{
+//    //    QString matName = material->getName();
+//    //    material->unload();
+//    //    Ogre::MaterialManager::getSingletonPtr()->remove(matName);
+//
+//    //    stream = fileInfoList.getPointer()->at(0).archive->open(matOrigin);
+//
+//    //    if(!stream.isNull())
+//    //    {	
+//    //        mScriptError = false;
+//    //        Ogre::MaterialManager::getSingleton().parseScript(stream, material->getGroup());
+//
+//    //        if(!mScriptError)
+//    //        {
+//    //            Ogre::MaterialPtr reloadedMaterial = Ogre::MaterialManager::getSingleton().getByName(matName);
+//    //            if (!reloadedMaterial.isNull())
+//    //            {
+//    //                reloadedMaterial->compile();
+//    //                reloadedMaterial->load();
+//    //                mMaterialViewWidget->getMaterialEditor()->setHandle(reloadedMaterial);
+//    //            }
+//
+//    //            stream->close();
+//    //            setTextModified(false);
+//    //            setWindowModified(false);
+//    //            //return matName;
+//    //        }
+//    //    }
+//    //}
+//    //else
+//    //{
+//    //    QMessageBox::information(QApplication::activeWindow(),"qtOgitor", tr("Error saving material script"));
+//    //}
+//
+//    ////return QString("");
+//
+//    return true;
+//}
+////-----------------------------------------------------------------------------------------
+//void MaterialTextEditorDocument::handleError(Ogre::ScriptCompiler *compiler, Ogre::uint32 code, const QString &file, int line, const QString &msg)
+//{
+//    mScriptError = true;
+//    QList<QTextEdit::ExtraSelection> extraSelections;
+//    QTextEdit::ExtraSelection selection;
+//    int currentLine = textCursor().blockNumber() + 1;
+//    QTextCursor cursor = textCursor();
+//    int lineDiff = line - currentLine;
+//    if(lineDiff > 0)
+//        cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, lineDiff);
+//    else if(lineDiff < 0)
+//        cursor.movePosition(QTextCursor::Up, QTextCursor::MoveAnchor, lineDiff);
+//    setTextCursor(cursor);
+//
+//    QColor lineColor = QColor(Qt::red).lighter(160);
+//    selection.format.setBackground(lineColor);
+//    selection.format.setProperty(QTextFormat::FullWidthSelection, true);
+//    selection.cursor = textCursor();
+//    selection.cursor.clearSelection();
+//    extraSelections.append(selection);
+//    setExtraSelections(extraSelections);
+//
+//    QString message = QString("Script Compiler error: %1\nLine: %2").arg(msg).arg(line);
+//    QMessageBox::information(QApplication::activeWindow(), "qtOgitor", tr(message.toAscii()));
+//}
+////-----------------------------------------------------------------------------------------

Plugins/OgMaterialEditor/materialtexteditor.hxx

 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 /// THE SOFTWARE.
 ////////////////////////////////////////////////////////////////////////////////*/
-#ifndef MATERIAL_TEXT_EDITOR_HXX
-#define MATERIAL_TEXT_EDITOR_HXX
+//#ifndef MATERIAL_TEXT_EDITOR_HXX
+//#define MATERIAL_TEXT_EDITOR_HXX
+//
+//#include <QtCore/QFile>
+//#include <QtCore/QTextStream>
+//
+//#include <QtGui/QPlainTextEdit>
+//#include <QtGui/QWidget>
+//#include <QtGui/QPainter>