forked from qt-creator/qt-creator
Bookmarks: Support manual editing of line number
Task-number: QTCREATORBUG-9721 Change-Id: I914568d58857bf897a3894a1d2a6082126e47b62 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6956eea8bf
commit
622c55cbf8
@@ -57,6 +57,14 @@ void Bookmark::updateLineNumber(int line)
|
||||
}
|
||||
}
|
||||
|
||||
void Bookmark::move(int line)
|
||||
{
|
||||
if (line != lineNumber()) {
|
||||
BaseTextMark::move(line);
|
||||
m_manager->updateBookmark(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Bookmark::updateBlock(const QTextBlock &block)
|
||||
{
|
||||
if (m_lineText != block.text()) {
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager);
|
||||
|
||||
void updateLineNumber(int lineNumber);
|
||||
void move(int line);
|
||||
void updateBlock(const QTextBlock &block);
|
||||
void updateFileName(const QString &fileName);
|
||||
void setNote(const QString ¬e);
|
||||
|
||||
@@ -45,15 +45,17 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/checkablemessagebox.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QAction>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QDebug>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QInputDialog>
|
||||
|
||||
Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
|
||||
|
||||
@@ -243,7 +245,7 @@ void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||
QMenu menu;
|
||||
QAction *moveUp = menu.addAction(tr("Move Up"));
|
||||
QAction *moveDown = menu.addAction(tr("Move Down"));
|
||||
QAction *editNote = menu.addAction(tr("Edit Note"));
|
||||
QAction *edit = menu.addAction(tr("&Edit"));
|
||||
menu.addSeparator();
|
||||
QAction *remove = menu.addAction(tr("&Remove"));
|
||||
menu.addSeparator();
|
||||
@@ -254,7 +256,7 @@ void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||
moveUp->setEnabled(false);
|
||||
moveDown->setEnabled(false);
|
||||
remove->setEnabled(false);
|
||||
editNote->setEnabled(false);
|
||||
edit->setEnabled(false);
|
||||
}
|
||||
|
||||
if (model()->rowCount() == 0)
|
||||
@@ -268,8 +270,8 @@ void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||
this, SLOT(removeFromContextMenu()));
|
||||
connect(removeAll, SIGNAL(triggered()),
|
||||
this, SLOT(removeAll()));
|
||||
connect(editNote, SIGNAL(triggered()),
|
||||
m_manager, SLOT(editNote()));
|
||||
connect(edit, SIGNAL(triggered()),
|
||||
m_manager, SLOT(edit()));
|
||||
|
||||
menu.exec(mapToGlobal(event->pos()));
|
||||
}
|
||||
@@ -673,27 +675,36 @@ void BookmarkManager::moveDown()
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
void BookmarkManager::editNote(const QString &fileName, int lineNumber)
|
||||
void BookmarkManager::edit(const QString &fileName, int lineNumber)
|
||||
{
|
||||
Bookmark *b = findBookmark(fileName, lineNumber);
|
||||
QModelIndex current = selectionModel()->currentIndex();
|
||||
selectionModel()->setCurrentIndex(current.sibling(m_bookmarksList.indexOf(b), 0),
|
||||
QItemSelectionModel::Select | QItemSelectionModel::Clear);
|
||||
|
||||
editNote();
|
||||
edit();
|
||||
}
|
||||
|
||||
void BookmarkManager::editNote()
|
||||
void BookmarkManager::edit()
|
||||
{
|
||||
QModelIndex current = selectionModel()->currentIndex();
|
||||
Bookmark *b = m_bookmarksList.at(current.row());
|
||||
|
||||
bool inputOk = false;
|
||||
QString noteText = QInputDialog::getText(0, tr("Edit Note"),
|
||||
tr("Note text:"), QLineEdit::Normal,
|
||||
b->note(), &inputOk);
|
||||
if (inputOk) {
|
||||
b->updateNote(noteText.replace(QLatin1Char('\t'), QLatin1Char(' ')));
|
||||
QDialog dlg;
|
||||
dlg.setWindowTitle(tr("Edit Bookmark"));
|
||||
auto layout = new QFormLayout(&dlg);
|
||||
auto noteEdit = new QLineEdit(b->note());
|
||||
auto lineNumberEdit = new QLineEdit(QString::number(b->lineNumber()));
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject()));
|
||||
lineNumberEdit->setValidator(new QIntValidator(0, INT_MAX));
|
||||
layout->addRow(tr("Note text:"), noteEdit);
|
||||
layout->addRow(tr("Line number:"), lineNumberEdit);
|
||||
layout->addWidget(buttonBox);
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
b->move(lineNumberEdit->text().toInt());
|
||||
b->updateNote(noteEdit->text().replace(QLatin1Char('\t'), QLatin1Char(' ')));
|
||||
emit dataChanged(current, current);
|
||||
saveBookmarks();
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public slots:
|
||||
void prev();
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void editNote();
|
||||
void editNote(const QString &fileName, int lineNumber);
|
||||
void edit();
|
||||
void edit(const QString &fileName, int lineNumber);
|
||||
bool gotoBookmark(Bookmark *bookmark);
|
||||
|
||||
signals:
|
||||
|
||||
@@ -105,7 +105,7 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
|
||||
cmd = Core::ActionManager::registerAction(m_docNextAction, BOOKMARKS_NEXTDOC_ACTION, globalcontext);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
m_editNoteAction = new QAction(tr("Edit Bookmark Note"), this);
|
||||
m_editBookmarkAction = new QAction(tr("Edit Bookmark"), this);
|
||||
|
||||
m_bookmarkManager = new BookmarkManager;
|
||||
|
||||
@@ -114,7 +114,7 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
|
||||
connect(m_nextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(next()));
|
||||
connect(m_docPrevAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(prevInDocument()));
|
||||
connect(m_docNextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(nextInDocument()));
|
||||
connect(m_editNoteAction, SIGNAL(triggered()), this, SLOT(bookmarkEditNoteActionTriggered()));
|
||||
connect(m_editBookmarkAction, SIGNAL(triggered()), this, SLOT(editBookmarkActionTriggered()));
|
||||
connect(m_bookmarkManager, SIGNAL(updateActions(int)), this, SLOT(updateActions(int)));
|
||||
updateActions(m_bookmarkManager->state());
|
||||
addAutoReleasedObject(new BookmarkViewFactory(m_bookmarkManager));
|
||||
@@ -189,7 +189,7 @@ void BookmarksPlugin::requestContextMenu(TextEditor::ITextEditor *editor,
|
||||
|
||||
menu->addAction(m_bookmarkMarginAction);
|
||||
if (m_bookmarkManager->hasBookmarkInPosition(m_bookmarkMarginActionFileName, m_bookmarkMarginActionLineNumber))
|
||||
menu->addAction(m_editNoteAction);
|
||||
menu->addAction(m_editBookmarkAction);
|
||||
}
|
||||
|
||||
void BookmarksPlugin::bookmarkMarginActionTriggered()
|
||||
@@ -198,9 +198,9 @@ void BookmarksPlugin::bookmarkMarginActionTriggered()
|
||||
m_bookmarkMarginActionLineNumber);
|
||||
}
|
||||
|
||||
void BookmarksPlugin::bookmarkEditNoteActionTriggered()
|
||||
void BookmarksPlugin::editBookmarkActionTriggered()
|
||||
{
|
||||
m_bookmarkManager->editNote(m_bookmarkMarginActionFileName, m_bookmarkMarginActionLineNumber);
|
||||
m_bookmarkManager->edit(m_bookmarkMarginActionFileName, m_bookmarkMarginActionLineNumber);
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(BookmarksPlugin)
|
||||
|
||||
@@ -70,7 +70,7 @@ private slots:
|
||||
void requestContextMenu(TextEditor::ITextEditor *editor,
|
||||
int lineNumber, QMenu *menu);
|
||||
void bookmarkMarginActionTriggered();
|
||||
void bookmarkEditNoteActionTriggered();
|
||||
void editBookmarkActionTriggered();
|
||||
|
||||
private:
|
||||
static BookmarksPlugin *m_instance;
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
QAction *m_nextAction;
|
||||
QAction *m_docPrevAction;
|
||||
QAction *m_docNextAction;
|
||||
QAction *m_editNoteAction;
|
||||
QAction *m_editBookmarkAction;
|
||||
|
||||
QAction *m_bookmarkMarginAction;
|
||||
int m_bookmarkMarginActionLineNumber;
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
TextMarks marksAt(int line) const;
|
||||
void removeMark(ITextMark *mark);
|
||||
void updateMark(ITextMark *mark);
|
||||
void moveMark(ITextMark *mark, int previousLine);
|
||||
|
||||
void removeMarkFromMarksCache(TextEditor::ITextMark *mark);
|
||||
private:
|
||||
@@ -177,6 +178,18 @@ void DocumentMarker::updateMark(ITextMark *mark)
|
||||
documentLayout->requestUpdate();
|
||||
}
|
||||
|
||||
void DocumentMarker::moveMark(ITextMark *mark, int previousLine)
|
||||
{
|
||||
QTextBlock block = document->findBlockByNumber(previousLine - 1);
|
||||
if (TextBlockUserData *data = BaseTextDocumentLayout::testUserData(block)) {
|
||||
if (!data->removeMark(mark))
|
||||
qDebug() << "Could not find mark" << mark << "on line" << previousLine;
|
||||
}
|
||||
removeMarkFromMarksCache(mark);
|
||||
mark->setMarkableInterface(0);
|
||||
addMark(mark);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TextEditor
|
||||
|
||||
|
||||
@@ -53,6 +53,16 @@ void ITextMark::updateLineNumber(int lineNumber)
|
||||
m_lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
void ITextMark::move(int line)
|
||||
{
|
||||
if (line == m_lineNumber)
|
||||
return;
|
||||
const int previousLine = m_lineNumber;
|
||||
m_lineNumber = line;
|
||||
if (m_markableInterface)
|
||||
m_markableInterface->moveMark(this, previousLine);
|
||||
}
|
||||
|
||||
void ITextMark::updateBlock(const QTextBlock &)
|
||||
{}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
virtual void paint(QPainter *painter, const QRect &rect) const;
|
||||
virtual void updateLineNumber(int lineNumber);
|
||||
virtual void updateBlock(const QTextBlock &block);
|
||||
virtual void move(int line);
|
||||
virtual void removedFromEditor();
|
||||
virtual bool isClickable() const;
|
||||
virtual void clicked();
|
||||
@@ -114,6 +115,7 @@ public:
|
||||
virtual TextMarks marksAt(int line) const = 0;
|
||||
virtual void removeMark(ITextMark *mark) = 0;
|
||||
virtual void updateMark(ITextMark *mark) = 0;
|
||||
virtual void moveMark(ITextMark *mark, int previousLine) = 0;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Reference in New Issue
Block a user