• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
kwritemain.cpp
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>
5 
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.
9 
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.
14 
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.
19 */
20 
21 #include "kwritemain.h"
22 #include "kwritemain.moc"
23 
24 #include <kate/document.h>
25 #include <kate/view.h>
26 
27 #include <tdetexteditor/configinterface.h>
28 #include <tdetexteditor/sessionconfiginterface.h>
29 #include <tdetexteditor/viewcursorinterface.h>
30 #include <tdetexteditor/printinterface.h>
31 #include <tdetexteditor/encodinginterface.h>
32 #include <tdetexteditor/editorchooser.h>
33 #include <tdetexteditor/popupmenuinterface.h>
34 
35 #include <tdeio/netaccess.h>
36 
37 #include <tdeversion.h>
38 #include <dcopclient.h>
39 #include <kurldrag.h>
40 #include <kencodingfiledialog.h>
41 #include <tdediroperator.h>
42 #include <kiconloader.h>
43 #include <tdeaboutdata.h>
44 #include <kstatusbar.h>
45 #include <kstdaction.h>
46 #include <tdeaction.h>
47 #include <kdebug.h>
48 #include <tdeglobal.h>
49 #include <tdeapplication.h>
50 #include <tdelocale.h>
51 #include <kurl.h>
52 #include <tdeconfig.h>
53 #include <tdecmdlineargs.h>
54 #include <tdemessagebox.h>
55 #include <kkeydialog.h>
56 #include <kedittoolbar.h>
57 #include <tdeparts/event.h>
58 #include <tdemenubar.h>
59 
60 #include <tqdropsite.h>
61 #include <tqdragobject.h>
62 #include <tqvbox.h>
63 #include <tqtextcodec.h>
64 #include <tqlayout.h>
65 
66 // StatusBar field IDs
67 #define KWRITE_ID_GEN 1
68 
69 TQPtrList<KTextEditor::Document> KWrite::docList;
70 TQPtrList<KWrite> KWrite::winList;
71 
72 KWrite::KWrite (KTextEditor::Document *doc)
73  : m_view(0),
74  m_recentFiles(0),
75  m_paShowPath(0),
76  m_paShowStatusBar(0)
77 {
78  if ( !doc )
79  {
80  if ( !(doc = KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document")) )
81  {
82  KMessageBox::error(this, i18n("A TDE text-editor component could not be found;\n"
83  "please check your TDE installation."));
84  kapp->exit(1);
85  }
86 
87  docList.append(doc);
88  }
89 
90  m_view = doc->createView (this, 0L);
91 
92  setCentralWidget(m_view);
93 
94  setupActions();
95  setupStatusBar();
96 
97  setAcceptDrops(true);
98 
99  connect(m_view,TQ_SIGNAL(newStatus()),this,TQ_SLOT(newCaption()));
100  connect(m_view,TQ_SIGNAL(viewStatusMsg(const TQString &)),this,TQ_SLOT(newStatus(const TQString &)));
101  connect(m_view->document(),TQ_SIGNAL(fileNameChanged()),this,TQ_SLOT(newCaption()));
102  connect(m_view->document(),TQ_SIGNAL(fileNameChanged()),this,TQ_SLOT(slotFileNameChanged()));
103  connect(m_view,TQ_SIGNAL(dropEventPass(TQDropEvent *)),this,TQ_SLOT(slotDropEvent(TQDropEvent *)));
104 
105  setXMLFile( "kwriteui.rc" );
106  createShellGUI( true );
107  guiFactory()->addClient( m_view );
108 
109  // install a working kate part popup dialog thingy
110  if (static_cast<Kate::View*>(m_view->tqt_cast("Kate::View")))
111  static_cast<Kate::View*>(m_view->tqt_cast("Kate::View"))->installPopup ((TQPopupMenu*)(factory()->container("tdetexteditor_popup", this)) );
112 
113  // init with more usefull size, stolen from konq :)
114  if (!initialGeometrySet())
115  resize( TQSize(700, 480).expandedTo(minimumSizeHint()));
116 
117  // call it as last thing, must be sure everything is already set up ;)
118  setAutoSaveSettings ();
119 
120  readConfig ();
121 
122  winList.append (this);
123 
124  show ();
125 }
126 
127 KWrite::~KWrite()
128 {
129  winList.remove (this);
130 
131  if (m_view->document()->views().count() == 1)
132  {
133  docList.remove(m_view->document());
134  delete m_view->document();
135  }
136 
137  kapp->config()->sync ();
138 }
139 
140 void KWrite::setupActions()
141 {
142  KStdAction::close( this, TQ_SLOT(slotFlush()), actionCollection(), "file_close" )->setWhatsThis(i18n("Use this to close the current document"));
143 
144  // setup File menu
145  KStdAction::print(this, TQ_SLOT(printDlg()), actionCollection())->setWhatsThis(i18n("Use this command to print the current document"));
146  KStdAction::openNew( this, TQ_SLOT(slotNew()), actionCollection(), "file_new" )->setWhatsThis(i18n("Use this command to create a new document"));
147  KStdAction::open( this, TQ_SLOT( slotOpen() ), actionCollection(), "file_open" )->setWhatsThis(i18n("Use this command to open an existing document for editing"));
148 
149  m_recentFiles = KStdAction::openRecent(this, TQ_SLOT(slotOpen(const KURL&)),
150  actionCollection());
151  m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
152 
153  TDEAction *a=new TDEAction(i18n("&New Window"), "window-new", 0, this, TQ_SLOT(newView()),
154  actionCollection(), "view_new_view");
155  a->setWhatsThis(i18n("Create another view containing the current document"));
156 
157  a=new TDEAction(i18n("Choose Editor Component..."),0,this,TQ_SLOT(changeEditor()),
158  actionCollection(),"settings_choose_editor");
159  a->setWhatsThis(i18n("Override the system wide setting for the default editing component"));
160 
161  KStdAction::quit(this, TQ_SLOT(close()), actionCollection())->setWhatsThis(i18n("Close the current document view"));
162 
163  // setup Settings menu
164  setStandardToolBarMenuEnabled(true);
165 
166  m_paShowStatusBar = KStdAction::showStatusbar(this, TQ_SLOT(toggleStatusBar()), actionCollection(), "settings_show_statusbar");
167  m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
168 
169  m_paShowPath = new TDEToggleAction(i18n("Sho&w Path"), 0, this, TQ_SLOT(newCaption()),
170  actionCollection(), "set_showPath");
171  m_paShowPath->setCheckedState(i18n("Hide Path"));
172  m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
173  a=KStdAction::keyBindings(this, TQ_SLOT(editKeys()), actionCollection());
174  a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
175 
176  a=KStdAction::configureToolbars(this, TQ_SLOT(editToolbars()), actionCollection());
177  a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
178 }
179 
180 void KWrite::setupStatusBar()
181 {
182  statusBar()->insertItem("", KWRITE_ID_GEN);
183 }
184 
185 // load on url
186 void KWrite::loadURL(const KURL &url)
187 {
188  m_view->document()->openURL(url);
189 }
190 
191 // is closing the window wanted by user ?
192 bool KWrite::queryClose()
193 {
194  if (m_view->document()->views().count() > 1)
195  return true;
196 
197  if (m_view->document()->queryClose())
198  {
199  writeConfig();
200 
201  return true;
202  }
203 
204  return false;
205 }
206 
207 void KWrite::changeEditor()
208 {
209  KWriteEditorChooser choose(this);
210  choose.exec();
211 }
212 
213 void KWrite::slotFlush ()
214 {
215  m_view->document()->closeURL();
216 }
217 
218 void KWrite::slotNew()
219 {
220  new KWrite();
221 }
222 
223 void KWrite::slotOpen()
224 {
225  if (KTextEditor::encodingInterface(m_view->document()))
226  {
227  KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenURLsAndEncoding(
228  KTextEditor::encodingInterface(m_view->document())->encoding(),
229  m_view->document()->url().url(),TQString::null,this,i18n("Open File"));
230 
231  for (KURL::List::Iterator i=r.URLs.begin(); i != r.URLs.end(); ++i)
232  {
233  encoding = r.encoding;
234  slotOpen ( *i );
235  }
236  }
237  else
238  {
239  KURL::List l=KFileDialog::getOpenURLs(m_view->document()->url().url(),TQString::null,this,TQString::null);
240  for (KURL::List::Iterator i=l.begin(); i != l.end(); ++i)
241  {
242  slotOpen ( *i );
243  }
244  }
245 }
246 
247 void KWrite::slotOpen( const KURL& url )
248 {
249  if (url.isEmpty()) return;
250 
251  if (!TDEIO::NetAccess::exists(url, true, this))
252  {
253  KMessageBox::error (this, i18n("The given file could not be read, check if it exists or if it is readable for the current user."));
254  return;
255  }
256 
257  if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
258  {
259  KWrite *t = new KWrite();
260  if (KTextEditor::encodingInterface(t->m_view->document())) KTextEditor::encodingInterface(t->m_view->document())->setEncoding(encoding);
261  t->loadURL(url);
262  }
263  else
264  {
265  if (KTextEditor::encodingInterface(m_view->document())) KTextEditor::encodingInterface(m_view->document())->setEncoding(encoding);
266  loadURL(url);
267  }
268 }
269 
270 void KWrite::slotFileNameChanged()
271 {
272  if ( ! m_view->document()->url().isEmpty() )
273  m_recentFiles->addURL( m_view->document()->url() );
274 }
275 
276 void KWrite::newView()
277 {
278  new KWrite(m_view->document());
279 }
280 
281 void KWrite::toggleStatusBar()
282 {
283  if( m_paShowStatusBar->isChecked() )
284  statusBar()->show();
285  else
286  statusBar()->hide();
287 }
288 
289 void KWrite::editKeys()
290 {
291  KKeyDialog dlg;
292  dlg.insert(actionCollection());
293  if( m_view )
294  dlg.insert(m_view->actionCollection());
295  dlg.configure();
296 }
297 
298 void KWrite::editToolbars()
299 {
300  saveMainWindowSettings( kapp->config(), "MainWindow" );
301  KEditToolbar *dlg = new KEditToolbar(guiFactory());
302  connect( dlg, TQ_SIGNAL(newToolbarConfig()), this, TQ_SLOT(slotNewToolbarConfig()) );
303  dlg->exec();
304  delete dlg;
305 }
306 
307 void KWrite::slotNewToolbarConfig()
308 {
309  applyMainWindowSettings( kapp->config(), "MainWindow" );
310 }
311 
312 
313 void KWrite::printNow()
314 {
315  KTextEditor::printInterface(m_view->document())->print ();
316 }
317 
318 void KWrite::printDlg()
319 {
320  KTextEditor::printInterface(m_view->document())->printDialog ();
321 }
322 
323 void KWrite::newStatus(const TQString &msg)
324 {
325  newCaption();
326 
327  statusBar()->changeItem(msg,KWRITE_ID_GEN);
328 }
329 
330 void KWrite::newCaption()
331 {
332  if (m_view->document()->url().isEmpty()) {
333  setCaption(i18n("Untitled"),m_view->document()->isModified());
334  }
335  else
336  {
337  TQString c;
338  if (!m_paShowPath->isChecked())
339  {
340  c = m_view->document()->url().fileName();
341 
342  //File name shouldn't be too long - Maciek
343  if (c.length() > 64)
344  c = c.left(64) + "...";
345  }
346  else
347  {
348  c = m_view->document()->url().prettyURL();
349 
350  //File name shouldn't be too long - Maciek
351  if (c.length() > 64)
352  c = "..." + c.right(64);
353  }
354 
355  setCaption (c, m_view->document()->isModified());
356  }
357 }
358 
359 void KWrite::dragEnterEvent( TQDragEnterEvent *event )
360 {
361  event->accept(KURLDrag::canDecode(event));
362 }
363 
364 void KWrite::dropEvent( TQDropEvent *event )
365 {
366  slotDropEvent(event);
367 }
368 
369 void KWrite::slotDropEvent( TQDropEvent *event )
370 {
371  KURL::List textlist;
372 
373  if (!KURLDrag::decode(event, textlist))
374  return;
375 
376  for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
377  slotOpen (*i);
378 }
379 
380 void KWrite::slotEnableActions( bool enable )
381 {
382  TQValueList<TDEAction *> actions = actionCollection()->actions();
383  TQValueList<TDEAction *>::ConstIterator it = actions.begin();
384  TQValueList<TDEAction *>::ConstIterator end = actions.end();
385 
386  for (; it != end; ++it )
387  (*it)->setEnabled( enable );
388 
389  actions = m_view->actionCollection()->actions();
390  it = actions.begin();
391  end = actions.end();
392 
393  for (; it != end; ++it )
394  (*it)->setEnabled( enable );
395 }
396 
397 //common config
398 void KWrite::readConfig(TDEConfig *config)
399 {
400  config->setGroup("General Options");
401 
402  m_paShowStatusBar->setChecked( config->readBoolEntry("ShowStatusBar") );
403  m_paShowPath->setChecked( config->readBoolEntry("ShowPath") );
404 
405  m_recentFiles->loadEntries(config, "Recent Files");
406 
407  if (m_view && KTextEditor::configInterface(m_view->document()))
408  KTextEditor::configInterface(m_view->document())->readConfig(config);
409 
410  if( m_paShowStatusBar->isChecked() )
411  statusBar()->show();
412  else
413  statusBar()->hide();
414 }
415 
416 void KWrite::writeConfig(TDEConfig *config)
417 {
418  config->setGroup("General Options");
419 
420  config->writeEntry("ShowStatusBar",m_paShowStatusBar->isChecked());
421  config->writeEntry("ShowPath",m_paShowPath->isChecked());
422 
423  m_recentFiles->saveEntries(config, "Recent Files");
424 
425  if (m_view && KTextEditor::configInterface(m_view->document()))
426  KTextEditor::configInterface(m_view->document())->writeConfig(config);
427 
428  config->sync ();
429 }
430 
431 //config file
432 void KWrite::readConfig()
433 {
434  TDEConfig *config = kapp->config();
435  readConfig(config);
436 }
437 
438 void KWrite::writeConfig()
439 {
440  TDEConfig *config = kapp->config();
441  writeConfig(config);
442 }
443 
444 // session management
445 void KWrite::restore(TDEConfig *config, int n)
446 {
447  readPropertiesInternal(config, n);
448 }
449 
450 void KWrite::readProperties(TDEConfig *config)
451 {
452  readConfig(config);
453 
454  if (KTextEditor::sessionConfigInterface(m_view))
455  KTextEditor::sessionConfigInterface(m_view)->readSessionConfig(config);
456 }
457 
458 void KWrite::saveProperties(TDEConfig *config)
459 {
460  writeConfig(config);
461  config->writeEntry("DocumentNumber",docList.find(m_view->document()) + 1);
462 
463  if (KTextEditor::sessionConfigInterface(m_view))
464  KTextEditor::sessionConfigInterface(m_view)->writeSessionConfig(config);
465 }
466 
467 void KWrite::saveGlobalProperties(TDEConfig *config) //save documents
468 {
469  config->setGroup("Number");
470  config->writeEntry("NumberOfDocuments",docList.count());
471 
472  for (uint z = 1; z <= docList.count(); z++)
473  {
474  TQString buf = TQString("Document %1").arg(z);
475  config->setGroup(buf);
476 
477  KTextEditor::Document *doc = docList.at(z - 1);
478 
479  if (KTextEditor::configInterface(doc))
480  KTextEditor::configInterface(doc)->writeSessionConfig(config);
481  }
482 
483  for (uint z = 1; z <= winList.count(); z++)
484  {
485  TQString buf = TQString("Window %1").arg(z);
486  config->setGroup(buf);
487 
488  config->writeEntry("DocumentNumber",docList.find(winList.at(z-1)->view()->document()) + 1);
489  }
490 }
491 
492 //restore session
493 void KWrite::restore()
494 {
495  TDEConfig *config = kapp->sessionConfig();
496 
497  if (!config)
498  return;
499 
500  int docs, windows;
501  TQString buf;
502  KTextEditor::Document *doc;
503  KWrite *t;
504 
505  config->setGroup("Number");
506  docs = config->readNumEntry("NumberOfDocuments");
507  windows = config->readNumEntry("NumberOfWindows");
508 
509  for (int z = 1; z <= docs; z++)
510  {
511  buf = TQString("Document %1").arg(z);
512  config->setGroup(buf);
513  doc=KTextEditor::EditorChooser::createDocument(0,"KTextEditor::Document");
514 
515  if (KTextEditor::configInterface(doc))
516  KTextEditor::configInterface(doc)->readSessionConfig(config);
517  docList.append(doc);
518  }
519 
520  for (int z = 1; z <= windows; z++)
521  {
522  buf = TQString("Window %1").arg(z);
523  config->setGroup(buf);
524  t = new KWrite(docList.at(config->readNumEntry("DocumentNumber") - 1));
525  t->restore(config,z);
526  }
527 }
528 
529 static TDECmdLineOptions options[] =
530 {
531  { "stdin", I18N_NOOP("Read the contents of stdin"), 0},
532  { "encoding <argument>", I18N_NOOP("Set encoding for the file to open"), 0 },
533  { "line <argument>", I18N_NOOP("Navigate to this line"), 0 },
534  { "column <argument>", I18N_NOOP("Navigate to this column"), 0 },
535  { "+[URL]", I18N_NOOP("Document to open"), 0 },
536  TDECmdLineLastOption
537 };
538 
539 extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
540 {
541  Kate::Document::setFileChangedDialogsActivated (true);
542 
543  TDELocale::setMainCatalogue("kate"); //lukas: set this to have the kwritepart translated using kate message catalog
544 
545  // here we go, construct the KWrite version
546  // TQString kWriteVersion = TQString ("%1.%2.%3").arg(KDE::versionMajor() + 1).arg(KDE::versionMinor()).arg(KDE::versionRelease());
550  TQString kWriteVersion = TQString ("4.5.%1").arg(KDE::versionMajor());
551 
552  TDEAboutData aboutData ( "kwrite",
553  I18N_NOOP("KWrite"),
554  kWriteVersion.latin1(),
555  I18N_NOOP( "KWrite - Text Editor" ), TDEAboutData::License_LGPL_V2,
556  I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0 );
557 
558  aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
559  aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
560  aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
561  aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
562  aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
563  aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
564  aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
565  aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
566  aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
567  aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
568  aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
569  aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
570  aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
571  aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
572  aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
573  aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
574 
575  aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
576  aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
577  aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
578  aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
579  aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
580  aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
581  aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
582  aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
583  aboutData.addCredit ("Daniel Naber","","");
584  aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
585  aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
586  aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
587  aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
588 
589  aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
590 
591  TDECmdLineArgs::init( argc, argv, &aboutData );
592  TDECmdLineArgs::addCmdLineOptions( options );
593 
594  TDEApplication a;
595 
596  TDEGlobal::locale()->insertCatalogue("katepart");
597 
598  DCOPClient *client = kapp->dcopClient();
599  if (!client->isRegistered())
600  {
601  client->attach();
602  client->registerAs("kwrite");
603  }
604 
605  TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
606 
607  if (kapp->isRestored())
608  {
609  KWrite::restore();
610  }
611  else
612  {
613  bool nav = false;
614  int line = 0, column = 0;
615 
616  TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0;
617 
618  if (args->isSet ("line"))
619  {
620  line = args->getOption ("line").toInt();
621  nav = true;
622  }
623 
624  if (args->isSet ("column"))
625  {
626  column = args->getOption ("column").toInt();
627  nav = true;
628  }
629 
630  if ( args->count() == 0 )
631  {
632  KWrite *t = new KWrite;
633 
634  if( args->isSet( "stdin" ) )
635  {
636  TQTextIStream input(stdin);
637 
638  // set chosen codec
639  if (codec)
640  input.setCodec (codec);
641 
642  TQString line;
643  TQString text;
644 
645  do
646  {
647  line = input.readLine();
648  text.append( line + "\n" );
649  } while( !line.isNull() );
650 
651 
652  KTextEditor::EditInterface *doc = KTextEditor::editInterface (t->view()->document());
653  if( doc )
654  doc->setText( text );
655  }
656 
657  if (nav && KTextEditor::viewCursorInterface(t->view()))
658  KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column);
659  }
660  else
661  {
662  for ( int z = 0; z < args->count(); z++ )
663  {
664  KWrite *t = new KWrite();
665 
666  // this file is no local dir, open it, else warn
667  bool noDir = !args->url(z).isLocalFile() || !TQDir (args->url(z).path()).exists();
668 
669  if (noDir)
670  {
671  if (Kate::document (t->view()->document()))
672  Kate::Document::setOpenErrorDialogsActivated (false);
673 
674  if (codec && KTextEditor::encodingInterface(t->view()->document()))
675  KTextEditor::encodingInterface(t->view()->document())->setEncoding(codec->name());
676 
677  t->loadURL( args->url( z ) );
678 
679  if (Kate::document (t->view()->document()))
680  Kate::Document::setOpenErrorDialogsActivated (true);
681 
682  if (nav && KTextEditor::viewCursorInterface(t->view()))
683  KTextEditor::viewCursorInterface(t->view())->setCursorPosition (line, column);
684  }
685  else
686  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()) );
687  }
688  }
689  }
690 
691  // no window there, uh, ohh, for example borked session config !!!
692  // create at least one !!
693  if (KWrite::noWindows())
694  new KWrite();
695 
696  return a.exec ();
697 }
698 
699 KWriteEditorChooser::KWriteEditorChooser(TQWidget *):
700  KDialogBase(KDialogBase::Plain,i18n("Choose Editor Component"),KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel)
701 {
702  (new TQVBoxLayout(plainPage()))->setAutoAdd(true);
703  m_chooser=new KTextEditor::EditorChooser(plainPage(),"Editor Chooser");
704  setMainWidget(m_chooser);
705  m_chooser->readAppSetting();
706 }
707 
708 KWriteEditorChooser::~KWriteEditorChooser() {
709 ;
710 }
711 
712 void KWriteEditorChooser::slotOk() {
713  m_chooser->writeAppSetting();
714  KDialogBase::slotOk();
715 }

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.9.1
This website is maintained by Timothy Pearson.