[Implemented] Clear empty sessions from Session History

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

[Implemented] Clear empty sessions from Session History

Post by kenmo »

I really like the Session History feature, but it seems silly that it saves "empty" sessions (no file activity).
It's harmless, but it really clutters up the dropdown list of sessions!

Yes, empty sessions occasionally happen. Maybe I pop open the IDE, then get distracted and don't edit anything.
Over time, I can build up 50+ quick empty sessions in my History list!


In the meantime, I wrote an invisible IDE tool to delete empty sessions at startup:

Code: Select all

; Build, add to IDE Tools with "Editor Startup" trigger
;
File.s = GetPathPart(GetEnvironmentVariable("PB_TOOL_Preferences")) + "History.db"
If (FileSize(File) > 0)
  UseSQLiteDatabase()
  If (OpenDatabase(0, File, "", ""))
    NewList SID.s()
    If (DatabaseQuery(0, "SELECT session_id FROM session"))
      While (NextDatabaseRow(0))
        AddElement(SID())
        SID() = GetDatabaseString(0, 0)
      Wend
      FinishDatabaseQuery(0)
      ForEach SID()
        If (DatabaseQuery(0, "SELECT COUNT(*) FROM event WHERE session_id='" + SID() + "'"))
          If (NextDatabaseRow(0))
            Count.i = GetDatabaseLong(0, 0)
            If (Count = 0)
              DatabaseUpdate(0, "DELETE FROM session WHERE session_id='" + SID() + "'")
            EndIf
          EndIf
          FinishDatabaseQuery(0)
        EndIf
      Next
    EndIf
    CloseDatabase(0)
  EndIf
EndIf
Last edited by kenmo on Fri Feb 07, 2020 4:03 am, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Clear empty sessions from Session History

Post by kenmo »

Merged in Pull Request #34 and should be available in PB 5.72+ :)
https://github.com/fantaisie-software/purebasic/pull/34

Marking this as [Implemented]
Post Reply