Skip to content

Commit

Permalink
Keep Order of Project Files
Browse files Browse the repository at this point in the history
  • Loading branch information
HeX0R authored and HeX0R101 committed Jan 26, 2022
1 parent 4d20f77 commit 0737728
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions PureBasicIDE/Common.pb
Expand Up @@ -2231,6 +2231,7 @@ Structure ProjectFileConfig
AutoScan.l ; Should the file be scanned for autocomplete ?
ShowPanel.l ; show in panel
ShowWarning.l ; show warning if file changes
SortIndex.l ; for sorting

PanelState$ ; string of "0"/"1" for every parent directory of the file to indicate whether it is expanded in panel (empty if ShowPanel=0)
EndStructure
Expand Down
40 changes: 30 additions & 10 deletions PureBasicIDE/ProjectManagement.pb
Expand Up @@ -706,10 +706,10 @@ Procedure AddProjectInfo()
; Probably a bug that should be fixed there. But this workaround will do the trick
If CountTabBarGadgetItems(#GADGET_FilesPanel) = 0
; first item, use #PB_Default
AddTabBarGadgetItem(#GADGET_FilesPanel, #PB_Default, Language("Project", "TabTitle"))
AddTabBarGadgetItem(#GADGET_FilesPanel, #PB_Default, Language("Project", "TabTitle") + " [" + ProjectName$ + "]")
Else
; items exist: using 0 works
AddTabBarGadgetItem(#GADGET_FilesPanel, 0, Language("Project", "TabTitle"))
AddTabBarGadgetItem(#GADGET_FilesPanel, 0, Language("Project", "TabTitle") + " [" + ProjectName$ + "]")
EndIf

SetTabBarGadgetItemColor(#GADGET_FilesPanel, 0, #PB_Gadget_FrontColor, #COLOR_FilePanelFront)
Expand Down Expand Up @@ -955,13 +955,15 @@ Procedure LoadProject(Filename$)
ProjectFiles()\ShowWarning = Xml_Boolean(GetXMLAttribute(*Config, "warn"))
ProjectFiles()\LastOpen = Xml_Boolean(GetXMLAttribute(*Config, "lastopen"))
ProjectFiles()\PanelState$ = Xml_SingleLine(GetXMLAttribute(*Config, "panelstate")) ; the default for this is "all open", so need no backward compatibility here
ProjectFiles()\SortIndex = Xml_Integer(GetXMLAttribute(*Config, "sortindex"))
Else
ProjectFiles()\AutoLoad = 0
ProjectFiles()\AutoScan = IsCodeFile(ProjectFiles()\Filename$)
ProjectFiles()\ShowPanel = 1
ProjectFiles()\ShowWarning = 1
ProjectFiles()\LastOpen = 0
ProjectFiles()\PanelState$ = ""
ProjectFiles()\SortIndex = 999
EndIf

*Fingerprint = XMLNodeFromPath(*File, "fingerprint")
Expand Down Expand Up @@ -1178,8 +1180,8 @@ Procedure LoadProject(Filename$)
EndIf
EndIf

; Auto-sort the project files for better handling
SortStructuredList(ProjectFiles(), #PB_Sort_Ascending | #PB_Sort_NoCase, OffsetOf(ProjectFile\FileName$), #PB_String)
; Sort project files according to their last position in the IDE
SortStructuredList(ProjectFiles(), #PB_Sort_Ascending, OffsetOf(ProjectFile\SortIndex), #PB_Long)

If CommandlineBuild = 0

Expand Down Expand Up @@ -1396,11 +1398,12 @@ Procedure SaveProject(ShowErrors)
SetXMLAttribute(*File, "name", CreateRelativePath(BasePath$, ProjectFiles()\FileName$))

*FileConfig = AppendNode(*File, "config")
SetXMLAttribute(*FileConfig, "load", Str(ProjectFiles()\AutoLoad))
SetXMLAttribute(*FileConfig, "scan", Str(ProjectFiles()\AutoScan))
SetXMLAttribute(*FileConfig, "panel", Str(ProjectFiles()\ShowPanel))
SetXMLAttribute(*FileConfig, "warn", Str(ProjectFiles()\ShowWarning))
SetXMLAttribute(*FileConfig, "lastopen", Str(ProjectFiles()\LastOpen))
SetXMLAttribute(*FileConfig, "load", Str(ProjectFiles()\AutoLoad))
SetXMLAttribute(*FileConfig, "scan", Str(ProjectFiles()\AutoScan))
SetXMLAttribute(*FileConfig, "panel", Str(ProjectFiles()\ShowPanel))
SetXMLAttribute(*FileConfig, "warn", Str(ProjectFiles()\ShowWarning))
SetXMLAttribute(*FileConfig, "lastopen", Str(ProjectFiles()\LastOpen))
SetXMLAttribute(*FileConfig, "sortindex", Str(ProjectFiles()\SortIndex))

If ProjectFiles()\ShowPanel
SetXMLAttribute(*FileConfig, "panelstate", ProjectFiles()\PanelState$)
Expand Down Expand Up @@ -1742,8 +1745,15 @@ Procedure CloseProject(IsIDEShutdown = #False)
ForEach ProjectFiles()
If ProjectFiles()\Source
ProjectFiles()\LastOpen = #True
ForEach FileList()
If ProjectFiles()\FileName$ = FileList()\FileName$
ProjectFiles()\SortIndex = ListIndex(FileList())
Break
EndIf
Next
Else
ProjectFiles()\LastOpen = #False
ProjectFiles()\SortIndex = 999
EndIf
Next ProjectFiles()

Expand Down Expand Up @@ -2145,6 +2155,8 @@ Procedure ProjectOptionsEvents(EventID)
If ProjectOK

; In case we create a new project. Now we have a project data
OldProjectName$ = ProjectName$
ProjectName$ = Trim(GetGadgetText(#GADGET_Project_Name))
If IsProjectCreation
IsProject = #True
ProjectFile$ = NewProjectFile$
Expand All @@ -2166,10 +2178,18 @@ Procedure ProjectOptionsEvents(EventID)
; switch to the info source, so the user can directly get to the projects compiler options etc
FirstElement(FileList())
ChangeActiveSourceCode()
ElseIf OldProjectName$ <> ProjectName$
;change name of Tab, if user changed the project name
;Tab can be moved by customer, therefore going through all open Tabs to find it. Maybe there is a better solution, but it works
For i = 0 To CountTabBarGadgetItems(#GADGET_FilesPanel) - 1
If GetTabBarGadgetItemText(#GADGET_FilesPanel, i) = Language("Project", "TabTitle") + " [" + OldProjectName$ + "]"
SetTabBarGadgetItemText(#GADGET_FilesPanel, i, Language("Project", "TabTitle") + " [" + ProjectName$ + "]")
Break
EndIf
Next i
EndIf

; Update the options
ProjectName$ = Trim(GetGadgetText(#GADGET_Project_Name))
ProjectComments$ = GetGadgetText(#GADGET_Project_Comments)

If GetGadgetState(#GADGET_Project_SetDefault)
Expand Down

0 comments on commit 0737728

Please sign in to comment.