sieukrem / jn-npp-plugin

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

change the Dockable when open different file #105

Closed Jzhenli closed 3 years ago

Jzhenli commented 3 years ago

hi, i want to have dockalbe to show the file structure automatically. for exapmle, when open fileA, the dockable show fileA structure. If I open fileB, then the dockable will show fileB structure. if several files are opened, when select the file from the tab, then the dockable should changed automatically.

Not sure if it's possible to implement this feature by JN plugin, pls give suggestion, thanks.

sieukrem commented 3 years ago

Hi, I assume you are looking for an tab activation event to be able to update the content of the dockable. You can find this feature in action here.

Jzhenli commented 3 years ago

Hi, I assume you are looking for an tab activation event to be able to update the content of the dockable. You can find this feature in action here.

thanks for your reply, I check the code you point out, but still cann't quite understand it. It's appreciate if you can give a simple example such as to auto show only current file name in the dockable when file is clicked in the tab.

Jzhenli commented 3 years ago

I have try with the BUFFERACTIVATED function, it works well, but seems the first call not works when open the notepad++, the code as follows, (function() { var seagateMenu = Editor.addMenu("Mytest"); var w = Editor.createDockable({ name:'Paragraph List', onbeforeclose:function(){ myView.checked = false; return false; }, onclose:function(){ } });

function myTest(v) {
    var d = w.document;

    d.write("<html><head></head><body></body></html>");
    d.close();
    d.body.innerHTML = v.files[v.file];
    delete d;
}

var myView = seagateMenu.addItem({
    text: "Myview",
    cmd: function() {
        myView.checked = !myView.checked;
        if(myView.checked)
        {
            w.visible = true;
            myTest(currentView);
        }
        else
        {
            w.visible = false;  
        }

    },
});

GlobalListener.addListener({
    BUFFERACTIVATED: function(v) {
        if (w.visible) {
            myTest(v);
        }
    }
});

})();