mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Cfg: Convert 'App - Startup' (start)
This commit is contained in:
parent
2f3a3a7a16
commit
bfc5c5b68e
@ -50,14 +50,15 @@ public class Xocfg_mgr {
|
||||
cache_mgr.Sub(sub, ctx, key, key);
|
||||
return cache_mgr.Get(ctx, key);
|
||||
}
|
||||
public boolean Get_bool_by_app_or(String key, boolean or) {
|
||||
public boolean Get_bool_app_or(String key, boolean or) {
|
||||
String rv = Get_str(Ctx__app, key);
|
||||
return rv == null ? or : Yn.parse_or(rv, or);
|
||||
}
|
||||
public boolean Get_bool_by_wiki_or(Xow_wiki wiki, String key, boolean or) {
|
||||
public boolean Get_bool_wiki_or(Xow_wiki wiki, String key, boolean or) {
|
||||
String rv = Get_str(wiki.Domain_itm().Abrv_xo_str(), key);
|
||||
return rv == null ? or : Yn.parse_or(rv, or);
|
||||
}
|
||||
public String Get_str_app_or(String key, String or) {return cache_mgr.Get_or(Ctx__app, key, or);}
|
||||
public String Get_str_app(String key) {return Get_str(Xocfg_mgr.Ctx__app, key);}
|
||||
public boolean Get_bool_or(String ctx, String key, boolean or) {
|
||||
String rv = cache_mgr.Get(ctx, key);
|
||||
@ -68,7 +69,7 @@ public class Xocfg_mgr {
|
||||
return or;
|
||||
}
|
||||
}
|
||||
public int Get_int_by_wiki_or(Xow_wiki wiki, String key, int or) {
|
||||
public int Get_int_wiki_or(Xow_wiki wiki, String key, int or) {
|
||||
String rv = Get_str(wiki.Domain_itm().Abrv_xo_str(), key);
|
||||
try {return Int_.parse(rv);}
|
||||
catch (Exception exc) {
|
||||
|
@ -35,6 +35,14 @@ public class Xocfg_cache_mgr {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
return grp.Get(ctx);
|
||||
}
|
||||
public String Get_or(String ctx, String key, String or) {
|
||||
Xocfg_cache_grp grp = (Xocfg_cache_grp)grps.Get_by(key);
|
||||
if (grp == null) {
|
||||
grp = Load_grp(key, or);
|
||||
grps.Add(key, grp);
|
||||
}
|
||||
return grp.Get(ctx);
|
||||
}
|
||||
public void Set(String ctx, String key, String val) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Set(ctx, val);
|
||||
@ -62,17 +70,17 @@ public class Xocfg_cache_mgr {
|
||||
private Xocfg_cache_grp Grps__get_or_load(String key) {
|
||||
Xocfg_cache_grp grp = (Xocfg_cache_grp)grps.Get_by(key);
|
||||
if (grp == null) {
|
||||
grp = Load_grp(key);
|
||||
grp = Load_grp(key, "");
|
||||
grps.Add(key, grp);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
private Xocfg_cache_grp Load_grp(String key) {
|
||||
private Xocfg_cache_grp Load_grp(String key, String or) {
|
||||
// get data from db
|
||||
Xocfg_itm_row meta_itm = db_app.Tbl__itm().Select_by_key_or_null(key);
|
||||
if (meta_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:itm not found; key=~{0}", key);
|
||||
return new Xocfg_cache_grp(key, "");
|
||||
return new Xocfg_cache_grp(key, or);
|
||||
}
|
||||
Xocfg_val_row[] itms = db_usr.Tbl__val().Select_all(meta_itm.Key());
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class Xob_term_cmd extends Xob_term_base {
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp__wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
|
||||
gplx.fsdb.Fsdb_db_mgr__v2_bldr.Get_or_make(wiki, false);// always build file.user db; DATE:2015-05-12
|
||||
if (wiki.App().Cfg().Get_bool_by_wiki_or(wiki, gplx.xowa.bldrs.filters.dansguardians.Dg_match_mgr.Cfg__enabled, false))
|
||||
if (wiki.App().Cfg().Get_bool_wiki_or(wiki, gplx.xowa.bldrs.filters.dansguardians.Dg_match_mgr.Cfg__enabled, false))
|
||||
new Xob_page_delete_cmd(wiki.Appe().Bldr(), wiki).Cmd_run();
|
||||
wiki.Data__core_mgr().Rls();
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class Dg_match_mgr {
|
||||
}
|
||||
public static Dg_match_mgr New_mgr(Xoa_app app, Xow_wiki wiki) {
|
||||
Xocfg_mgr cfg_mgr = app.Cfg();
|
||||
if (!cfg_mgr.Get_bool_by_wiki_or(wiki, Cfg__enabled, false)) return null;
|
||||
if (!cfg_mgr.Get_bool_wiki_or(wiki, Cfg__enabled, false)) return null;
|
||||
String ctx = cfg_mgr.To_ctx(wiki);
|
||||
return new Dg_match_mgr
|
||||
( cfg_mgr.Get_url_or(ctx, Cfg__root_dir, app.Fsys_mgr().Bin_xowa_dir().GenSubDir_nest("cfg", "bldr", "filter")).GenSubDir(wiki.Domain_str())
|
||||
|
@ -27,7 +27,7 @@ public class Xog_win_itm_ {
|
||||
win_box.BackColor_(ColorAdp_.White);
|
||||
win.Tab_mgr().Tab_mgr().BackColor_(ColorAdp_.White);
|
||||
|
||||
app.Usere().Cfg_mgr().Startup_mgr().Window_mgr().Init_window(win_box);
|
||||
Xog_win_itm_startup_.Startup(app, win_box);
|
||||
win.Resizer().Exec_win_resize(app, win_box.Width(), win_box.Height());
|
||||
|
||||
win_box.Icon_(IconAdp.file_or_blank(app.Fsys_mgr().Bin_xowa_dir().GenSubFil_nest("file", "app.window", "app_icon.png")));
|
||||
|
126
400_xowa/src/gplx/xowa/guis/views/Xog_win_itm_startup_.java
Normal file
126
400_xowa/src/gplx/xowa/guis/views/Xog_win_itm_startup_.java
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.gfui.*; import gplx.gfui.envs.*; import gplx.gfui.controls.windows.*;
|
||||
public class Xog_win_itm_startup_ {
|
||||
public static void Startup(Xoa_app app, GfuiWin win) {
|
||||
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = app.Cfg();
|
||||
String window_mode = cfg_mgr.Get_str_app_or(Cfg__window_mode, "previous");
|
||||
Rect_ref manual_rect = Rect_ref.parse(cfg_mgr.Get_str_app_or(Cfg__manual_rect, "0,0,800,640"));
|
||||
|
||||
// change win_rect per mode: previous; absolute; etc.
|
||||
boolean init_is_maximized = false;
|
||||
if (String_.Eq(window_mode, "previous")) {
|
||||
if (cfg_mgr.Get_bool_app_or(Cfg__prev_maximized, false)) {
|
||||
win.Maximized_(true);
|
||||
init_is_maximized = true;
|
||||
}
|
||||
else {
|
||||
Rect_ref previous_rect = null;
|
||||
String s = cfg_mgr.Get_str_app_or(Cfg__prev_rect, "");
|
||||
if (String_.Eq(s, "")) {
|
||||
SizeAdp size = Screen_maximized_calc();
|
||||
previous_rect = new Rect_ref(0, 0, size.Width(), size.Height());
|
||||
}
|
||||
else
|
||||
previous_rect = Rect_ref.parse(s);
|
||||
win.Rect_set(previous_rect.XtoRectAdp());
|
||||
}
|
||||
}
|
||||
else if (String_.Eq(window_mode, "absolute")) {
|
||||
win.Rect_set(manual_rect.XtoRectAdp());
|
||||
}
|
||||
else if (String_.Eq(window_mode, "maximized")) {
|
||||
win.Maximized_(true);
|
||||
init_is_maximized = true;
|
||||
}
|
||||
else if (String_.Eq(window_mode, "default")) {} // noop
|
||||
else if (String_.Eq(window_mode, "relative")) {
|
||||
SizeAdp screen_maximized = Screen_maximized_calc();
|
||||
Rect_ref win_rect = new Rect_ref(0, 0, screen_maximized.Width(), screen_maximized.Height());
|
||||
win.Rect_set(win_rect.XtoRectAdp_add(manual_rect));
|
||||
}
|
||||
|
||||
// make sure win_rect is safe
|
||||
boolean safe_mode = cfg_mgr.Get_bool_app_or(Cfg__manual_safe, true);
|
||||
if (safe_mode && !init_is_maximized) {
|
||||
RectAdp rect = win.Rect();
|
||||
boolean force = false; int x = rect.X(), y = rect.Y(), w = rect.Width(), h = rect.Height();
|
||||
SizeAdp screen_size = Screen_maximized_calc();
|
||||
int max_w = screen_size.Width(), max_h = screen_size.Height();
|
||||
int Safe_mode_buffer = 20; // allow minor negative positioning (x=-5), off-screen positioning (w=1605)
|
||||
if (x < -Safe_mode_buffer || x > max_w + Safe_mode_buffer) {force = true; x = 0;}
|
||||
if (y < -Safe_mode_buffer || y > max_h + Safe_mode_buffer) {force = true; y = 0;}
|
||||
if (w < Safe_mode_buffer || x + w > max_w + Safe_mode_buffer) {force = true; w = max_w - x;}
|
||||
if (h < Safe_mode_buffer || y + h > max_h + Safe_mode_buffer) {force = true; h = max_h - y;}
|
||||
if (force)
|
||||
win.Rect_set(RectAdp_.new_(x, y, w, h));
|
||||
}
|
||||
}
|
||||
public static void Shutdown(Xoae_app app, GfuiWin win) {
|
||||
gplx.xowa.addons.apps.cfgs.Xocfg_mgr cfg_mgr = app.Cfg();
|
||||
if (String_.Eq(cfg_mgr.Get_str_app_or(Cfg__window_mode, "previous"), "previous")) {
|
||||
cfg_mgr.Set_str_app(Cfg__prev_rect , win.Rect().Xto_str());
|
||||
cfg_mgr.Set_str_app(Cfg__prev_maximized , Yn.To_str(win.Maximized()));
|
||||
}
|
||||
gplx.xowa.apps.cfgs.Xoa_cfg_mgr cfg_mgr2 = app.Cfg_mgr();
|
||||
gplx.xowa.apps.apis.xowa.startups.tabs.Xoapi_startup_tabs startup_tabs = app.Api_root().App().Startup().Tabs();
|
||||
if (startup_tabs.Type() == gplx.xowa.apps.apis.xowa.startups.tabs.Xoapi_startup_tabs_tid_.Tid_previous) {
|
||||
cfg_mgr2.Set_by_app("xowa.api.app.startup.tabs.previous" , Calc_previous_tabs(app.Gui_mgr().Browser_win().Tab_mgr()));
|
||||
}
|
||||
cfg_mgr2.Set_by_app("xowa.api.app.env.version_previous" , Xoa_app_.Version);
|
||||
app.Api_root().Html().Page().Toggle_mgr().Save(cfg_mgr2);
|
||||
cfg_mgr2.Db_save_txt();
|
||||
}
|
||||
private static String Calc_previous_tabs(gplx.xowa.guis.views.Xog_tab_mgr tab_mgr) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = tab_mgr.Tabs_len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
gplx.xowa.guis.views.Xog_tab_itm tab = tab_mgr.Tabs_get_at(i);
|
||||
bfr.Add_str_u8(tab.Page().Url().To_str());
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public static SizeAdp Screen_maximized_calc() {
|
||||
Op_sys os = Op_sys.Cur();
|
||||
SizeAdp screen = ScreenAdp_.screen_(0).Size();
|
||||
int w = screen.Width();
|
||||
int h = screen.Height() - 30; // -20=application menu bar; -10 for start bar padding
|
||||
switch (os.Tid()) {
|
||||
case Op_sys.Tid_wnt:
|
||||
switch (os.Sub_tid()) {
|
||||
case Op_sys.Sub_tid_win_xp: h += -4; break; // NOOP; will keep values as above
|
||||
default: break; // for all else, use Windows 7 border (which is thicker); note that Windows 8 is being detected as "Windows NT (unknown)", so need to use default; this may not work with Windows 2000
|
||||
}
|
||||
break;
|
||||
default:
|
||||
h += -4; // default adjustments since version 0.0.0.0; seems to work on XP and LNX
|
||||
break;
|
||||
}
|
||||
return SizeAdp_.new_(w, h);
|
||||
}
|
||||
private static final String
|
||||
Cfg__window_mode = "xowa.app.startup.window.mode"
|
||||
, Cfg__manual_rect = "xowa.app.startup.window.manual_rect"
|
||||
, Cfg__manual_safe = "xowa.app.startup.window.manual_safe"
|
||||
, Cfg__prev_rect = "xowa.app.startup.window.previous_rect"
|
||||
, Cfg__prev_maximized = "xowa.app.startup.window.previous_maximized"
|
||||
;
|
||||
}
|
@ -30,12 +30,12 @@ public class Xoh_head_itm__popups extends Xoh_head_itm__base {
|
||||
}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
Xocfg_mgr cfg_mgr = app.Cfg();
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_delay , cfg_mgr.Get_int_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_show_delay, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_hide_delay , cfg_mgr.Get_int_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_hide_delay, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_w , cfg_mgr.Get_int_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_max_w, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_h , cfg_mgr.Get_int_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_max_h, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_all_max_w , cfg_mgr.Get_int_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_show_all_max_w, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_bind_focus_blur , cfg_mgr.Get_bool_by_wiki_or(wiki, Xow_popup_mgr.Cfg__win_bind_focus_blur, false));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_delay , cfg_mgr.Get_int_wiki_or(wiki, Xow_popup_mgr.Cfg__win_show_delay, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_hide_delay , cfg_mgr.Get_int_wiki_or(wiki, Xow_popup_mgr.Cfg__win_hide_delay, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_w , cfg_mgr.Get_int_wiki_or(wiki, Xow_popup_mgr.Cfg__win_max_w, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_h , cfg_mgr.Get_int_wiki_or(wiki, Xow_popup_mgr.Cfg__win_max_h, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_all_max_w , cfg_mgr.Get_int_wiki_or(wiki, Xow_popup_mgr.Cfg__win_show_all_max_w, 0));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_bind_focus_blur , cfg_mgr.Get_bool_wiki_or(wiki, Xow_popup_mgr.Cfg__win_bind_focus_blur, false));
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_bind_hover_area , bind_hover_area);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users; import gplx.*; import gplx.xowa.*;
|
||||
public class Xou_session implements Gfo_invk {
|
||||
public Xou_session(Xoue_user user) {this.user = user; window_mgr = new Xous_window_mgr(user);}
|
||||
public Xoue_user User() {return user;} private Xoue_user user;
|
||||
public Xous_window_mgr Window_mgr() {return window_mgr;} private Xous_window_mgr window_mgr;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_window)) return window_mgr;
|
||||
return this;
|
||||
} public static final String Invk_window = "window";
|
||||
}
|
@ -17,8 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users; import gplx.*; import gplx.xowa.*;
|
||||
public class Xouc_startup_mgr implements Gfo_invk {
|
||||
public Xouc_startup_mgr(Xou_cfg config) {this.config = config; window_mgr = new Xouc_window_mgr(config.User());} private Xou_cfg config;
|
||||
public Xouc_window_mgr Window_mgr() {return window_mgr;} private Xouc_window_mgr window_mgr;
|
||||
public Xouc_startup_mgr(Xou_cfg config) {this.config = config;} private Xou_cfg config;
|
||||
public String Page() {return page;} public Xouc_startup_mgr Page_(String v) {page = v; return this;} private String page = "xowa";
|
||||
public String Page_url() {
|
||||
byte v = Page_parse(page);
|
||||
@ -34,10 +33,9 @@ public class Xouc_startup_mgr implements Gfo_invk {
|
||||
else if (ctx.Match(k, Invk_page_)) page = m.ReadStr("v");
|
||||
else if (ctx.Match(k, Invk_custom_config)) return Custom_config();
|
||||
else if (ctx.Match(k, Invk_custom_config_)) Custom_config_(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_window)) return window_mgr;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_window = "window", Invk_page = "page", Invk_page_ = "page_", Invk_custom_config = "custom_config", Invk_custom_config_ = "custom_config_";
|
||||
public static final String Invk_page = "page", Invk_page_ = "page_", Invk_custom_config = "custom_config", Invk_custom_config_ = "custom_config_";
|
||||
private byte Page_parse(String s) {
|
||||
if (String_.Eq(s, "home")) return Page_home;
|
||||
else if (String_.Eq(s, "last")) return Page_last;
|
||||
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.gfui.*; import gplx.gfui.envs.*; import gplx.gfui.controls.windows.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
public class Xouc_window_mgr implements Gfo_invk {
|
||||
public Xouc_window_mgr(Xoue_user user) {this.user = user;} private Xoue_user user;
|
||||
public byte Mode_tid() {return mode_tid;} private byte mode_tid = Mode_tid_previous;
|
||||
public String Mode_str() {return mode_str;} private String mode_str = "previous";
|
||||
public Rect_ref Rect() {return rect;} Rect_ref rect = new Rect_ref(0, 0, 800, 640);
|
||||
public boolean Safe_mode() {return safe_mode;} private boolean safe_mode = true;
|
||||
public Rect_ref Previous_adj() {return previous_adj;} Rect_ref previous_adj = new Rect_ref(0, 0, 0, 0);
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_mode)) return mode_str;
|
||||
else if (ctx.Match(k, Invk_mode_)) {mode_str = m.ReadStr("v"); mode_tid = Xto_mode_tid(mode_str);}
|
||||
else if (ctx.Match(k, Invk_mode_list)) return Options_mode_list;
|
||||
else if (ctx.Match(k, Invk_rect)) return rect;
|
||||
else if (ctx.Match(k, Invk_rect_)) rect = Rect_ref.parse(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_safe_mode)) return Yn.To_str(safe_mode);
|
||||
else if (ctx.Match(k, Invk_safe_mode_)) safe_mode = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_previous_adj)) return previous_adj;
|
||||
else if (ctx.Match(k, Invk_previous_adj_)) previous_adj = Rect_ref.parse(m.ReadStr("v"));
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_mode = "mode", Invk_mode_ = "mode_", Invk_mode_list = "mode_list"
|
||||
, Invk_rect = "rect", Invk_rect_ = "rect_", Invk_safe_mode = "safe_mode", Invk_safe_mode_ = "safe_mode_", Invk_previous_adj = "previous_adj", Invk_previous_adj_ = "previous_adj_";
|
||||
private static Keyval[] Options_mode_list = Keyval_.Ary(Keyval_.new_("previous"), Keyval_.new_("maximized"), Keyval_.new_("absolute"), Keyval_.new_("relative"), Keyval_.new_("default"));
|
||||
public void Init_window(GfuiWin win) {
|
||||
boolean init_is_maximized = false;
|
||||
switch (mode_tid) {
|
||||
case Mode_tid_previous:
|
||||
Xous_window_mgr session_window = user.Session_mgr().Window_mgr();
|
||||
if (session_window.Maximized()) {
|
||||
win.Maximized_(true);
|
||||
init_is_maximized = true;
|
||||
}
|
||||
else
|
||||
win.Rect_set(session_window.Rect().XtoRectAdp_add(previous_adj));
|
||||
break;
|
||||
case Mode_tid_absolute: win.Rect_set(rect.XtoRectAdp()); break;
|
||||
case Mode_tid_maximized: win.Maximized_(true); init_is_maximized = true; break;
|
||||
case Mode_tid_default: break; // noop
|
||||
case Mode_tid_relative:
|
||||
SizeAdp screen_maximized = Screen_maximized_calc();
|
||||
Rect_ref win_rect = new Rect_ref(0, 0, screen_maximized.Width(), screen_maximized.Height());
|
||||
win.Rect_set(win_rect.XtoRectAdp_add(rect));
|
||||
break;
|
||||
}
|
||||
if (safe_mode && !init_is_maximized) {
|
||||
RectAdp rect = win.Rect();
|
||||
boolean force = false; int x = rect.X(), y = rect.Y(), w = rect.Width(), h = rect.Height();
|
||||
SizeAdp screen_size = Screen_maximized_calc();
|
||||
int max_w = screen_size.Width(), max_h = screen_size.Height();
|
||||
if (x < -Safe_mode_buffer || x > max_w + Safe_mode_buffer) {force = true; x = 0;}
|
||||
if (y < -Safe_mode_buffer || y > max_h + Safe_mode_buffer) {force = true; y = 0;}
|
||||
if (w < Safe_mode_buffer || x + w > max_w + Safe_mode_buffer) {force = true; w = max_w - x;}
|
||||
if (h < Safe_mode_buffer || y + h > max_h + Safe_mode_buffer) {force = true; h = max_h - y;}
|
||||
if (force)
|
||||
win.Rect_set(RectAdp_.new_(x, y, w, h));
|
||||
}
|
||||
} private static final int Safe_mode_buffer = 20; // allow minor negative positioning (x=-5), off-screen positioning (w=1605)
|
||||
public static SizeAdp Screen_maximized_calc() {
|
||||
Op_sys os = Op_sys.Cur();
|
||||
SizeAdp screen = ScreenAdp_.screen_(0).Size();
|
||||
int w = screen.Width();
|
||||
int h = screen.Height() - 30; // -20=application menu bar; -10 for start bar padding
|
||||
switch (os.Tid()) {
|
||||
case Op_sys.Tid_wnt:
|
||||
switch (os.Sub_tid()) {
|
||||
case Op_sys.Sub_tid_win_xp: h += -4; break; // NOOP; will keep values as above
|
||||
default: break; // for all else, use Windows 7 border (which is thicker); note that Windows 8 is being detected as "Windows NT (unknown)", so need to use default; this may not work with Windows 2000
|
||||
}
|
||||
break;
|
||||
default:
|
||||
h += -4; // default adjustments since version 0.0.0.0; seems to work on XP and LNX
|
||||
break;
|
||||
}
|
||||
return SizeAdp_.new_(w, h);
|
||||
}
|
||||
private static byte Xto_mode_tid(String s) {
|
||||
if (String_.Eq(s, "previous")) return Mode_tid_previous;
|
||||
else if (String_.Eq(s, "maximized")) return Mode_tid_maximized;
|
||||
else if (String_.Eq(s, "absolute")) return Mode_tid_absolute;
|
||||
else if (String_.Eq(s, "relative")) return Mode_tid_relative;
|
||||
else if (String_.Eq(s, "default")) return Mode_tid_default;
|
||||
else return Mode_tid_previous;
|
||||
}
|
||||
public static final byte Mode_tid_previous = 0, Mode_tid_maximized = 1, Mode_tid_absolute = 2, Mode_tid_relative = 3, Mode_tid_default = 4;
|
||||
}
|
@ -31,7 +31,6 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
||||
this.cfg_mgr = new Xou_cfg(this);
|
||||
this.history_mgr = new Xou_history_mgr(fsys_mgr.App_data_history_fil());
|
||||
this.prefs_mgr = new gplx.xowa.users.prefs.Prefs_mgr(app);
|
||||
this.session_mgr = new Xou_session(this);
|
||||
}
|
||||
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private final Gfo_evt_mgr ev_mgr;
|
||||
public String Key() {return key;} private String key;
|
||||
@ -50,7 +49,6 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
||||
public Xowe_wiki Wiki() {if (wiki == null) wiki = Xou_user_.new_or_create_(this, app); return wiki;} private Xowe_wiki wiki;
|
||||
public Xou_history_mgr History_mgr() {return history_mgr;} private Xou_history_mgr history_mgr;
|
||||
public Xou_cfg Cfg_mgr() {return cfg_mgr;} private Xou_cfg cfg_mgr;
|
||||
public Xou_session Session_mgr() {return session_mgr;} private Xou_session session_mgr;
|
||||
public gplx.xowa.users.prefs.Prefs_mgr Prefs_mgr() {return prefs_mgr;} gplx.xowa.users.prefs.Prefs_mgr prefs_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {
|
||||
if (msg_mgr == null)
|
||||
@ -67,7 +65,7 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
||||
}
|
||||
}
|
||||
public void App_term() {
|
||||
session_mgr.Window_mgr().Save_window(app.Gui_mgr().Browser_win().Win_box());
|
||||
gplx.xowa.guis.views.Xog_win_itm_startup_.Shutdown(app, app.Gui_mgr().Browser_win().Win_box()); // save window position
|
||||
history_mgr.Save(app);
|
||||
if (app.Gui_mgr().Browser_win().Tab_mgr().Page_load_mode_is_url())
|
||||
Io_mgr.Instance.DeleteDirDeep(fsys_mgr.App_temp_html_dir());
|
||||
@ -93,13 +91,12 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
|
||||
else if (ctx.Match(k, Invk_fsys)) return fsys_mgr;
|
||||
else if (ctx.Match(k, Invk_prefs)) return prefs_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg)) return cfg_mgr;
|
||||
else if (ctx.Match(k, Invk_session)) return session_mgr;
|
||||
else if (ctx.Match(k, "name")) return key; //throw Err_.new_unhandled(k); // OBSOLETE: used to return key
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_available_from_fsys = "available_from_fsys", Invk_available_from_bulk = "available_from_bulk", Invk_bookmarks_add_fmt_ = "bookmarks_add_fmt_"
|
||||
, Invk_wiki = "wiki", Invk_history = "history", Invk_fsys = "fsys", Invk_lang = "lang", Invk_msgs = "msgs", Invk_prefs = "prefs", Invk_cfg = "cfg", Invk_session = "session";
|
||||
, Invk_wiki = "wiki", Invk_history = "history", Invk_fsys = "fsys", Invk_lang = "lang", Invk_msgs = "msgs", Invk_prefs = "prefs", Invk_cfg = "cfg";
|
||||
public static final String Key_xowa_user = "anonymous";
|
||||
public static final String Evt_lang_changed = "lang_changed";
|
||||
public void Available_from_fsys() {
|
||||
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.users; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.gfui.controls.windows.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.apps.apis.xowa.startups.tabs.*;
|
||||
public class Xous_window_mgr implements Gfo_invk {
|
||||
public Xous_window_mgr(Xoue_user user) {
|
||||
this.user = user;
|
||||
}
|
||||
public Xoue_user User() {return user;} private Xoue_user user;
|
||||
public Rect_ref Rect() {if (rect == null) rect = Rect_new(); return rect;} Rect_ref rect;
|
||||
public boolean Maximized() {return maximized;} private boolean maximized = false;
|
||||
public void Save_window(GfuiWin win) {
|
||||
Xoae_app app = user.Appe();
|
||||
gplx.xowa.apps.cfgs.Xoa_cfg_mgr cfg_mgr = app.Cfg_mgr();
|
||||
if (user.Cfg_mgr().Startup_mgr().Window_mgr().Mode_tid() == Xouc_window_mgr.Mode_tid_previous) {
|
||||
cfg_mgr.Set_by_app("app.user.session.window.maximized" , Yn.To_str(win.Maximized()));
|
||||
cfg_mgr.Set_by_app("app.user.session.window.rect" , win.Rect().Xto_str());
|
||||
}
|
||||
Xoapi_startup_tabs startup_tabs = app.Api_root().App().Startup().Tabs();
|
||||
if (startup_tabs.Type() == Xoapi_startup_tabs_tid_.Tid_previous) {
|
||||
cfg_mgr.Set_by_app("xowa.api.app.startup.tabs.previous" , Calc_previous_tabs(app.Gui_mgr().Browser_win().Tab_mgr()));
|
||||
}
|
||||
cfg_mgr.Set_by_app("xowa.api.app.env.version_previous" , Xoa_app_.Version);
|
||||
app.Api_root().Html().Page().Toggle_mgr().Save(cfg_mgr);
|
||||
cfg_mgr.Db_save_txt();
|
||||
}
|
||||
private String Calc_previous_tabs(Xog_tab_mgr tab_mgr) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = tab_mgr.Tabs_len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_nl();
|
||||
Xog_tab_itm tab = tab_mgr.Tabs_get_at(i);
|
||||
bfr.Add_str_u8(tab.Page().Url().To_str());
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_rect)) return rect;
|
||||
else if (ctx.Match(k, Invk_rect_)) rect = Rect_ref.parse(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_maximized)) return Yn.To_str(maximized);
|
||||
else if (ctx.Match(k, Invk_maximized_)) maximized = m.ReadYn("v");
|
||||
return this;
|
||||
} public static final String Invk_rect = "rect", Invk_rect_ = "rect_", Invk_maximized = "maximized", Invk_maximized_ = "maximized_";
|
||||
private static Rect_ref Rect_new() { // NOTE: lazy initialization, else will fail for non-X11 environments; DATE:2014-03-02
|
||||
gplx.gfui.SizeAdp size = Xouc_window_mgr.Screen_maximized_calc();
|
||||
return new Rect_ref(0, 0, size.Width(), size.Height());
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ public class Xow_page_cache {
|
||||
return rv == null ? null : rv.Wtxt__direct();
|
||||
}
|
||||
public boolean Get_ifexist_by_mem(byte[] ifexists_key) {
|
||||
// check ifexists_cache
|
||||
Xow_page_cache_itm ifexists_itm = (Xow_page_cache_itm)ifexists_cache.Get_by(ifexists_key);
|
||||
if (ifexists_itm == Xow_page_cache_itm.Missing)
|
||||
return false;
|
||||
@ -47,7 +48,6 @@ public class Xow_page_cache {
|
||||
return false;
|
||||
}
|
||||
public boolean Load_ifexist(Xoa_ttl ttl) {
|
||||
// check ifexists_cache
|
||||
byte[] ifexists_key = ttl.Full_db();
|
||||
Xow_page_cache_itm ifexists_itm = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user