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