Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -704,28 +704,34 @@ sub saveFileChanges ($c, $outputFilePath, $backup = 0) {
}

# If the file is being saved as a new file in a new location, and the file is accompanied by auxiliary files
# transfer them as well. If the file is a pg file, then assume there are auxiliary files. Copy all files not
# ending in .pg from the original directory to the new one.
if ($c->{action} eq 'save_as' && $outputFilePath =~ /\.pg/) {
# transfer them as well. If the option 'copyAuxFiles' is set and the file is a pg file, then assume there are
# auxiliary files. Copy all files not ending in .pg from the original directory to the new one.
if ($c->{action} eq 'save_as' && $c->param('copyAuxFiles') && $outputFilePath =~ /\.pg/) {
my $sourceDirectory = Mojo::File->new(($c->{sourceFilePath} || '') =~ s|/[^/]+\.pg$||r);
my $outputDirectory = Mojo::File->new($outputFilePath =~ s|/[^/]+\.pg$||r);

# Only perform the copy if the output directory is an actual new location.
if ($sourceDirectory ne $outputDirectory && -d $sourceDirectory) {
my $filesCopied = 0;
for my $file (@{ $sourceDirectory->list }) {
# The .pg file being edited has already been transferred. Ignore any others in the directory.
next if $file =~ /\.pg$/;
my $toPath = $outputDirectory->child($file->basename);
# Only copy regular files that are readable and that have not already been copied.
if (-f $file && -r $file && !-e $toPath) {
eval { $file->copy_to($toPath) };
$c->addbadmessage($c->maketext('Error copying [_1] to [_2].', $file, $toPath)) if $@;
if ($@) {
$c->addbadmessage($c->maketext('Error copying [_1] to [_2].', $file, $toPath));
} else {
$filesCopied = 1;
}
}
}
$c->addgoodmessage($c->maketext(
'Copied auxiliary files from [_1] to new location at [_2].',
$sourceDirectory, $outputDirectory
));
))
if $filesCopied;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<%= hidden_field 'action.save_as.source_file' => $c->{editFilePath} =%>
<%= hidden_field 'action.save_as.file_type' => $c->{file_type} =%>
</div>
<div class="form-check">
% param('copyAuxFiles', 1) unless defined param('copyAuxFiles');
<%= check_box copyAuxFiles => 1, id => 'copyAuxFiles', class => 'form-check-input' =%>
<%= hidden_field copyAuxFiles => 0 =%>
<%= label_for copyAuxFiles => maketext('Copy auxiliary files.'), class => 'form-check-label' =%>
</div>
% if ($can_add_problem_to_set) {
<div class="form-check">
<%= radio_button 'action.save_as.saveMode' => 'rename', id => 'action_save_as_saveMode_rename_id',
Expand Down
5 changes: 5 additions & 0 deletions templates/HelpFiles/InstructorPGProblemEditor.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@
. 'append to the end to then end of the current set as a new problem, or create a problem that is not '
. 'attached to a problem set.') =%>
</p>
<p>
<%= maketext('When saving the problem in a new location (directory), by default all auxiliary files, such '
. 'as images, or other files that do not end in ".pg", will also be copied to the new location. To '
. 'stop this behavior, uncheck the "Copy auxiliary files" option.') =%>
</p>
<p>
<%= maketext('You may want to create an unattached problem if you are using the current problem as a model '
. 'for a new problem. You can add the new file to a homework set from the Library Browser or via the '
Expand Down