Commit 75191ad8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add insert breaking space as plugin

parent 2ab4a3e4
......@@ -2,3 +2,4 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kmail_editor_plugins\")
add_subdirectory(insertspecialcharacter)
add_subdirectory(changecase)
add_subdirectory(zoomtext)
add_subdirectory(nonbreakingspace)
set(kmail_nonbreakingspaceeditorplugin_SRCS
nonbreakingspaceplugineditor.cpp
nonbreakingspaceplugineditorinterface.cpp
)
add_library(kmail_nonbreakingspaceeditorplugin MODULE ${kmail_nonbreakingspaceeditorplugin_SRCS})
target_link_libraries(kmail_nonbreakingspaceeditorplugin
KF5::IconThemes KF5::MessageComposer KF5::XmlGui KF5::I18n
)
install(TARGETS kmail_nonbreakingspaceeditorplugin DESTINATION ${PLUGIN_INSTALL_DIR}/kmail)
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
macro(add_kmail_editorplugin_unittest _source _additional)
set( _test ${_source} ${_additional})
get_filename_component(_name ${_source} NAME_WE)
add_executable( ${_name} ${_test} )
add_test( ${_name} ${_name} )
ecm_mark_as_test(kmail_editorplugin-${_name})
target_link_libraries( ${_name} Qt5::Test KF5::XmlGui KF5::IconThemes KF5::MessageComposer KF5::I18n)
endmacro ()
add_kmail_editorplugin_unittest(nonbreakingspaceplugineditortest.cpp "../nonbreakingspaceplugineditor.cpp;../nonbreakingspaceplugineditorinterface.cpp")
add_kmail_editorplugin_unittest(nonbreakingspaceplugineditorinterfacetest.cpp "../nonbreakingspaceplugineditorinterface.cpp")
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "nonbreakingspaceplugineditorinterfacetest.h"
#include "../nonbreakingspaceplugineditorinterface.h"
#include <QTest>
NonBreakingSpacePluginEditorInterfaceTest::NonBreakingSpacePluginEditorInterfaceTest(QObject *parent)
: QObject(parent)
{
}
NonBreakingSpacePluginEditorInterfaceTest::~NonBreakingSpacePluginEditorInterfaceTest()
{
}
void NonBreakingSpacePluginEditorInterfaceTest::shouldHaveDefaultValue()
{
NonBreakingSpacePluginEditorInterface interface;
QVERIFY(!interface.hasConfigureDialog());
QVERIFY(!interface.hasPopupMenuSupport());
QVERIFY(!interface.hasToolBarSupport());
}
QTEST_MAIN(NonBreakingSpacePluginEditorInterfaceTest)
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NonBreakingSpacePLUGINEDITORINTERFACETEST_H
#define NonBreakingSpacePLUGINEDITORINTERFACETEST_H
#include <QObject>
class NonBreakingSpacePluginEditorInterfaceTest : public QObject
{
Q_OBJECT
public:
explicit NonBreakingSpacePluginEditorInterfaceTest(QObject *parent = Q_NULLPTR);
~NonBreakingSpacePluginEditorInterfaceTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "nonbreakingspaceplugineditortest.h"
#include "../nonbreakingspaceplugineditor.h"
#include <KActionCollection>
#include <QTest>
NonBreakingSpacePluginEditorTest::NonBreakingSpacePluginEditorTest(QObject *parent)
: QObject(parent)
{
}
NonBreakingSpacePluginEditorTest::~NonBreakingSpacePluginEditorTest()
{
}
void NonBreakingSpacePluginEditorTest::shouldHaveDefaultValue()
{
NonBreakingSpacePluginEditor plugin;
QVERIFY(plugin.createInterface(new KActionCollection(this)));
}
QTEST_MAIN(NonBreakingSpacePluginEditorTest)
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NonBreakingSpacePLUGINEDITORTEST_H
#define NonBreakingSpacePLUGINEDITORTEST_H
#include <QObject>
class NonBreakingSpacePluginEditorTest : public QObject
{
Q_OBJECT
public:
explicit NonBreakingSpacePluginEditorTest(QObject *parent = Q_NULLPTR);
~NonBreakingSpacePluginEditorTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif
{
"KPlugin": {
"Name": "Insert Non Braking Space",
"ServiceTypes": [
"KMailEditor/Plugin"
],
"Version": "1.0"
},
"X-KDE-KMailEditor-Order": "2"
}
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "nonbreakingspaceplugineditor.h"
#include "nonbreakingspaceplugineditorinterface.h"
#include <kpluginfactory.h>
K_PLUGIN_FACTORY_WITH_JSON(NonBreakingSpacePluginEditorFactory, "kmail_nonbreakingspaceeditorplugin.json", registerPlugin<NonBreakingSpacePluginEditor>();)
NonBreakingSpacePluginEditor::NonBreakingSpacePluginEditor(QObject *parent, const QList<QVariant> &)
: MessageComposer::PluginEditor(parent)
{
}
NonBreakingSpacePluginEditor::~NonBreakingSpacePluginEditor()
{
}
MessageComposer::PluginEditorInterface *NonBreakingSpacePluginEditor::createInterface(KActionCollection *ac, QObject *parent)
{
NonBreakingSpacePluginEditorInterface *interface = new NonBreakingSpacePluginEditorInterface(parent);
interface->createAction(ac);
return interface;
}
#include "nonbreakingspaceplugineditor.moc"
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NONBREAKINGSPACEPLUGINEDITOR_H
#define NONBREAKINGSPACEPLUGINEDITOR_H
#include <messagecomposer/plugineditor.h>
#include <messagecomposer/plugineditorinterface.h>
#include <QVariant>
class NonBreakingSpacePluginEditor : public MessageComposer::PluginEditor
{
Q_OBJECT
public:
explicit NonBreakingSpacePluginEditor(QObject *parent = Q_NULLPTR, const QList<QVariant> & = QList<QVariant>());
~NonBreakingSpacePluginEditor();
MessageComposer::PluginEditorInterface *createInterface(KActionCollection *ac, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE;
};
#endif
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "nonbreakingspaceplugineditorinterface.h"
#include <KPIMTextEdit/RichTextEditor>
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
#include <QDebug>
NonBreakingSpacePluginEditorInterface::NonBreakingSpacePluginEditorInterface(QObject *parent)
: MessageComposer::PluginEditorInterface(parent)
{
}
NonBreakingSpacePluginEditorInterface::~NonBreakingSpacePluginEditorInterface()
{
}
void NonBreakingSpacePluginEditorInterface::createAction(KActionCollection *ac)
{
QAction *action = new QAction(i18n("Insert Non Breaking Space"), this);
ac->addAction(QStringLiteral("insert_non_breaking_space"), action);
ac->setDefaultShortcut(action, Qt::CTRL + Qt::Key_Space);
connect(action, &QAction::triggered, this, &NonBreakingSpacePluginEditorInterface::slotActivated);
MessageComposer::ActionType type(action, MessageComposer::ActionType::Edit);
setActionType(type);
}
void NonBreakingSpacePluginEditorInterface::slotActivated()
{
Q_EMIT emitPluginActivated(this);
}
void NonBreakingSpacePluginEditorInterface::exec()
{
richTextEditor()->insertPlainText(QChar(0x000A0));
}
/*
Copyright (C) 2016 Montel Laurent <montel@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef NONBREAKINGSPACEPLUGINEDITORINTERFACE_H
#define NONBREAKINGSPACEPLUGINEDITORINTERFACE_H
#include <messagecomposer/plugineditorinterface.h>
#include <QPointer>
class NonBreakingSpacePluginEditorInterface : public MessageComposer::PluginEditorInterface
{
Q_OBJECT
public:
explicit NonBreakingSpacePluginEditorInterface(QObject *parent = Q_NULLPTR);
~NonBreakingSpacePluginEditorInterface();
void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
void exec() Q_DECL_OVERRIDE;
private Q_SLOTS:
void slotActivated();
};
#endif
Supports Markdown
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