From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- editors/editor-chooser/editorchooser_widget.cpp | 132 ++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 editors/editor-chooser/editorchooser_widget.cpp (limited to 'editors/editor-chooser/editorchooser_widget.cpp') diff --git a/editors/editor-chooser/editorchooser_widget.cpp b/editors/editor-chooser/editorchooser_widget.cpp new file mode 100644 index 00000000..6c9f7071 --- /dev/null +++ b/editors/editor-chooser/editorchooser_widget.cpp @@ -0,0 +1,132 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + + +#include "editorchooser_widget.h" + + +EditorChooserWidget::EditorChooserWidget(QWidget *parent, const char *name) + : EditChooser(parent, name) +{ + // ask the trader which editors he has to offer + m_offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes"); + + // remove the vim-part, it's known to crash + KTrader::OfferList::Iterator it = m_offers.begin(); + while( it != m_offers.end() ) + { + if ( ((*it)->desktopEntryName() == "vimpart") + || ((*it)->desktopEntryName() == "qeditor_part") ) + { + m_offers.remove( it ); + break; + } + ++it; + } + + load(); + slotEditPartChanged(QString()); +} + + +void EditorChooserWidget::load() +{ + EditorPart->clear(); + + // find the editor to use + KConfig *config = kapp->config(); + config->setGroup("Editor"); + QString editor = config->readPathEntry("EmbeddedKTextEditor"); + + // add the entries to the listview + KTrader::OfferList::Iterator it; + int index=-1, current=0; + for (it = m_offers.begin(); it != m_offers.end(); ++it) + { + EditorPart->insertItem((*it)->name()); + if ( (*it)->desktopEntryName() == editor ) + index = current; + ++current; + } + + if (index >=0) + EditorPart->setCurrentItem(index); + + QString dirtyAction = config->readEntry( "DirtyAction" ); + + if ( dirtyAction == "reload" ) + { + reload->setChecked( true ); + } + else if ( dirtyAction == "alert" ) + { + alert->setChecked( true ); + } + else + { + nothing->setChecked( true ); + } +} + + +void EditorChooserWidget::save() +{ + KConfig *config = kapp->config(); + config->setGroup("Editor"); + + KTrader::OfferList::Iterator it; + for (it = m_offers.begin(); it != m_offers.end(); ++it) + if ( EditorPart->currentText() == (*it)->name() ) + { + config->writePathEntry("EmbeddedKTextEditor", (*it)->desktopEntryName()); + } + + if ( reload->isChecked() ) + { + config->writeEntry( "DirtyAction", "reload" ); + } + else if ( alert->isChecked() ) + { + config->writeEntry( "DirtyAction", "alert" ); + } + else + { + config->writeEntry( "DirtyAction", "nothing" ); + } + + config->sync(); +} + + +void EditorChooserWidget::accept() +{ + save(); +} + +void EditorChooserWidget::slotEditPartChanged( const QString & ) +{ + KTrader::OfferList::Iterator it; + for (it = m_offers.begin(); it != m_offers.end(); ++it) + { + if ( EditorPart->currentText() == (*it)->name() ) + { + external_changes_group->setEnabled( (*it)->desktopEntryName() == "katepart" ); + return; + } + } + external_changes_group->setEnabled( false ); +} + + +#include "editorchooser_widget.moc" + + + + -- cgit v1.2.1