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., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, 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 <kdeversion.h> 00038 #include <dcopclient.h> 00039 #include <kurldrag.h> 00040 #include <kencodingfiledialog.h> 00041 #include <kdiroperator.h> 00042 #include <kiconloader.h> 00043 #include <kaboutdata.h> 00044 #include <kstatusbar.h> 00045 #include <kstdaction.h> 00046 #include <kaction.h> 00047 #include <kdebug.h> 00048 #include <kglobal.h> 00049 #include <kapplication.h> 00050 #include <klocale.h> 00051 #include <kurl.h> 00052 #include <kconfig.h> 00053 #include <kcmdlineargs.h> 00054 #include <kmessagebox.h> 00055 #include <kkeydialog.h> 00056 #include <kedittoolbar.h> 00057 #include <kparts/event.h> 00058 #include <kmenubar.h> 00059 00060 #include <tqdropsite.h> 00061 #include <tqdragobject.h> 00062 #include <tqvbox.h> 00063 #include <tqtextcodec.h> 00064 #include <tqlayout.h> 00065 00066 // StatusBar field IDs 00067 #define KWRITE_ID_GEN 1 00068 00069 TQPtrList<KTextEditor::Document> KWrite::docList; 00070 TQPtrList<KWrite> KWrite::winList; 00071 00072 KWrite::KWrite (KTextEditor::Document *doc) 00073 : m_view(0), 00074 m_recentFiles(0), 00075 m_paShowPath(0), 00076 m_paShowStatusBar(0) 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,TQT_SIGNAL(newStatus()),this,TQT_SLOT(newCaption())); 00100 connect(m_view,TQT_SIGNAL(viewStatusMsg(const TQString &)),this,TQT_SLOT(newStatus(const TQString &))); 00101 connect(m_view->document(),TQT_SIGNAL(fileNameChanged()),this,TQT_SLOT(newCaption())); 00102 connect(m_view->document(),TQT_SIGNAL(fileNameChanged()),this,TQT_SLOT(slotFileNameChanged())); 00103 connect(m_view,TQT_SIGNAL(dropEventPass(TQDropEvent *)),this,TQT_SLOT(slotDropEvent(TQDropEvent *))); 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 ((TQPopupMenu*)(factory()->container("ktexteditor_popup", this)) ); 00112 00113 // init with more usefull size, stolen from konq :) 00114 if (!initialGeometrySet()) 00115 resize( TQSize(700, 480).expandedTo(minimumSizeHint())); 00116 00117 // call it as last thing, must be sure everything is already set up ;) 00118 setAutoSaveSettings (); 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( TQT_TQOBJECT(this), TQT_SLOT(slotFlush()), actionCollection(), "file_close" )->setWhatsThis(i18n("Use this to close the current document")); 00143 00144 // setup File menu 00145 KStdAction::print(TQT_TQOBJECT(this), TQT_SLOT(printDlg()), actionCollection())->setWhatsThis(i18n("Use this command to print the current document")); 00146 KStdAction::openNew( TQT_TQOBJECT(this), TQT_SLOT(slotNew()), actionCollection(), "file_new" )->setWhatsThis(i18n("Use this command to create a new document")); 00147 KStdAction::open( TQT_TQOBJECT(this), TQT_SLOT( slotOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Use this command to open an existing document for editing")); 00148 00149 m_recentFiles = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_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, TQT_TQOBJECT(this), TQT_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,TQT_TQOBJECT(this),TQT_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(TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection())->setWhatsThis(i18n("Close the current document view")); 00162 00163 // setup Settings menu 00164 setStandardToolBarMenuEnabled(true); 00165 00166 m_paShowStatusBar = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_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, TQT_TQOBJECT(this), TQT_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(TQT_TQOBJECT(this), TQT_SLOT(editKeys()), actionCollection()); 00174 a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments.")); 00175 00176 a=KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(editToolbars()), actionCollection()); 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 // 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 new KWrite(); 00221 } 00222 00223 void KWrite::slotOpen() 00224 { 00225 if (KTextEditor::encodingInterface(m_view->document())) 00226 { 00227 KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding( 00228 KTextEditor::encodingInterface(m_view->document())->encoding(), 00229 m_view->document()->url().url(),TQString::null,this,i18n("Open File")); 00230 00231 for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i) 00232 { 00233 encoding = r.encoding; 00234 slotOpen ( *i ); 00235 } 00236 } 00237 else 00238 { 00239 KURL::List l=KFileDialog::getOpenURLs(m_view->document()->url().url(),TQString::null,this,TQString::null); 00240 for (KURL::List::Iterator i=l.begin(); i != l.end(); ++i) 00241 { 00242 slotOpen ( *i ); 00243 } 00244 } 00245 } 00246 00247 void KWrite::slotOpen( const KURL& url ) 00248 { 00249 if (url.isEmpty()) return; 00250 00251 if (!KIO::NetAccess::exists(url, true, this)) 00252 { 00253 KMessageBox::error (this, i18n("The given file could not be read, check if it exists or if it is readable for the current user.")); 00254 return; 00255 } 00256 00257 if (m_view->document()->isModified() || !m_view->document()->url().isEmpty()) 00258 { 00259 KWrite *t = new KWrite(); 00260 if (KTextEditor::encodingInterface(t->m_view->document())) KTextEditor::encodingInterface(t->m_view->document())->setEncoding(encoding); 00261 t->loadURL(url); 00262 } 00263 else 00264 { 00265 if (KTextEditor::encodingInterface(m_view->document())) KTextEditor::encodingInterface(m_view->document())->setEncoding(encoding); 00266 loadURL(url); 00267 } 00268 } 00269 00270 void KWrite::slotFileNameChanged() 00271 { 00272 if ( ! m_view->document()->url().isEmpty() ) 00273 m_recentFiles->addURL( m_view->document()->url() ); 00274 } 00275 00276 void KWrite::newView() 00277 { 00278 new KWrite(m_view->document()); 00279 } 00280 00281 void KWrite::toggleStatusBar() 00282 { 00283 if( m_paShowStatusBar->isChecked() ) 00284 statusBar()->show(); 00285 else 00286 statusBar()->hide(); 00287 } 00288 00289 void KWrite::editKeys() 00290 { 00291 KKeyDialog dlg; 00292 dlg.insert(actionCollection()); 00293 if( m_view ) 00294 dlg.insert(m_view->actionCollection()); 00295 dlg.configure(); 00296 } 00297 00298 void KWrite::editToolbars() 00299 { 00300 saveMainWindowSettings( kapp->config(), "MainWindow" ); 00301 KEditToolbar *dlg = new KEditToolbar(guiFactory()); 00302 connect( dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) ); 00303 dlg->exec(); 00304 delete dlg; 00305 } 00306 00307 void KWrite::slotNewToolbarConfig() 00308 { 00309 applyMainWindowSettings( kapp->config(), "MainWindow" ); 00310 } 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 TQString &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 TQString 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( TQDragEnterEvent *event ) 00360 { 00361 event->accept(KURLDrag::canDecode(event)); 00362 } 00363 00364 void KWrite::dropEvent( TQDropEvent *event ) 00365 { 00366 slotDropEvent(event); 00367 } 00368 00369 void KWrite::slotDropEvent( TQDropEvent *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 TQValueList<KAction *> actions = actionCollection()->actions(); 00383 TQValueList<KAction *>::ConstIterator it = actions.begin(); 00384 TQValueList<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 TQString buf = TQString("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 TQString buf = TQString("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 TQString 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 = TQString("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 = TQString("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 { "encoding <argument>", I18N_NOOP("Set encoding for the file to open"), 0 }, 00533 { "line <argument>", I18N_NOOP("Navigate to this line"), 0 }, 00534 { "column <argument>", I18N_NOOP("Navigate to this column"), 0 }, 00535 { "+[URL]", I18N_NOOP("Document to open"), 0 }, 00536 KCmdLineLastOption 00537 }; 00538 00539 extern "C" KDE_EXPORT int kdemain(int argc, char **argv) 00540 { 00541 Kate::Document::setFileChangedDialogsActivated (true); 00542 00543 KLocale::setMainCatalogue("kate"); //lukas: set this to have the kwritepart translated using kate message catalog 00544 00545 // here we go, construct the KWrite version 00546 TQString kWriteVersion = TQString ("%1.%2.%3").arg(KDE::versionMajor() + 1).arg(KDE::versionMinor()).arg(KDE::versionRelease()); 00547 00548 KAboutData aboutData ( "kwrite", 00549 I18N_NOOP("KWrite"), 00550 kWriteVersion.latin1(), 00551 I18N_NOOP( "KWrite - Text Editor" ), KAboutData::License_LGPL_V2, 00552 I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org" ); 00553 00554 aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de"); 00555 aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk"); 00556 aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371"); 00557 aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org"); 00558 aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" ); 00559 aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org"); 00560 aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com"); 00561 aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at"); 00562 aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz"); 00563 aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" ); 00564 aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org"); 00565 aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" ); 00566 aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" ); 00567 aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com"); 00568 aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net"); 00569 aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org"); 00570 00571 aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it"); 00572 aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu"); 00573 aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),""); 00574 aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),""); 00575 aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),""); 00576 aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),""); 00577 aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),""); 00578 aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),""); 00579 aboutData.addCredit ("Daniel Naber","",""); 00580 aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),""); 00581 aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),""); 00582 aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), ""); 00583 aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"",""); 00584 00585 aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails")); 00586 00587 KCmdLineArgs::init( argc, argv, &aboutData ); 00588 KCmdLineArgs::addCmdLineOptions( options ); 00589 00590 KApplication a; 00591 00592 KGlobal::locale()->insertCatalogue("katepart"); 00593 00594 DCOPClient *client = kapp->dcopClient(); 00595 if (!client->isRegistered()) 00596 { 00597 client->attach(); 00598 client->registerAs("kwrite"); 00599 } 00600 00601 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 00602 00603 if (kapp->isRestored()) 00604 { 00605 KWrite::restore(); 00606 } 00607 else 00608 { 00609 bool nav = false; 00610 int line = 0, column = 0; 00611 00612 TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0; 00613 00614 if (args->isSet ("line")) 00615 { 00616 line = args->getOption ("line").toInt(); 00617 nav = true; 00618 } 00619 00620 if (args->isSet ("column")) 00621 { 00622 column = args->getOption ("column").toInt(); 00623 nav = true; 00624 } 00625 00626 if ( args->count() == 0 ) 00627 { 00628 KWrite *t = new KWrite; 00629 00630 if( args->isSet( "stdin" ) ) 00631 { 00632 TQTextIStream input(stdin); 00633 00634 // set chosen codec 00635 if (codec) 00636 input.setCodec (codec); 00637 00638 TQString line; 00639 TQString text; 00640 00641 do 00642 { 00643 line = input.readLine(); 00644 text.append( line + "\n" ); 00645 } while( !line.isNull() ); 00646 00647 00648 KTextEditor::EditInterface *doc = KTextEditor::editInterface (t->view()->document()); 00649 if( doc ) 00650 doc->setText( text ); 00651 } 00652 00653 if (nav && KTextEditor::viewCursorInterface(t->view())) 00654 KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column); 00655 } 00656 else 00657 { 00658 for ( int z = 0; z < args->count(); z++ ) 00659 { 00660 KWrite *t = new KWrite(); 00661 00662 // this file is no local dir, open it, else warn 00663 bool noDir = !args->url(z).isLocalFile() || !TQDir (args->url(z).path()).exists(); 00664 00665 if (noDir) 00666 { 00667 if (Kate::document (t->view()->document())) 00668 Kate::Document::setOpenErrorDialogsActivated (false); 00669 00670 if (codec && KTextEditor::encodingInterface(t->view()->document())) 00671 KTextEditor::encodingInterface(t->view()->document())->setEncoding(codec->name()); 00672 00673 t->loadURL( args->url( z ) ); 00674 00675 if (Kate::document (t->view()->document())) 00676 Kate::Document::setOpenErrorDialogsActivated (true); 00677 00678 if (nav && KTextEditor::viewCursorInterface(t->view())) 00679 KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column); 00680 } 00681 else 00682 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()) ); 00683 } 00684 } 00685 } 00686 00687 // no window there, uh, ohh, for example borked session config !!! 00688 // create at least one !! 00689 if (KWrite::noWindows()) 00690 new KWrite(); 00691 00692 return a.exec (); 00693 } 00694 00695 KWriteEditorChooser::KWriteEditorChooser(TQWidget *): 00696 KDialogBase(KDialogBase::Plain,i18n("Choose Editor Component"),KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel) 00697 { 00698 (new TQVBoxLayout(plainPage()))->setAutoAdd(true); 00699 m_chooser=new KTextEditor::EditorChooser(plainPage(),"Editor Chooser"); 00700 setMainWidget(m_chooser); 00701 m_chooser->readAppSetting(); 00702 } 00703 00704 KWriteEditorChooser::~KWriteEditorChooser() { 00705 ; 00706 } 00707 00708 void KWriteEditorChooser::slotOk() { 00709 m_chooser->writeAppSetting(); 00710 KDialogBase::slotOk(); 00711 } 00712 // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;