No announcement yet.

IDE Loses Opened File List

  • Filter
  • Time
  • Show
Clear All
new posts

  • IDE Loses Opened File List

    Normally, the IDE reopens files from the last session.

    I discovered that if I open the IDE from SHELL with a file name as an argument (to open that file), that the IDE loses the list of previously opened files (does not reopen files from the last session).

    Is that a known thing?

    Here's the line I use in gbThreads but I've never noticed until tonight that the IDE loses the list of previously opened files.

    iResult = Shell(PowerBASICIDE + " " + $Dq + fName$ + $Dq)
    I'd rather the new file was added to the list of previously opened files.

  • #2
    Some more info. When I open the PBWin.ini file, I see a list of all of the previously opened files. It's not obvious to me how the IDE knows to exclude those when it opens, after being SHELL'd to by my code.


    • #3
      It's always been that way when you pass a filename to the IDE

      It's only when you open PBEdit directly without any parameters that it re-opens previously open files.

      Drag & drop a .bas file onto the PB Shortcut and it just opens that file.

      Double click on a .bas file (or right click and select "Open" and it just opens that file.

      FWIW, I almost always open a bas file to start PBEdit so I'm used to that behaviour.


      • #4
        Re your second post.

        You appear to be confusing two different things:

        1. The files that were open when PBEDIT was closed.
        2. The Recent Files list.

        These two are totally independent. You do not lose the Recent Files list when opening a PBEdit with a file specified. That's the list you see in PBWIN.ini.

        (I've just tried opening/closing PBEdit with diffreent files open.and monitoring PBWin.ini - I can't see anywhere it keeps track of what files were open )


        • #5
          Hey Gary,
          You could read the ini and SHELL wilh multiple filenames from it.
          ProcessId = Shell("D:\Basic\PBEDIT.exe " & $DQ & "D:\Basic\Bas\Tst1.bas" & $DQ & $SPC & $DQ & "D:\Basic\Bas\Tst2.bas" & $DQ)

          An easy way would be to SHELL with no filename and simulate a file drop.
          Change PbEdit and .bas filename path...

          #COMPILE EXE '#Win#
          #DIM ALL
          #INCLUDE ""
          TYPE DROPFILES '20 bytes
            pFiles AS DWORD    'Offset of a double null terminated file list
            pt     AS POINTAPI 'Drop point client coords
            fNC    AS LONG     'It is on NonClient area and pt is in screen coords
            fWide  AS LONG     'Zero = ANSI else WIDE
          END TYPE
           LOCAL DropFile     AS DROPFILES
           LOCAL sItemArray   AS STRING
           LOCAL hMem         AS DWORD
           LOCAL pMem         AS DWORD
           LOCAL ProcessId    AS DWORD
           LOCAL ProcessIdTry AS DWORD
           LOCAL hTry         AS DWORD
           LOCAL hPbEdit      AS DWORD
           LOCAL Looper       AS LONG
           ProcessId = Shell("D:\Basic\Win\bin\PBEDIT.exe")
           'Since it will take some time for Windows to create the dialog,
           'the use of this FOR/NEXT loop will wait up to 10 seconds...
           FOR Looper = 1 TO 100                            'Try for 10 seconds (100 * 0.1 second)
             hTry = GetForegroundWindow()                   'Get handle of foreground window
               GetWindowThreadProcessId(hTry, ProcessIdTry) 'Get ProcessId of try window
               IF ProcessId = ProcessIdTry THEN             'Found our process id ?
                 hPbEdit = hTry
                 EXIT FOR                                   'Job done
               END IF
               hTry = GetNextWindow(hTry, %GW_HWNDNEXT)     'Get next window handle
             LOOP UNTIL hTry = 0                            'No more handle to check if zero
             SLEEP 100                                      'Give Windows time to create dialog, 0.1 second delay
           IF hPbEdit THEN
             'Double zero terminated array of zero terminated string, may be Ansi or UNICODE
             sItemArray = "D:\Basic\Bas\SRC\Test04.bas" & $NUL & $NUL
             DropFile.pFiles = SIZEOF(DROPFILES) '+ LEN(sItemArray) '20 - Offset of a double null terminated file list
      = 0 '400 'Drop point client coords
      = 0 '300 'Drop point client coords
             DropFile.fNC    = 0 'Is it on NonClient area and pt is in screen coords
             DropFile.fWide  = 0 'Zero = ANSI else WIDE
             hMem = GlobalAlloc(%GMEM_FIXED OR %GMEM_ZEROINIT, SIZEOF(DROPFILES) + LEN(sItemArray))
             pMem = GlobalLock(hMem)
             CopyMemory(pMem, VARPTR(DropFile), SIZEOF(DROPFILES))
             CopyMemory(pMem + SIZEOF(DROPFILES), STRPTR(sItemArray), LEN(sItemArray))
             PostMessage(hPbEdit, %WM_DROPFILES, hMem, 0)
             'SLEEP 2000 'Give time to PbEdit to free memory
             'IF GlobalFlags(hMem) <> %GMEM_INVALID_HANDLE THEN
             '  'PbEdit will free memory via DragFinish(CBWPARAM) so next two lines are not needed if all goes well
             '  GlobalUnlock(pMem)
             '  GlobalFree(hMem)
             'END IF
           END IF
          END FUNCTION


          • #6
            Yo Stuart!

            Nor could I, see how the INI determines which files to re-open automatically in the next session. The only list of the files is the limited number of recently opened files, which is not the re-open list of files. Where the heck is the list of files to re-open kept!?

            and, Howdy Pierre!
            But if the INI does not contain the list of files to re-open, your suggestion of reading the INI won't help, will it?

            I like the idea of faking a drag/drop! I'll go give it a try.


            • #7
              You are right, for the file to load, look in Default.pbprj
              You will see lines like "SaveFile000="/A/W:0,0,0,0:C:\Basic\String\Test01.bas"

              /A: Active file
              /P: for primary file
              /W:0,0,0,0 Scroll position

              You may add your file there before Shelling with no filenames.


              • #8
                Yep, Pierre, you are correct. The IDE created a pbprj file that contains the list of files to be re-opened. It's more like a "session.pbprj" than a "default.pbprj", but regardless of name, you have pointed out the location.

                So, if I want to SHELL to the IDE without interrupting the list of files to be re-opened, I could add a new line "SaveFileXXX" to that INI before restarting the IDE.

                I wonder if the SaveFile line item has to have sequential values ... SaveFile000, SaveFile001, ... SaveFile009?

                I just did a quick trial and inserted a line using "SaveFile999". The IDE did insert the new line item. But then when the session ended, it sequentially renumbered the files in the updated INI.


                • #9
                  On the assumption no one ever opens 999 files at one time, I'll change my gbThreads code to add that line item "SaveFile999" into Default.PBprj. That will keep the session file list from being erased.

                  Cool beans! Thanks for the help.


                  • #10
                    If you feel like having fun, you may edit the 3 filenames and try this code...

                    #COMPILE EXE '#Win JR include#
                    #DIM ALL
                    #INCLUDE ""
                    FUNCTION PBMAIN() AS LONG
                     LOCAL sIniFileName   AS STRING
                     LOCAL sFileNameToAdd AS STRING
                     LOCAL sPbEditExe     AS STRING
                     LOCAL hFile          AS LONG
                     LOCAL LineCount      AS LONG
                     LOCAL index          AS LONG
                     LOCAL StringPos      AS LONG
                     LOCAL SaveFileNum    AS LONG
                     LOCAL InsertionPoint AS LONG
                     sFileNameToAdd  = "D:\Basic\SRC\Test05.bas"
                     sIniFileName    = "D:\Basic\Win\bin\Default.pbprj"
                     sPbEditExe      = "D:\Basic\Win\Bin\PbEdit.exe"
                     hFile = FREEFILE
                     OPEN sIniFileName FOR INPUT AS hFile LEN = 65536
                     FILESCAN #hFile, RECORDS TO LineCount
                     DIM TextLine(1 TO LineCount) AS STRING
                     LINE INPUT #hFile, TextLine()
                     CLOSE #hFile
                     'Reset active file
                     FOR index = 1 TO LineCount
                       IF LEFT$(TextLine(index), 8) = "SaveFile" THEN
                         SaveFileNum    = VAL(MID$(TextLine(index), 9)) + 1
                         InsertionPoint = index + 1
                         StringPos = INSTR(TextLine(index), "/A:")
                         IF StringPos THEN 'Remove "/A:" active flag, we want it for ourselve
                           TextLine(index) = LEFT$(TextLine(index), StringPos - 1) & MID$(TextLine(index), StringPos + 3)
                           EXIT FOR
                         END IF
                       END IF
                     'Add our file
                     INCR LineCount 
                     REDIM PRESERVE TextLine(1 TO LineCount)
                     ARRAY INSERT TextLine(InsertionPoint), _
                                  "SaveFile" & FORMAT$(SaveFileNum, "000") & _
                                  "=" & $DQ & "/A:/W:0,0,0,0:" & sFileNameToAdd & $DQ
                     hFile = FREEFILE
                     OPEN sIniFileName FOR OUTPUT AS hFile
                     PRINT #hFile, JOIN$(TextLine(), $CRLF)
                     CLOSE #hFile
                     MessageBox(%HWND_DESKTOP, JOIN$(TextLine(), $CRLF), "Default.pbprj", %MB_OK OR %MB_TOPMOST)
                     SHELL sPbEditExe
                    END FUNCTION


                    • #11
                      Originally posted by Pierre Bellisle View Post
                      You are right, for the file to load, look in Default.pbprj
                      You will see lines like "SaveFile000="/A/W:0,0,0,0:C:\Basic\String\Test01.bas"

                      /A: Active file
                      /P: for primary file
                      /W:0,0,0,0 Scroll position

                      You may add your file there before Shelling with no filenames.
                      Darn, should have noticed that Default.pbprj always had the same file time as PBWin.ini