• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateindentscript.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include "kateindentscript.h"
00020 
00021 #include <QScriptValue>
00022 #include <QScriptEngine>
00023 
00024 #include "katedocument.h"
00025 #include "kateview.h"
00026 
00027 KateIndentScript::KateIndentScript(const QString &url, const KateScriptInformation &information)
00028   : KateScript(url, information), m_triggerCharactersSet (false)
00029 {
00030 }
00031 
00032 const QString &KateIndentScript::triggerCharacters()
00033 {
00034   // already set, perfect, just return...
00035   if (m_triggerCharactersSet)
00036     return m_triggerCharacters;
00037 
00038   m_triggerCharactersSet = true;
00039 
00040   m_triggerCharacters = global("triggerCharacters").toString();
00041 
00042   kDebug( 13050 ) << "trigger chars: '" << m_triggerCharacters << "'";
00043 
00044   return m_triggerCharacters;
00045 }
00046 
00047 QPair<int, int> KateIndentScript::indent(KateView* view, const KTextEditor::Cursor& position,
00048                                          QChar typedCharacter, int indentWidth)
00049 {
00050   // if it hasn't loaded or we can't load, return
00051   if(!setView(view))
00052     return qMakePair(-2,-2);
00053 
00054   clearExceptions();
00055   QScriptValue indentFunction = function("indent");
00056   if(!indentFunction.isValid()) {
00057     return qMakePair(-2,-2);
00058   }
00059   // add the arguments that we are going to pass to the function
00060   QScriptValueList arguments;
00061   arguments << QScriptValue(m_engine, position.line());
00062   arguments << QScriptValue(m_engine, indentWidth);
00063   arguments << QScriptValue(m_engine, typedCharacter.isNull() ? QString("") : QString(typedCharacter));
00064   // get the required indent
00065   QScriptValue result = indentFunction.call(QScriptValue(), arguments);
00066   // error during the calling?
00067   if(m_engine->hasUncaughtException()) {
00068     displayBacktrace(result, "Error calling indent()");
00069     return qMakePair(-2,-2);
00070   }
00071   int indentAmount = -2;
00072   int alignAmount = -2;
00073   if (result.isArray()) {
00074     indentAmount = result.property(0).toInt32();
00075     alignAmount = result.property(1).toInt32();
00076   } else {
00077     indentAmount = result.toInt32();
00078   }
00079   if(m_engine->hasUncaughtException()) {
00080     displayBacktrace(QScriptValue(), "Bad return type (must be integer)");
00081     return qMakePair(-2,-2);
00082   }
00083   return qMakePair(indentAmount, alignAmount);
00084 }
00085 
00086 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal