Debian Codegraph @

artemis_parts/mru.pl

raw
1 ## -*- cperl -*-
2 ##
3 ## This file is part of Artemis, copyright (c) 2002-2008 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, $type) = @_;
13 my ($name, $path, $suffix) = fileparse($file);
14
15 return if ($file eq $autosave_filename);
16 ## set some global variables
17 $current_data_dir = $path;
18 # ($project_name = $file) if (&is_record($file));
19 return unless ($push_file);
20
21 my $item = $file . ' [' . $type . ']';
22 ## check to see if this file is already in the sack
23 my $im = $config{general}{mru_limit};
24 my $ifound = 0;
25 foreach my $i (1 .. $im-1) {
26 ($ifound = $i), last if ($item eq $mru{mru}{$i});
27 };
28
29 ## if it is on the stack already, remove it and move all lower ones
30 ## up
31 if ($ifound) {
32 foreach my $i ($ifound+1 .. $im) {
33 my $j = $i - 1;
34 $mru{mru}{$j} = $mru{mru}{$i};
35 };
36 };
37
38 ## push each entry down in the stack
39 foreach my $i (reverse(1 .. $im-1)) {
40 my $j = $i + 1;
41 $mru{mru}{$j} = $mru{mru}{$i};
42 };
43 ## push this file to the top of the stack
44 $mru{mru}{1} = $item;
45
46 ## update the mru menu
47 &set_recent_menu;
48
49 ## save the mru file
50 tied(%mru) -> WriteConfig($mrufile);
51
52 return $name;
53 };
54
55 sub set_recent_menu {
56 my $menu = $file_menu -> cget('-menu') -> entrycget('Recent files', '-menu');
57 $menu -> delete(0,'end');
58 foreach my $i (1 .. $config{general}{mru_limit}) {
59 last unless ($mru{mru}{$i});
60 my $label = $mru{mru}{$i};
61 if ($config{general}{mru_display} eq "name") {
62 $label =~ /^([^\[]*)(\[.*\])/;
63 my $type = $2;
64 (my $file = $1) =~ s/\s+$//;
65 $label = basename($file) . " " . $type;
66 };
67 $menu -> add('command', -label=>$label, @menu_args,
68 -command=>sub{&dispatch_mru($mru{mru}{$i})});
69 };
70 };
71
72
73 sub dispatch_mru {
74 return unless $_[0];
75 my ($file, $type) = ($_[0], "");
76 ($file, $type) = ($1, $2) if ($_[0] =~ /(.+) \[(\w+)\]$/);
77 Echo("Could not find \"$file\""), return unless (-e $file);
78 Echo("Reading recent file \"$file\"");
79 if ($type eq 'atoms') {
80 &import_atoms($file);
81 } elsif ($type eq 'feff') {
82 &read_feff($file);
83 } elsif ($type eq 'feffit') {
84 &feffit_convert_input($file);
85 } elsif ($type eq 'project') {
86 &read_data($paths{$current}->data, $file);
87 } elsif ($type eq 'athena') {
88 &read_athena($file);
89 } else { # data
90 my @data = &every_data;
91 my $this = $paths{$current}->data;
92 if ($#data or $paths{$this}->get('file')) {
93 my $message = "Do you wish to read in a new data file (that is, to do multiple data set fitting), or do you wish to change the current data file (that is, to apply this fitting model to a different data set) ?";
94 my $dialog =
95 $top -> Dialog(-bitmap => 'questhead',
96 -text => $message,
97 -title => 'Athena: Reading data',
98 -buttons => [qw/Change New Cancel/],
99 -default_button => 'Change',
100 -font => $config{fonts}{med},
101 -popover => 'cursor');
102 &posted_Dialog;
103 my $response = $dialog->Show();
104 Echo("Canceling data import"), return if ($response eq 'Cancel');
105 Echo("Reading \"$file\"");
106 my $change = ($response eq 'Change') ? 1 : 0;
107 read_data($change, $file);
108 } else {
109 read_data(0, $file);
110 };
111 ##&dispatch_read_data(1, $file);
112 };
113 ## make sure something is marked for plotting after the fit
114 my @all = &all_data;
115 foreach (@all) {
116 return $type if $paths{$_}->get('plot');
117 };
118 $widgets{op_plot} -> select;
119 $paths{$all[0]}->make(plot=>1);
120 return $type;
121 };
122
123
124 ## END OF MRU SUBSECTION
125 ##########################################################################################