Menu

No method for getting the filename of a particular view?

2015-10-14
2015-10-15
  • W P Blatchley

    W P Blatchley - 2015-10-14

    I've started using this great plugin quite a lot now. It's my first foray into Python, too. Seems to be a very powerful tool indeed.

    Anyway, I don't think there's a method for getting the filename of a particular view at the moment. There's notepad.getCurrentFilename(), but you can't pass the view as a parameter. The workarounds available would seem to me to be either temporarily switch to the other view and use the aforementioned method (quick 'n' dirty) or walk the list returned by notepad.getFiles() until you match the doc index returned by notepad.getCurrentDocIndex(view) for the view in question.

    So one solution seems a little hacky, and the other a little long-winded. Is there a better way?

    If not, perhaps this could be an addition to the API for a future release?

     
  • Sasumner

    Sasumner - 2015-10-15

    I guess at some point the API designer has to decide when to stop. Perhaps this is one of those cases. I don't sweat this type of thing as I like to write code; so I can wrap this in my own function. In fact, I have supplemental "notepad" and "editor" classes that add in functionality. For example, I don't think there is a direct function to get the number of the line the caret is on in the currently active view and document, thus I have written:

    def getCurLineNumber(self):
        return editor.lineFromPosition(editor.getCurrentPos())
    

    I just pulled a simple case, sometimes it gets more complex. Unfortunately, I don't have a function written right now that implements your desired functionality, but it could easily be written! Fun!

     
  • W P Blatchley

    W P Blatchley - 2015-10-15

    Thanks for that. I'd just figured on overloading the notepad object myself today, too. That way, I can add in functions I use a lot. Unfortunately, due to the bug in notepad.getFiles() (discussed here: https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/bc28b0dd/), only the hacky-switch-temporarily-to-the-other-view method above can work reliably at the moment.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.