changeset 16407:4d438dffbfac

gui: call external editor when opening a file and custom editor is selected * file-editor.cc(request_open_file): call custom editor if desired * settings-dialog.ui: custom editor command with %f and %l for file and line
author Torsten <ttl@justmail.de>
date Mon, 01 Apr 2013 21:19:23 +0200
parents 7779d9947366
children b1ea3813e37d
files libgui/src/m-editor/file-editor.cc libgui/src/settings-dialog.ui
diffstat 2 files changed, 43 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc
+++ b/libgui/src/m-editor/file-editor.cc
@@ -36,6 +36,7 @@
 #include <QMessageBox>
 #include <QStyle>
 #include <QTextStream>
+#include <QProcess>
 
 #include "octave-link.h"
 
@@ -151,6 +152,19 @@
                                 bool debug_pointer,
                                 bool dbstop_marker, bool insert)
 {
+  // Check if the user wants to use a custom file editor.
+  QSettings *settings = resource_manager::get_settings ();
+  if (settings->value ("useCustomFileEditor").toBool ())
+    {
+      QString editor = settings->value ("customFileEditor").toString ();
+      editor.replace ("%f",openFileName);
+      editor.replace ("%l",QString::number (line));
+      QProcess::startDetached (editor);
+      if (line < 0)
+        handle_mru_add_file(QDir::cleanPath (openFileName));
+      return;
+    }
+
   if (openFileName.isEmpty ())
     {
       // ??  Not sure this will happen.  This routine isn't even called
--- a/libgui/src/settings-dialog.ui
+++ b/libgui/src/settings-dialog.ui
@@ -222,14 +222,24 @@
         </spacer>
        </item>
        <item>
+        <widget class="QCheckBox" name="useCustomFileEditor">
+         <property name="enabled">
+          <bool>true</bool>
+         </property>
+         <property name="text">
+          <string>Use custom file editor</string>
+         </property>
+        </widget>
+       </item>
+       <item>
         <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
-          <widget class="QCheckBox" name="useCustomFileEditor">
+          <widget class="QLabel" name="customEditorLabel">
            <property name="enabled">
-            <bool>true</bool>
+            <bool>false</bool>
            </property>
            <property name="text">
-            <string>Use custom file editor:</string>
+            <string>Command  line (%f=file, %l=line):</string>
            </property>
           </widget>
          </item>
@@ -786,5 +796,21 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>useCustomFileEditor</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>customEditorLabel</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>349</x>
+     <y>383</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>111</x>
+     <y>413</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
 </ui>