Commit c1e7919f authored by Christoph Cullmann's avatar Christoph Cullmann

purge editor chooser, nothing like pain, there is no other implementation since 10 years

parent b747d908
#include "../../ktexteditor/editorchooser.h"
......@@ -13,7 +13,6 @@ set(KTEXTEDITOR_PUBLIC_HEADERS
searchinterface.h
markinterface.h
sessionconfiginterface.h
editorchooser.h
texthintinterface.h
variableinterface.h
templateinterface.h
......@@ -46,7 +45,6 @@ set(ktexteditor_LIB_SRCS
documentcursor.cpp
templateinterface.cpp
templateinterface2.cpp
editorchooser.cpp
attribute.cpp
codecompletioninterface.cpp
codecompletionmodel.cpp
......@@ -63,9 +61,6 @@ set(ktexteditor_LIB_SRCS
documentadaptor_p.h
)
kde4_add_ui_files(ktexteditor_LIB_SRCS editorchooser_ui.ui )
add_library (ktexteditor SHARED ${ktexteditor_LIB_SRCS} ${KTEXTEDITOR_PUBLIC_HEADERS})
target_link_libraries(ktexteditor
......
......@@ -293,16 +293,16 @@ class KTEXTEDITOR_EXPORT Editor : public QObject
class EditorPrivate* const d;
};
/**
* Helper function for the EditorChooser.
* Usually you do not have to use this function. Instead, use
* KTextEditor::EditorChooser::editor().
* \param libname library name, for example "katepart"
* \return the Editor object on success, otherwise NULL
* \see KTextEditor::EditorChooser::editor()
* Accessor to get the Editor instance of the currently used
* KTextEditor component (per default this will be KatePart).
*
* That Editor instance can be qobject-cast to specific extensions.
* If the result of the cast is not NULL, that extension is supported:
*
* \return Editor controller or NULL, if no editor component could be found
*/
KTEXTEDITOR_EXPORT Editor *editor ( const char *libname );
KTEXTEDITOR_EXPORT Editor *editor ();
}
......
/* This file is part of the KDE libraries
* Copyright (C) 2005 Joseph Wenninger <jowenn@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <editorchooser.h>
#include <editorchooser.moc>
#include <QComboBox>
#include <QtCore/QStringList>
#include <QLabel>
#include <QLayout>
#include <kmimetypetrader.h>
#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include "ui_editorchooser_ui.h"
#include <kconfiggroup.h>
using namespace KTextEditor;
namespace KTextEditor
{
class PrivateEditorChooser
{
public:
PrivateEditorChooser()
{
}
~PrivateEditorChooser(){}
// Data Members
Ui::EditorChooser *chooser;
QStringList ElementNames;
QStringList elements;
};
}
EditorChooser::EditorChooser(QWidget *parent)
: QWidget(parent)
{
d = new PrivateEditorChooser ();
d->chooser = new Ui::EditorChooser();
d->chooser->setupUi(this);
KService::List offers = KMimeTypeTrader::self()->query("text/plain", "KTextEditor/Document");
KConfigGroup config = KSharedConfig::openConfig("default_components")->group("KTextEditor");
QString editor = config.readPathEntry("embeddedEditor", QString());
if (editor.isEmpty()) editor = "katepart";
// search default component
for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
if ((*it)->desktopEntryName().contains(editor))
{
d->chooser->editorCombo->addItem(i18n("System Default (currently: %1)", (*it)->name()));
break;
}
}
// add list of all available components
for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
d->chooser->editorCombo->addItem((*it)->name());
d->elements.append((*it)->desktopEntryName());
}
d->chooser->editorCombo->setCurrentIndex(0);
connect(d->chooser->editorCombo,SIGNAL(activated(int)),this,SIGNAL(changed()));
setMinimumSize(sizeHint());
}
EditorChooser:: ~EditorChooser()
{
delete d->chooser;
delete d;
}
void EditorChooser::readAppSetting(const QString& postfix)
{
KConfigGroup cg(KGlobal::config(), "KTEXTEDITOR:" + postfix);
QString editor = cg.readPathEntry("editor", QString());
if (editor.isEmpty())
d->chooser->editorCombo->setCurrentIndex(0);
else
{
// + 1, because item 0 is the default one.
int idx = d->elements.indexOf(editor) + 1;
d->chooser->editorCombo->setCurrentIndex(idx);
}
}
void EditorChooser::writeAppSetting(const QString& postfix)
{
KConfigGroup cg(KGlobal::config(), "KTEXTEDITOR:" + postfix);
cg.writeEntry("DEVELOPER_INFO","NEVER TRY TO USE VALUES FROM THAT GROUP, THEY ARE SUBJECT TO CHANGES");
cg.writePathEntry("editor", (d->chooser->editorCombo->currentIndex()<=0) ? //< for broken installations, where editor list is empty
QString() : QString(d->elements.at(d->chooser->editorCombo->currentIndex()-1)));
}
KTextEditor::Editor *EditorChooser::editor(const QString& postfix,
bool fallBackToKatePart)
{
// try to read the used library from the application's config
KConfigGroup cg(KGlobal::config(), "KTEXTEDITOR:" + postfix);
QString editor = cg.readPathEntry("editor", QString());
if (editor.isEmpty())
{
// there is no library set in the application's config,
// fall back to KDE's system default
KConfig config("default_components");
editor = config.group("KTextEditor").readPathEntry("embeddedEditor", "katepart");
}
KService::Ptr serv = KService::serviceByDesktopName(editor);
if (serv)
{
KTextEditor::Editor *tmpEd = KTextEditor::editor(serv->library().toLatin1().data());
if (tmpEd) return tmpEd;
}
if (fallBackToKatePart)
return KTextEditor::editor("katepart");
return 0;
}
// kate: space-indent on; indent-width 2; replace-tabs on;
/* This file is part of the KDE libraries
* Copyright (C) 2005 Joseph Wenninger <jowenn@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _EDITOR_CHOOSER_H_
#define _EDITOR_CHOOSER_H_
#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/document.h>
#include <ktexteditor/editor.h>
#include <QWidget>
class KConfig;
class QString;
namespace KTextEditor
{
/**
* \brief Editor Component Chooser.
*
* Topics:
* - \ref chooser_intro
* - \ref chooser_gui
* - \ref chooser_editor
*
* \section chooser_intro Introduction
*
* The EditorChooser is responsible for two different tasks: It provides
* - a GUI, with which the user can choose the preferred editor part
* - a static accessor, with which the current selected editor part can be
* obtained.
*
* \section chooser_gui The GUI Editor Chooser
* The EditorChooser is a simple widget with a group box containing an
* information label and a combo box which lists all available KTextEditor
* implementations. To give the user the possibility to choose a text editor
* implementation, create an instance of this class and put it into the GUI:
* \code
* KTextEditor::EditorChooser* ec = new KTextEditor::EditorChooser(parent);
* // read the settings from the application's KConfig object
* ec->readAppSetting();
* // optionally connect the signal changed()
* // plug the widget into a layout
* layout->addWidget(ec);
* \endcode
* Later, for example when the user clicks the Apply-button:
* \code
* // save the user's choice
* ec->writeAppSetting();
* \endcode
* After this, the static accessor editor() will return the new editor part
* object. Now, either the application has to be restarted, or you need code
* that closes all current documents so that you can safely switch and use the
* new editor part. Restarting is probably much easier.
*
* \note If you do not put the EditorChooser into the GUI, the default editor
* component will be used. The default editor is configurable in KDE's
* control center in
* "KDE Components > Component Chooser > Embedded Text Editor".
*
* \section chooser_editor Accessing the Editor Part
* The call of editor() will return the currently used editor part, either the
* KDE default or the one configured with the EditorChooser's GUI
* (see \ref chooser_gui). Example:
* \code
* KTextEditor::Editor* editor = KTextEditor::EditorChooser::editor();
* \endcode
*
* \see KTextEditor::Editor
* \author Joseph Wenninger \<jowenn@kde.org\>
*/
class KTEXTEDITOR_EXPORT EditorChooser: public QWidget
{
friend class PrivateEditorChooser;
Q_OBJECT
public:
/**
* Constructor.
*
* Create an editor chooser widget.
* \param parent the parent widget
*/
EditorChooser(QWidget *parent=0);
/**
* Destructor.
*/
virtual ~EditorChooser();
/* void writeSysDefault();*/
/**
* Read the configuration from the application's config file. The group
* is handeled internally (it is called "KTEXTEDITOR:", but it is possible
* to add a string to extend the group name with \p postfix.
* \param postfix config group postfix string
* \see writeAppSetting()
*/
void readAppSetting(const QString& postfix=QString());
/**
* Write the configuration to the application's config file.
* \param postfix config group postfix string
* \see readAppSetting()
*/
void writeAppSetting(const QString& postfix=QString());
/**
* Static accessor to get the Editor instance of the currently used
* KTextEditor component.
*
* That Editor instance can be qobject-cast to specific extensions.
* If the result of the cast is not NULL, that extension is supported:
*
* \param postfix config group postfix string
* \param fallBackToKatePart if \e true, the returned Editor component
* will be a katepart if no other implementation can be found
* \return Editor controller or NULL, if no editor component could be
* found
*/
static KTextEditor::Editor *editor (const QString& postfix=QString(), bool fallBackToKatePart = true);
Q_SIGNALS:
/**
* This signal is emitted whenever the selected item in the combo box
* changed.
*/
void changed();
private:
class PrivateEditorChooser *d;
};
/*
class EditorChooserBackEnd: public ComponentChooserPlugin {
Q_OBJECT
public:
EditorChooserBackEnd(QObject *parent=0, const char *name=0);
virtual ~EditorChooserBackEnd();
virtual QWidget *widget(QWidget *);
virtual const QStringList &choices();
virtual void saveSettings();
void readAppSetting(KConfig *cfg,const QString& postfix);
void writeAppSetting(KConfig *cfg,const QString& postfix);
public Q_SLOTS:
virtual void madeChoice(int pos,const QString &choice);
};
*/
}
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
<ui version="4.0" >
<class>EditorChooser</class>
<widget class="QWidget" name="EditorChooser" >
<property name="windowTitle" >
<string>Editor Chooser</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="TextLabel1" >
<property name="minimumSize" >
<size>
<width>460</width>
<height>0</height>
</size>
</property>
<property name="text" >
<string>Please choose the default text editing component that you wish to use in this application. If you choose &lt;B>System Default&lt;/B>, the application will honor your changes in the System Settings. All other choices will override that setting.</string>
</property>
<property name="textFormat" >
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="editorCombo" />
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>editorCombo</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
......@@ -147,9 +147,9 @@ KTextEditorFactorySet::~KTextEditorFactorySet() {
qDeleteAll(*this);
}
Editor *KTextEditor::editor(const char *libname)
Editor *KTextEditor::editor()
{
KPluginFactory *fact=KPluginLoader(libname).factory();
KPluginFactory *fact=KPluginLoader("katepart").factory();
KTextEditor::Factory *ef=qobject_cast<KTextEditor::Factory*>(fact);
......
......@@ -19,7 +19,6 @@ Boston, MA 02110-1301, USA.
#include "kwriteapp.h"
#include <ktexteditor/editor.h>
#include <ktexteditor/editorchooser.h>
#include <kcmdlineargs.h>
#include <kmessagebox.h>
......@@ -32,7 +31,7 @@ KWriteApp::KWriteApp(int & argc, char ** argv)
: QApplication (argc, argv)
, m_args(m_args)
{
m_editor = KTextEditor::EditorChooser::editor();
m_editor = KTextEditor::editor();
if ( !m_editor )
{
......
......@@ -26,7 +26,6 @@
#include <ktexteditor/sessionconfiginterface.h>
#include <ktexteditor/modificationinterface.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/editorchooser.h>
#include <kio/netaccess.h>
......@@ -487,7 +486,7 @@ void KWrite::restore()
if (!config)
return;
KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
KTextEditor::Editor *editor = KTextEditor::editor();
if ( !editor )
{
......
......@@ -25,9 +25,11 @@
#include "snippetrepository.h"
#include <ktexteditor/editor.h>
#include <ktexteditor/document.h>
#include <KLocalizedString>
#include <KTextEditor/EditorChooser>
#include <KPushButton>
#include <KUser>
......@@ -47,7 +49,7 @@ EditRepository::EditRepository(SnippetRepository* repository, QWidget* parent)
connect(repoNameEdit, SIGNAL(textEdited(QString)), this, SLOT(validate()));
// fill list of available modes
KTextEditor::Document *document = KTextEditor::EditorChooser::editor()->createDocument(0);
KTextEditor::Document *document = KTextEditor::editor()->createDocument(0);
repoFileTypesList->addItems(document->highlightingModes());
repoFileTypesList->sortItems();
repoFileTypesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
......
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