<%
    use obfui::cmn;
    my ($dirstr,$qpv,$dirs,$files,$dire,$prj,$modeselect_html,$dirsep,$opts) = @_;
    
    my @dirs_path = split($dirsep,$dirstr);
    shift @dirs_path if $dirs_path[0] eq '';
%>
<script language=javascript>
<!--
function select_all(do_select)
{
    var f = document.forms['fmain'];
    for(var idx=0; idx < f.length; ++idx)
    {
	var i = document.forms['fmain'][idx];
	if (!i['name'])	continue;
	if (i.name.indexOf('_direntry_') ==0)
	{
	    i.checked = do_select;
	}
    }
}
-->
</script>
<form method=post name=fmain>
<input type=hidden name=havevals value=1>
<input type=hidden name=dir value="<%= $dirstr %>" >
<input type=hidden name=sortby value=<%$ $qpv->{sortby} %>>
<%
if (@dirs_path) {
    my $curdir = '';
%><%= __('Directory: ') %>
<a href=project.files?dir=<%? '/' %>&sortby<%$ $qpv->{sortby} %>>
<%= __('<TOP>') %></a> / 
<%
    foreach (@dirs_path)
    {
	my $d = $_;
	$curdir .= $dirsep . $d;
%>
<a href=project.files?dir=<%? length($curdir) ? $curdir : '/'
     %>&sortby<%$ $qpv->{sortby} %>><%= $d %></a> / 
<%
    }
} %>
<p>
<% $forge->include('wgt-gobtn',__('Sort by ext'), 
    'project.files?sortby=ext&dir=' . $forge->escape_uri($dirstr) ) %>
<% $forge->include('wgt-gobtn',__('Sort by name'), 
    'project.files?sortby=name&dir=' . $forge->escape_uri($dirstr) ) %>
<p>
<table class=filebrowser>
<thead>
<tr><th></th><th class=name><%= __('Name') %></th>
    <th class=mode><%= __('Mode') %></th>
<tbody>
<% 
    my $i = 0;
    foreach ($dirs,$files) {
	my $idx = 0;
	foreach my $e (@$_) {
	    my $nm = $e->[0];
	    my $cbnm = '_direntry_' . join('',map { sprintf('%02x',ord($_))}
			    split(//,$nm));
	    my $wgtnm = $i ? 'file' : 'dir';
	    $forge->include('wgt-direntry-' . $wgtnm, $cbnm, $nm, $dirstr,
		    "${dirstr}/$nm", $e->[1],$idx,$prj,$e->[2]);
	    ++$idx;
	}
	++$i;
 } %>
</tbody>
</table><p>

<br>
<% $forge->include('wgt-jsbtn',__('Select all'),  'select_all(1)' ) %>
<% $forge->include('wgt-jsbtn',__('Unselect all'),  'select_all(0)' ) %>
<p>
<h3><%= __('Operations with selected objects:')%></h3>
<input type=checkbox class=checkbox name=recursive checked>
<%$ hstr('files.recursive',__('Apply to subdirectories if object is a directory')) %>
<br>
<div class=wideselect>
<%$ $modeselect_html %>
<br>
<% $forge->include('wgt-submitbtn-wide',
	__('Assign processing mode'), 'setmode'); %>
</div>
<p>
<% $forge->include('wgt-submitbtn',
	__('Force rebuilding'), 'touchin',__('Mark objects as "changed", so that "Build->Rebuild changed" will rebuild the objects.')); %>
<% $forge->include('wgt-submitbtn',
	__('Block next rebuilding'), 'touchout', __('Click this so that all selected objects are not to be rebuilt next time you click "Build->Rebuild changed"')); %>

<br>
<% $forge->include('wgt-submitbtn',
	__('Add to project'), 'manage'); %>

<% $forge->include('wgt-submitbtn',
	__('Stop managing'), 'unmanage', __('Do not handle selected objects anymore. This is especially useful if you have removed the objects from input directory (e.g. if you renamed them)')); %>
<p>

<div class=wideselect>
<input type=text class=text style='width:30em;' name=newname>
<br>
<% $forge->include('wgt-submitbtn-wide',
	__('Rename object in metadata of project'), 'setname',
	__('If you have removed a file in your project input directory, select the former name of file in the list above and enter new name of file here, and click this button.')); %>
</div>
</form>


<%$ __('If you are frequently adding new files to your project, you do not have to go here each time to select them and click on "Add to project". Just go to <a href=settings.unlistedfiles>Settings&rArr;edit handling of unlisted files</a> and define once and forever what do to with new files (that are not registered within the project) based on their extensions.') %>