KDevelop API Documentation

editorchooser_widget.cpp

Go to the documentation of this file.
00001 #include <qcombobox.h>
00002 #include <qbuttongroup.h>
00003 #include <qradiobutton.h>
00004 
00005 #include <kapplication.h>
00006 #include <kdeversion.h>
00007 #include <ktrader.h>
00008 #include <kservice.h>
00009 #include <kdebug.h>
00010 #include <kconfig.h>
00011 
00012 
00013 #include "editorchooser_widget.h"
00014 
00015 
00016 EditorChooserWidget::EditorChooserWidget(QWidget *parent, const char *name)
00017         : EditChooser(parent, name)
00018 {
00019     load();
00020 }
00021 
00022 
00023 void EditorChooserWidget::load()
00024 {
00025     EditorPart->clear();
00026 
00027     // ask the trader which editors he has to offer
00028     KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
00029 
00030     // find the editor to use
00031     KConfig *config = kapp->config();
00032     config->setGroup("Editor");
00033     QString editor = config->readPathEntry("EmbeddedKTextEditor");
00034 
00035     // add the entries to the listview
00036     KTrader::OfferList::Iterator it;
00037     int index=-1, current=0;
00038     for (it = offers.begin(); it != offers.end(); ++it)
00039     {
00040         EditorPart->insertItem((*it)->name());
00041         if ( (*it)->name() == editor )
00042             index = current;
00043         ++current;
00044     }
00045 
00046     if (index >=0)
00047         EditorPart->setCurrentItem(index);
00048 
00049     QString dirtyAction = config->readEntry( "DirtyAction" );
00050     
00051     if ( dirtyAction == "reload" )
00052     {
00053         reload->setChecked( true );
00054     }
00055     else if ( dirtyAction == "alert" )
00056     {
00057         alert->setChecked( true );
00058     }
00059     else
00060     {
00061         nothing->setChecked( true );
00062     }
00063 }
00064 
00065 
00066 void EditorChooserWidget::save()
00067 {
00068     KConfig *config = kapp->config();
00069     config->setGroup("Editor");
00070 
00071     KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
00072 
00073     KTrader::OfferList::Iterator it;
00074     for (it = offers.begin(); it != offers.end(); ++it)
00075         if ( EditorPart->currentText() == (*it)->name() )
00076         {
00077             config->writePathEntry("EmbeddedKTextEditor", (*it)->name());
00078         }
00079 
00080     if ( reload->isChecked() )
00081     {
00082         config->writeEntry( "DirtyAction", "reload" );
00083     }
00084     else if ( alert->isChecked() )
00085     {
00086         config->writeEntry( "DirtyAction", "alert" );
00087     }
00088     else 
00089     {
00090         config->writeEntry( "DirtyAction", "nothing" );
00091     }
00092 
00093     config->sync();
00094 }
00095 
00096 
00097 void EditorChooserWidget::accept()
00098 {
00099     save();
00100 }
00101 
00102 void EditorChooserWidget::slotEditPartChanged( const QString & )
00103 {
00104     KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KTextEditor/Document' in ServiceTypes");
00105 
00106     KTrader::OfferList::Iterator it;
00107     for (it = offers.begin(); it != offers.end(); ++it)
00108     {
00109         if ( EditorPart->currentText() == (*it)->name() )
00110         {
00111             external_changes_group->setEnabled( (*it)->desktopEntryName() == "katepart" );
00112             return;
00113         }
00114     }
00115 }
00116 
00117 
00118 #include "editorchooser_widget.moc"
00119 
00120 
00121 
00122 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003