Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kwrite / kwritemain.cpp
bloba08800854a30804d23aebb85beafc2d2314f9392
1 /* This file is part of the KDE project
2 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4 Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "kwritemain.h"
22 #include "kwritemain.moc"
23 #include <ktexteditor/document.h>
24 #include <ktexteditor/view.h>
25 #include <ktexteditor/sessionconfiginterface.h>
26 #include <ktexteditor/modificationinterface.h>
27 #include <ktexteditor/editor.h>
28 #include <ktexteditor/editorchooser.h>
30 #include <kio/netaccess.h>
32 #include <kaboutapplicationdialog.h>
33 #include <kaboutdata.h>
34 #include <kaction.h>
35 #include <kactioncollection.h>
36 #include <kapplication.h>
37 #include <kcmdlineargs.h>
38 #include <kdeversion.h>
39 #include <kdiroperator.h>
40 #include <kedittoolbar.h>
41 #include <kencodingfiledialog.h>
42 #include <kiconloader.h>
43 #include <klocale.h>
44 #include <kmessagebox.h>
45 #include <krecentfilesaction.h>
46 #include <kshortcutsdialog.h>
47 #include <kstatusbar.h>
48 #include <kstandardaction.h>
49 #include <ksqueezedtextlabel.h>
50 #include <kstringhandler.h>
51 #include <kxmlguifactory.h>
53 #include <QtCore/QTimer>
54 #include <QtCore/QTextCodec>
56 QList<KTextEditor::Document*> KWrite::docList;
57 QList<KWrite*> KWrite::winList;
59 KWrite::KWrite (KTextEditor::Document *doc)
60 : m_view(0),
61 m_recentFiles(0),
62 m_paShowPath(0),
63 m_paShowStatusBar(0)
65 if ( !doc )
67 KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
69 if ( !editor )
71 KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\n"
72 "please check your KDE installation."));
73 kapp->exit(1);
76 doc = editor->createDocument(0);
78 // enable the modified on disk warning dialogs if any
79 if (qobject_cast<KTextEditor::ModificationInterface *>(doc))
80 qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning (true);
82 docList.append(doc);
85 m_view = qobject_cast<KTextEditor::View*>(doc->createView (this));
87 setCentralWidget(m_view);
89 setupActions();
90 setupStatusBar();
92 // signals for the statusbar
93 connect(m_view, SIGNAL(cursorPositionChanged(KTextEditor::View *, const KTextEditor::Cursor &)), this, SLOT(cursorPositionChanged(KTextEditor::View *)));
94 connect(m_view, SIGNAL(viewModeChanged(KTextEditor::View *)), this, SLOT(viewModeChanged(KTextEditor::View *)));
95 connect(m_view, SIGNAL(selectionChanged (KTextEditor::View *)), this, SLOT(selectionChanged (KTextEditor::View *)));
96 connect(m_view, SIGNAL(informationMessage (KTextEditor::View *, const QString &)), this, SLOT(informationMessage (KTextEditor::View *, const QString &)));
97 connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document *)), this, SLOT(modifiedChanged()));
98 connect(m_view->document(), SIGNAL(modifiedOnDisk(KTextEditor::Document *, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason)), this, SLOT(modifiedChanged()) );
99 connect(m_view->document(), SIGNAL(documentNameChanged(KTextEditor::Document *)), this, SLOT(documentNameChanged()));
100 connect(m_view->document(),SIGNAL(documentUrlChanged(KTextEditor::Document *)), this, SLOT(urlChanged()));
101 connect(m_view->document(), SIGNAL(modeChanged(KTextEditor::Document *)), this, SLOT(modeChanged(KTextEditor::Document *)));
103 setAcceptDrops(true);
104 connect(m_view,SIGNAL(dropEventPass(QDropEvent *)),this,SLOT(slotDropEvent(QDropEvent *)));
106 setXMLFile( "kwriteui.rc" );
107 createShellGUI( true );
108 guiFactory()->addClient( m_view );
110 // install a working kate part popup dialog thingy
111 m_view->setContextMenu ((QMenu*)(factory()->container("ktexteditor_popup", this)) );
113 // init with more useful size, stolen from konq :)
114 if (!initialGeometrySet())
115 resize( QSize(700, 480).expandedTo(minimumSizeHint()));
117 // call it as last thing, must be sure everything is already set up ;)
118 setAutoSaveSettings ();
120 readConfig ();
122 winList.append (this);
124 updateStatus ();
125 show ();
128 KWrite::~KWrite()
130 winList.removeAll(this);
132 if (m_view->document()->views().count() == 1)
134 docList.removeAll(m_view->document());
135 delete m_view->document();
138 KGlobal::config()->sync ();
141 void KWrite::setupActions()
143 actionCollection()->addAction( KStandardAction::Close, "file_close", this, SLOT(slotFlush()) )
144 ->setWhatsThis(i18n("Use this to close the current document"));
146 // setup File menu
147 actionCollection()->addAction( KStandardAction::New, "file_new", this, SLOT(slotNew()) )
148 ->setWhatsThis(i18n("Use this command to create a new document"));
149 actionCollection()->addAction( KStandardAction::Open, "file_open", this, SLOT(slotOpen()) )
150 ->setWhatsThis(i18n("Use this command to open an existing document for editing"));
152 m_recentFiles = KStandardAction::openRecent(this, SLOT(slotOpen(const KUrl&)), this);
153 actionCollection()->addAction(m_recentFiles->objectName(), m_recentFiles);
154 m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
156 QAction *a = actionCollection()->addAction( "view_new_view" );
157 a->setIcon( KIcon("window-new") );
158 a->setText( i18n("&New Window") );
159 connect( a, SIGNAL(triggered()), this, SLOT(newView()) );
160 a->setWhatsThis(i18n("Create another view containing the current document"));
162 a = actionCollection()->addAction( "settings_choose_editor" );
163 a->setText( i18n("Choose Editor...") );
164 connect( a, SIGNAL(triggered()), this, SLOT(changeEditor()) );
165 a->setWhatsThis(i18n("Override the system wide setting for the default editing component"));
167 actionCollection()->addAction( KStandardAction::Quit, this, SLOT(close()) )
168 ->setWhatsThis(i18n("Close the current document view"));
170 // setup Settings menu
171 setStandardToolBarMenuEnabled(true);
173 m_paShowStatusBar = KStandardAction::showStatusbar(this, SLOT(toggleStatusBar()), this);
174 actionCollection()->addAction( "settings_show_statusbar", m_paShowStatusBar);
175 m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
177 m_paShowPath = new KToggleAction( i18n("Sho&w Path"), this );
178 actionCollection()->addAction( "set_showPath", m_paShowPath );
179 connect( m_paShowPath, SIGNAL(triggered()), this, SLOT(documentNameChanged()) );
180 m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
182 a= actionCollection()->addAction( KStandardAction::KeyBindings, this, SLOT(editKeys()) );
183 a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
185 a = actionCollection()->addAction( KStandardAction::ConfigureToolbars, "options_configure_toolbars",
186 this, SLOT(editToolbars()) );
187 a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
189 a = actionCollection()->addAction( "help_about_editor" );
190 a->setText( i18n("&About Editor Component") );
191 connect( a, SIGNAL(triggered()), this, SLOT(aboutEditor()) );
195 void KWrite::setupStatusBar()
197 // statusbar stuff
198 m_lineColLabel = new QLabel( statusBar() );
199 statusBar()->addWidget( m_lineColLabel, 0 );
200 m_lineColLabel->setAlignment( Qt::AlignCenter );
202 m_modifiedLabel = new QLabel( QString(" "), statusBar() );
203 statusBar()->addWidget( m_modifiedLabel, 0 );
204 m_modifiedLabel->setAlignment( Qt::AlignCenter );
206 m_insertModeLabel = new QLabel( i18n(" INS "), statusBar() );
207 statusBar()->addWidget( m_insertModeLabel, 0 );
208 m_insertModeLabel->setAlignment( Qt::AlignCenter );
210 m_selectModeLabel = new QLabel( i18n(" LINE "), statusBar() );
211 statusBar()->addWidget( m_selectModeLabel, 0 );
212 m_selectModeLabel->setAlignment( Qt::AlignCenter );
214 m_modeLabel = new QLabel( QString(), statusBar() );
215 statusBar()->addWidget( m_modeLabel, 0 );
216 m_modeLabel->setAlignment( Qt::AlignCenter );
218 m_fileNameLabel=new KSqueezedTextLabel( statusBar() );
219 statusBar()->addPermanentWidget( m_fileNameLabel, 1 );
220 m_fileNameLabel->setMinimumSize( 0, 0 );
221 m_fileNameLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
222 m_fileNameLabel->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft );
224 m_modPm = SmallIcon("modified");
225 m_modDiscPm = SmallIcon("modonhd");
226 m_modmodPm = SmallIcon("modmod");
227 m_noPm = SmallIcon("null");
230 // load on url
231 void KWrite::loadURL(const KUrl &url)
233 m_view->document()->openUrl(url);
236 // is closing the window wanted by user ?
237 bool KWrite::queryClose()
239 if (m_view->document()->views().count() > 1)
240 return true;
242 if (m_view->document()->queryClose())
244 writeConfig();
246 return true;
249 return false;
252 void KWrite::changeEditor()
254 KWriteEditorChooser choose(this);
255 choose.exec();
258 void KWrite::slotFlush ()
260 m_view->document()->closeUrl();
263 void KWrite::slotNew()
265 new KWrite();
268 void KWrite::slotOpen()
270 KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenUrlsAndEncoding(m_view->document()->encoding(), m_view->document()->url().url(),QString(),this,i18n("Open File"));
272 for (KUrl::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i)
274 encoding = r.encoding;
275 slotOpen ( *i );
279 void KWrite::slotOpen( const KUrl& url )
281 if (url.isEmpty()) return;
283 if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this))
285 KMessageBox::error (this, i18n("The given file could not be read, check if it exists or if it is readable for the current user."));
286 return;
289 if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
291 KWrite *t = new KWrite();
292 t->m_view->document()->setEncoding(encoding);
293 t->loadURL(url);
295 else
297 m_view->document()->setEncoding(encoding);
298 loadURL(url);
302 void KWrite::urlChanged()
304 if ( ! m_view->document()->url().isEmpty() )
305 m_recentFiles->addUrl( m_view->document()->url() );
308 void KWrite::newView()
310 new KWrite(m_view->document());
313 void KWrite::toggleStatusBar()
315 if( m_paShowStatusBar->isChecked() )
316 statusBar()->show();
317 else
318 statusBar()->hide();
321 void KWrite::editKeys()
323 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
324 dlg.addCollection(actionCollection());
325 if( m_view )
326 dlg.addCollection(m_view->actionCollection());
327 dlg.configure();
330 void KWrite::editToolbars()
332 saveMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );
333 KEditToolBar dlg(guiFactory(), this);
335 connect( &dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()) );
336 dlg.exec();
339 void KWrite::slotNewToolbarConfig()
341 applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );
344 void KWrite::dragEnterEvent( QDragEnterEvent *event )
346 KUrl::List uriList = KUrl::List::fromMimeData( event->mimeData() );
347 if(!uriList.isEmpty())
348 event->accept();
351 void KWrite::dropEvent( QDropEvent *event )
353 slotDropEvent(event);
356 void KWrite::slotDropEvent( QDropEvent *event )
358 KUrl::List textlist = KUrl::List::fromMimeData( event->mimeData() );
360 if (textlist.isEmpty())
361 return;
363 for (KUrl::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
364 slotOpen (*i);
367 void KWrite::slotEnableActions( bool enable )
369 QList<QAction *> actions = actionCollection()->actions();
370 QList<QAction *>::ConstIterator it = actions.begin();
371 QList<QAction *>::ConstIterator end = actions.end();
373 for (; it != end; ++it )
374 (*it)->setEnabled( enable );
376 actions = m_view->actionCollection()->actions();
377 it = actions.begin();
378 end = actions.end();
380 for (; it != end; ++it )
381 (*it)->setEnabled( enable );
384 //common config
385 void KWrite::readConfig(KSharedConfigPtr config)
387 KConfigGroup cfg( config, "General Options");
389 m_paShowStatusBar->setChecked( cfg.readEntry("ShowStatusBar", false) );
390 m_paShowPath->setChecked( cfg.readEntry("ShowPath", false) );
392 m_recentFiles->loadEntries( config->group( "Recent Files" ));
394 m_view->document()->editor()->readConfig(config.data());
396 if( m_paShowStatusBar->isChecked() )
397 statusBar()->show();
398 else
399 statusBar()->hide();
402 void KWrite::writeConfig(KSharedConfigPtr config)
404 KConfigGroup generalOptions( config, "General Options");
406 generalOptions.writeEntry("ShowStatusBar",m_paShowStatusBar->isChecked());
407 generalOptions.writeEntry("ShowPath",m_paShowPath->isChecked());
409 m_recentFiles->saveEntries(KConfigGroup(config, "Recent Files"));
411 // Writes into its own group
412 m_view->document()->editor()->writeConfig(config.data());
414 config->sync ();
417 //config file
418 void KWrite::readConfig()
420 readConfig(KGlobal::config());
423 void KWrite::writeConfig()
425 writeConfig(KGlobal::config());
428 // session management
429 void KWrite::restore(KConfig *config, int n)
431 readPropertiesInternal(config, n);
434 void KWrite::readProperties(KSharedConfigPtr config)
436 readConfig(config);
438 if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view))
439 iface->readSessionConfig(KConfigGroup(config, "General Options"));
442 void KWrite::saveProperties(KSharedConfigPtr config)
444 writeConfig(config);
446 KConfigGroup group(config, QString());
447 group.writeEntry("DocumentNumber",docList.indexOf(m_view->document()) + 1);
449 if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view)) {
450 KConfigGroup cg( config, "General Options" );
451 iface->writeSessionConfig(cg);
455 void KWrite::saveGlobalProperties(KConfig *config) //save documents
457 config->group("Number").writeEntry("NumberOfDocuments",docList.count());
459 for (int z = 1; z <= docList.count(); z++)
461 QString buf = QString("Document %1").arg(z);
462 KConfigGroup cg( config, buf );
463 KTextEditor::Document *doc = docList.at(z - 1);
465 if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc))
466 iface->writeSessionConfig(cg);
469 for (int z = 1; z <= winList.count(); z++)
471 QString buf = QString("Window %1").arg(z);
472 KConfigGroup cg( config, buf );
473 cg.writeEntry("DocumentNumber",docList.indexOf(winList.at(z-1)->view()->document()) + 1);
477 //restore session
478 void KWrite::restore()
480 KConfig *config = kapp->sessionConfig();
482 if (!config)
483 return;
485 KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
487 if ( !editor )
489 KMessageBox::error(0, i18n("A KDE text-editor component could not be found;\n"
490 "please check your KDE installation."));
491 kapp->exit(1);
494 int docs, windows;
495 QString buf;
496 KTextEditor::Document *doc;
497 KWrite *t;
499 KConfigGroup numberConfig(config, "Number");
500 docs = numberConfig.readEntry("NumberOfDocuments", 0);
501 windows = numberConfig.readEntry("NumberOfWindows", 0);
503 for (int z = 1; z <= docs; z++)
505 buf = QString("Document %1").arg(z);
506 KConfigGroup cg(config, buf);
507 doc=editor->createDocument(0);
509 if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc))
510 iface->readSessionConfig(cg);
511 docList.append(doc);
514 for (int z = 1; z <= windows; z++)
516 buf = QString("Window %1").arg(z);
517 KConfigGroup cg(config, buf);
518 t = new KWrite(docList.at(cg.readEntry("DocumentNumber", 0) - 1));
519 t->restore(config,z);
523 void KWrite::aboutEditor()
525 KAboutApplicationDialog dlg(m_view->document()->editor()->aboutData(), this);
526 dlg.exec();
529 void KWrite::updateStatus ()
531 viewModeChanged (m_view);
532 cursorPositionChanged (m_view);
533 selectionChanged (m_view);
534 modifiedChanged ();
535 documentNameChanged ();
536 modeChanged (m_view->document());
539 void KWrite::viewModeChanged ( KTextEditor::View *view )
541 m_insertModeLabel->setText( view->viewMode() );
544 void KWrite::cursorPositionChanged ( KTextEditor::View *view )
546 KTextEditor::Cursor position (view->cursorPositionVirtual());
548 m_lineColLabel->setText(
549 i18n(" Line: %1 Col: %2 ", KGlobal::locale()->formatNumber(position.line()+1, 0),
550 KGlobal::locale()->formatNumber(position.column()+1, 0)) );
553 void KWrite::selectionChanged (KTextEditor::View *view)
555 m_selectModeLabel->setText( view->blockSelection() ? i18n(" BLOCK ") : i18n(" LINE ") );
558 void KWrite::informationMessage (KTextEditor::View *view, const QString &message)
560 Q_UNUSED(view)
562 m_fileNameLabel->setText( message );
564 // timer to reset this after 4 seconds
565 QTimer::singleShot(4000, this, SLOT(documentNameChanged()));
568 void KWrite::modifiedChanged()
570 bool mod = m_view->document()->isModified();
572 /* const KateDocumentInfo *info
573 = KateDocManager::self()->documentInfo ( m_view->document() );
575 // bool modOnHD = false; //info && info->modifiedOnDisc;
577 m_modifiedLabel->setPixmap(
578 mod ? m_modPm : m_noPm
579 /*info && modOnHD ?
580 m_modmodPm :
581 m_modPm :
582 info && modOnHD ?
583 m_modDiscPm :
584 m_noPm*/
587 documentNameChanged(); // update the modified flag in window title
590 void KWrite::documentNameChanged ()
592 m_fileNameLabel->setText( KStringHandler::lsqueeze(m_view->document()->documentName (), 64) );
594 if (m_view->document()->url().isEmpty()) {
595 setCaption(i18n("Untitled"),m_view->document()->isModified());
597 else
599 QString c;
600 if (!m_paShowPath->isChecked())
602 c = m_view->document()->url().fileName();
604 //File name shouldn't be too long - Maciek
605 if (c.length() > 64)
606 c = c.left(64) + "...";
608 else
610 c = m_view->document()->url().prettyUrl();
612 //File name shouldn't be too long - Maciek
613 if (c.length() > 64)
614 c = "..." + c.right(64);
617 setCaption (c, m_view->document()->isModified());
621 void KWrite::modeChanged ( KTextEditor::Document *document )
623 m_modeLabel->setText (document->mode());
626 extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
628 KAboutData aboutData ( "kwrite", "kate",
629 ki18n("KWrite"),
630 KDE_VERSION_STRING,
631 ki18n( "KWrite - Text Editor" ), KAboutData::License_LGPL_V2,
632 ki18n( "(c) 2000-2005 The Kate Authors" ), KLocalizedString(), "http://www.kate-editor.org" );
633 aboutData.addAuthor (ki18n("Christoph Cullmann"), ki18n("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
634 aboutData.addAuthor (ki18n("Anders Lund"), ki18n("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
635 aboutData.addAuthor (ki18n("Joseph Wenninger"), ki18n("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
636 aboutData.addAuthor (ki18n("Hamish Rodda"),ki18n("Core Developer"), "rodda@kde.org");
637 aboutData.addAuthor (ki18n("Dominik Haumann"), ki18n("Developer & Highlight wizard"), "dhdev@gmx.de");
638 aboutData.addAuthor (ki18n("Waldo Bastian"), ki18n( "The cool buffersystem" ), "bastian@kde.org" );
639 aboutData.addAuthor (ki18n("Charles Samuels"), ki18n("The Editing Commands"), "charles@kde.org");
640 aboutData.addAuthor (ki18n("Matt Newell"), ki18n("Testing, ..."), "newellm@proaxis.com");
641 aboutData.addAuthor (ki18n("Michael Bartl"), ki18n("Former Core Developer"), "michael.bartl1@chello.at");
642 aboutData.addAuthor (ki18n("Michael McCallum"), ki18n("Core Developer"), "gholam@xtra.co.nz");
643 aboutData.addAuthor (ki18n("Jochen Wilhemly"), ki18n( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
644 aboutData.addAuthor (ki18n("Michael Koch"),ki18n("KWrite port to KParts"), "koch@kde.org");
645 aboutData.addAuthor (ki18n("Christian Gebauer"), KLocalizedString(), "gebauer@kde.org" );
646 aboutData.addAuthor (ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org" );
647 aboutData.addAuthor (ki18n("Glen Parker"),ki18n("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
648 aboutData.addAuthor (ki18n("Scott Manson"),ki18n("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
649 aboutData.addAuthor (ki18n("John Firebaugh"),ki18n("Patches and more"), "jfirebaugh@kde.org");
651 aboutData.addCredit (ki18n("Matteo Merli"),ki18n("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
652 aboutData.addCredit (ki18n("Rocky Scaletta"),ki18n("Highlighting for VHDL"), "rocky@purdue.edu");
653 aboutData.addCredit (ki18n("Yury Lebedev"),ki18n("Highlighting for SQL"));
654 aboutData.addCredit (ki18n("Chris Ross"),ki18n("Highlighting for Ferite"));
655 aboutData.addCredit (ki18n("Nick Roux"),ki18n("Highlighting for ILERPG"));
656 aboutData.addCredit (ki18n("Carsten Niehaus"), ki18n("Highlighting for LaTeX"));
657 aboutData.addCredit (ki18n("Per Wigren"), ki18n("Highlighting for Makefiles, Python"));
658 aboutData.addCredit (ki18n("Jan Fritz"), ki18n("Highlighting for Python"));
659 aboutData.addCredit (ki18n("Daniel Naber"));
660 aboutData.addCredit (ki18n("Roland Pabel"),ki18n("Highlighting for Scheme"));
661 aboutData.addCredit (ki18n("Cristi Dumitrescu"),ki18n("PHP Keyword/Datatype list"));
662 aboutData.addCredit (ki18n("Carsten Pfeiffer"), ki18n("Very nice help"));
663 aboutData.addCredit (ki18n("All people who have contributed and I have forgotten to mention"));
665 KCmdLineArgs::init( argc, argv, &aboutData );
667 KCmdLineOptions options;
668 options.add("stdin", ki18n("Read the contents of stdin"));
669 options.add("encoding <argument>", ki18n("Set encoding for the file to open"));
670 options.add("line <argument>", ki18n("Navigate to this line"));
671 options.add("column <argument>", ki18n("Navigate to this column"));
672 options.add("+[URL]", ki18n("Document to open"));
673 KCmdLineArgs::addCmdLineOptions( options );
675 KApplication a;
677 QApplication::setWindowIcon(KIcon("accessories-text-editor"));
679 KGlobal::locale()->insertCatalog("katepart4");
680 #if 0
681 DCOPClient *client = kapp->dcopClient();
682 if (!client->isRegistered())
684 client->attach();
685 client->registerAs("kwrite");
687 #endif
688 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
690 if (a.isSessionRestored())
692 KWrite::restore();
694 else
696 bool nav = false;
697 int line = 0, column = 0;
699 QTextCodec *codec = args->isSet("encoding") ? QTextCodec::codecForName(args->getOption("encoding").toLocal8Bit()) : 0;
701 if (args->isSet ("line"))
703 line = args->getOption ("line").toInt() - 1;
704 nav = true;
707 if (args->isSet ("column"))
709 column = args->getOption ("column").toInt() - 1;
710 nav = true;
713 if ( args->count() == 0 )
715 KWrite *t = new KWrite;
717 if( args->isSet( "stdin" ) )
719 QTextStream input(stdin, QIODevice::ReadOnly);
721 // set chosen codec
722 if (codec)
723 input.setCodec (codec);
725 QString line;
726 QString text;
730 line = input.readLine();
731 text.append( line + '\n' );
732 } while( !line.isNull() );
735 KTextEditor::Document *doc = t->view()->document();
736 if( doc )
737 doc->setText( text );
740 if (nav && t->view())
741 t->view()->setCursorPosition (KTextEditor::Cursor (line, column));
743 else
745 int docs_opened = 0;
746 for ( int z = 0; z < args->count(); z++ )
748 // this file is no local dir, open it, else warn
749 bool noDir = !args->url(z).isLocalFile() || !QDir (args->url(z).path()).exists();
751 if (noDir)
753 ++docs_opened;
754 KWrite *t = new KWrite();
756 // if (Kate::document (t->view()->document()))
757 // KTextEditor::Document::setOpenErrorDialogsActivated (false);
759 if (codec)
760 t->view()->document()->setEncoding(codec->name());
762 t->loadURL( args->url( z ) );
764 // if (Kate::document (t->view()->document()))
765 // KTextEditor::Document::setOpenErrorDialogsActivated (true);
767 if (nav)
768 t->view()->setCursorPosition (KTextEditor::Cursor (line, column));
770 else
772 KMessageBox::sorry(0, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", args->url(z).url()));
775 if (!docs_opened) return 1; // see http://bugs.kde.org/show_bug.cgi?id=124708
779 // no window there, uh, ohh, for example borked session config !!!
780 // create at least one !!
781 if (KWrite::noWindows())
782 new KWrite();
784 return a.exec ();
788 KWriteEditorChooser::KWriteEditorChooser(QWidget *parent):
789 KDialog( parent )
791 setCaption( i18n("Choose Editor Component") );
792 setButtons( Ok | Cancel );
793 setDefaultButton(KDialog::Cancel);
794 m_chooser = new KTextEditor::EditorChooser(this);
795 resizeLayout(m_chooser, 0, spacingHint());
796 setMainWidget(m_chooser);
797 m_chooser->readAppSetting();
799 connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
802 KWriteEditorChooser::~KWriteEditorChooser()
806 void KWriteEditorChooser::slotOk()
808 m_chooser->writeAppSetting();
811 // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;