Don't create modify actions for KomparePart if created as ReadOnlyPart

parent eb50f111
......@@ -35,7 +35,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
WidgetsAddons
)
find_package(LibKompareDiff2 5.1 CONFIG)
find_package(LibKompareDiff2 5.2 CONFIG)
set_package_properties(LibKompareDiff2 PROPERTIES
TYPE REQUIRED
)
......
......@@ -2,6 +2,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kompare\")
set( komparepart_PART_SRCS
kompare_part.cpp
kompare_partfactory.cpp
kompareconnectwidget.cpp
komparesplitter.cpp
komparelistview.cpp
......
......@@ -35,7 +35,6 @@
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <KPluginFactory>
#include <KSharedConfig>
#include <KStandardAction>
#include <KStandardShortcut>
......@@ -58,26 +57,14 @@
#include "komparesplitter.h"
#include "kompareview.h"
K_PLUGIN_FACTORY( KomparePartFactory, registerPlugin<KomparePart>(); )
ViewSettings* KomparePart::m_viewSettings = nullptr;
DiffSettings* KomparePart::m_diffSettings = nullptr;
static KAboutData createAboutData()
{
KAboutData about(QStringLiteral("komparepart"), i18n("KomparePart"), QStringLiteral("4.0"),
QString(), KAboutLicense::GPL);
about.addAuthor(i18n("John Firebaugh"), i18n("Author"), QStringLiteral("jfirebaugh@kde.org"));
about.addAuthor(i18n("Otto Bruggeman"), i18n("Author"), QStringLiteral("bruggie@gmail.com"));
about.addAuthor(i18n("Kevin Kofler"), i18n("Author"), QStringLiteral("kevin.kofler@chello.at"));
return about;
}
KomparePart::KomparePart( QWidget *parentWidget, QObject *parent, const QVariantList & /*args*/ ) :
KomparePart::KomparePart(QWidget* parentWidget, QObject* parent, const KAboutData& aboutData, Modus modus) :
KParts::ReadWritePart(parent),
m_info()
{
setComponentData(createAboutData());
setComponentData(aboutData);
// set our XML-UI resource file
setXMLFile(QStringLiteral("komparepartui.rc"));
......@@ -96,7 +83,7 @@ KomparePart::KomparePart( QWidget *parentWidget, QObject *parent, const QVariant
m_splitter = m_view->splitter();
// This creates the "Model creator" and connects the signals and slots
m_modelList = new Diff2::KompareModelList( m_diffSettings, m_splitter, this, "komparemodellist" , KParts::ReadWritePart::isReadWrite());
m_modelList = new Diff2::KompareModelList( m_diffSettings, m_splitter, this, "komparemodellist" , (modus == ReadWriteModus));
Q_FOREACH(QAction* action, m_modelList->actionCollection()->actions())
{
......@@ -161,11 +148,11 @@ KomparePart::KomparePart( QWidget *parentWidget, QObject *parent, const QVariant
m_splitter, SLOT(slotApplyDifference(const Diff2::Difference*, bool)) );
connect( this, SIGNAL(configChanged()), m_splitter, SIGNAL(configChanged()) );
setupActions();
setupActions(modus);
// we are read-write by default -> uhm what if we are opened by lets say konq in RO mode ?
// Then we should not be doing this...
setReadWrite( true );
setReadWrite((modus == ReadWriteModus));
// we are not modified since we haven't done anything yet
setModified( false );
......@@ -178,17 +165,23 @@ KomparePart::~KomparePart()
cleanUpTemporaryFiles();
}
void KomparePart::setupActions()
void KomparePart::setupActions(Modus modus)
{
// create our actions
m_saveAll = actionCollection()->addAction(QStringLiteral("file_save_all"), this, SLOT(saveAll()));
m_saveAll->setIcon(QIcon::fromTheme(QStringLiteral("document-save-all")));
m_saveAll->setText(i18n("Save &All"));
m_saveDiff = actionCollection()->addAction(QStringLiteral("file_save_diff"), this, SLOT(saveDiff()));
m_saveDiff->setText(i18n("Save &Diff..."));
m_swap = actionCollection()->addAction(QStringLiteral("file_swap"), this, SLOT(slotSwap()));
m_swap->setText(i18n("Swap Source with Destination"));
if (modus == ReadWriteModus) {
m_saveAll = actionCollection()->addAction(QStringLiteral("file_save_all"), this, SLOT(saveAll()));
m_saveAll->setIcon(QIcon::fromTheme(QStringLiteral("document-save-all")));
m_saveAll->setText(i18n("Save &All"));
m_saveDiff = actionCollection()->addAction(QStringLiteral("file_save_diff"), this, SLOT(saveDiff()));
m_saveDiff->setText(i18n("Save &Diff..."));
m_swap = actionCollection()->addAction(QStringLiteral("file_swap"), this, SLOT(slotSwap()));
m_swap->setText(i18n("Swap Source with Destination"));
} else {
m_saveAll = nullptr;
m_saveDiff = nullptr;
m_swap = nullptr;
}
m_diffStats = actionCollection()->addAction(QStringLiteral("file_diffstats"), this, SLOT(slotShowDiffstats()));
m_diffStats->setText(i18n("Show Statistics"));
m_diffRefresh = actionCollection()->addAction(QStringLiteral("file_refreshdiff"), this, SLOT(slotRefreshDiff()));
......@@ -203,9 +196,9 @@ void KomparePart::setupActions()
void KomparePart::updateActions()
{
m_saveAll->setEnabled ( m_modelList->hasUnsavedChanges() );
m_saveDiff->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
m_swap->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
if (m_saveAll) m_saveAll->setEnabled ( m_modelList->hasUnsavedChanges() );
if (m_saveDiff) m_saveDiff->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
if (m_swap) m_swap->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
m_diffRefresh->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
m_diffStats->setEnabled ( m_modelList->modelCount() > 0 );
m_print->setEnabled ( m_modelList->modelCount() > 0 ); // If modellist has models then we have something to print, it's that simple.
......@@ -944,6 +937,12 @@ bool KomparePart::queryClose()
return true;
}
void KomparePart::setReadWrite(bool readWrite)
{
m_modelList->setReadWrite(readWrite);
KParts::ReadWritePart::setReadWrite(readWrite);
}
int KomparePart::readProperties( KConfig *config )
{
m_viewSettings->loadSettings( config );
......@@ -969,5 +968,3 @@ void KomparePart::optionsPreferences()
if ( pref.exec() )
emit configChanged();
}
#include "kompare_part.moc"
......@@ -61,10 +61,15 @@ class KomparePart : public KParts::ReadWritePart,
Q_OBJECT
Q_INTERFACES(KompareInterface)
public:
enum Modus {
ReadOnlyModus = 0,
ReadWriteModus = 1
};
/**
* Default constructor
*/
KomparePart( QWidget *parentWidget, QObject *parent, const QVariantList & /*args*/);
KomparePart(QWidget* parentWidget, QObject* parent, const KAboutData& aboutData, Modus modus);
/**
* Destructor
......@@ -80,6 +85,7 @@ public:
// we need it now to save the properties of the part when apps don't (can't)
// use the readProperties and saveProperties methods
bool queryClose() override;
void setReadWrite(bool readWrite) override;
// Do we really want to expose this ???
const Diff2::KompareModelList* model() const { return m_modelList; };
......@@ -200,7 +206,7 @@ protected Q_SLOTS:
private:
void cleanUpTemporaryFiles();
void setupActions();
void setupActions(Modus modus);
bool exists( const QString& url );
bool isDirectory( const QUrl& url );
// FIXME (like in cpp file not urgent) Replace with enum, cant find a proper
......
/***************************************************************************
kompare_partfactory.h
--------------
begin : Wed Oct 11 2017
Copyright 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
***************************************************************************/
#include "kompare_partfactory.h"
#include "kompare_part.h"
// KF
#include <KLocalizedString>
KomparePartFactory::KomparePartFactory()
: m_aboutData(QStringLiteral("komparepart"),
i18n("KomparePart"),
QStringLiteral("4.0"),
QString(),
KAboutLicense::GPL
)
{
m_aboutData.addAuthor(i18n("John Firebaugh"), i18n("Author"), QStringLiteral("jfirebaugh@kde.org"));
m_aboutData.addAuthor(i18n("Otto Bruggeman"), i18n("Author"), QStringLiteral("bruggie@gmail.com"));
m_aboutData.addAuthor(i18n("Kevin Kofler"), i18n("Author"), QStringLiteral("kevin.kofler@chello.at"));
}
KomparePartFactory::~KomparePartFactory() = default;
QObject* KomparePartFactory::create(const char* iface,
QWidget* parentWidget, QObject* parent,
const QVariantList& args, const QString& keyword)
{
Q_UNUSED(args);
Q_UNUSED(keyword);
const bool wantReadOnly = (strcmp(iface, "KParts::ReadOnlyPart") == 0);
const KomparePart::Modus modus =
wantReadOnly ? KomparePart::ReadOnlyModus :
/* else */ KomparePart::ReadWriteModus;
KomparePart* part = new KomparePart(parentWidget, parent, m_aboutData, modus);
return part;
}
/***************************************************************************
kompare_partfactory.h
--------------
begin : Wed Oct 11 2017
Copyright 2017 Friedrich W. H. Kossebau <kossebau@kde.org>
****************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
***************************************************************************/
#ifndef KOMPAREPARTFACTORY_H
#define KOMPAREPARTFACTORY_H
#include <KPluginFactory>
#include <KAboutData>
class KomparePartFactory : public KPluginFactory
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.KPluginFactory")
Q_INTERFACES(KPluginFactory)
public:
KomparePartFactory();
~KomparePartFactory() override;
QObject* create(const char* iface,
QWidget* parentWidget, QObject* parent,
const QVariantList& args, const QString& keyword) override;
private:
KAboutData m_aboutData;
};
#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