20 #include "katejscript.h"
22 #include "katedocument.h"
24 #include "katefactory.h"
25 #include "kateconfig.h"
26 #include "kateautoindent.h"
27 #include "katehighlight.h"
28 #include "katetextline.h"
30 #include "kateindentscriptabstracts.h"
32 #include <sys/types.h>
37 #include <kstandarddirs.h>
39 #include <tdemessagebox.h>
40 #include <tdeconfig.h>
42 #include <kjs/function_object.h>
43 #include <kjs/interpreter.h>
44 #include <kjs/lookup.h>
47 #include <tqfileinfo.h>
48 #include <tqpopupmenu.h>
50 #include <tqtextstream.h>
61 UString::UString(
const TQString &d)
63 unsigned int len = d.length();
64 UChar *dat =
new UChar[len];
65 memcpy(dat, d.unicode(), len *
sizeof(UChar));
66 rep = UString::Rep::create(dat, len);
69 TQString UString::qstring()
const
71 return TQString((TQChar*) data(), size());
74 TQConstString UString::qconststring()
const
76 return TQConstString((TQChar*) data(), size());
80 class KateJSGlobalFunctions :
public ObjectImp
83 KateJSGlobalFunctions(
int i,
int length);
84 virtual bool implementsCall()
const {
return true; }
85 virtual Value call(ExecState *exec, Object &thisObj,
const List &args);
94 KateJSGlobalFunctions::KateJSGlobalFunctions(
int i,
int length) : ObjectImp(), id(i)
96 putDirect(lengthPropertyName,length,DontDelete|ReadOnly|DontEnum);
98 Value KateJSGlobalFunctions::call(ExecState *exec, Object &,
const List &args)
102 tqDebug(
"Kate (KJS Scripting): %s", args[0].toString(exec).ascii());
116 class KateJSGlobal :
public KJS::ObjectImp {
118 virtual KJS::UString className()
const {
return "global"; }
121 class KateJSDocument :
public KJS::ObjectImp
124 KateJSDocument (KJS::ExecState *exec, KateDocument *_doc);
126 KJS::Value
get( KJS::ExecState *exec,
const KJS::Identifier &propertyName)
const;
128 KJS::Value getValueProperty(KJS::ExecState *exec,
int token)
const;
130 void put(KJS::ExecState *exec,
const KJS::Identifier &propertyName,
const KJS::Value& value,
int attr = KJS::None);
132 void putValueProperty(KJS::ExecState *exec,
int token,
const KJS::Value& value,
int attr);
134 const KJS::ClassInfo* classInfo()
const {
return &info; }
167 static const KJS::ClassInfo info;
170 class KateJSView :
public KJS::ObjectImp
173 KateJSView (KJS::ExecState *exec, KateView *_view);
175 KJS::Value
get( KJS::ExecState *exec,
const KJS::Identifier &propertyName)
const;
177 KJS::Value getValueProperty(KJS::ExecState *exec,
int token)
const;
179 void put(KJS::ExecState *exec,
const KJS::Identifier &propertyName,
const KJS::Value& value,
int attr = KJS::None);
181 void putValueProperty(KJS::ExecState *exec,
int token,
const KJS::Value& value,
int attr);
183 const KJS::ClassInfo* classInfo()
const {
return &info; }
189 SetCursorPositionReal,
205 static const KJS::ClassInfo info;
208 class KateJSIndenter :
public KJS::ObjectImp
211 KateJSIndenter (KJS::ExecState *exec);
221 const KJS::ClassInfo* classInfo()
const {
return &info; }
231 static const KJS::ClassInfo info;
234 #include "katejscript.lut.h"
239 : m_global (new
KJS::Object (new KateJSGlobal ()))
240 , m_interpreter (new
KJS::Interpreter (*m_global))
241 , m_document (new
KJS::Object(wrapDocument(m_interpreter->globalExec(), 0)))
242 , m_view (new
KJS::Object (wrapView(m_interpreter->globalExec(), 0)))
249 KJS::Object(
new KateJSGlobalFunctions(KateJSGlobalFunctions::Debug,1)));
262 return new KateJSDocument(exec, doc);
267 return new KateJSView(exec, view);
275 errorMsg = i18n(
"Could not access view");
280 static_cast<KateJSDocument *
>(
m_document->imp() )->doc = view->doc();
281 static_cast<KateJSView *
>(
m_view->imp() )->view = view;
286 if (comp.complType() == KJS::Throw)
290 KJS::Value exVal = comp.value();
292 char *msg = exVal.toString(exec).ascii();
296 if (exVal.type() == KJS::ObjectType)
298 KJS::Value lineVal = KJS::Object::dynamicCast(exVal).get(exec,
"line");
300 if (lineVal.type() == KJS::NumberType)
301 lineno =
int(lineVal.toNumber(exec));
304 errorMsg = i18n(
"Exception, line %1: %2").arg(lineno).arg(msg);
357 DEFINE_PROTOTYPE(
"KateJSDocument",KateJSDocumentProto)
358 IMPLEMENT_PROTOFUNC(KateJSDocumentProtoFunc)
359 IMPLEMENT_PROTOTYPE(KateJSDocumentProto,KateJSDocumentProtoFunc)
361 const
KJS::ClassInfo KateJSDocument::info = {
"KateJSDocument", 0, 0, 0 };
363 KJS::Value KJS::KateJSDocumentProtoFunc::call(KJS::ExecState *exec, KJS::Object &thisObj,
const KJS::List &args)
365 KJS_CHECK_THIS( KateJSDocument, thisObj );
367 KateDocument *doc =
static_cast<KateJSDocument *
>( thisObj.imp() )->doc;
370 return KJS::Undefined();
374 case KateJSDocument::FullText:
375 return KJS::String (doc->text());
377 case KateJSDocument::Text:
378 return KJS::String (doc->text(args[0].toUInt32(exec), args[1].toUInt32(exec), args[2].toUInt32(exec), args[3].toUInt32(exec)));
380 case KateJSDocument::TextLine:
381 return KJS::String (doc->textLine (args[0].toUInt32(exec)));
383 case KateJSDocument::Lines:
384 return KJS::Number (doc->numLines());
386 case KateJSDocument::Length:
387 return KJS::Number (doc->length());
389 case KateJSDocument::LineLength:
390 return KJS::Number (doc->lineLength(args[0].toUInt32(exec)));
392 case KateJSDocument::SetText:
393 return KJS::Boolean (doc->setText(args[0].toString(exec).qstring()));
395 case KateJSDocument::Clear:
396 return KJS::Boolean (doc->clear());
398 case KateJSDocument::InsertText:
399 return KJS::Boolean (doc->insertText (args[0].toUInt32(exec), args[1].toUInt32(exec), args[2].toString(exec).qstring()));
401 case KateJSDocument::RemoveText:
402 return KJS::Boolean (doc->removeText(args[0].toUInt32(exec), args[1].toUInt32(exec), args[2].toUInt32(exec), args[3].toUInt32(exec)));
404 case KateJSDocument::InsertLine:
405 return KJS::Boolean (doc->insertLine (args[0].toUInt32(exec), args[1].toString(exec).qstring()));
407 case KateJSDocument::RemoveLine:
408 return KJS::Boolean (doc->removeLine (args[0].toUInt32(exec)));
410 case KateJSDocument::EditBegin:
414 case KateJSDocument::EditEnd:
418 case KateJSDocument::IsInWord:
419 return KJS::Boolean( doc->highlight()->isInWord( args[0].toString(exec).qstring().at(0), args[1].toUInt32(exec) ) );
421 case KateJSDocument::CanBreakAt:
422 return KJS::Boolean( doc->highlight()->canBreakAt( args[0].toString(exec).qstring().at(0), args[1].toUInt32(exec) ) );
424 case KateJSDocument::CanComment:
425 return KJS::Boolean( doc->highlight()->canComment( args[0].toUInt32(exec), args[1].toUInt32(exec) ) );
427 case KateJSDocument::CommentMarker:
428 return KJS::String( doc->highlight()->getCommentSingleLineStart( args[0].toUInt32(exec) ) );
430 case KateJSDocument::CommentStart:
431 return KJS::String( doc->highlight()->getCommentStart( args[0].toUInt32(exec) ) );
433 case KateJSDocument::CommentEnd:
434 return KJS::String( doc->highlight()->getCommentEnd( args[0].toUInt32(exec) ) );
436 case KateJSDocument::Attribute:
437 return KJS::Number( doc->kateTextLine(args[0].toUInt32(exec))->attribute(args[1].toUInt32(exec)) );
440 return KJS::Undefined();
443 KJS::Value KateJSDocument::get( KJS::ExecState *exec,
const KJS::Identifier &propertyName)
const
445 return KJS::lookupGetValue<KateJSDocument,KJS::ObjectImp>(exec, propertyName, &KateJSDocumentTable, this );
448 KJS::Value KateJSDocument::getValueProperty(KJS::ExecState *exec,
int token)
const
451 return KJS::Undefined ();
454 case KateJSDocument::IndentWidth:
455 return KJS::Number( doc->config()->indentationWidth() );
457 case KateJSDocument::IndentMode:
460 case KateJSDocument::SpaceIndent:
461 return KJS::Boolean( doc->config()->configFlags() & KateDocumentConfig::cfSpaceIndent );
463 case KateJSDocument::MixedIndent:
464 return KJS::Boolean( doc->config()->configFlags() & KateDocumentConfig::cfMixedIndent );
466 case KateJSDocument::HighlightMode:
467 return KJS::String( doc->hlModeName( doc->hlMode() ) );
470 return KJS::Undefined ();
473 void KateJSDocument::put(KJS::ExecState *exec,
const KJS::Identifier &propertyName,
const KJS::Value& value,
int attr)
475 KJS::lookupPut<KateJSDocument,KJS::ObjectImp>(exec, propertyName, value, attr, &KateJSDocumentTable, this );
478 void KateJSDocument::putValueProperty(KJS::ExecState *exec,
int token,
const KJS::Value& value,
int attr)
484 KateJSDocument::KateJSDocument (KJS::ExecState *exec, KateDocument *_doc)
485 :
KJS::ObjectImp (KateJSDocumentProto::self(exec))
520 DEFINE_PROTOTYPE(
"KateJSView",KateJSViewProto)
521 IMPLEMENT_PROTOFUNC(KateJSViewProtoFunc)
522 IMPLEMENT_PROTOTYPE(KateJSViewProto,KateJSViewProtoFunc)
524 const
KJS::ClassInfo KateJSView::info = {
"KateJSView", 0, &KateJSViewTable, 0 };
526 KJS::Value KJS::KateJSViewProtoFunc::call(KJS::ExecState *exec, KJS::Object &thisObj,
const KJS::List &args)
528 KJS_CHECK_THIS( KateJSView, thisObj );
530 KateView *view =
static_cast<KateJSView *
>( thisObj.imp() )->view;
533 return KJS::Undefined();
537 case KateJSView::CursorLine:
538 return KJS::Number (view->cursorLine());
540 case KateJSView::CursorColumn:
541 return KJS::Number (view->cursorColumn());
543 case KateJSView::CursorColumnReal:
544 return KJS::Number (view->cursorColumnReal());
546 case KateJSView::SetCursorPosition:
547 return KJS::Boolean( view->setCursorPosition( args[0].toUInt32(exec), args[1].toUInt32(exec) ) );
549 case KateJSView::SetCursorPositionReal:
550 return KJS::Boolean( view->setCursorPositionReal( args[0].toUInt32(exec), args[1].toUInt32(exec) ) );
553 case KateJSView::Selection:
554 return KJS::String( view->selection() );
556 case KateJSView::HasSelection:
557 return KJS::Boolean( view->hasSelection() );
559 case KateJSView::SetSelection:
560 return KJS::Boolean( view->setSelection(args[0].toUInt32(exec),
561 args[1].toUInt32(exec),
562 args[2].toUInt32(exec),
563 args[3].toUInt32(exec)) );
565 case KateJSView::RemoveSelectedText:
566 return KJS::Boolean( view->removeSelectedText() );
568 case KateJSView::SelectAll:
569 return KJS::Boolean( view->selectAll() );
571 case KateJSView::ClearSelection:
572 return KJS::Boolean( view->clearSelection() );
575 return KJS::Undefined();
578 KateJSView::KateJSView (KJS::ExecState *exec, KateView *_view)
579 :
KJS::ObjectImp (KateJSViewProto::self(exec))
584 KJS::Value KateJSView::get( KJS::ExecState *exec,
const KJS::Identifier &propertyName)
const
586 return KJS::lookupGetValue<KateJSView,KJS::ObjectImp>(exec, propertyName, &KateJSViewTable, this );
589 KJS::Value KateJSView::getValueProperty(KJS::ExecState *exec,
int token)
const
592 return KJS::Undefined ();
595 case KateJSView::SelStartLine:
596 return KJS::Number( view->selStartLine() );
598 case KateJSView::SelStartCol:
599 return KJS::Number( view->selStartCol() );
601 case KateJSView::SelEndLine:
602 return KJS::Number( view->selEndLine() );
604 case KateJSView::SelEndCol:
605 return KJS::Number( view->selEndCol() );
608 return KJS::Undefined ();
611 void KateJSView::put(KJS::ExecState *exec,
const KJS::Identifier &propertyName,
const KJS::Value& value,
int attr)
613 KJS::lookupPut<KateJSView,KJS::ObjectImp>(exec, propertyName, value, attr, &KateJSViewTable, this );
616 void KateJSView::putValueProperty(KJS::ExecState *exec,
int token,
const KJS::Value& value,
int attr)
628 KateJScriptManager::KateJScriptManager ()
630 m_scripts.setAutoDelete (
true);
634 KateJScriptManager::~KateJScriptManager ()
638 void KateJScriptManager::collectScripts (
bool force)
641 if (!m_scripts.isEmpty())
645 TDEConfig config(
"katepartjscriptrc",
false,
false);
648 config.setGroup (
"General");
649 if (config.readNumEntry (
"Version") > config.readNumEntry (
"CachedVersion"))
651 config.writeEntry (
"CachedVersion", config.readNumEntry (
"Version"));
659 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
662 TQString Group=
"Cache "+ *it;
665 config.setGroup(Group);
669 memset (&sbuf, 0,
sizeof(sbuf));
670 stat(TQFile::encodeName(*it), &sbuf);
673 if (!force && config.hasGroup(Group) && (sbuf.st_mtime == config.readNumEntry(
"lastModified")))
680 TQString desktopFile = (*it).left((*it).length()-2).append (
"desktop");
682 kdDebug (13050) <<
"add script (desktop file): " << desktopFile <<
endl;
684 TQFileInfo dfi (desktopFile);
689 df.setDesktopGroup ();
692 TQString cmdname = df.readEntry (
"X-Kate-Command");
693 if (cmdname.isEmpty())
696 cmdname = fi.baseName();
699 if (m_scripts[cmdname])
702 KateJScriptManager::Script *s =
new KateJScriptManager::Script ();
706 s->desktopFileExists =
true;
708 m_scripts.insert (s->name, s);
712 kdDebug (13050) <<
"add script: fallback, no desktop file around!" <<
endl;
716 if (m_scripts[fi.baseName()])
719 KateJScriptManager::Script *s =
new KateJScriptManager::Script ();
721 s->name = fi.baseName();
723 s->desktopFileExists =
false;
725 m_scripts.insert (s->name, s);
734 bool KateJScriptManager::exec(
Kate::View *view,
const TQString &_cmd, TQString &errorMsg )
737 KateView *v = (KateView*) view;
741 errorMsg = i18n(
"Could not access view");
746 TQStringList args( TQStringList::split( TQRegExp(
"\\s+"), _cmd ) );
747 TQString cmd ( args.first() );
748 args.remove( args.first() );
754 errorMsg = i18n(
"Command not found");
758 TQFile file (m_scripts[cmd]->filename);
760 if ( !file.open( IO_ReadOnly ) )
762 errorMsg = i18n(
"JavaScript file not found");
766 TQTextStream stream( &file );
767 stream.setEncoding (TQTextStream::UnicodeUTF8);
769 TQString source = stream.read ();
773 return KateFactory::self()->jscript()->execute(v, source, errorMsg);
776 bool KateJScriptManager::help(
Kate::View *,
const TQString &cmd, TQString &msg )
778 if (!m_scripts[cmd] || !m_scripts[cmd]->desktopFileExists)
781 TDEConfig df (m_scripts[cmd]->desktopFilename(),
true,
false);
782 df.setDesktopGroup ();
784 msg = df.readEntry (
"X-Kate-Help");
792 TQStringList KateJScriptManager::cmds()
796 TQDictIterator<KateJScriptManager::Script> it( m_scripts );
797 for( ; it.current(); ++it )
798 l << it.current()->name;
826 KateJSIndenter::KateJSIndenter (KJS::ExecState *exec)
827 :
KJS::ObjectImp (KateJSViewProto::self(exec))
831 DEFINE_PROTOTYPE(
"KateJSIndenter",KateJSIndenterProto)
832 IMPLEMENT_PROTOFUNC(KateJSIndenterProtoFunc)
833 IMPLEMENT_PROTOTYPE(KateJSIndenterProto,KateJSIndenterProtoFunc)
835 const
KJS::ClassInfo KateJSIndenter::info = {
"KateJSIndenter", 0, &KateJSIndenterTable, 0 };
837 KJS::Value KJS::KateJSIndenterProtoFunc::call(KJS::ExecState *exec, KJS::Object &thisObj,
const KJS::List &args)
839 KJS_CHECK_THIS( KateJSIndenter, thisObj );
841 return KJS::Undefined();
847 KateIndentJScriptImpl::KateIndentJScriptImpl(
const TQString& internalName,
848 const TQString &filePath,
const TQString &niceName,
849 const TQString ©right,
double version):
850 KateIndentScriptImplAbstract(internalName,filePath,niceName,copyright,version),m_interpreter(0),m_indenter(0)
855 KateIndentJScriptImpl::~KateIndentJScriptImpl()
860 void KateIndentJScriptImpl::decRef()
862 KateIndentScriptImplAbstract::decRef();
869 void KateIndentJScriptImpl::deleteInterpreter()
875 delete m_interpreter;
879 bool KateIndentJScriptImpl::setupInterpreter(TQString &errorMsg)
884 m_interpreter=
new KJS::Interpreter(KJS::Object(
new KateJSGlobal()));
885 m_docWrapper=
new KateJSDocument(m_interpreter->globalExec(),0);
886 m_viewWrapper=
new KateJSView(m_interpreter->globalExec(),0);
887 m_indenter=
new KJS::Object(
new KateJSIndenter(m_interpreter->globalExec()));
888 m_interpreter->globalObject().put(m_interpreter->globalExec(),
"document",KJS::Object(m_docWrapper),KJS::DontDelete | KJS::ReadOnly);
889 m_interpreter->globalObject().put(m_interpreter->globalExec(),
"view",KJS::Object(m_viewWrapper),KJS::DontDelete | KJS::ReadOnly);
890 m_interpreter->globalObject().put(m_interpreter->globalExec(),
"debug", KJS::Object(
new
891 KateJSGlobalFunctions(KateJSGlobalFunctions::Debug,1)));
892 m_interpreter->globalObject().put(m_interpreter->globalExec(),
"indenter",*m_indenter,KJS::DontDelete | KJS::ReadOnly);
893 TQFile file (filePath());
895 if ( !file.open( IO_ReadOnly ) )
897 errorMsg = i18n(
"JavaScript file not found");
902 TQTextStream stream( &file );
903 stream.setEncoding (TQTextStream::UnicodeUTF8);
905 TQString source = stream.read ();
909 KJS::Completion comp (m_interpreter->evaluate(source));
910 if (comp.complType() == KJS::Throw)
912 KJS::ExecState *exec = m_interpreter->globalExec();
914 KJS::Value exVal = comp.value();
916 char *msg = exVal.toString(exec).ascii();
920 if (exVal.type() == KJS::ObjectType)
922 KJS::Value lineVal = KJS::Object::dynamicCast(exVal).get(exec,
"line");
924 if (lineVal.type() == KJS::NumberType)
925 lineno =
int(lineVal.toNumber(exec));
928 errorMsg = i18n(
"Exception, line %1: %2").arg(lineno).arg(msg);
938 inline static bool KateIndentJScriptCall(
Kate::View *view, TQString &errorMsg, KateJSDocument *docWrapper, KateJSView *viewWrapper,
939 KJS::Interpreter *interpreter, KJS::Object lookupobj,
const KJS::Identifier& func,KJS::List params)
944 errorMsg = i18n(
"Could not access view");
948 KateView *v=(KateView*)view;
950 KJS::Object o=lookupobj.get(interpreter->globalExec(),func).toObject(interpreter->globalExec());
951 if (interpreter->globalExec()->hadException())
953 errorMsg=interpreter->globalExec()->exception().toString(interpreter->globalExec()).qstring();
955 interpreter->globalExec()->clearException();
960 docWrapper->doc = v->doc();
961 viewWrapper->view = v;
964 o.call(interpreter->globalExec(),interpreter->globalObject(),params);
965 if (interpreter->globalExec()->hadException())
967 errorMsg=interpreter->globalExec()->exception().toString(interpreter->globalExec()).ascii();
969 interpreter->globalExec()->clearException();
975 bool KateIndentJScriptImpl::processChar(
Kate::View *view, TQChar c, TQString &errorMsg )
978 kdDebug(13050)<<
"KateIndentJScriptImpl::processChar"<<
endl;
979 if (!setupInterpreter(errorMsg))
return false;
981 params.append(KJS::String(TQString(c)));
982 return KateIndentJScriptCall(view,errorMsg,m_docWrapper,m_viewWrapper,m_interpreter,*m_indenter,KJS::Identifier(
"onchar"),params);
987 kdDebug(13050)<<
"KateIndentJScriptImpl::processLine"<<
endl;
988 if (!setupInterpreter(errorMsg))
return false;
989 return KateIndentJScriptCall(view,errorMsg,m_docWrapper,m_viewWrapper,m_interpreter,*m_indenter,KJS::Identifier(
"online"),KJS::List());
992 bool KateIndentJScriptImpl::processNewline(
class Kate::View *view,
const KateDocCursor &begin,
bool needcontinue, TQString &errorMsg )
994 kdDebug(13050)<<
"KateIndentJScriptImpl::processNewline"<<
endl;
995 if (!setupInterpreter(errorMsg))
return false;
996 return KateIndentJScriptCall(view,errorMsg,m_docWrapper,m_viewWrapper,m_interpreter,*m_indenter,KJS::Identifier(
"onnewline"),KJS::List());
1001 KateIndentJScriptManager::KateIndentJScriptManager():KateIndentScriptManagerAbstract()
1003 m_scripts.setAutoDelete (
true);
1007 KateIndentJScriptManager::~KateIndentJScriptManager ()
1011 void KateIndentJScriptManager::collectScripts (
bool force)
1014 if (!m_scripts.isEmpty())
1019 TDEConfig config(
"katepartindentjscriptrc",
false,
false);
1022 config.setGroup (
"General");
1023 if (config.readNumEntry (
"Version") > config.readNumEntry (
"CachedVersion"))
1025 config.writeEntry (
"CachedVersion", config.readNumEntry (
"Version"));
1034 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
1037 TQString Group=
"Cache "+ *it;
1040 config.setGroup(Group);
1044 memset (&sbuf, 0,
sizeof(sbuf));
1045 stat(TQFile::encodeName(*it), &sbuf);
1049 if (!force && config.hasGroup(Group) && (sbuf.st_mtime == config.readNumEntry(
"lastModified")))
1051 config.setGroup(Group);
1052 TQString filePath=*it;
1053 TQString internalName=config.readEntry(
"internlName",
"KATE-ERROR");
1054 if (internalName==
"KATE-ERROR") readnew=
true;
1057 TQString niceName=config.readEntry(
"niceName",internalName);
1058 TQString copyright=config.readEntry(
"copyright",i18n(
"(Unknown)"));
1059 double version=config.readDoubleNumEntry(
"version",0.0);
1060 KateIndentJScriptImpl *s=
new KateIndentJScriptImpl(
1061 internalName,filePath,niceName,copyright,version);
1062 m_scripts.insert (internalName, s);
1068 TQFileInfo fi (*it);
1070 if (m_scripts[fi.baseName()])
1073 TQString internalName=fi.baseName();
1074 TQString filePath=*it;
1075 TQString niceName=internalName;
1076 TQString copyright=i18n(
"(Unknown)");
1078 parseScriptHeader(filePath,&niceName,©right,&version);
1080 config.setGroup(Group);
1081 config.writeEntry(
"lastModified",sbuf.st_mtime);
1082 config.writeEntry(
"internalName",internalName);
1083 config.writeEntry(
"niceName",niceName);
1084 config.writeEntry(
"copyright",copyright);
1085 config.writeEntry(
"version",version);
1086 KateIndentJScriptImpl *s=
new KateIndentJScriptImpl(
1087 internalName,filePath,niceName,copyright,version);
1088 m_scripts.insert (internalName, s);
1096 KateIndentScript KateIndentJScriptManager::script(
const TQString &scriptname) {
1097 KateIndentJScriptImpl *s=m_scripts[scriptname];
1099 return KateIndentScript(s);
1102 void KateIndentJScriptManager::parseScriptHeader(
const TQString &filePath,
1103 TQString *niceName,TQString *copyright,
double *version)
1105 TQFile f(TQFile::encodeName(filePath));
1106 if (!f.open(IO_ReadOnly) ) {
1107 kdDebug(13050)<<
"Header could not be parsed, because file could not be opened"<<
endl;
1110 TQTextStream st(&f);
1111 st.setEncoding (TQTextStream::UnicodeUTF8);
1112 if (!st.readLine().upper().startsWith(
"/**KATE")) {
1118 kdDebug(13050)<<
"Parsing indent script header"<<
endl;
1119 enum {NOTHING=0,COPYRIGHT=1} currentState=NOTHING;
1121 TQString tmpblockdata=
"";
1122 TQRegExp endExpr(
"[\\s\\t]*\\*\\*\\/[\\s\\t]*$");
1123 TQRegExp keyValue(
"[\\s\\t]*\\*\\s*(.+):(.*)$");
1124 TQRegExp blockContent(
"[\\s\\t]*\\*(.*)$");
1125 while ((line=st.readLine())!=TQString::null) {
1126 if (endExpr.exactMatch(line)) {
1128 if (currentState==NOTHING)
break;
1129 if (currentState==COPYRIGHT) {
1130 *copyright=tmpblockdata;
1135 if (currentState==NOTHING)
1137 if (keyValue.exactMatch(line)) {
1138 TQStringList sl=keyValue.capturedTexts();
1139 kdDebug(13050)<<
"key:"<<sl[1]<<endl<<
"value:"<<sl[2]<<
endl;
1140 kdDebug(13050)<<
"key-length:"<<sl[1].length()<<endl<<
"value-length:"<<sl[2].length()<<
endl;
1142 TQString value=sl[2];
1143 if (key==
"NAME") (*niceName)=value.stripWhiteSpace();
1144 else if (key==
"VERSION") (*version)=value.stripWhiteSpace().toDouble(0);
1145 else if (key==
"COPYRIGHT")
1148 if (value.stripWhiteSpace().length()>0) tmpblockdata=value;
1149 currentState=COPYRIGHT;
1153 if (blockContent.exactMatch(line))
1155 TQString bl=blockContent.capturedTexts()[1];
1159 (*copyright)=tmpblockdata;
1160 kdDebug(13050)<<
"Copyright block:"<<endl<<(*copyright)<<
endl;
1161 currentState=NOTHING;
1162 }
else tmpblockdata=tmpblockdata+
"\n"+bl;
Cursor class with a pointer to its document.
KJS::ObjectImp * wrapDocument(KJS::ExecState *exec, KateDocument *doc)
creates a JS wrapper object for given KateDocument
int key(StdAccel) KDE_DEPRECATED
KJS::Object * m_global
global object of interpreter
bool execute(KateView *view, const TQString &script, TQString &errorMsg)
execute given script the script will get the doc and view exposed via document and view object in glo...
The Kate::View text editor interface.
kdbgstream kdDebug(int area=0)
static TDEStandardDirs * dirs()
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
KJS::Object * m_view
object for view
KateJScript()
generate new global interpreter for part scripting
static TQString modeName(uint mode)
Return the mode name given the mode.
Cool, this is all we need here.
KJS::Interpreter * m_interpreter
js interpreter
kndbgstream & endl(kndbgstream &s)
KJS::Object * m_document
object for document
KJS::ObjectImp * wrapView(KJS::ExecState *exec, KateView *view)
creates a JS wrapper object for given KateView
virtual ~KateJScript()
be destructive