kate Library API Documentation

kwritemain.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "kwritemain.h"
00022 #include "kwritemain.moc"
00023 
00024 #include <kate/document.h>
00025 #include <kate/view.h>
00026 
00027 #include <ktexteditor/configinterface.h>
00028 #include <ktexteditor/sessionconfiginterface.h>
00029 #include <ktexteditor/viewcursorinterface.h>
00030 #include <ktexteditor/printinterface.h>
00031 #include <ktexteditor/encodinginterface.h>
00032 #include <ktexteditor/editorchooser.h>
00033 #include <ktexteditor/popupmenuinterface.h>
00034 
00035 #include <kio/netaccess.h>
00036 
00037 #include <dcopclient.h>
00038 #include <kurldrag.h>
00039 #include <kencodingfiledialog.h>
00040 #include <kdiroperator.h>
00041 #include <kiconloader.h>
00042 #include <kaboutdata.h>
00043 #include <kstatusbar.h>
00044 #include <kstdaction.h>
00045 #include <kaction.h>
00046 #include <kdebug.h>
00047 #include <kglobal.h>
00048 #include <kapplication.h>
00049 #include <klocale.h>
00050 #include <kurl.h>
00051 #include <kconfig.h>
00052 #include <kcmdlineargs.h>
00053 #include <kmessagebox.h>
00054 #include <kkeydialog.h>
00055 #include <kedittoolbar.h>
00056 #include <kparts/event.h>
00057 #include <kmenubar.h>
00058 
00059 #include <qdropsite.h>
00060 #include <qdragobject.h>
00061 #include <qvbox.h>
00062 #include <qlayout.h>
00063 
00064 // StatusBar field IDs
00065 #define KWRITE_ID_GEN 1
00066 
00067 QPtrList<KTextEditor::Document> KWrite::docList;
00068 QPtrList<KWrite> KWrite::winList;
00069 
00070 KWrite::KWrite (KTextEditor::Document *doc)
00071     : m_view(0),
00072       m_recentFiles(0),
00073       m_paShowPath(0),
00074       m_paShowStatusBar(0)
00075 {
00076   setMinimumSize(200,200);
00077 
00078   if ( !doc )
00079   {
00080     if ( !(doc = KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document")) )
00081     {
00082       KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\n"
00083                                     "please check your KDE installation."));
00084       kapp->exit(1);
00085     }
00086 
00087     docList.append(doc);
00088   }
00089 
00090   m_view = doc->createView (this, 0L);
00091 
00092   setCentralWidget(m_view);
00093 
00094   setupActions();
00095   setupStatusBar();
00096 
00097   setAcceptDrops(true);
00098 
00099   connect(m_view,SIGNAL(newStatus()),this,SLOT(newCaption()));
00100   connect(m_view,SIGNAL(viewStatusMsg(const QString &)),this,SLOT(newStatus(const QString &)));
00101   connect(m_view->document(),SIGNAL(fileNameChanged()),this,SLOT(newCaption()));
00102   connect(m_view,SIGNAL(dropEventPass(QDropEvent *)),this,SLOT(slotDropEvent(QDropEvent *)));
00103 
00104   setXMLFile( "kwriteui.rc" );
00105   createShellGUI( true );
00106   guiFactory()->addClient( m_view );
00107 
00108   // install a working kate part popup dialog thingy
00109   if (static_cast<Kate::View*>(m_view->qt_cast("Kate::View")))
00110     static_cast<Kate::View*>(m_view->qt_cast("Kate::View"))->installPopup ((QPopupMenu*)(factory()->container("ktexteditor_popup", this)) );
00111 
00112   // call it as last thing, must be sure everything is already set up ;)
00113   setAutoSaveSettings ("MainWindow Settings");
00114 
00115   // init with more usefull size, stolen from konq :)
00116   if ( !initialGeometrySet() && !kapp->config()->hasGroup("MainWindow Settings"))
00117     resize( 700, 480 );
00118 
00119   readConfig ();
00120 
00121   winList.append (this);
00122 
00123   show ();
00124 }
00125 
00126 KWrite::~KWrite()
00127 {
00128   winList.remove (this);
00129 
00130   if (m_view->document()->views().count() == 1)
00131   {
00132     docList.remove(m_view->document());
00133     delete m_view->document();
00134   }
00135 
00136   kapp->config()->sync ();
00137 }
00138 
00139 void KWrite::setupActions()
00140 {
00141   KStdAction::close( this, SLOT(slotFlush()), actionCollection(), "file_close" )->setWhatsThis(i18n("Use this to close the current document"));
00142 
00143   // setup File menu
00144   KStdAction::print(this, SLOT(printDlg()), actionCollection())->setWhatsThis(i18n("Use this command to print the current document"));
00145   KStdAction::openNew( this, SLOT(slotNew()), actionCollection(), "file_new" )->setWhatsThis(i18n("Use this command to create a new document"));
00146   KStdAction::open( this, SLOT( slotOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Use this command to open an existing document for editing"));
00147 
00148   m_recentFiles = KStdAction::openRecent(this, SLOT(slotOpen(const KURL&)),
00149                                          actionCollection());
00150   m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
00151 
00152   KAction *a=new KAction(i18n("&New Window"), "window_new", 0, this, SLOT(newView()),
00153               actionCollection(), "view_new_view");
00154   a->setWhatsThis(i18n("Create another view containing the current document"));
00155 
00156   a=new KAction(i18n("Choose Editor..."),0,this,SLOT(changeEditor()),
00157         actionCollection(),"settings_choose_editor");
00158   a->setWhatsThis(i18n("Override the system wide setting for the default editing component"));
00159 
00160   KStdAction::quit(this, SLOT(close()), actionCollection())->setWhatsThis(i18n("Close the current document view"));
00161 
00162   // setup Settings menu
00163   setStandardToolBarMenuEnabled(true);
00164 
00165   m_paShowStatusBar = KStdAction::showStatusbar(this, SLOT(toggleStatusBar()), actionCollection(), "settings_show_statusbar");
00166   m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
00167 
00168   m_paShowPath = new KToggleAction(i18n("Sho&w Path"), 0, this, SLOT(newCaption()),
00169                     actionCollection(), "set_showPath");
00170   m_paShowPath->setCheckedState(i18n("Hide Path"));
00171   m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
00172   a=KStdAction::keyBindings(this, SLOT(editKeys()), actionCollection());
00173   a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
00174 
00175   a=KStdAction::configureToolbars(this, SLOT(editToolbars()), actionCollection(), "set_configure_toolbars");
00176   a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
00177 }
00178 
00179 void KWrite::setupStatusBar()
00180 {
00181   statusBar()->insertItem("", KWRITE_ID_GEN);
00182 }
00183 
00184 // load on url
00185 void KWrite::loadURL(const KURL &url)
00186 {
00187   m_recentFiles->addURL( url );
00188   m_view->document()->openURL(url);
00189 }
00190 
00191 // is closing the window wanted by user ?
00192 bool KWrite::queryClose()
00193 {
00194   if (m_view->document()->views().count() > 1)
00195     return true;
00196 
00197   if (m_view->document()->queryClose())
00198   {
00199     writeConfig();
00200 
00201     return true;
00202   }
00203 
00204   return false;
00205 }
00206 
00207 void KWrite::changeEditor()
00208 {
00209   KWriteEditorChooser choose(this);
00210   choose.exec();
00211 }
00212 
00213 void KWrite::slotFlush ()
00214 {
00215    m_view->document()->closeURL();
00216 }
00217 
00218 void KWrite::slotNew()
00219 {
00220   if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
00221     new KWrite();
00222   else
00223     m_view->document()->openURL(KURL());
00224 }
00225 
00226 void KWrite::slotOpen()
00227 {
00228   if (KTextEditor::encodingInterface(m_view->document()))
00229   {
00230     KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding(
00231         KTextEditor::encodingInterface(m_view->document())->encoding(),
00232     m_view->document()->url().url(),QString::null,this,i18n("Open File"));
00233 
00234     for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i)
00235     {
00236       encoding = r.encoding;
00237       slotOpen ( *i );
00238     }
00239   }
00240   else
00241   {
00242     KURL::List l=KFileDialog::getOpenURLs(m_view->document()->url().url(),QString::null,this,QString::null);
00243     for (KURL::List::Iterator i=l.begin(); i != l.end(); ++i)
00244     {
00245       slotOpen ( *i );
00246     }
00247   }
00248 }
00249 
00250 void KWrite::slotOpen( const KURL& url )
00251 {
00252   if (url.isEmpty()) return;
00253 
00254   if (!KIO::NetAccess::exists(url, true, this))
00255   {
00256     KMessageBox::error (this, i18n("The given file could not be read, check if it exists or if it is readable for the current user."));
00257     return;
00258   }
00259 
00260   if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
00261   {
00262     KWrite *t = new KWrite();
00263     if (KTextEditor::encodingInterface(t->m_view->document())) KTextEditor::encodingInterface(t->m_view->document())->setEncoding(encoding);
00264     t->loadURL(url);
00265   }
00266   else
00267   {
00268     if (KTextEditor::encodingInterface(m_view->document())) KTextEditor::encodingInterface(m_view->document())->setEncoding(encoding);
00269     loadURL(url);
00270   }
00271 }
00272 
00273 void KWrite::newView()
00274 {
00275   new KWrite(m_view->document());
00276 }
00277 
00278 void KWrite::toggleStatusBar()
00279 {
00280   if( m_paShowStatusBar->isChecked() )
00281     statusBar()->show();
00282   else
00283     statusBar()->hide();
00284 }
00285 
00286 void KWrite::editKeys()
00287 {
00288   KKeyDialog dlg;
00289   dlg.insert(actionCollection());
00290   if( m_view )
00291     dlg.insert(m_view->actionCollection());
00292   dlg.configure();
00293 }
00294 
00295 void KWrite::editToolbars()
00296 {
00297   KEditToolbar *dlg = new KEditToolbar(guiFactory());
00298 
00299   if (dlg->exec())
00300   {
00301     KParts::GUIActivateEvent ev1( false );
00302     QApplication::sendEvent( m_view, &ev1 );
00303     guiFactory()->removeClient( m_view );
00304     createShellGUI( false );
00305     createShellGUI( true );
00306     guiFactory()->addClient( m_view );
00307     KParts::GUIActivateEvent ev2( true );
00308     QApplication::sendEvent( m_view, &ev2 );
00309   }
00310 
00311   delete dlg;
00312 }
00313 
00314 void KWrite::printNow()
00315 {
00316   KTextEditor::printInterface(m_view->document())->print ();
00317 }
00318 
00319 void KWrite::printDlg()
00320 {
00321   KTextEditor::printInterface(m_view->document())->printDialog ();
00322 }
00323 
00324 void KWrite::newStatus(const QString &msg)
00325 {
00326   newCaption();
00327 
00328   statusBar()->changeItem(msg,KWRITE_ID_GEN);
00329 }
00330 
00331 void KWrite::newCaption()
00332 {
00333   if (m_view->document()->url().isEmpty()) {
00334     setCaption(i18n("Untitled"),m_view->document()->isModified());
00335   }
00336   else
00337   {
00338     QString c;
00339     if (!m_paShowPath->isChecked())
00340     {
00341       c = m_view->document()->url().filename();
00342 
00343       //File name shouldn't be too long - Maciek
00344       if (c.length() > 64)
00345         c = c.left(64) + "...";
00346     }
00347     else
00348     {
00349       c = m_view->document()->url().prettyURL();
00350 
00351       //File name shouldn't be too long - Maciek
00352       if (c.length() > 64)
00353         c = "..." + c.right(64);
00354     }
00355 
00356     setCaption (c, m_view->document()->isModified());
00357   }
00358 }
00359 
00360 void KWrite::dragEnterEvent( QDragEnterEvent *event )
00361 {
00362   event->accept(KURLDrag::canDecode(event));
00363 }
00364 
00365 void KWrite::dropEvent( QDropEvent *event )
00366 {
00367   slotDropEvent(event);
00368 }
00369 
00370 void KWrite::slotDropEvent( QDropEvent *event )
00371 {
00372   KURL::List textlist;
00373 
00374   if (!KURLDrag::decode(event, textlist))
00375     return;
00376 
00377   for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
00378     slotOpen (*i);
00379 }
00380 
00381 void KWrite::slotEnableActions( bool enable )
00382 {
00383   QValueList<KAction *> actions = actionCollection()->actions();
00384   QValueList<KAction *>::ConstIterator it = actions.begin();
00385   QValueList<KAction *>::ConstIterator end = actions.end();
00386 
00387   for (; it != end; ++it )
00388       (*it)->setEnabled( enable );
00389 
00390   actions = m_view->actionCollection()->actions();
00391   it = actions.begin();
00392   end = actions.end();
00393 
00394   for (; it != end; ++it )
00395       (*it)->setEnabled( enable );
00396 }
00397 
00398 //common config
00399 void KWrite::readConfig(KConfig *config)
00400 {
00401   config->setGroup("General Options");
00402 
00403   m_paShowStatusBar->setChecked( config->readBoolEntry("ShowStatusBar") );
00404   m_paShowPath->setChecked( config->readBoolEntry("ShowPath") );
00405 
00406   m_recentFiles->loadEntries(config, "Recent Files");
00407 
00408   if (m_view && KTextEditor::configInterface(m_view->document()))
00409     KTextEditor::configInterface(m_view->document())->readConfig(config);
00410 
00411   if( m_paShowStatusBar->isChecked() )
00412     statusBar()->show();
00413   else
00414     statusBar()->hide();
00415 }
00416 
00417 void KWrite::writeConfig(KConfig *config)
00418 {
00419   config->setGroup("General Options");
00420 
00421   config->writeEntry("ShowStatusBar",m_paShowStatusBar->isChecked());
00422   config->writeEntry("ShowPath",m_paShowPath->isChecked());
00423 
00424   m_recentFiles->saveEntries(config, "Recent Files");
00425 
00426   if (m_view && KTextEditor::configInterface(m_view->document()))
00427     KTextEditor::configInterface(m_view->document())->writeConfig(config);
00428 
00429   config->sync ();
00430 }
00431 
00432 //config file
00433 void KWrite::readConfig()
00434 {
00435   KConfig *config = kapp->config();
00436   readConfig(config);
00437 }
00438 
00439 void KWrite::writeConfig()
00440 {
00441   KConfig *config = kapp->config();
00442   writeConfig(config);
00443 }
00444 
00445 // session management
00446 void KWrite::restore(KConfig *config, int n)
00447 {
00448   readPropertiesInternal(config, n);
00449 }
00450 
00451 void KWrite::readProperties(KConfig *config)
00452 {
00453   readConfig(config);
00454 
00455   if (KTextEditor::sessionConfigInterface(m_view))
00456     KTextEditor::sessionConfigInterface(m_view)->readSessionConfig(config);
00457 }
00458 
00459 void KWrite::saveProperties(KConfig *config)
00460 {
00461   writeConfig(config);
00462   config->writeEntry("DocumentNumber",docList.find(m_view->document()) + 1);
00463 
00464   if (KTextEditor::sessionConfigInterface(m_view))
00465     KTextEditor::sessionConfigInterface(m_view)->writeSessionConfig(config);
00466 }
00467 
00468 void KWrite::saveGlobalProperties(KConfig *config) //save documents
00469 {
00470   config->setGroup("Number");
00471   config->writeEntry("NumberOfDocuments",docList.count());
00472 
00473   for (uint z = 1; z <= docList.count(); z++)
00474   {
00475      QString buf = QString("Document %1").arg(z);
00476      config->setGroup(buf);
00477 
00478      KTextEditor::Document *doc = docList.at(z - 1);
00479 
00480      if (KTextEditor::configInterface(doc))
00481        KTextEditor::configInterface(doc)->writeSessionConfig(config);
00482   }
00483 
00484   for (uint z = 1; z <= winList.count(); z++)
00485   {
00486      QString buf = QString("Window %1").arg(z);
00487      config->setGroup(buf);
00488 
00489      config->writeEntry("DocumentNumber",docList.find(winList.at(z-1)->view()->document()) + 1);
00490   }
00491 }
00492 
00493 //restore session
00494 void KWrite::restore()
00495 {
00496   KConfig *config = kapp->sessionConfig();
00497 
00498   if (!config)
00499     return;
00500 
00501   int docs, windows;
00502   QString buf;
00503   KTextEditor::Document *doc;
00504   KWrite *t;
00505 
00506   config->setGroup("Number");
00507   docs = config->readNumEntry("NumberOfDocuments");
00508   windows = config->readNumEntry("NumberOfWindows");
00509 
00510   for (int z = 1; z <= docs; z++)
00511   {
00512      buf = QString("Document %1").arg(z);
00513      config->setGroup(buf);
00514      doc=KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document");
00515 
00516      if (KTextEditor::configInterface(doc))
00517        KTextEditor::configInterface(doc)->readSessionConfig(config);
00518      docList.append(doc);
00519   }
00520 
00521   for (int z = 1; z <= windows; z++)
00522   {
00523     buf = QString("Window %1").arg(z);
00524     config->setGroup(buf);
00525     t = new KWrite(docList.at(config->readNumEntry("DocumentNumber") - 1));
00526     t->restore(config,z);
00527   }
00528 }
00529 
00530 static KCmdLineOptions options[] =
00531 {
00532   { "stdin",    I18N_NOOP("Read the contents of stdin"), 0},
00533   { "+[URL]",   I18N_NOOP("Document to open"), 0 },
00534   KCmdLineLastOption
00535 };
00536 
00537 extern "C" int kdemain(int argc, char **argv)
00538 {
00539   Kate::Document::setFileChangedDialogsActivated (true);
00540 
00541   KLocale::setMainCatalogue("kate");         //lukas: set this to have the kwritepart translated using kate message catalog
00542 
00543   KAboutData aboutData ( "kwrite", I18N_NOOP("KWrite"), "4.3",
00544                          I18N_NOOP( "KWrite - Text Editor" ), KAboutData::License_LGPL_V2,
00545                          I18N_NOOP( "(c) 2000-2004 The Kate Authors" ), 0, "http://kate.kde.org" );
00546 
00547   aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
00548   aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
00549   aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
00550   aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
00551   aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
00552   aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
00553   aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
00554   aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
00555   aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
00556   aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
00557   aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
00558   aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
00559   aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
00560   aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
00561   aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
00562   aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
00563 
00564   aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
00565   aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
00566   aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
00567   aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
00568   aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
00569   aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
00570   aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
00571   aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
00572   aboutData.addCredit ("Daniel Naber","","");
00573   aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
00574   aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
00575   aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
00576   aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
00577 
00578   aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
00579 
00580   KCmdLineArgs::init( argc, argv, &aboutData );
00581   KCmdLineArgs::addCmdLineOptions( options );
00582 
00583   KApplication a;
00584 
00585   KGlobal::locale()->insertCatalogue("katepart");
00586 
00587   DCOPClient *client = kapp->dcopClient();
00588   if (!client->isRegistered())
00589   {
00590     client->attach();
00591     client->registerAs("kwrite");
00592   }
00593 
00594   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00595 
00596   if (kapp->isRestored())
00597   {
00598     KWrite::restore();
00599   }
00600   else
00601   {
00602     if ( args->count() == 0 )
00603     {
00604         KWrite *t = new KWrite;
00605 
00606         if( args->isSet( "stdin" ) )
00607         {
00608           QTextIStream input(stdin);
00609           QString line;
00610           QString text;
00611 
00612           do
00613           {
00614             line = input.readLine();
00615             text.append( line + "\n" );
00616           } while( !line.isNull() );
00617 
00618 
00619           KTextEditor::EditInterface *doc = KTextEditor::editInterface (t->view()->document());
00620           if( doc )
00621               doc->setText( text );
00622         }
00623     }
00624     else
00625     {
00626       for ( int z = 0; z < args->count(); z++ )
00627       {
00628         KWrite *t = new KWrite();
00629 
00630         if (!KIO::NetAccess::mimetype( args->url(z), t ).startsWith(QString ("inode/directory")))
00631         {
00632           if (Kate::document (t->view()->document()))
00633             Kate::Document::setOpenErrorDialogsActivated (false);
00634 
00635           t->loadURL( args->url( z ) );
00636 
00637           if (Kate::document (t->view()->document()))
00638             Kate::Document::setOpenErrorDialogsActivated (true);
00639         }
00640         else
00641           KMessageBox::sorry( t, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(args->url(z).url()) );
00642       }
00643     }
00644   }
00645 
00646   // no window there, uh, ohh, for example borked session config !!!
00647   // create at least one !!
00648   if (KWrite::noWindows())
00649     new KWrite();
00650 
00651   return a.exec ();
00652 }
00653 
00654 KWriteEditorChooser::KWriteEditorChooser(QWidget *):
00655     KDialogBase(KDialogBase::Plain,i18n("Choose Editor Component"),KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel)
00656 {
00657     (new QVBoxLayout(plainPage()))->setAutoAdd(true);
00658     m_chooser=new KTextEditor::EditorChooser(plainPage(),"Editor Chooser");
00659     setMainWidget(m_chooser);
00660     m_chooser->readAppSetting();
00661 }
00662 
00663 KWriteEditorChooser::~KWriteEditorChooser() {
00664 ;
00665 }
00666 
00667 void KWriteEditorChooser::slotOk() {
00668     m_chooser->writeAppSetting();
00669     KDialogBase::slotOk();
00670 }
KDE Logo
This file is part of the documentation for kate Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 8 02:43:14 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003