mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Edit: Add page backup feature
This commit is contained in:
parent
45d355454e
commit
96b3b0afb8
@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.pagebaks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
|
||||
import gplx.xowa.specials.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Pagebaks_addon implements Xoax_addon_itm {
|
||||
public static void On_page_saved(Xoae_app app, Xowe_wiki wiki, Xoa_ttl ttl, byte[] text) {
|
||||
// get vars
|
||||
if (!app.Cfg().Get_bool_app_or("xowa.wiki.edit.pagebaks.enabled", true)) return;
|
||||
|
||||
// #save file
|
||||
// get file name; note encoding for wnt even on lnx systems just to be consistent
|
||||
Gfo_url_encoder encoder = Gfo_url_encoder_.New__fsys_wnt().Make();
|
||||
byte[] file_name = encoder.Encode(ttl.Full_db());
|
||||
|
||||
// save file to backup dir; EX: /xowa/wiki/en.w/user/temp/save_backups/Earth/20170303_080102_123.txt
|
||||
Io_url bak_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("user", "temp", "page_backups", String_.new_u8(file_name));
|
||||
Io_url file_url = bak_dir.GenSubFil_ary(Datetime_now.Get().XtoStr_fmt("yyyyMMdd_HHmmss_fff"), ".txt");
|
||||
Io_mgr.Instance.SaveFilBry(file_url, text);
|
||||
|
||||
// #prune dir
|
||||
// get files for pruning
|
||||
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(bak_dir);
|
||||
Array_.Sort(fils);
|
||||
|
||||
// calc files
|
||||
int num_files = fils.length;
|
||||
int max_files = app.Cfg().Get_int_app_or("xowa.wiki.edit.pagebaks.max_backups", 16);
|
||||
int cutoff = num_files - max_files;
|
||||
|
||||
// do pruning
|
||||
for (int i = 0; i < cutoff; i++) {// EX: 3 files and 2 max; 1st file (index 0) needs to be deleted
|
||||
Io_mgr.Instance.DeleteFil(fils[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public String Addon__key() {return "xowa.wikis.edits.pagebaks";}
|
||||
}
|
@ -45,7 +45,11 @@ public class Xog_tab_itm_edit_mgr {
|
||||
, String_.new_u8(page.Ttl().Full_txt_raw())
|
||||
, Datetime_now.Get().XtoStr_fmt("HH:mm:ss.fff")
|
||||
);
|
||||
if (!quick_save) { // full_save; save page and go to read mode
|
||||
|
||||
// full_save; save page and go to read mode
|
||||
if (!quick_save) {
|
||||
gplx.xowa.addons.wikis.pagebaks.Pagebaks_addon.On_page_saved(wiki.Appe(), wiki, page.Ttl(), new_text);
|
||||
|
||||
// update categories
|
||||
try {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read); // NOTE: need to write html to fill Wtxt().Ctgs
|
||||
@ -54,6 +58,10 @@ public class Xog_tab_itm_edit_mgr {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to update categories; err=~{0}", Err_.Message_gplx_log(e));
|
||||
}
|
||||
|
||||
// TODO: save html copy
|
||||
//wiki.Db_mgr().Hdump_mgr().Save(page);
|
||||
|
||||
// parse page and show it
|
||||
page.Html_data().Edit_preview_(Bry_.Empty);
|
||||
Xoae_page stack_page = tab.History_mgr().Cur_page(wiki); // NOTE: must be to CurPage() else changes will be lost when going Bwd,Fwd
|
||||
stack_page.Db().Text().Text_bry_(page.Db().Text().Text_bry()); // NOTE: overwrite with "saved" changes
|
||||
@ -62,7 +70,6 @@ public class Xog_tab_itm_edit_mgr {
|
||||
win_itm.Page__mode_(Xopg_page_.Tid_read);
|
||||
win_itm.Page__async__bgn(tab);
|
||||
}
|
||||
// wiki.Db_mgr().Hdump_mgr().Save(page);
|
||||
}
|
||||
public static void Preview(Xog_tab_itm tab) {
|
||||
if (tab.View_mode() != Xopg_page_.Tid_edit) return; // exit if not edit; handles preview somehow being called?
|
||||
|
Loading…
Reference in New Issue
Block a user