var EventEmitter = require("events").EventEmitter; var util = require("util"); var Types = require("./types.js"); //A controler owned buffer representation function Buffer (client, buffId, path) { "use strict"; EventEmitter.call(this); var self = this; this.path = path; this.title = undefined; var typeNum = 0; //WARNING : check if this should be unique to a buffer var serNum = 0; //WARNING : check if this should be unique to a buffer /* COMMANDS */ //Add an annotation into buffer. annoType is obtained through defineAnnoType. off is the position //The anno id is returned by the call this.addAnno = function (annoType, off) { serNum += 1; client.sendCommand("addAnno", buffId, serNum, annoType,Types.position(off), 0 ); return serNum; }; //Close the buffer this.close = function(){ client.sendCommand("close", buffId); }; //Define an annotation type. typename : friendly name, glyphFile : icon, fg and bg are the colors //The anno type id is returned by the call this.defineAnnoType = function (typeName, glyphFile, fg, bg) { typeNum += 1; client.sendCommand("defineAnnoType", buffId, typeNum, Types.string(typeName), Types.string(""), Types.string(glyphFile), Types.color(fg), Types.color(bg)); return typeNum; }; //Start listening for insert and remove events on buffer this.startDocumentListen = function () { client.sendCommand("startDocumentListen", buffId); }; //Stop listening for insert and remove events on buffer this.stopDocumentListen = function () { client.sendCommand("stopDocumentListen", buffId); }; //Guard an area of the buffer. off is the position, len the length of text this.guard = function (off, len) { client.sendCommand("guard",buffId, Types.position(off), len); }; //Tell Vim that the buffer is ready to be used this.initDone = function () { client.sendCommand("initdone", buffId); }; //Tell Vim that inserts are done this.insertDone = function () { client.sendCommand("insertDone", buffId); }; //Tell Vim that the buffer is owned by the controler //Réception d'événéments si vrai this.netbeansBuffer = function (isNetBeansBuffer) { client.sendCommand("netbeansBuffer", buffId, Types.bool(isNetBeansBuffer)); }; //Start an atomic opperation. Vim screen is not updated untill endAtomic is called //BUG : Interprété comme un startDocumentListen this.startAtomic = function () { client.sendCommand("startAtomic", buffId); }; //End an atomic opperation. //BUG : Ne fais rien du tout this.endAtomic = function() { client.sendCommand("endAtmoic", buffId ); }; //Remove and anno this.removeAnno = function (serNum) { client.sendCommand("removeAnno",buffId,serNum); }; //Tell Vim to save the buffer this.save = function () { client.sendCommand("save", buffId); }; //Tell Vim that the controler have saved the buffer this.saveDone = function () { client.sendCommand("saveDone", buffId); }; //Set the cursor position (and make the buffer the current buffer) this.setDot = function (off) { client.sendCommand("setDot", buffId, Types.position(off)); }; //Set the filename of a buffer. It does not actually feed the buffer with file content, use insert for that this.setFullName = function (pathName) { client.sendCommand("setFullName", buffId, Types.string(pathName)); }; //Set the modified flag this.setModified = function (modified) { client.sendCommand("setModified", buffId, Types.bool(modified)); }; //Set the modtime this.setModtime = function (time) { client.sendCommand("setModtime", buffId, time); }; //Set the file as read-only this.setReadOnly = function () { client.sendCommand("setReadOnly", buffId); }; //Set the title of the buffer. The title is just an internal name, it's not visible by the user this.setTitle = function (name) { self.title = name; client.sendCommand("setTitle", buffId, Types.string(name)); }; //Show the buffer this.setVisible = function () { client.sendCommand("setVisible", buffId, Types.bool(true)); }; //Show a balloon containing the text around the cursor (GVim only) this.showBalloon = function (text) { client.sendCommand("showBalloon", buffId,Types.string(text)); }; //Ungard the text. off is the starting position, len the length of the text //BUG : Doesn't works at all, text area keeps guard this.unguard = function (off, len) { client.sendCommand("unguard", buffId, Types.position(off), len); }; //Edit the file in the current buffer this.editFile = function (pathName){ self.name = pathName; client.sendCommand("editFile", buffId, Types.string(pathName)); }; /* FUNCTIONS */ //Get the length of current buffer. this.getLength = function (callback) { client.callFunction("getLength", buffId, callback); }; //Get the line position of an anno this.getAnno = function (serNum, callback) { client.callFunction("getAnno", buffId, serNum, callback); }; //Get the status of modified flag this.getModified = function (callback) { client.callFunction("getModified", buffId, callback); }; //Return the content of the buffer as string this.getText = function (callback) { client.callFunction("getText", buffId, callback); }; //Insert text at the position. Callback get nothing if everything went good, the error otherwise this.insert = function (off, text, callback){ client.callFunction("insert", buffId, Types.position(off), Types.string(text), callback); }; //Remove text at the position. Callback get nothing if everything went good, the error otherwise this.remove = function (off, length, callback) { client.callFunction("remove", buffId, Types.position(off), length, callback); }; } util.inherits(Buffer, EventEmitter); module.exports = Buffer;