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>
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>
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
)
67 KTextEditor::Editor
*editor
= KTextEditor::EditorChooser::editor();
71 // TODO KDE 4.3 Replace ; with a .
72 KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\n"
73 "please check your KDE installation."));
78 editor
->setSimpleMode (true);
80 doc
= editor
->createDocument(0);
82 // enable the modified on disk warning dialogs if any
83 if (qobject_cast
<KTextEditor::ModificationInterface
*>(doc
))
84 qobject_cast
<KTextEditor::ModificationInterface
*>(doc
)->setModifiedOnDiskWarning (true);
89 m_view
= qobject_cast
<KTextEditor::View
*>(doc
->createView (this));
91 setCentralWidget(m_view
);
96 // signals for the statusbar
97 connect(m_view
, SIGNAL(cursorPositionChanged(KTextEditor::View
*, const KTextEditor::Cursor
&)), this, SLOT(cursorPositionChanged(KTextEditor::View
*)));
98 connect(m_view
, SIGNAL(viewModeChanged(KTextEditor::View
*)), this, SLOT(viewModeChanged(KTextEditor::View
*)));
99 connect(m_view
, SIGNAL(selectionChanged (KTextEditor::View
*)), this, SLOT(selectionChanged (KTextEditor::View
*)));
100 connect(m_view
, SIGNAL(informationMessage (KTextEditor::View
*, const QString
&)), this, SLOT(informationMessage (KTextEditor::View
*, const QString
&)));
101 connect(m_view
->document(), SIGNAL(modifiedChanged(KTextEditor::Document
*)), this, SLOT(modifiedChanged()));
102 connect(m_view
->document(), SIGNAL(modifiedOnDisk(KTextEditor::Document
*, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason
)), this, SLOT(modifiedChanged()) );
103 connect(m_view
->document(), SIGNAL(documentNameChanged(KTextEditor::Document
*)), this, SLOT(documentNameChanged()));
104 connect(m_view
->document(),SIGNAL(documentUrlChanged(KTextEditor::Document
*)), this, SLOT(urlChanged()));
105 connect(m_view
->document(), SIGNAL(modeChanged(KTextEditor::Document
*)), this, SLOT(modeChanged(KTextEditor::Document
*)));
107 setAcceptDrops(true);
108 connect(m_view
,SIGNAL(dropEventPass(QDropEvent
*)),this,SLOT(slotDropEvent(QDropEvent
*)));
110 setXMLFile( "kwriteui.rc" );
111 createShellGUI( true );
112 guiFactory()->addClient( m_view
);
114 // install a working kate part popup dialog thingy
115 m_view
->setContextMenu ((QMenu
*)(factory()->container("ktexteditor_popup", this)) );
117 // init with more useful size, stolen from konq :)
118 if (!initialGeometrySet())
119 resize( QSize(700, 480).expandedTo(minimumSizeHint()));
121 // call it as last thing, must be sure everything is already set up ;)
122 setAutoSaveSettings ();
126 winList
.append (this);
132 m_view
->setFocus (Qt::OtherFocusReason
);
137 winList
.removeAll(this);
139 if (m_view
->document()->views().count() == 1)
141 docList
.removeAll(m_view
->document());
142 delete m_view
->document();
145 KGlobal::config()->sync ();
148 void KWrite::setupActions()
150 // TODO KDE 4.3 change to "Use this command to close the current document" to be in flow with the
152 actionCollection()->addAction( KStandardAction::Close
, "file_close", this, SLOT(slotFlush()) )
153 ->setWhatsThis(i18n("Use this to close the current document"));
156 actionCollection()->addAction( KStandardAction::New
, "file_new", this, SLOT(slotNew()) )
157 ->setWhatsThis(i18n("Use this command to create a new document"));
158 actionCollection()->addAction( KStandardAction::Open
, "file_open", this, SLOT(slotOpen()) )
159 ->setWhatsThis(i18n("Use this command to open an existing document for editing"));
161 m_recentFiles
= KStandardAction::openRecent(this, SLOT(slotOpen(const KUrl
&)), this);
162 actionCollection()->addAction(m_recentFiles
->objectName(), m_recentFiles
);
163 m_recentFiles
->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
165 QAction
*a
= actionCollection()->addAction( "view_new_view" );
166 a
->setIcon( KIcon("window-new") );
167 a
->setText( i18n("&New Window") );
168 connect( a
, SIGNAL(triggered()), this, SLOT(newView()) );
169 a
->setWhatsThis(i18n("Create another view containing the current document"));
171 actionCollection()->addAction( KStandardAction::Quit
, this, SLOT(close()) )
172 ->setWhatsThis(i18n("Close the current document view"));
174 // setup Settings menu
175 setStandardToolBarMenuEnabled(true);
177 m_paShowStatusBar
= KStandardAction::showStatusbar(this, SLOT(toggleStatusBar()), this);
178 actionCollection()->addAction( "settings_show_statusbar", m_paShowStatusBar
);
179 m_paShowStatusBar
->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
181 m_paShowPath
= new KToggleAction( i18n("Sho&w Path"), this );
182 actionCollection()->addAction( "set_showPath", m_paShowPath
);
183 connect( m_paShowPath
, SIGNAL(triggered()), this, SLOT(documentNameChanged()) );
184 m_paShowPath
->setWhatsThis(i18n("Show the complete document path in the window caption"));
186 a
= actionCollection()->addAction( KStandardAction::KeyBindings
, this, SLOT(editKeys()) );
187 a
->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
189 a
= actionCollection()->addAction( KStandardAction::ConfigureToolbars
, "options_configure_toolbars",
190 this, SLOT(editToolbars()) );
191 a
->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
193 a
= actionCollection()->addAction( "help_about_editor" );
194 a
->setText( i18n("&About Editor Component") );
195 connect( a
, SIGNAL(triggered()), this, SLOT(aboutEditor()) );
199 void KWrite::setupStatusBar()
202 m_lineColLabel
= new QLabel( statusBar() );
203 statusBar()->addWidget( m_lineColLabel
, 0 );
204 m_lineColLabel
->setAlignment( Qt::AlignCenter
);
206 m_modifiedLabel
= new QLabel( statusBar() );
207 m_modifiedLabel
->setFixedSize( 16, 16 );
208 statusBar()->addWidget( m_modifiedLabel
, 0 );
209 m_modifiedLabel
->setAlignment( Qt::AlignCenter
);
211 m_insertModeLabel
= new QLabel( i18n(" INS "), statusBar() );
212 statusBar()->addWidget( m_insertModeLabel
, 0 );
213 m_insertModeLabel
->setAlignment( Qt::AlignCenter
);
215 m_selectModeLabel
= new QLabel( i18nc("@info:status Statusbar label for line selection mode", " LINE "), statusBar() );
216 statusBar()->addWidget( m_selectModeLabel
, 0 );
217 m_selectModeLabel
->setAlignment( Qt::AlignCenter
);
219 m_modeLabel
= new QLabel( QString(), statusBar() );
220 statusBar()->addWidget( m_modeLabel
, 0 );
221 m_modeLabel
->setAlignment( Qt::AlignCenter
);
223 m_fileNameLabel
=new KSqueezedTextLabel( statusBar() );
224 statusBar()->addPermanentWidget( m_fileNameLabel
, 1 );
225 m_fileNameLabel
->setMinimumSize( 0, 0 );
226 m_fileNameLabel
->setSizePolicy(QSizePolicy( QSizePolicy::Ignored
, QSizePolicy::Fixed
));
227 m_fileNameLabel
->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft
);
229 // m_modDiscPm = KIcon("drive-harddisk").pixmap(16);
230 // m_modmodPm = KIcon("modmod").pixmap(16); // is it still required? icon is broken.
234 void KWrite::loadURL(const KUrl
&url
)
236 m_view
->document()->openUrl(url
);
239 // is closing the window wanted by user ?
240 bool KWrite::queryClose()
242 if (m_view
->document()->views().count() > 1)
245 if (m_view
->document()->queryClose())
255 void KWrite::slotFlush ()
257 m_view
->document()->closeUrl();
260 void KWrite::slotNew()
265 void KWrite::slotOpen()
267 const KEncodingFileDialog::Result r
=KEncodingFileDialog::getOpenUrlsAndEncoding(m_view
->document()->encoding(), m_view
->document()->url().url(),QString(),this,i18n("Open File"));
269 for (KUrl::List::ConstIterator i
=r
.URLs
.constBegin(); i
!= r
.URLs
.constEnd(); ++i
)
271 encoding
= r
.encoding
;
276 void KWrite::slotOpen( const KUrl
& url
)
278 if (url
.isEmpty()) return;
280 if (!KIO::NetAccess::exists(url
, KIO::NetAccess::SourceSide
, this))
282 KMessageBox::error (this, i18n("The file given could not be read; check whether it exists or is readable for the current user."));
286 if (m_view
->document()->isModified() || !m_view
->document()->url().isEmpty())
288 KWrite
*t
= new KWrite();
289 t
->m_view
->document()->setEncoding(encoding
);
294 m_view
->document()->setEncoding(encoding
);
299 void KWrite::urlChanged()
301 if ( ! m_view
->document()->url().isEmpty() )
302 m_recentFiles
->addUrl( m_view
->document()->url() );
305 void KWrite::newView()
307 new KWrite(m_view
->document());
310 void KWrite::toggleStatusBar()
312 if( m_paShowStatusBar
->isChecked() )
318 void KWrite::editKeys()
320 KShortcutsDialog
dlg(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
321 dlg
.addCollection(actionCollection());
323 dlg
.addCollection(m_view
->actionCollection());
327 void KWrite::editToolbars()
329 saveMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );
330 KEditToolBar
dlg(guiFactory(), this);
332 connect( &dlg
, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()) );
336 void KWrite::slotNewToolbarConfig()
338 applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );
341 void KWrite::dragEnterEvent( QDragEnterEvent
*event
)
343 KUrl::List uriList
= KUrl::List::fromMimeData( event
->mimeData() );
344 if(!uriList
.isEmpty())
348 void KWrite::dropEvent( QDropEvent
*event
)
350 slotDropEvent(event
);
353 void KWrite::slotDropEvent( QDropEvent
*event
)
355 const KUrl::List textlist
= KUrl::List::fromMimeData( event
->mimeData() );
357 if (textlist
.isEmpty())
360 for (KUrl::List::ConstIterator i
=textlist
.constBegin(); i
!= textlist
.constEnd(); ++i
)
364 void KWrite::slotEnableActions( bool enable
)
366 QList
<QAction
*> actions
= actionCollection()->actions();
367 QList
<QAction
*>::ConstIterator it
= actions
.constBegin();
368 QList
<QAction
*>::ConstIterator end
= actions
.constEnd();
370 for (; it
!= end
; ++it
)
371 (*it
)->setEnabled( enable
);
373 actions
= m_view
->actionCollection()->actions();
374 it
= actions
.constBegin();
375 end
= actions
.constEnd();
377 for (; it
!= end
; ++it
)
378 (*it
)->setEnabled( enable
);
382 void KWrite::readConfig(KSharedConfigPtr config
)
384 KConfigGroup
cfg( config
, "General Options");
386 m_paShowStatusBar
->setChecked( cfg
.readEntry("ShowStatusBar", true) );
387 m_paShowPath
->setChecked( cfg
.readEntry("ShowPath", false) );
389 m_recentFiles
->loadEntries( config
->group( "Recent Files" ));
391 m_view
->document()->editor()->readConfig(config
.data());
393 if( m_paShowStatusBar
->isChecked() )
399 void KWrite::writeConfig(KSharedConfigPtr config
)
401 KConfigGroup
generalOptions( config
, "General Options");
403 generalOptions
.writeEntry("ShowStatusBar",m_paShowStatusBar
->isChecked());
404 generalOptions
.writeEntry("ShowPath",m_paShowPath
->isChecked());
406 m_recentFiles
->saveEntries(KConfigGroup(config
, "Recent Files"));
408 // Writes into its own group
409 m_view
->document()->editor()->writeConfig(config
.data());
415 void KWrite::readConfig()
417 readConfig(KGlobal::config());
420 void KWrite::writeConfig()
422 writeConfig(KGlobal::config());
425 // session management
426 void KWrite::restore(KConfig
*config
, int n
)
428 readPropertiesInternal(config
, n
);
431 void KWrite::readProperties(KSharedConfigPtr config
)
435 if (KTextEditor::SessionConfigInterface
*iface
= qobject_cast
<KTextEditor::SessionConfigInterface
*>(m_view
))
436 iface
->readSessionConfig(KConfigGroup(config
, "General Options"));
439 void KWrite::saveProperties(KSharedConfigPtr config
)
443 KConfigGroup
group(config
, QString());
444 group
.writeEntry("DocumentNumber",docList
.indexOf(m_view
->document()) + 1);
446 if (KTextEditor::SessionConfigInterface
*iface
= qobject_cast
<KTextEditor::SessionConfigInterface
*>(m_view
)) {
447 KConfigGroup
cg( config
, "General Options" );
448 iface
->writeSessionConfig(cg
);
452 void KWrite::saveGlobalProperties(KConfig
*config
) //save documents
454 config
->group("Number").writeEntry("NumberOfDocuments",docList
.count());
456 for (int z
= 1; z
<= docList
.count(); z
++)
458 QString buf
= QString("Document %1").arg(z
);
459 KConfigGroup
cg( config
, buf
);
460 KTextEditor::Document
*doc
= docList
.at(z
- 1);
462 if (KTextEditor::SessionConfigInterface
*iface
= qobject_cast
<KTextEditor::SessionConfigInterface
*>(doc
))
463 iface
->writeSessionConfig(cg
);
466 for (int z
= 1; z
<= winList
.count(); z
++)
468 QString buf
= QString("Window %1").arg(z
);
469 KConfigGroup
cg( config
, buf
);
470 cg
.writeEntry("DocumentNumber",docList
.indexOf(winList
.at(z
-1)->view()->document()) + 1);
475 void KWrite::restore()
477 KConfig
*config
= kapp
->sessionConfig();
482 KTextEditor::Editor
*editor
= KTextEditor::EditorChooser::editor();
486 // TODO KDE 4.3 Replace ; with a .
487 KMessageBox::error(0, i18n("A KDE text-editor component could not be found;\n"
488 "please check your KDE installation."));
493 editor
->setSimpleMode (true);
497 KTextEditor::Document
*doc
;
500 KConfigGroup
numberConfig(config
, "Number");
501 docs
= numberConfig
.readEntry("NumberOfDocuments", 0);
502 windows
= numberConfig
.readEntry("NumberOfWindows", 0);
504 for (int z
= 1; z
<= docs
; z
++)
506 buf
= QString("Document %1").arg(z
);
507 KConfigGroup
cg(config
, buf
);
508 doc
=editor
->createDocument(0);
510 if (KTextEditor::SessionConfigInterface
*iface
= qobject_cast
<KTextEditor::SessionConfigInterface
*>(doc
))
511 iface
->readSessionConfig(cg
);
515 for (int z
= 1; z
<= windows
; z
++)
517 buf
= QString("Window %1").arg(z
);
518 KConfigGroup
cg(config
, buf
);
519 t
= new KWrite(docList
.at(cg
.readEntry("DocumentNumber", 0) - 1));
520 t
->restore(config
,z
);
524 void KWrite::aboutEditor()
526 KAboutApplicationDialog
dlg(m_view
->document()->editor()->aboutData(), this);
530 void KWrite::updateStatus ()
532 viewModeChanged (m_view
);
533 cursorPositionChanged (m_view
);
534 selectionChanged (m_view
);
536 documentNameChanged ();
537 modeChanged (m_view
->document());
540 void KWrite::viewModeChanged ( KTextEditor::View
*view
)
542 m_insertModeLabel
->setText( view
->viewMode() );
545 void KWrite::cursorPositionChanged ( KTextEditor::View
*view
)
547 KTextEditor::Cursor
position (view
->cursorPositionVirtual());
549 m_lineColLabel
->setText(
550 i18nc("@info:status Statusbar label for cursor line and column position",
551 " Line: %1 Col: %2 ", position
.line()+1, position
.column()+1) ) ;
554 void KWrite::selectionChanged (KTextEditor::View
*view
)
556 m_selectModeLabel
->setText(
557 view
->blockSelection() ? i18nc("@info:status Statusbar label for block selection mode", " BLOCK ") :
558 i18nc("@info:status Statusbar label for line selection mode", " LINE ") );
561 void KWrite::informationMessage (KTextEditor::View
*view
, const QString
&message
)
565 m_fileNameLabel
->setText( message
);
567 // timer to reset this after 4 seconds
568 QTimer::singleShot(4000, this, SLOT(documentNameChanged()));
571 void KWrite::modifiedChanged()
573 bool mod
= m_view
->document()->isModified();
575 if (mod
&& m_modPm
.isNull()) {
576 m_modPm
= KIcon("document-properties").pixmap(16);
579 /* const KateDocumentInfo *info
580 = KateDocManager::self()->documentInfo ( m_view->document() );
582 // bool modOnHD = false; //info && info->modifiedOnDisc;
584 m_modifiedLabel
->setPixmap(
585 mod
? m_modPm
: QPixmap()
594 documentNameChanged(); // update the modified flag in window title
597 void KWrite::documentNameChanged ()
599 m_fileNameLabel
->setText( KStringHandler::lsqueeze(m_view
->document()->documentName (), 64) );
601 if (m_view
->document()->url().isEmpty()) {
602 setCaption(i18n("Untitled"),m_view
->document()->isModified());
607 if (!m_paShowPath
->isChecked())
609 c
= m_view
->document()->url().fileName();
611 //File name shouldn't be too long - Maciek
613 c
= c
.left(64) + "...";
617 c
= m_view
->document()->url().prettyUrl();
619 //File name shouldn't be too long - Maciek
621 c
= "..." + c
.right(64);
624 setCaption (c
, m_view
->document()->isModified());
628 void KWrite::modeChanged ( KTextEditor::Document
*document
)
630 m_modeLabel
->setText (document
->mode());
633 extern "C" KDE_EXPORT
int kdemain(int argc
, char **argv
)
635 KAboutData
aboutData ( "kwrite", 0,
638 ki18n( "KWrite - Text Editor" ), KAboutData::License_LGPL_V2
,
639 ki18n( "(c) 2000-2005 The Kate Authors" ), KLocalizedString(), "http://www.kate-editor.org" );
640 aboutData
.addAuthor (ki18n("Christoph Cullmann"), ki18n("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
641 aboutData
.addAuthor (ki18n("Anders Lund"), ki18n("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
642 aboutData
.addAuthor (ki18n("Joseph Wenninger"), ki18n("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
643 aboutData
.addAuthor (ki18n("Hamish Rodda"),ki18n("Core Developer"), "rodda@kde.org");
644 aboutData
.addAuthor (ki18n("Dominik Haumann"), ki18n("Developer & Highlight wizard"), "dhdev@gmx.de");
645 aboutData
.addAuthor (ki18n("Waldo Bastian"), ki18n( "The cool buffersystem" ), "bastian@kde.org" );
646 aboutData
.addAuthor (ki18n("Charles Samuels"), ki18n("The Editing Commands"), "charles@kde.org");
647 aboutData
.addAuthor (ki18n("Matt Newell"), ki18nc("Credit text for someone that did testing and some other similar things", "Testing, ..."), "newellm@proaxis.com");
648 aboutData
.addAuthor (ki18n("Michael Bartl"), ki18n("Former Core Developer"), "michael.bartl1@chello.at");
649 aboutData
.addAuthor (ki18n("Michael McCallum"), ki18n("Core Developer"), "gholam@xtra.co.nz");
650 aboutData
.addAuthor (ki18n("Jochen Wilhemly"), ki18n( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
651 aboutData
.addAuthor (ki18n("Michael Koch"),ki18n("KWrite port to KParts"), "koch@kde.org");
652 aboutData
.addAuthor (ki18n("Christian Gebauer"), KLocalizedString(), "gebauer@kde.org" );
653 aboutData
.addAuthor (ki18n("Simon Hausmann"), KLocalizedString(), "hausmann@kde.org" );
654 aboutData
.addAuthor (ki18n("Glen Parker"),ki18n("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
655 aboutData
.addAuthor (ki18n("Scott Manson"),ki18n("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
656 aboutData
.addAuthor (ki18n("John Firebaugh"),ki18n("Patches and more"), "jfirebaugh@kde.org");
658 aboutData
.addCredit (ki18n("Matteo Merli"),ki18n("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
659 aboutData
.addCredit (ki18n("Rocky Scaletta"),ki18n("Highlighting for VHDL"), "rocky@purdue.edu");
660 aboutData
.addCredit (ki18n("Yury Lebedev"),ki18n("Highlighting for SQL"));
661 aboutData
.addCredit (ki18n("Chris Ross"),ki18n("Highlighting for Ferite"));
662 aboutData
.addCredit (ki18n("Nick Roux"),ki18n("Highlighting for ILERPG"));
663 aboutData
.addCredit (ki18n("Carsten Niehaus"), ki18n("Highlighting for LaTeX"));
664 aboutData
.addCredit (ki18n("Per Wigren"), ki18n("Highlighting for Makefiles, Python"));
665 aboutData
.addCredit (ki18n("Jan Fritz"), ki18n("Highlighting for Python"));
666 aboutData
.addCredit (ki18n("Daniel Naber"));
667 aboutData
.addCredit (ki18n("Roland Pabel"),ki18n("Highlighting for Scheme"));
668 aboutData
.addCredit (ki18n("Cristi Dumitrescu"),ki18n("PHP Keyword/Datatype list"));
669 aboutData
.addCredit (ki18n("Carsten Pfeiffer"), ki18nc("Credit text for someone that helped a lot", "Very nice help"));
670 aboutData
.addCredit (ki18n("All people who have contributed and I have forgotten to mention"));
672 aboutData
.setProgramIconName ("accessories-text-editor");
674 KCmdLineArgs::init( argc
, argv
, &aboutData
);
676 KCmdLineOptions options
;
677 options
.add("stdin", ki18n("Read the contents of stdin"));
678 options
.add("encoding <argument>", ki18n("Set encoding for the file to open"));
679 options
.add("line <argument>", ki18n("Navigate to this line"));
680 options
.add("column <argument>", ki18n("Navigate to this column"));
681 options
.add("+[URL]", ki18n("Document to open"));
682 KCmdLineArgs::addCmdLineOptions( options
);
686 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
688 if (a
.isSessionRestored())
695 int line
= 0, column
= 0;
697 QTextCodec
*codec
= args
->isSet("encoding") ? QTextCodec::codecForName(args
->getOption("encoding").toLocal8Bit()) : 0;
699 if (args
->isSet ("line"))
701 line
= args
->getOption ("line").toInt() - 1;
705 if (args
->isSet ("column"))
707 column
= args
->getOption ("column").toInt() - 1;
711 if ( args
->count() == 0 )
713 KWrite
*t
= new KWrite
;
715 if( args
->isSet( "stdin" ) )
717 QTextStream
input(stdin
, QIODevice::ReadOnly
);
721 input
.setCodec (codec
);
728 line
= input
.readLine();
729 text
.append( line
+ '\n' );
730 } while( !line
.isNull() );
733 KTextEditor::Document
*doc
= t
->view()->document();
735 doc
->setText( text
);
738 if (nav
&& t
->view())
739 t
->view()->setCursorPosition (KTextEditor::Cursor (line
, column
));
744 for ( int z
= 0; z
< args
->count(); z
++ )
746 // this file is no local dir, open it, else warn
747 bool noDir
= !args
->url(z
).isLocalFile() || !QDir (args
->url(z
).path()).exists();
752 KWrite
*t
= new KWrite();
754 t
->view()->document()->setSuppressOpeningErrorDialogs (true);
757 t
->view()->document()->setEncoding(codec
->name());
759 t
->loadURL( args
->url( z
) );
761 t
->view()->document()->setSuppressOpeningErrorDialogs (false);
764 t
->view()->setCursorPosition (KTextEditor::Cursor (line
, column
));
768 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()));
771 if (!docs_opened
) return 1; // see http://bugs.kde.org/show_bug.cgi?id=124708
775 // no window there, uh, ohh, for example borked session config !!!
776 // create at least one !!
777 if (KWrite::noWindows())
784 KWriteEditorChooser::KWriteEditorChooser(QWidget
*parent
):
787 setCaption( i18n("Choose Editor Component") );
788 setButtons( Ok
| Cancel
);
789 setDefaultButton(KDialog::Cancel
);
790 m_chooser
= new KTextEditor::EditorChooser(this);
791 resizeLayout(m_chooser
, 0, spacingHint());
792 setMainWidget(m_chooser
);
793 m_chooser
->readAppSetting();
795 connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
798 KWriteEditorChooser::~KWriteEditorChooser()
802 void KWriteEditorChooser::slotOk()
804 m_chooser
->writeAppSetting();
807 // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;