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

List:       kde-commits
Subject:    kdelibs/kate
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2005-03-16 17:28:52
Message-ID: 20050316172852.F162A17D06 () office ! kde ! org
[Download RAW message or body]

CVS commit by cullmann: 

execute scripts for real, better error handling, now show the error even in the right \
places instead of dumb kdDebug ()


  M +1 -1      part/katecmds.cpp   1.48
  M +39 -6     part/katejscript.cpp   1.20
  M +2 -1      part/katejscript.h   1.6
  M +2 -2      scripts/jstest.js   1.3


--- kdelibs/kate/part/katecmds.cpp  #1.47:1.48
@@ -109,5 +109,5 @@ bool KateCommands::CoreCommands::exec(Ka
   else if ( cmd == "run-myself" )
   {
-    return KateFactory::self()->jscript()->execute(v, v->doc()->text());
+    return KateFactory::self()->jscript()->execute(v, v->doc()->text(), errorMsg);
   }
   else if ( cmd == "unindent" )

--- kdelibs/kate/part/katejscript.cpp  #1.19:1.20
@@ -21,4 +21,5 @@
 #include "katedocument.h"
 #include "kateview.h"
+#include "katefactory.h"
 
 #include <sys/types.h>
@@ -39,4 +40,5 @@
 #include <qfileinfo.h>
 #include <qregexp.h>
+#include <qtextstream.h>
 
 namespace KJS {
@@ -166,8 +168,11 @@ KJS::ObjectImp *KateJScript::wrapView (K
 }
 
-bool KateJScript::execute (KateView *view, const QString &script)
+bool KateJScript::execute (KateView *view, const QString &script, QString &errorMsg)
 {
   if (!view)
+  {
+    errorMsg = i18n("Could not access view");
     return false;
+  }
 
   // put some stuff into env.
@@ -196,10 +201,8 @@ bool KateJScript::execute (KateView *vie
     }
 
-    kdDebug () << "Exception, line " << lineno << ": " << msg << endl;
-
+    errorMsg = i18n("Exception, line %1: %2").arg(lineno).arg(msg);
     return false;
   }
 
-  kdDebug () << "script executed" << endl;
   return true;
 }
@@ -518,4 +521,13 @@ void KateJScriptManager::collectScripts 
 bool KateJScriptManager::exec( class Kate::View *view, const QString &_cmd, QString \
&errorMsg )  {
+  // cast it hardcore, we know that it is really a kateview :)
+  KateView *v = (KateView*) view;
+
+  if ( !v )
+  {
+    errorMsg = i18n("Could not access view");
+    return false;
+  }
+
    //create a list of args
   QStringList args( QStringList::split( QRegExp("\\s+"), _cmd ) );
@@ -523,7 +535,28 @@ bool KateJScriptManager::exec( class Kat
   args.remove( args.first() );
 
-  kdDebug(13050) << cmd << endl;
+  kdDebug(13050) << "try to exec: " << cmd << endl;
 
+  if (!m_scripts[cmd])
+  {
+    errorMsg = i18n("Command not found");
+    return false;
+  }
+
+  QFile file (m_scripts[cmd]->filename);
+
+  if ( !file.open( IO_ReadOnly ) )
+    {
+    errorMsg = i18n("JavaScript file not found");
   return false;
+  }
+
+  QTextStream stream( &file );
+  stream.setEncoding (QTextStream::UnicodeUTF8);
+
+  QString source = stream.read ();
+
+  file.close();
+
+  return KateFactory::self()->jscript()->execute(v, source, errorMsg);
 }
 

--- kdelibs/kate/part/katejscript.h  #1.5:1.6
@@ -79,7 +79,8 @@ class KateJScript
      * @param view view to expose
      * @param script source code of script to execute
+     * @param errorMsg error to return if no success
      * @return success or not?
      */
-    bool execute (KateView *view, const QString &script);
+    bool execute (KateView *view, const QString &script, QString &errorMsg);
 
   private:

--- kdelibs/kate/scripts/jstest.js  #1.2:1.3
@@ -3,5 +3,5 @@
 {
     document.removeText( 0, 0, 0, document.lineLength(0) );
-    document.insertText( 0, 0, "// initial selection: " + view.selStartLine() + "," \
+ view.selStartCol() + " - " + view.selEndLine() + "," + view.selEndCol() ); +    \
document.insertText( 0, 0, "// initial selection: " + view.selStartLine + "," + \
view.selStartCol + " - " + view.selEndLine + "," + view.selEndCol );  }
 // test selection interface
@@ -24,4 +24,4 @@
 view.setSelection( line, 0, line, document.lineLength(line) );
 
-document.insertText( line, document.lineLength( line ), " Selection is " + \
view.selStartLine() + "," + view.selStartCol() + " - " + view.selEndLine() + "," + \
view.selEndCol() ); +document.insertText( line, document.lineLength( line ), " \
Selection is " + view.selStartLine + "," + view.selStartCol + " - " + view.selEndLine \
+ "," + view.selEndCol );  


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

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