2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "basetextmark.h"
|
2010-10-29 15:20:10 +02:00
|
|
|
#include "itexteditor.h"
|
2010-05-28 14:06:57 +02:00
|
|
|
#include "basetextdocument.h"
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QTimer>
|
2010-10-29 15:20:10 +02:00
|
|
|
#include <QtGui/QIcon>
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class InternalMark : public TextEditor::ITextMark
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit InternalMark(BaseTextMark *parent) : m_parent(parent) {}
|
|
|
|
|
|
|
|
|
|
virtual QIcon icon() const
|
|
|
|
|
{
|
|
|
|
|
return m_parent->icon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void updateLineNumber(int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
return m_parent->updateLineNumber(lineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void updateBlock(const QTextBlock &block)
|
|
|
|
|
{
|
|
|
|
|
return m_parent->updateBlock(block);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void removedFromEditor()
|
|
|
|
|
{
|
|
|
|
|
m_parent->childRemovedFromEditor(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void documentClosing()
|
|
|
|
|
{
|
|
|
|
|
m_parent->documentClosingFor(this);
|
|
|
|
|
}
|
2011-03-02 18:43:26 +01:00
|
|
|
|
|
|
|
|
virtual Priority priority() const
|
|
|
|
|
{
|
|
|
|
|
return m_parent->priority();
|
|
|
|
|
}
|
2010-10-29 15:20:10 +02:00
|
|
|
private:
|
|
|
|
|
BaseTextMark *m_parent;
|
|
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-29 15:20:10 +02:00
|
|
|
} // namespace Internal
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
BaseTextMark::BaseTextMark(const QString &filename, int line)
|
2010-05-28 14:06:57 +02:00
|
|
|
: m_markableInterface(0)
|
|
|
|
|
, m_internalMark(0)
|
|
|
|
|
, m_fileName(filename)
|
|
|
|
|
, m_line(line)
|
|
|
|
|
, m_init(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
// Why is this?
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(init()));
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-28 14:06:57 +02:00
|
|
|
BaseTextMark::~BaseTextMark()
|
|
|
|
|
{
|
|
|
|
|
// oha we are deleted
|
|
|
|
|
if (m_markableInterface)
|
|
|
|
|
m_markableInterface->removeMark(m_internalMark);
|
|
|
|
|
removeInternalMark();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void BaseTextMark::init()
|
|
|
|
|
{
|
|
|
|
|
m_init = true;
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(em, SIGNAL(editorOpened(Core::IEditor *)), this, SLOT(editorOpened(Core::IEditor *)));
|
|
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (Core::IEditor *editor, em->openedEditors())
|
2008-12-02 12:01:29 +01:00
|
|
|
editorOpened(editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseTextMark::editorOpened(Core::IEditor *editor)
|
|
|
|
|
{
|
2009-04-29 16:59:51 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
if (m_fileName.compare(editor->file()->fileName(), Qt::CaseInsensitive))
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2008-12-02 12:01:29 +01:00
|
|
|
if (editor->file()->fileName() != m_fileName)
|
|
|
|
|
return;
|
2009-04-29 16:59:51 +02:00
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
|
|
|
|
|
if (m_markableInterface == 0) { // We aren't added to something
|
|
|
|
|
m_markableInterface = textEditor->markableInterface();
|
2010-10-29 15:20:10 +02:00
|
|
|
m_internalMark = new Internal::InternalMark(this);
|
2010-01-11 12:47:01 +01:00
|
|
|
|
2010-05-28 14:06:57 +02:00
|
|
|
if (m_markableInterface->addMark(m_internalMark, m_line)) {
|
|
|
|
|
// Handle reload of text documents, readding the mark as necessary
|
|
|
|
|
connect(textEditor->file(), SIGNAL(reloaded()),
|
|
|
|
|
this, SLOT(documentReloaded()), Qt::UniqueConnection);
|
|
|
|
|
} else {
|
|
|
|
|
removeInternalMark();
|
2010-01-11 12:47:01 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-28 14:06:57 +02:00
|
|
|
void BaseTextMark::documentReloaded()
|
|
|
|
|
{
|
|
|
|
|
if (m_markableInterface)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BaseTextDocument *doc = qobject_cast<BaseTextDocument*>(sender());
|
|
|
|
|
if (!doc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_markableInterface = doc->documentMarker();
|
2010-10-29 15:20:10 +02:00
|
|
|
m_internalMark = new Internal::InternalMark(this);
|
2010-05-28 14:06:57 +02:00
|
|
|
|
|
|
|
|
if (!m_markableInterface->addMark(m_internalMark, m_line))
|
|
|
|
|
removeInternalMark();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-29 15:20:10 +02:00
|
|
|
void BaseTextMark::childRemovedFromEditor(Internal::InternalMark *mark)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(mark)
|
|
|
|
|
// m_internalMark was removed from the editor
|
2010-05-28 14:06:57 +02:00
|
|
|
removeInternalMark();
|
2008-12-02 12:01:29 +01:00
|
|
|
removedFromEditor();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-29 15:20:10 +02:00
|
|
|
void BaseTextMark::documentClosingFor(Internal::InternalMark *mark)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(mark)
|
2010-05-28 14:06:57 +02:00
|
|
|
removeInternalMark();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-05-28 14:06:57 +02:00
|
|
|
void BaseTextMark::removeInternalMark()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
delete m_internalMark;
|
|
|
|
|
m_internalMark = 0;
|
|
|
|
|
m_markableInterface = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#include <QDebug>
|
|
|
|
|
|
|
|
|
|
void BaseTextMark::updateMarker()
|
|
|
|
|
{
|
|
|
|
|
//qDebug()<<"BaseTextMark::updateMarker()"<<m_markableInterface<<m_internalMark;
|
|
|
|
|
if (m_markableInterface)
|
|
|
|
|
m_markableInterface->updateMark(m_internalMark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseTextMark::moveMark(const QString & /* filename */, int /* line */)
|
|
|
|
|
{
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!m_init) {
|
|
|
|
|
connect(em, SIGNAL(editorOpened(Core::IEditor *)), this, SLOT(editorOpened(Core::IEditor *)));
|
|
|
|
|
m_init = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_markableInterface)
|
|
|
|
|
m_markableInterface->removeMark(m_internalMark);
|
2010-05-28 14:06:57 +02:00
|
|
|
// This is only necessary since m_internalMark is created in editorOpened
|
|
|
|
|
removeInternalMark();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (Core::IEditor *editor, em->openedEditors())
|
2008-12-02 12:01:29 +01:00
|
|
|
editorOpened(editor);
|
|
|
|
|
}
|
2010-10-29 15:20:10 +02:00
|
|
|
} // namespace TextEditor
|