-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_editor_state.m
41 lines (35 loc) · 1.5 KB
/
load_editor_state.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% 2022-10
% Loads a previously save 'editor_status' file and opens the files listed
% in it in the Matlab editor.
function load_editor_state(start_fresh)
if ~exist('start_fresh', 'var')
start_fresh = 0;
% if start_fresh is 0: Will leave open all currently opened files,
% add the ones from the saved state
% if start_fresh is 1: will close all existing files and only open
% the saved ones
end
cur_dir = pwd(); % this is where the file will be found!
% Load the editor status file
ed_fn = 'editor_status.mat';
full_ed_fn = [cur_dir filesep ed_fn];
if isfile(full_ed_fn)
editor_status = load(full_ed_fn);
editor_status = editor_status.editor_status;
if start_fresh
% As a backup before closing open files, save the current filelist
save_editor_state('editor_status_backup')
% Start by closing already open files
close(matlab.desktop.editor.getAll)
end
% open each of these files one by one
for file_i = 1:size(editor_status.openfiles,2)
matlab.desktop.editor.openDocument(editor_status.openfiles{file_i});
end
% Focus the editor on the one which was the active file
matlab.desktop.editor.openDocument(editor_status.active_file);
disp('Previous editor state loaded! Ready to Rock')
else
disp('No editor status found. Unable to load previous editor state for this project')
end
end