Permalink
Browse files

Partially Fix DFileBrowser

It doesn't want to show subfolders and I don't know why.
  • Loading branch information...
1 parent df3efc2 commit 8a77ade751628f4bec208aaec98f2f6b41f3ff07 @robotboy655 robotboy655 committed Mar 3, 2014
Showing with 11 additions and 9 deletions.
  1. +11 −9 garrysmod/lua/vgui/dfilebrowser.lua
@@ -26,9 +26,9 @@ function PANEL:Init()
self.Tree:SetWidth( 200 )
self.Tree.DoClick = function( _, node )
-
- if ( !node.FileName ) then return end
- self:ShowFolder( node.FileName )
+
+ if ( !node:GetFolder() ) then return end
+ self:ShowFolder( node:GetFolder() )
end
@@ -43,24 +43,26 @@ function PANEL:Paint( w, h )
DPanel.Paint( self, w, h )
if ( !self.bSetup ) then
- self:Setup()
- self.bSetup = true
+ self.bSetup = self:Setup()
end
end
function PANEL:Setup()
- local root = self.Tree.RootNode:AddFolder( self.m_strName, self.m_strPath, false );
- root:SetExpanded( true );
+ if ( !self.m_strName || !self.m_strPath ) then return false end
+
+ local root = self.Tree.RootNode:AddFolder( self.m_strName, self.m_strPath, false )
+
+ return true
end
function PANEL:ShowFolder( path )
self.Icons:Clear()
- local files = file.Find( path .. "/" .. self.m_strFilter, "GAME" )
+ local files = file.Find( path .. "/" .. (self.m_strFilter or "*.*"), "GAME" )
for k, v in pairs( files ) do
@@ -93,4 +95,4 @@ function PANEL:OnSelect( path, button )
end
-derma.DefineControl( "DFileBrowser", "", PANEL, "DPanel" )
+derma.DefineControl( "DFileBrowser", "", PANEL, "DPanel" )

4 comments on commit 8a77ade

@8BallBomBom

file.Find returns 2 tables, try this.

local files, folders = file.Find( path .. "/" .. (self.m_strFilter or "*.*"), "GAME" )
@robotboy655
Collaborator

I know, the node:AddFolder should automatically create folders but it doesn't.

@Acecool
Contributor
Acecool commented on 8a77ade Mar 7, 2014

This is how my fileio class does creation of directories:

//
// Creates a directory. 
//
function fileio:CreateDir( _folder, _external, _external_path )
    if ( self:Exists( _folder, "/", _external, _external_path ) ) then return false; end
    return file.CreateDir( self:GetFolder( _folder ) );
end

It's just file.CreateDir with the folder path... Using that within AddFolder should fix any issues.

@robotboy655
Collaborator

I meant create folders in the DTree.

Please sign in to comment.