File: ZenCoding.cpp

package info (click to toggle)
juffed 0.10-89-g3690b60-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,160 kB
  • sloc: cpp: 21,060; ansic: 446; xml: 329; sh: 68; makefile: 16
file content (109 lines) | stat: -rw-r--r-- 2,861 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <QDebug>

#include "ZenCoding.h"

#include <QtCore>
//#include <QtGui>
#include "Document.h"
#include "EditorSettings.h"
#include "DocWrapper.h"

void readFile(QScriptEngine& engine, const QString& fileName) {
	QString scriptFileName(QString("/home/mrz/zen/javascript/") + fileName);
	QFile scriptFile(scriptFileName);
	if ( scriptFile.open(QIODevice::ReadOnly) ) {
		QScriptValue result = engine.evaluate(scriptFile.readAll());
		scriptFile.close();
		if ( engine.hasUncaughtException() ) {
			qDebug() << "Error in file " << fileName;
			qDebug() << "Line: " << engine.uncaughtExceptionLineNumber();
			qDebug() << engine.uncaughtExceptionBacktrace();
		}
	}
	else {
		qDebug() << "Failed to open file " << fileName;
	}
}

ZenCoding::ZenCoding() : QObject(), JuffPlugin() {
	expandAct_ = new QAction(tr("Zen Coding expand"), this);
	expandAct_->setShortcut(QKeySequence("Ctrl+,"));
	connect(expandAct_, SIGNAL(triggered()), this, SLOT(expandAbbr()));
	
	docWrapper_ = new DocWrapper();
	QScriptValue wrapperObj = engine_.newQObject(docWrapper_);
	engine_.globalObject().setProperty("docFacade", wrapperObj);
	
	readFile(engine_, "zen_settings.js");
	readFile(engine_, "zen_resources.js");
	readFile(engine_, "base64.js");
	readFile(engine_, "html_matcher.js");
	readFile(engine_, "zen_file.js");
	readFile(engine_, "zen_coding.js");
	readFile(engine_, "zen_actions.js");
	readFile(engine_, "zen_parser.js");
	readFile(engine_, "ZenScript.js");
/*	QString scriptFileName("/home/mrz/zen/javascript/ZenScript.js");
	QFile scriptFile(scriptFileName);
	scriptFile.open(QIODevice::ReadOnly);
	QString scriptText = scriptFile.readAll();
	scriptFile.close();
	
	QScriptValue result = engine_.evaluate(scriptText);
	if ( engine_.hasUncaughtException() ) {
		qDebug() << "Error!!!!";
	}*/
}

void ZenCoding::init() {
	connect(api(), SIGNAL(docActivated(Juff::Document*)), SLOT(onDocActivated(Juff::Document*)));
}

ZenCoding::~ZenCoding() {
	delete docWrapper_;
}

QString ZenCoding::name() const {
	return "Zen Coding";
}

QString ZenCoding::targetEngine() const {
	return "all";
}

QString ZenCoding::description() const {
	return "Zen Coding plugin";
}

Juff::ActionList ZenCoding::mainMenuActions(Juff::MenuID id) const {
	Juff::ActionList list;
	if ( Juff::MenuTools == id ) {
		list << expandAct_;
	}
	return list;
}



void ZenCoding::expandAbbr() {
	Juff::Document* doc = api()->currentDocument();
	if ( doc->isNull() ) {
		return;
	}
	
	engine_.evaluate("expand()");
	if ( engine_.hasUncaughtException() ) {
		qDebug() << "Error!!!!";
//		qDebug() << engine_.uncaughtException();
		qDebug() << engine_.uncaughtExceptionLineNumber();
		qDebug() << engine_.uncaughtExceptionBacktrace();
	}
}


void ZenCoding::onDocActivated(Juff::Document* doc) {
	docWrapper_->setDoc(doc);
	engine_.evaluate("docChanged();");
}

Q_EXPORT_PLUGIN2(zencoding, ZenCoding)