Changeset View
Changeset View
Standalone View
Standalone View
addons/konsole/kateconsole.cpp
Context not available. | |||||
24 | #include <klocalizedstring.h> | 24 | #include <klocalizedstring.h> | ||
---|---|---|---|---|---|
25 | #include <ktexteditor/document.h> | 25 | #include <ktexteditor/document.h> | ||
26 | #include <ktexteditor/view.h> | 26 | #include <ktexteditor/view.h> | ||
27 | #include <ktexteditor/message.h> | ||||
27 | 28 | | |||
28 | #include <kde_terminal_interface.h> | 29 | #include <kde_terminal_interface.h> | ||
29 | #include <kshell.h> | 30 | #include <kshell.h> | ||
Context not available. | |||||
39 | #include <QShowEvent> | 40 | #include <QShowEvent> | ||
40 | #include <QLabel> | 41 | #include <QLabel> | ||
41 | #include <QCheckBox> | 42 | #include <QCheckBox> | ||
43 | #include <QGroupBox> | ||||
44 | #include <QLineEdit> | ||||
45 | #include <QPushButton> | ||||
42 | #include <QVBoxLayout> | 46 | #include <QVBoxLayout> | ||
43 | #include <QFileInfo> | 47 | #include <QFileInfo> | ||
44 | 48 | | |||
Context not available. | |||||
136 | a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_sync")); | 140 | a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_sync")); | ||
137 | a->setText(i18nc("@action", "S&ynchronize Terminal with Current Document")); | 141 | a->setText(i18nc("@action", "S&ynchronize Terminal with Current Document")); | ||
138 | connect(a, SIGNAL(triggered()), this, SLOT(slotManualSync())); | 142 | connect(a, SIGNAL(triggered()), this, SLOT(slotManualSync())); | ||
143 | | ||||
144 | a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_run")); | ||||
145 | a->setText(i18nc("@action", "Run Current Document")); | ||||
146 | connect(a, SIGNAL(triggered()), this, SLOT(slotRun())); | ||||
139 | 147 | | |||
140 | a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_toggle_focus")); | 148 | a = actionCollection()->addAction(QStringLiteral("katekonsole_tools_toggle_focus")); | ||
141 | a->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); | 149 | a->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); | ||
Context not available. | |||||
293 | if ( ! m_part || ! m_part->widget()->isVisible() ) | 301 | if ( ! m_part || ! m_part->widget()->isVisible() ) | ||
294 | m_mw->showToolView( parentWidget() ); | 302 | m_mw->showToolView( parentWidget() ); | ||
295 | } | 303 | } | ||
304 | | ||||
305 | void KateConsole::slotRun() | ||||
306 | { | ||||
307 | if ( m_mw->activeView() ) { | ||||
308 | KTextEditor::Document *document = m_mw->activeView()->document(); | ||||
309 | QUrl u = document->url(); | ||||
310 | if (! u.isValid()) { | ||||
311 | KMessageBox::sorry(0, i18n ("Invalid document URL")); | ||||
312 | return; | ||||
313 | } | ||||
314 | if (! u.isLocalFile() ) { | ||||
315 | QPointer<KTextEditor::Message> message = | ||||
316 | new KTextEditor::Message( | ||||
317 | i18n("Not a local file: '%1'", u.path() ), KTextEditor::Message::Error); | ||||
318 | // auto hide is enabled and set to a sane default value of several seconds. | ||||
319 | message->setAutoHide(0); | ||||
320 | document->postMessage(message); | ||||
321 | return; | ||||
322 | } | ||||
323 | // ensure that file is saved | ||||
324 | if (document->isModified() ) { | ||||
325 | document->save(); | ||||
326 | } | ||||
327 | | ||||
328 | // The string that should be output to terminal, upon acceptance | ||||
329 | QString output_str; | ||||
330 | // prefix first | ||||
331 | output_str += KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("RunPrefix", ""); | ||||
332 | // then filename | ||||
333 | if ( KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("RemoveExtension", true) ) { | ||||
334 | // append filename without extension (i.e. keep only the basename) | ||||
335 | output_str += QFileInfo( u.path() ).baseName() + QLatin1Char('\n'); | ||||
336 | } else { | ||||
337 | // append filename to the terminal | ||||
338 | output_str += QFileInfo( u.path() ).fileName() + QLatin1Char('\n'); | ||||
339 | } | ||||
340 | | ||||
341 | if (KMessageBox::Continue != | ||||
342 | KMessageBox::warningContinueCancel( | ||||
343 | m_mw->window(), | ||||
344 | i18n ("Do you really want to Run the document ?\n" | ||||
345 | "This will execute the following command,\n" | ||||
346 | "with your user rights, in the terminal:\n'%1'", output_str), | ||||
347 | i18n ("Run in Terminal?"), | ||||
348 | KGuiItem(i18n("Run")), | ||||
349 | KStandardGuiItem::cancel(), | ||||
350 | QStringLiteral("Konsole: Run in Terminal Warning")) | ||||
351 | ) { | ||||
352 | return; | ||||
353 | } | ||||
354 | // echo to terminal | ||||
355 | sendInput( output_str ); | ||||
356 | } | ||||
357 | } | ||||
358 | | ||||
296 | void KateConsole::slotToggleFocus() | 359 | void KateConsole::slotToggleFocus() | ||
297 | { | 360 | { | ||
298 | QAction *action = actionCollection()->action(QStringLiteral("katekonsole_tools_toggle_focus")); | 361 | QAction *action = actionCollection()->action(QStringLiteral("katekonsole_tools_toggle_focus")); | ||
Context not available. | |||||
340 | 403 | | |||
341 | cbAutoSyncronize = new QCheckBox( i18n("&Automatically synchronize the terminal with the current document when possible"), this ); | 404 | cbAutoSyncronize = new QCheckBox( i18n("&Automatically synchronize the terminal with the current document when possible"), this ); | ||
342 | lo->addWidget( cbAutoSyncronize ); | 405 | lo->addWidget( cbAutoSyncronize ); | ||
406 | | ||||
407 | QVBoxLayout *vboxRun = new QVBoxLayout; | ||||
408 | QGroupBox *groupRun = new QGroupBox( i18n("Run in terminal"), this ); | ||||
409 | // Remove extension | ||||
410 | cbRemoveExtension = new QCheckBox( i18n("&Remove extension"), this ); | ||||
411 | vboxRun->addWidget( cbRemoveExtension ); | ||||
412 | // Prefix | ||||
413 | QFrame *framePrefix = new QFrame( this ); | ||||
414 | QHBoxLayout *hboxPrefix = new QHBoxLayout( framePrefix ); | ||||
415 | QLabel *label = new QLabel( i18n("Prefix:"), framePrefix ); | ||||
416 | hboxPrefix->addWidget( label ); | ||||
417 | lePrefix = new QLineEdit( framePrefix ); | ||||
418 | hboxPrefix->addWidget( lePrefix ); | ||||
419 | vboxRun->addWidget( framePrefix ); | ||||
420 | // show warning next time | ||||
421 | QFrame *frameWarn = new QFrame( this ); | ||||
422 | QHBoxLayout *hboxWarn = new QHBoxLayout( frameWarn ); | ||||
423 | QPushButton *buttonWarn = new QPushButton( i18n("&Show warning next time"), frameWarn); | ||||
424 | buttonWarn->setWhatsThis ( | ||||
425 | i18n ( "The next time '%1' is executed, " | ||||
426 | "make sure a warning window will pop up, " | ||||
427 | "displaying the command to be sent to terminal, " | ||||
428 | "for review.", | ||||
429 | i18n ("Run in terminal") | ||||
430 | ) | ||||
431 | ); | ||||
432 | connect( buttonWarn, &QPushButton::pressed, | ||||
433 | this, &KateKonsoleConfigPage::slotEnableRunWarning ); | ||||
434 | hboxWarn->addWidget( buttonWarn ); | ||||
435 | vboxRun->addWidget( frameWarn ); | ||||
436 | groupRun->setLayout( vboxRun ); | ||||
437 | lo->addWidget( groupRun ); | ||||
438 | | ||||
343 | cbSetEditor = new QCheckBox( i18n("Set &EDITOR environment variable to 'kate -b'"), this ); | 439 | cbSetEditor = new QCheckBox( i18n("Set &EDITOR environment variable to 'kate -b'"), this ); | ||
344 | lo->addWidget( cbSetEditor ); | 440 | lo->addWidget( cbSetEditor ); | ||
345 | QLabel *tmp = new QLabel(this); | 441 | QLabel *tmp = new QLabel(this); | ||
Context not available. | |||||
348 | reset(); | 444 | reset(); | ||
349 | lo->addStretch(); | 445 | lo->addStretch(); | ||
350 | connect( cbAutoSyncronize, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); | 446 | connect( cbAutoSyncronize, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); | ||
447 | connect( cbRemoveExtension, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); | ||||
448 | connect( lePrefix, &QLineEdit::textChanged, | ||||
449 | this, &KateKonsoleConfigPage::changed ); | ||||
351 | connect( cbSetEditor, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); | 450 | connect( cbSetEditor, SIGNAL(stateChanged(int)), SIGNAL(changed()) ); | ||
352 | } | 451 | } | ||
353 | 452 | | |||
453 | void KateKonsoleConfigPage::slotEnableRunWarning () | ||||
454 | { | ||||
455 | KMessageBox::enableMessage(QStringLiteral("Konsole: Run in Terminal Warning")); | ||||
456 | } | ||||
457 | | ||||
458 | | ||||
354 | QString KateKonsoleConfigPage::name() const | 459 | QString KateKonsoleConfigPage::name() const | ||
355 | { | 460 | { | ||
356 | return i18n("Terminal"); | 461 | return i18n("Terminal"); | ||
Context not available. | |||||
370 | { | 475 | { | ||
371 | KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); | 476 | KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); | ||
372 | config.writeEntry("AutoSyncronize", cbAutoSyncronize->isChecked()); | 477 | config.writeEntry("AutoSyncronize", cbAutoSyncronize->isChecked()); | ||
478 | config.writeEntry("RemoveExtension", cbRemoveExtension->isChecked()); | ||||
479 | config.writeEntry("RunPrefix", lePrefix->text()); | ||||
373 | config.writeEntry("SetEditor", cbSetEditor->isChecked()); | 480 | config.writeEntry("SetEditor", cbSetEditor->isChecked()); | ||
374 | config.sync(); | 481 | config.sync(); | ||
375 | mPlugin->readConfig(); | 482 | mPlugin->readConfig(); | ||
Context not available. | |||||
379 | { | 486 | { | ||
380 | KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); | 487 | KConfigGroup config(KSharedConfig::openConfig(), "Konsole"); | ||
381 | cbAutoSyncronize->setChecked(config.readEntry("AutoSyncronize", false)); | 488 | cbAutoSyncronize->setChecked(config.readEntry("AutoSyncronize", false)); | ||
489 | cbRemoveExtension->setChecked(config.readEntry("RemoveExtension", false)); | ||||
490 | lePrefix->setText(config.readEntry("RunPrefix", "")); | ||||
382 | cbSetEditor->setChecked(config.readEntry("SetEditor", false)); | 491 | cbSetEditor->setChecked(config.readEntry("SetEditor", false)); | ||
383 | } | 492 | } | ||
384 | 493 | | |||
Context not available. |