• Login
Community
  • Login

last modified date in status bar?

Scheduled Pinned Locked Moved General Discussion
40 Posts 5 Posters 18.7k 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.
  • P
    patrickdrd
    last edited by May 2, 2018, 11:25 AM

    yes, it’s pretty good!!

    some help with date formating?

    I would prefer dd/mm/yyyy hh:mm please :D

    e.g. 13/02/2018 15:14

    C 1 Reply Last reply May 2, 2018, 11:37 AM Reply Quote 0
    • C
      Claudia Frank @patrickdrd
      last edited by Claudia Frank May 2, 2018, 11:37 AM May 2, 2018, 11:37 AM

      @patrickdrd

      using

      last_modified_date.strftime('%d/%m/%Y %H:%M')
      

      should do the trick.
      More infos, if other format is wanted can be seen here .

      Cheers
      Claudia

      S 1 Reply Last reply May 2, 2018, 11:51 AM Reply Quote 3
      • S
        Scott Sumner @Claudia Frank
        last edited by May 2, 2018, 11:51 AM

        This might be a more direct link than Claudia’s…for what seems to be wanted for adjustment.

        1 Reply Last reply Reply Quote 3
        • P
          patrickdrd
          last edited by May 6, 2018, 9:18 AM

          why do I have to link anywhere inside the file in order for it to work?
          I mean when I double click on a file from windows explorer,
          I have set initialization atstartup,
          does it need something else/more maybe?

          1 Reply Last reply Reply Quote 0
          • P
            patrickdrd
            last edited by May 6, 2018, 10:27 AM

            I think I found that, I added:

            notepad.callback(StatusbarSelOverride, [NOTIFICATION.READY])

            S 1 Reply Last reply May 6, 2018, 12:18 PM Reply Quote 0
            • S
              Scott Sumner @patrickdrd
              last edited by May 6, 2018, 12:18 PM

              @patrickdrd said:

              notepad.callback(StatusbarSelOverride, [NOTIFICATION.READY])

              Interesting. I found that I don’t need the “READY”–I don’t have to click inside the document tab to see the mod time updated after loading a file. I don’t use Explorer integration such that a double-click opens the file in Notepad++, but it works for me either via Explorer right-click or drag-n-drop from Explorer.

              1 Reply Last reply Reply Quote 0
              • S
                SalviaSage
                last edited by May 6, 2018, 12:19 PM

                patrickdd, have you been able to add the modified date to the section 1 of the statusbar, where the language name is, without overriding the language name? if so, can you please post the full code? thanks.

                S 1 Reply Last reply May 6, 2018, 12:30 PM Reply Quote 0
                • S
                  Scott Sumner @SalviaSage
                  last edited by May 6, 2018, 12:30 PM

                  @SalviaSage said:

                  section 1 of the statusbar

                  Just change .DOCSIZE to .DOCTYPE. No need to post more code.

                  That kind of change should be really obvious from the third posting I made (the one with the images of the status bar) in this thread .

                  1 Reply Last reply Reply Quote 1
                  • P
                    patrickdrd
                    last edited by May 6, 2018, 12:38 PM

                    Scott, the difference is that notepad++ is closed in my case, before opening the file, in that case only initial script doesn’t work

                    S C 2 Replies Last reply May 6, 2018, 1:14 PM Reply Quote 1
                    • S
                      Scott Sumner @patrickdrd
                      last edited by May 6, 2018, 1:14 PM

                      @patrickdrd said:

                      notepad++ is closed in my case, before opening the file

                      Yeah, that’s a case I don’t think about, or code for. Because, as the best program on my PC, Notepad++ never gets closed. :-D

                      1 Reply Last reply Reply Quote 2
                      • C
                        Claudia Frank @patrickdrd
                        last edited by May 6, 2018, 2:53 PM

                        @patrickdrd

                        does READY callback work for you?
                        It seems that this one can’t really be used when running on linux.
                        BUFFERACTIVATED might be another callback which is useful in such cases.

                        Cheers
                        Claudia

                        1 Reply Last reply Reply Quote 0
                        • S
                          Scott Sumner
                          last edited by PeterJones Aug 24, 2024, 8:19 PM May 6, 2018, 3:22 PM

                          …without overriding the language name?

                          Ah…so I guess I missed this part of @SalviaSage 's posting. Okay, so there is no prebuilt function to get the statusbar data, like there is to set the statusbar data…but we can create one:

                          import ctypes
                          from ctypes.wintypes import BOOL, HWND, LPARAM
                          
                          def npp_get_statusbar(statusbar_item_number):
                          
                              WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
                              FindWindow = ctypes.windll.user32.FindWindowW
                              SendMessage = ctypes.windll.user32.SendMessageW
                              EnumChildWindows = ctypes.windll.user32.EnumChildWindows
                              GetClassName = ctypes.windll.user32.GetClassNameW
                              create_unicode_buffer = ctypes.create_unicode_buffer
                              WM_USER = 0x400; SB_GETTEXTLENGTHW = WM_USER + 12; SB_GETTEXTW = WM_USER + 13
                          
                              npp_get_statusbar.STATUSBAR_HANDLE = None
                          
                              def get_data_from_statusbar(statusbar_item_number):
                                  retcode = SendMessage(npp_get_statusbar.STATUSBAR_HANDLE, SB_GETTEXTLENGTHW, statusbar_item_number, 0)
                                  length = retcode & 0xFFFF
                                  type = (retcode >> 16) & 0xFFFF
                                  text_buffer = create_unicode_buffer(length)
                                  retcode = SendMessage(npp_get_statusbar.STATUSBAR_HANDLE, SB_GETTEXTW, statusbar_item_number, text_buffer)
                                  retval = '{}'.format(text_buffer[:length])
                                  return retval
                          
                              def EnumCallback(hwnd, lparam):
                                  curr_class = create_unicode_buffer(256)
                                  GetClassName(hwnd, curr_class, 256)
                                  if curr_class.value.lower() == "msctls_statusbar32":
                                      npp_get_statusbar.STATUSBAR_HANDLE = hwnd
                                      return False
                                  return True
                          
                              EnumChildWindows(FindWindow(u"Notepad++", None), WNDENUMPROC(EnumCallback), 0)
                          
                              return get_data_from_statusbar(statusbar_item_number) if npp_get_statusbar.STATUSBAR_HANDLE else None
                          

                          Thus to add the modification timestamp info to the first section of the status bar, one would call npp_get_statusbar(0) and then use the returned string (if not None) by adding the time to it, e.g.:

                          notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, npp_get_statusbar(0) + ' ' * 8 + last_modified_date)

                          I’m sure the basis for this status bar code goes back to some @Claudia-Frank code, but I can’t find the reference to it right now. Sorry, CF.

                          -----
                          note from the future: if this code gives you all NULL for the characters read back from the status bar, use the updated code found in this 2024 post

                          1 Reply Last reply Reply Quote 1
                          • P
                            patrickdrd
                            last edited by patrickdrd May 6, 2018, 3:27 PM May 6, 2018, 3:27 PM

                            yes, it works CF

                            I tried BUFFERACTIVATED but it didn’t work

                            1 Reply Last reply Reply Quote 1
                            • S
                              SalviaSage
                              last edited by SalviaSage May 7, 2018, 9:21 PM May 7, 2018, 9:19 PM

                              @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
                              • P
                                patrickdrd
                                last edited by May 8, 2018, 5:17 AM

                                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
                                • S
                                  SalviaSage
                                  last edited by May 8, 2018, 12:55 PM

                                  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.

                                  D 1 Reply Last reply May 8, 2018, 2:32 PM Reply Quote 0
                                  • P
                                    patrickdrd
                                    last edited by May 8, 2018, 1:30 PM

                                    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
                                    • D
                                      dail @SalviaSage
                                      last edited by dail May 8, 2018, 2:42 PM May 8, 2018, 2:32 PM

                                      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:

                                      C 1 Reply Last reply May 8, 2018, 2:38 PM Reply Quote 2
                                      • C
                                        Claudia Frank @dail
                                        last edited by May 8, 2018, 2:38 PM

                                        @dail

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

                                        Cheers
                                        Claudia

                                        D 1 Reply Last reply May 8, 2018, 2:39 PM Reply Quote 1
                                        • D
                                          dail @Claudia Frank
                                          last edited by May 8, 2018, 2:39 PM

                                          @Claudia-Frank

                                          Ah. Thanks for clarifying.

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