[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    kate patch, pipe & increment line
From:       Cole Beck <cole.beck () vanderbilt ! edu>
Date:       2012-07-05 22:45:58
Message-ID: 4FF61926.9060407 () vanderbilt ! edu
[Download RAW message or body]

Greetings,

I wrote a small patch to add a new item to the Tools menu in Kate.  This 
command will pipe the text of the current line into the terminal and 
then move the cursor down one line.  Very simple, but hopefully helpful.

Thanks,
Cole Beck

["pipe_increment.patch" (text/x-patch)]

From 479b7cf2132659571912de1eb19e188d08c3e88c Mon Sep 17 00:00:00 2001
From: beckca <cole.beck@vanderbilt.edu>
Date: Thu, 5 Jul 2012 17:39:42 -0500
Subject: [PATCH] add Kate Tools menu item to pipe current line and go to next
 line

---
 kate/plugins/konsole/CMakeLists.txt  |    2 +-
 kate/plugins/konsole/kateconsole.cpp |   21 +++++++++++++++++++++
 kate/plugins/konsole/kateconsole.h   |    5 +++++
 kate/plugins/konsole/ui.rc           |    1 +
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/kate/plugins/konsole/CMakeLists.txt \
b/kate/plugins/konsole/CMakeLists.txt index 49cc56e..6a21fcb 100644
--- a/kate/plugins/konsole/CMakeLists.txt
+++ b/kate/plugins/konsole/CMakeLists.txt
@@ -8,7 +8,7 @@ set(katekonsoleplugin_PART_SRCS kateconsole.cpp )
 kde4_add_plugin(katekonsoleplugin ${katekonsoleplugin_PART_SRCS})
 
 
-target_link_libraries(katekonsoleplugin  ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} \
kateinterfaces ) +target_link_libraries(katekonsoleplugin  ${KDE4_KDEUI_LIBS} \
${KDE4_KPARTS_LIBS} kateinterfaces ktexteditor )  
 install(TARGETS katekonsoleplugin  DESTINATION ${PLUGIN_INSTALL_DIR} )
 
diff --git a/kate/plugins/konsole/kateconsole.cpp \
b/kate/plugins/konsole/kateconsole.cpp index 56569cd..d40db69 100644
--- a/kate/plugins/konsole/kateconsole.cpp
+++ b/kate/plugins/konsole/kateconsole.cpp
@@ -147,6 +147,10 @@ KateConsole::KateConsole (KateKonsolePlugin* plugin, \
Kate::MainWindow *mw, QWidg  a->setText(i18nc("@action", "&Pipe to Terminal"));
   connect(a, SIGNAL(triggered()), this, SLOT(slotPipeToConsole()));
 
+  a = actionCollection()->addAction("katekonsole_tools_pipe_and_increment");
+  a->setText(i18n("Pipe to Terminal then Increment Line"));
+  connect(a, SIGNAL(triggered()), this, SLOT(slotPipeAndIncrement()));
+
   a = actionCollection()->addAction("katekonsole_tools_sync");
   a->setText(i18nc("@action", "S&ynchronize Terminal with Current Document"));
   connect(a, SIGNAL(triggered()), this, SLOT(slotManualSync()));
@@ -257,6 +261,23 @@ void KateConsole::slotPipeToConsole ()
     sendInput (v->document()->text());
 }
 
+void KateConsole::slotPipeAndIncrement ()
+{
+  KTextEditor::View *v = m_mw->activeView();
+
+  if (!v)
+    return;
+
+  KTextEditor::Cursor mypos = v->cursorPosition();
+  int lineno = mypos.line();
+  //   send the current line to the console
+  sendInput(v->document()->line(lineno));
+  sendInput("\n");
+  //   move cursor to next line
+  mypos.setLine(lineno + 1);
+  v->setCursorPosition(mypos);
+}
+
 void KateConsole::slotSync()
 {
   if (m_mw->activeView() ) {
diff --git a/kate/plugins/konsole/kateconsole.h b/kate/plugins/konsole/kateconsole.h
index 9f7a61b..f261fef 100644
--- a/kate/plugins/konsole/kateconsole.h
+++ b/kate/plugins/konsole/kateconsole.h
@@ -142,6 +142,11 @@ class KateConsole : public KVBox, public Kate::XMLGUIClient
     void slotPipeToConsole ();
 
     /**
+     * pipe current line to console and move cursor to next line
+     */
+    void slotPipeAndIncrement ();
+
+    /**
      * synchronize the konsole with the current document (cd to the directory)
      */
     void slotSync();
diff --git a/kate/plugins/konsole/ui.rc b/kate/plugins/konsole/ui.rc
index bdc359a..749aa0f 100644
--- a/kate/plugins/konsole/ui.rc
+++ b/kate/plugins/konsole/ui.rc
@@ -3,6 +3,7 @@
 <MenuBar>
  <Menu name="tools"><text>&amp;Tools</text>
     <Action name="katekonsole_tools_pipe_to_terminal" group="tools_operations"/>
+    <Action name="katekonsole_tools_pipe_and_increment" group="tools_operations"/>
     <Action name="katekonsole_tools_sync" group="tools_operations"/>
     <Action name="katekonsole_tools_toggle_focus" group="tools_operations"/>
  </Menu>
-- 
1.7.9.5



_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic