| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel |
| 4 |
## |
| 5 |
## This implements the most-recently-used (MRU) file functionality |
| 6 |
|
| 7 |
|
| 8 |
## handle the MRU stack. Also deal with the global variables that |
| 9 |
## keep track of the current working directory and the current project |
| 10 |
## file name. |
| 11 |
sub push_mru { |
| 12 |
my ($file, $push_file, $project, $complete) = @_; |
| 13 |
my ($name, $path, $suffix) = fileparse($file); |
| 14 |
|
| 15 |
## set some global variables |
| 16 |
$current_data_dir = $path; |
| 17 |
## if this is a project, then set the global project name |
| 18 |
## variable. however, if the global variable is already set, then |
| 19 |
## set the global variable to a single space. the idea here is that |
| 20 |
## the project name should be explicitly set upon saving in the case |
| 21 |
## where projects are merged |
| 22 |
if ($project and $complete) { |
| 23 |
##$project_name = ($project_name !~ /^\s*$/) ? " " : $file; |
| 24 |
$project_name = $file; |
| 25 |
$plot_features{project} = $project_name; |
| 26 |
}; |
| 27 |
return unless ($push_file); |
| 28 |
|
| 29 |
## check to see if this file is already in the sack |
| 30 |
my $im = $config{general}{mru_limit}; |
| 31 |
my $ifound = 0; |
| 32 |
foreach my $i (1 .. $im-1) { |
| 33 |
next unless exists($mru{mru}{$i}); |
| 34 |
($ifound = $i), last if ($file eq $mru{mru}{$i}); |
| 35 |
}; |
| 36 |
## if it is on the stack already, remove it and move all lower ones |
| 37 |
## up |
| 38 |
if ($ifound) { |
| 39 |
foreach my $i ($ifound+1 .. $im) { |
| 40 |
my $j = $i - 1; |
| 41 |
$mru{mru}{$j} = $mru{mru}{$i}; |
| 42 |
}; |
| 43 |
}; |
| 44 |
|
| 45 |
## push each entry down in the stack |
| 46 |
foreach my $i (reverse(1 .. $im-1)) { |
| 47 |
my $j = $i + 1; |
| 48 |
$mru{mru}{$j} = $mru{mru}{$i}; |
| 49 |
}; |
| 50 |
## push this file to the top of the stack |
| 51 |
$mru{mru}{1} = $file; |
| 52 |
|
| 53 |
## update the mru menu |
| 54 |
&set_recent_menu; |
| 55 |
|
| 56 |
## save the mru file |
| 57 |
tied(%mru) -> WriteConfig($mrufile); |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
sub set_recent_menu { |
| 62 |
my $menu = $file_menu -> cget('-menu') -> entrycget('Recent files', '-menu'); |
| 63 |
$menu -> delete(0,'end'); |
| 64 |
foreach my $i (1 .. $config{general}{mru_limit}) { |
| 65 |
last unless ($mru{mru}{$i}); |
| 66 |
my $label = $mru{mru}{$i}; |
| 67 |
($label = basename($label)) if ($config{general}{mru_display} eq "name"); |
| 68 |
$menu -> add('command', -label=>$label, @menu_args, |
| 69 |
-command=>sub{&read_file(0, $mru{mru}{$i})}); |
| 70 |
}; |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
## END OF MRU SUBSECTION |
| 76 |
########################################################################################## |