1 #include "recentfiles.hpp"
6 recent_files::recent_files(const std::string
& _cfgfile
, size_t _maxcount
)
12 void recent_files::add(const std::string
& file
)
14 std::list
<std::string
> ents
;
17 std::ifstream
in(cfgfile
);
24 //Probe for existence.
26 regex_results r
= regex("(.*) <.*>", f
);
29 delete &open_file_relative(g
, "");
30 } catch(std::exception
& e
) {
38 //Search for matches. If found, move to front, otherwise push to first.
39 auto itr
= ents
.begin();
40 for(; itr
!= ents
.end(); itr
++)
45 ents
.push_front(file
);
46 //Write up to maxcount entries.
49 std::ofstream
out(cfgfile
);
50 for(itr
= ents
.begin(); itr
!= ents
.end() && i
< maxcount
; itr
++, i
++)
51 out
<< *itr
<< std::endl
;
57 void recent_files::add_hook(hook
& h
)
62 void recent_files::remove_hook(hook
& h
)
64 for(auto itr
= hooks
.begin(); itr
!= hooks
.end(); itr
++)
71 std::list
<std::string
> recent_files::get()
74 std::list
<std::string
> ents
;
77 std::ifstream
in(cfgfile
);
92 recent_files::recent_files::hook::~hook()