📄 item.cpp
字号:
//PK 2006/08/29 - 2007/03/08
#include "global.h"
#include "item.h"
#include "utility.h"
#include "Book.h"
#include "Records.h"
bool CItem::operator == (const CItem & rh)
{ //PK 2007/03/05
if (_title.empty() || rh._title.empty()) return false;
if (_title != rh._title) return false;
return _file_name == rh._file_name;
}
void CItem::file_name(fs::path fn)
{ //PK 2007/02/22
assert(!fn.has_branch_path());
_file_name = _book->dir() / fn;
}
void CItem::info()
{ //PK 2007/02/22
_info = _book->recorder().get_info(title());
}
bool CItem::load_title()
{ //PK 2007/02/10 - 03/05
//PK load the title from file, if the title is empty return false.
fs::ifstream ifs(_file_name);
getline(ifs, _title);
trim(_title);
// _title.erase(0, _title.find_first_not_of(' '));
// _title.erase(_title.find_last_not_of(' ') + 1);
return !_title.empty();
}
const string & CItem::get_article()
{ //PK 2006/10/08 - 2007/03/05
if (!_content.empty()) return _content;
if (!fs::exists(_file_name)) return _content;
fs::ifstream ifs(_file_name, std::ios::binary);
_content.reserve(10000);
_content.assign(istreambuf_iterator<char>(ifs.rdbuf()), istreambuf_iterator<char>());
return _content;
}
bool CItem::attach_article(const string & text)
{ //PK 2006/10/08 - 2007/03/08
if (text.empty()) return false;
_content = text;
//PK save the item
fs::ofstream ofs(_file_name, std::ios::binary);
ofs << _content;
_title.clear();
return true;
}
void CItem::update()
{ //PK 2006/10/09 - 2007/02/10
_info->update();
_book->dirty();
}
date CItem::next_day()
{ //PK 2006/10/17 - 2007/02/10
return _info->next_day();
}
int CItem::priority()
{ //PK 206/10/17
date today = day_clock::local_day();
if (_info->no_study()) return 0;
if (next_day() > today) return -1;
return 1;
}
int CItem::compare(CItem * item)
{ //PK 2006/10/17 - 26
if (item == this) return 0;
if (priority() > item->priority()) return -1;
if (priority() < item->priority()) return 1;
if (next_day() > item->next_day()) return 1;
if (next_day() < item->next_day()) return -1;
//PK when next day is same, we compare the studied times
if (access_times() < item->access_times()) return -1;
if (access_times() > item->access_times()) return 1;
return 0;
}
void CItem::access_date(date d)
{ //PK 2007/02/26
_info->_last_access = d;
}
date CItem::access_date()
{ //PK 2007/02/26
return _info->_last_access;
}
void CItem::access_times(int t)
{ //PK 2007/02/26
_info->_times = t;
}
int CItem::access_times()
{ //PK 2007/02/26
return _info->_times;
}
bool CItem::remove_article()
{ //PK 2007/03/05
if (!fs::exists(_file_name)) return false;
fs::remove(_file_name);
return true;
}
void CItem::title_changed(const string & origin)
{ //PK 2007/03/08
_book->change_record_name(origin, title());
info(_book->recorder().get_info(title()));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -