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