--[[
	MOD/lua/file_view/cl/print_file_list.lua [#1794 (#1896), 1809304704, UID:2099631115]
	xX-TrueMLGPlayer420Trikshot-Xx | STEAM_0:0:71356345 <82.238.182.218:27005> | [22.06.14 02:38:38PM]
	===BadFile===
]]

local btns={}
local cd = { "" }
local pd = {}
local function draw_b( dp, t )
	if(#t==0)then 
		local b=vgui.Create( "DButton", dp )
		table.insert(btns,b)
		b:SetSize(373,40)
		b:SetPos(0,0)
		b:SetText("Done loading. No readable files present." )
		return
	end
	local i=0
	for i=1,#btns do
		btns[i]:Remove()
	end
	
	for k,v in pairs(t) do
	
	local b=vgui.Create( "DButton", dp )
	table.insert(btns,b)
	b:SetSize(373,40)
	b:SetPos(0,40*i)
	
	if(type(v)=="table")then
		b:SetText(k)
	else
		b.is_file=true
		b:SetText(v)
	end
	
	function b:DoClick()
		local txt=self:GetText()
		if(self.is_file) then
			local str
			if( cd[#cd] == "" ) then
				str = txt
			else
				str = cd[#cd].."/"..txt
			end
			net.Start("print_file_text" )
				net.WriteString(str)
			net.SendToServer()
			
			else
			
			for i = 1,#btns do
				btns[i]:Remove()
			end
			local str
			if( cd[#cd] == "" ) then
				str = txt
			else
				str = cd[#cd].."/"..txt
			end
			net.Start( "view_dir" )
				net.WriteString(str.."/")
			net.SendToServer()
			
			table.insert(cd,cd[#cd].."/"..txt)
			table.insert(pd,t)
			
		end
	end
	i=i+1
	
	end
end

	local dm=vgui.Create("DFrame")
	dm:SetSize(400,425)
	dm:Center()
	dm:SetTitle("")
	function dm:Think()
		if(cd[#cd][1]=='/')then cd[#cd]=string.SetChar(cd[#cd],1,"") end
		self:SetTitle(cd[#cd])
	end
	function dm:OnClose()
		net.Start("close_view")
		net.SendToServer()
	end
	dm:MakePopup(true)
	dm:ShowCloseButton(true)
	
	local dp = vgui.Create("DScrollPanel",dm)
	dp:Dock(FILL)
	local bb=vgui.Create("DButton",dm)
	bb:SetPos(299,3)
	bb:SetSize(65,18)
	bb:SetText("Back")
	function bb:DoClick()
		if(#pd!=0)then
			draw_b(dp,pd[#pd])
			table.remove(pd)
			table.remove(cd)
		end
	end

net.Receive( "print_file_list", function()
local t=net.ReadTable()
draw_b(dp,t)
end)
