Community
    • Login

    last modified date in status bar?

    Scheduled Pinned Locked Moved General Discussion
    40 Posts 5 Posters 18.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SalviaSageS
      SalviaSage
      last edited by SalviaSage

      @patrickdrd, have you been able to get this working? I’ve been trying here from my end. I can’t get the last modified date to display on the statusbar. If you have been able to get this working, can you please post the code?

      Thank you.

      1 Reply Last reply Reply Quote 0
      • patrickdrdP
        patrickdrd
        last edited by

        from Npp import editor, notepad, SCINTILLANOTIFICATION, NOTIFICATION, STATUSBARSECTION
        import os
        from datetime import datetime

        def StatusbarSelOverride(args):
        modified_time = os.path.getmtime(notepad.getCurrentFilename())
        last_modified_date = datetime.fromtimestamp(modified_time)
        notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, ‘Mod: {:%d/%m/%Y %H:%M}’.format(last_modified_date))

        editor.callback(StatusbarSelOverride, [SCINTILLANOTIFICATION.UPDATEUI])
        notepad.callback(StatusbarSelOverride, [NOTIFICATION.FILESAVED])
        notepad.callback(StatusbarSelOverride, [NOTIFICATION.READY])

        1 Reply Last reply Reply Quote 0
        • SalviaSageS
          SalviaSage
          last edited by

          I still can’t figure out how to add the timestamp and still keep the original contents of a statusbar section.

          Scott Sumner, I would appreciate it very much if you can fix this code and post it here. thank you.

          dailD 1 Reply Last reply Reply Quote 0
          • patrickdrdP
            patrickdrd
            last edited by

            I don’t think you need the original contents, if we’re talking about the first tab,
            is DOCTYPE really that important for you?
            If so, why?
            I can’t think that’s important, that’s why I’m overwriting it

            1 Reply Last reply Reply Quote 0
            • dailD
              dail @SalviaSage
              last edited by dail

              Using LuaScript I’ve been able to keep the doc type and display the file modification time. Should be easily translatable to PythonScript.

              Note this works with a yet-to-be released version of LuaScript

              npp.AddEventHandler({"OnSave", "OnSwitchFile", "OnLangChange"}, function()
              	-- Make sure it is a "real" file first
              	if npp:GetCurrentDirectory() == "" then
              		return
              	end
              
              	local text = npp.LanguageDescription[npp.BufferLangType[npp.CurrentBufferID]] .. " - " .. os.date('%d/%m/%Y %H:%M', winfile.attributes(npp:GetFullCurrentPath(), "modification"))
              	npp.StatusBar[STATUSBAR_DOC_TYPE] = text
              end)
              

              Gives the results:

              Claudia FrankC 1 Reply Last reply Reply Quote 2
              • Claudia FrankC
                Claudia Frank @dail
                last edited by

                @dail

                unfortunately not, as python script hasn’t been updated with recent npp messages yet.

                Cheers
                Claudia

                dailD 1 Reply Last reply Reply Quote 1
                • dailD
                  dail @Claudia Frank
                  last edited by

                  @Claudia-Frank

                  Ah. Thanks for clarifying.

                  1 Reply Last reply Reply Quote 0
                  • SalviaSageS
                    SalviaSage
                    last edited by SalviaSage

                    @dail
                    Nice, I will be using your script then.
                    When is the release of the next version of luascript?

                    Thanks.

                    1 Reply Last reply Reply Quote 0
                    • dailD
                      dail
                      last edited by

                      Not sure. You can download a prelease though.

                      • 32 bit
                      • 64 bit

                      Just drop the DLL in with the other plugins. Edit the startup script with Plugins > LuaScript > Edit startup script and put the above code in there, save, and restart Notepad++.

                      1 Reply Last reply Reply Quote 2
                      • SalviaSageS
                        SalviaSage
                        last edited by

                        Thanks. the code works.

                        1 Reply Last reply Reply Quote 0
                        • patrickdrdP
                          patrickdrd
                          last edited by patrickdrd

                          I think I’ve found a bug:

                          I had around 10 tabs opened in npp, and my work shift is close to the end so I decided to close npp, so I pressed the x in the top right corner to find out that:

                          there was a file open which was attached to an email,
                          it was opened as read-only originally,
                          I clicked on edit -> clear read-only and I edited it,
                          I never saved it,

                          the date on the bottom left corner is updated continuously/ every minute that passes (on the clock), even though I’m not saving it (I can see a star on the top left corner - the star that means that the file is not saved),
                          I opened the containing folder and the file doesn’t exist there,
                          I’m using autosave plugin to run every time focus is switched off
                          from the current file as well

                          edit: more likely its an autosave bug

                          Claudia FrankC 1 Reply Last reply Reply Quote 0
                          • Claudia FrankC
                            Claudia Frank @patrickdrd
                            last edited by Claudia Frank

                            @patrickdrd

                            something is strange here - how can python get a modified timestamp if the file doesn’t exist at all??
                            The autosave plugin could explain why you see the continuous update of the timestamp
                            but only if there is a file which can be saved.
                            Sorry, but, are you really sure that the file doesn’t exist?

                            Cheers
                            Claudia

                            1 Reply Last reply Reply Quote 0
                            • patrickdrdP
                              patrickdrd
                              last edited by

                              yes, I checked in windows explorer, it should be easy to reproduce it yourself

                              1 Reply Last reply Reply Quote 0
                              • patrickdrdP
                                patrickdrd
                                last edited by

                                I’m also using the lua script too, not the python one

                                1 Reply Last reply Reply Quote 0
                                • dailD
                                  dail
                                  last edited by

                                  @patrickdrd

                                  The Lua I posted above simply askes the operating system (i.e. Windows) when the file was last modified. Even if the file isn’t being saved from Notepad++, it would appear something else is changing the file’s modification timestamp.

                                  1 Reply Last reply Reply Quote 2
                                  • SalviaSageS
                                    SalviaSage
                                    last edited by

                                    @dail

                                    Hi dail, I just tested your script today and it is not working anymore on notepad++ v7.5.8

                                    Can you please also check it and maybe we can come up with a fix.

                                    File:8: attempt to index a nil value (global 'winfile')
                                    stack traceback:
                                        File:8: in function <File:3>
                                    Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
                                    
                                    1 Reply Last reply Reply Quote 0
                                    • patrickdrdP
                                      patrickdrd
                                      last edited by

                                      lua script implementation works fine with 7.5.8

                                      1 Reply Last reply Reply Quote 1
                                      • SalviaSageS
                                        SalviaSage
                                        last edited by

                                        It does, but this particular code does not work for me as of this date. I fear windows OS might have changed something, since this script calls something from the OS.

                                        npp.AddEventHandler({"OnSave", "OnSwitchFile", "OnLangChange"}, function()
                                            -- Make sure it is a "real" file first
                                            if npp:GetCurrentDirectory() == "" then
                                                return
                                            end
                                        
                                            local text = npp.LanguageDescription[npp.BufferLangType[npp.CurrentBufferID]] .. " - " .. os.date('%d/%m/%Y %H:%M', winfile.attributes(npp:GetFullCurrentPath(), "modification"))
                                            npp.StatusBar[STATUSBAR_DOC_TYPE] = text
                                        end)
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • dailD
                                          dail
                                          last edited by

                                          My guess is that since it is reporting winfile as null then you do not have a version of LuaScript that supports this. The official v0.7.1 available via the plugin manager will not work. You have to grab one of the versions listed above.

                                          1 Reply Last reply Reply Quote 1
                                          • SalviaSageS
                                            SalviaSage
                                            last edited by

                                            dail, I can see that the latest beta version of your plugin is v0.7.1.23

                                            But, there isn’t a built .dll file for this, so I downloaded the source and the MSVS told me that I don’t have the xp v14.00 tools installed or something. So, I launched the MSVS installer and installed that under c++ tools. And then, when I tried to build it I got a whole bunch of errors.

                                            Here is a screenshot of the errors: https://i.imgur.com/FRGtDej.png

                                            So… Can you please give me more instructions on how to build this or you can release a .dll of v0.7.1.23

                                            Simply opening LuaScript.sln in MSVS and pressing f7 does not do anything like you say in your description page.
                                            Can you please update that area which deals with how to build LuaScript from source?

                                            Thanks man…

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors