Commit 68bcb8d3 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Create a single fixedview in pluginView


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent cd6e34ed
......@@ -14,6 +14,7 @@
#include "kateprojectview.h"
#include <QComboBox>
#include <QMenu>
#include <QPointer>
#include <QStackedWidget>
#include <QToolButton>
......@@ -100,6 +101,39 @@ public:
return m_plugin;
}
/**
* @brief Shows diff in a fixed view, i.e., the view is recycled instead
* of creating new view every time
* @param contents diff contents
*/
void showDiffInFixedView(const QByteArray &contents)
{
if (!m_fixedView.view) {
m_fixedView.view = mainWindow()->openUrl(QUrl());
m_fixedView.defaultMenu = m_fixedView.view->contextMenu();
}
if (m_fixedView.view->document()) {
m_fixedView.view->document()->setText(QString::fromUtf8(contents));
m_fixedView.view->document()->setHighlightingMode(QStringLiteral("Diff"));
m_fixedView.restoreMenu();
}
}
/**
* Same as above with call back for setting a context menu
*
* @param cb Callback on the view. This should always take KTextEditor::View*
* as a parameter. This is mainly used to plug-in context-menu actions.
*/
template<typename ViewCallback>
void showDiffInFixedView(const QByteArray &contents, ViewCallback cb)
{
showDiffInFixedView(contents);
cb(m_fixedView.view);
}
public Q_SLOTS:
/**
* Create views for given project.
......@@ -319,6 +353,25 @@ private:
*/
QAction *m_gotoSymbolAction;
QAction *m_gotoSymbolActionAppMenu;
class FixedView
{
public:
QPointer<KTextEditor::View> view;
QPointer<QMenu> defaultMenu;
void restoreMenu()
{
if (view && defaultMenu) {
view->setContextMenu(defaultMenu);
}
}
};
/**
* Fixed view for viewing diffs
*/
FixedView m_fixedView;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment