sieukrem / jn-npp-plugin

Plugin for Notepad++ allowing you to automate some tasks using JavaScript
https://github.com/sieukrem/jn-npp-plugin/wiki
110 stars 24 forks source link

How execute cli task in NppExec console? #86

Closed WinterSilence closed 4 years ago

WinterSilence commented 4 years ago

How display result in console of plugin NppExec? Or how create same console?

var myMenu = Editor.addMenu({text: 'PHP'});
var myCmd = myMenu.addItem({
    getFile: function () {
        return Editor.currentView.files[Editor.currentView.file];
    },
    shell: new ActiveXObject('WScript.Shell'),
    text: 'Check syntax',
    cmd: function(menu) {
        var cmd = this.shell.Exec('%PHP% --file "' + this.getFile() + '" -l -e');
        Editor.alert(cmd.StdOut.ReadAll()); // replace to output in console
    }
});
sieukrem commented 4 years ago

If you only want to create output window you can use following snippet.

function CreateOutputView(name){
    var view = new Dialog({
        npp: Editor,
        html: "<div id='output' style='margin:0; padding:0; width:100%; height:100%;'></div>", 
        title: "Output",
        css: "body, html{background-color: buttonface; overflow:auto; padding:0em; margin:0em}",
        oncreate: function(){
            var outputEl = this.getElementById("output");

            this.Dialog.log = function (msg){
                outputEl.innerHTML += "<div>"+msg+"</div>";

                if (!view.htmlDialog.visible)
                    console.show();
            }
        },

        dockable:{
            name: name, 
            docking:"bottom",
            onclose:function(){
            },
            onbeforeclose:function(){ 
                return false;
            }
        }
    });

    return view;
}

var console = CreateOutputView("PHP");

console.log("my cool output");

Take a look inside of jN/includes/Dialog.js for more insights.

WinterSilence commented 4 years ago

@sieukrem thanks, yet another few questions:

  1. var fso = new ActiveXObject("Scripting.FileSystemObject"); Where find list of objects like as Scripting.FileSystemObject?
  2. var plugin = new Library("../notepad++/plugins/foo/foo.dll"); Can I use something like this? And how grab/stub function from dll's?
sieukrem commented 4 years ago

I assume you did not find the Wiki pages, they are not so present on github as the *.md files.

  1. var fso = new ActiveXObject("Scripting.FileSystemObject"); Where find list of objects like as Scripting.FileSystemObject?

I linked some microsoft pages in Helpful scripts article

  1. var plugin = new Library("../notepad++/plugins/foo/foo.dll"); Can I use something like this? And how grab/stub function from dll's?

Explanation how jN dispatches native calls.

trdm commented 4 years ago

I also use messages from scripts in N++ my implementation: https://github.com/trdm/jn-npp-scripts/blob/master/includes/intelMessage.js

WinterSilence commented 4 years ago

@sieukrem little doto (: move Dialog.js to lib/ - i think class Dialog required somewhere in "core" and remove it :(