Skip to content

Commit

Permalink
Merge pull request #25 from NuPogodi/master
Browse files Browse the repository at this point in the history
Moving global settings for crengine to ./data/cr3.ini
  • Loading branch information
houqp committed Jun 29, 2013
2 parents f4561cf + 4ec0c65 commit efeaab3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,26 @@ static int newDocView(lua_State *L) {
doc->text_view->Resize(width, height);
doc->text_view->setPageHeaderInfo(PGHDR_AUTHOR|PGHDR_TITLE|PGHDR_PAGE_NUMBER|PGHDR_PAGE_COUNT|PGHDR_CHAPTER_MARKS|PGHDR_CLOCK);

// it will overwrite all settings by values found in ./data/cr3.ini
CRPropRef props = doc->text_view->propsGetCurrent();
LVStreamRef stream = LVOpenFileStream("data/cr3.ini", LVOM_READ);
if ( !stream.isNull() && props->loadFromStream(stream.get()) ) {
doc->text_view->propsApply(props);
} else {
stream = LVOpenFileStream("data/cr3.ini", LVOM_WRITE);
props->saveToStream(stream.get());
}

return 1;
}

static int saveDefaults(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
CRPropRef props = doc->text_view->propsGetCurrent();
LVStreamRef stream = LVOpenFileStream("data/cr3.ini", LVOM_WRITE);
return props->saveToStream(stream.get());
}

static int getGammaIndex(lua_State *L) {
lua_pushinteger(L, fontMan->GetGammaIndex());

Expand Down Expand Up @@ -762,6 +779,7 @@ static const struct luaL_Reg credocument_meth[] = {
{"getPageLinks", getPageLinks},
{"gotoLink", gotoLink},
{"clearSelection", clearSelection},
{"saveDefaults", saveDefaults},
{"close", closeDocument},
{"__gc", closeDocument},
{NULL, NULL}
Expand Down

0 comments on commit efeaab3

Please sign in to comment.