Ejemplo n.º 1
0
 /// <summary>
 /// JavaScript callback. Returns current output profile name (see profile module). In most cases,
 /// this method should return <code>null</code> and let Emmet guess best profile name for current
 /// syntax and user data. In case you’re using advanced editor with access to syntax scopes (like
 /// Sublime Text 2), you can return syntax name for current scope. For example, you may return
 /// `line` profile when editor caret is inside string of programming language.
 /// </summary>
 public InternalHandle GetProfileName(
     V8Engine engine,
     bool isConstructCall,
     InternalHandle self,
     params InternalHandle[] args)
 {
     // Let Emmet engine detect profile
     return(engine.CreateNullValue());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// JavaScript callback. Returns current editor's file path.
 /// </summary>
 public InternalHandle GetFilePath(
     V8Engine engine,
     bool isConstructCall,
     InternalHandle self,
     params InternalHandle[] args)
 {
     // As of version 1.3 this callback is required only for actions with external images that we don't
     // support.
     return(engine.CreateNullValue());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// JavaScript callback. Asks user to enter something.
        /// </summary>
        public InternalHandle Prompt(
            V8Engine engine,
            bool isConstructCall,
            InternalHandle self,
            params InternalHandle[] args)
        {
            string input = _editor.Prompt();

            if (string.IsNullOrWhiteSpace(input))
            {
                return(engine.CreateNullValue());
            }

            return(engine.CreateValue(input));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// JavaScript callback. Reads the specified file content and returns it as string.
        /// </summary>
        public InternalHandle Read(
            V8Engine engine,
            bool isConstructCall,
            InternalHandle self,
            params InternalHandle[] args)
        {
            if (args.Length != 3)
            {
                this.TraceError("IEmmetFile read called with invalid number of arguments.");
                return(engine.CreateValue(false));
            }

            string       targetFilePath = args[0].AsString;
            int          chunkSize      = args[1].AsInt32;
            ObjectHandle callback       = args[2];

            if (!File.Exists(targetFilePath))
            {
                this.TraceError($"Emmet requested file {targetFilePath} that does not exist.");
                callback.StaticCall(engine.CreateValue(true), engine.CreateNullValue());

                return(engine.CreateValue(false));
            }

            char[]     buf    = new char[chunkSize];
            FileStream stream = File.OpenRead(targetFilePath);

            using (StreamReader reader = new StreamReader(stream))
            {
                chunkSize = reader.ReadBlock(buf, 0, chunkSize);
            }

            string retVal = new string(buf, 0, chunkSize);

            callback.StaticCall(engine.CreateValue(false), engine.CreateValue(retVal));

            return(engine.CreateValue(true));
        }