#if 0 #include "TCtrlLibHelp.h" #pragma hdrstop #define LAYOUTFILE #include class DlgHelpRename : public WithHelpRenameLayout { public: typedef DlgHelpRename CLASSNAME; DlgHelpRename(const VectorMap& mod_map); bool Run(VectorMap& key_map); private: void Find(int start, bool rev); TOOL(Existing) TOOL(ExistingFind) TOOL(ExistingFindPrev) TOOL(ExistingFindNext) TOOL(ExistingAssign) TOOL(Aliased) TOOL(AliasedRemove) private: String find_text; const VectorMap& mod_map; }; RegisterHelpTopicObjectTitle(DlgHelpRename, t_("Map changed identifiers")) DlgHelpRename::DlgHelpRename(const VectorMap& mod_map) : mod_map(mod_map) { CtrlLayoutOKCancel(*this, DlgHelpRenameHelpTitle()); HelpTopic("DlgHelpRename"); unmatched.AutoHideSb(); unmatched.AddColumn(t_("Loaded file")); existing.AutoHideSb(); existing.AddColumn(t_("Identifier map")); existing.WhenBar = THISBACK(ToolExisting); aliased.AutoHideSb(); aliased.AddColumn(t_("Old")); aliased.AddColumn(t_("Mapped")); aliased.AddColumn(t_("Module")); aliased.WhenBar = THISBACK(ToolAliased); } bool DlgHelpRename::Run(VectorMap& key_map) { Vector lmap = key_map.PickKeys(); Sort(lmap, GetLanguageInfo()); Append(unmatched, lmap); lmap <<= mod_map.GetKeys(); Sort(lmap, GetLanguageInfo()); Append(existing, lmap); if(TopWindow::Run() != IDOK) return false; key_map.Clear(); for(int i = 0; i < aliased.GetCount(); i++) key_map.Add(aliased.Get(i, 0), aliased.Get(i, 1)); return true; } void DlgHelpRename::ToolExisting(Bar& bar) { bar.Add(unmatched.IsCursor() && existing.IsCursor(), t_("Map"), THISBACK(OnExistingAssign)) .Key(K_INSERT); bar.Add(t_("Find"), THISBACK(OnExistingFind)) .Key(K_CTRL_F); bar.Add(t_("Find next"), THISBACK(OnExistingFindNext)) .Key(K_F3); bar.Add(t_("Find previous"), THISBACK(OnExistingFindPrev)) .Key(K_SHIFT_F3); } static bool IdentMatch(const char *mask, const char *name) { for(;;) switch(*mask++) { case 0: return *name == 0; case '*': do if(IdentMatch(mask, name)) return true; while(*name++); return false; case '?': if(*name++ == 0) return false; break; default: if(ToLower(mask[-1]) != ToLower(*name++)) return false; break; } } RegisterHelpTopicObjectTitle(DlgHelpRenameFind, t_("Find")) void DlgHelpRename::OnExistingFind() { WithHelpRenameFindLayout finddlg; finddlg.find <<= find_text; CtrlLayoutOKCancel(finddlg, DlgHelpRenameFindHelpTitle()); finddlg.HelpTopic("DlgHelpRenameFind"); if(finddlg.Run() == IDOK) { find_text = ~finddlg.find; Find(0, false); } } void DlgHelpRename::OnExistingFindNext() { Find(existing.GetCursor() + 1, false); } void DlgHelpRename::OnExistingFindPrev() { Find(existing.GetCursor() - 1, true); } void DlgHelpRename::Find(int start, bool rev) { String ft = "*" + find_text + "*"; for(int i = start; i >= 0 && i < existing.GetCount(); i += (rev ? -1 : 1)) if(IdentMatch(ft, String(existing.Get(i, 0)))) { existing.SetCursor(i); return; } BeepExclamation(); } void DlgHelpRename::OnExistingAssign() { int u = unmatched.GetCursor(), e = existing.GetCursor(); if(u >= 0 && e >= 0) { int a = aliased.GetCount(); String ex = existing.Get(0); aliased.Add(unmatched.Get(0), ex, mod_map.Get(ex, Null)); aliased.SetCursor(a); unmatched.Remove(u); existing.Remove(e); if(u > 1) unmatched.SetCursor(u < unmatched.GetCount() ? u : u - 1); if(e > 1) existing.SetCursor(e < existing.GetCount() ? e : e - 1); } } void DlgHelpRename::ToolAliased(Bar& bar) { bar.Add(t_("Remove alias"), THISBACK(OnAliasedRemove)) .Key(K_DELETE); } void DlgHelpRename::OnAliasedRemove() { int a = aliased.GetCursor(); if(a >= 0) { unmatched.Add(aliased.Get(0)); existing.Add(aliased.Get(1)); aliased.Remove(a); if(a > 1) aliased.SetCursor(a < aliased.GetCount() ? a : a - 1); unmatched.SetCursor(unmatched.GetCount() - 1); existing.SetCursor(existing.GetCount() - 1); } } ////////////////////////////////////////////////////////////////////// // DlgHelpLang:: class DlgHelpLang : public WithHelpLangLayout { public: typedef DlgHelpLang CLASSNAME; DlgHelpLang(); bool Run(VectorMap& ext_lang, int& init_lang); private: void OnExtLangEdit(); void OnLangFileBrowse(); private: DropList lang_edit; EditField lang_file; ExtendedButton lang_file_browse; }; bool RunDlgHelpLang(VectorMap& ext_lang, int& init_lang) { return DlgHelpLang().Run(ext_lang, init_lang); } RegisterHelpTopicObjectTitle(DlgHelpLang, t_("Application languages")) DlgHelpLang::DlgHelpLang() { CtrlLayoutOKCancel(*this, DlgHelpLangHelpTitle()); HelpTopic("DlgHelpLang"); ext_lang.AutoHideSb(); ext_lang.AddColumn(t_("Language code"), 10).SetConvert(lang_edit).Edit(lang_edit); ext_lang.AddColumn(t_("Language file"), 30).Edit(lang_file); ext_lang.Inserting().Removing().NoAskRemove(); ext_lang.WhenArrayAction = THISBACK(OnExtLangEdit); lang_file.AddFrame(lang_file_browse); lang_file_browse <<= THISBACK(OnLangFileBrowse); for(const int *p = GetAllLanguages(); *p; p++) lang_edit.Add(*p, LNGAsText(*p)); } bool DlgHelpLang::Run(VectorMap& el, int& il) { int i; for(i = 0; i < el.GetCount(); i++) ext_lang.Add(el.GetKey(i), el[i]); OnExtLangEdit(); init_lang <<= il; if(TopWindow::Run() != IDOK) return false; el.Clear(); for(i = 0; i < ext_lang.GetCount(); i++) el.Add(ext_lang.Get(i, 0), ext_lang.Get(i, 1)); il = ~init_lang; return true; } void DlgHelpLang::OnExtLangEdit() { int oi = ~init_lang; init_lang.Clear(); Index app_lang = GetLanguages(); for(int i = 0; i < ext_lang.GetCount(); i++) app_lang.FindAdd(ext_lang.Get(i, 0)); Index lmask; for(int i = 0; i < app_lang.GetCount(); i++) { int l = app_lang[i], l0 = SetLNGCharset(l, CHARSET_DEFAULT); if(lmask.Find(l0) < 0) { lmask.Add(l0); init_lang.Add(l, LNGAsText(l0)); } } init_lang <<= (init_lang.FindKey(oi) < 0 ? app_lang[0] : oi); } void DlgHelpLang::OnLangFileBrowse() { FileSelector fsel; fsel.Type(t_("Language files (*.lng)"), t_("*.lng")); fsel.DefaultExt("lng"); fsel.AllFilesType(); fsel <<= String(~lang_file_browse); if(fsel.ExecuteOpen(t_("Language file"))) { lang_file_browse <<= ~fsel; lang_file_browse.Action(); } } class DlgHelpDirty : public WithHelpDirtyLayout { public: typedef DlgHelpDirty CLASSNAME; DlgHelpDirty(); bool Run(VectorMap& files); private: void OnAdd(); void OnAddAll(); void OnRemove(); void OnRemoveAll(); void OnBrowse(); void UpdateGUI(); bool DoAdd(); bool DoRemove(); bool BrowseFile(String& fn, int lang); private: VectorMap files; }; bool RunDlgHelpDirty(VectorMap& files) { return DlgHelpDirty().Run(files); } RegisterHelpTopicObjectTitle(DlgHelpDirty, t_("Save changes...")) DlgHelpDirty::DlgHelpDirty() { CtrlLayoutOKCancel(*this, DlgHelpDirtyHelpTitle()); HelpTopic("DlgHelpDirty"); dirty_files.AutoHideSb(); dirty_files.AddIndex(); dirty_files.AddColumn("Jazyk"); dirty_files.AddKey(K_RIGHT, add <<= THISBACK(OnAdd)); dirty_files.AddKey(K_CTRL_RIGHT, add_all <<= THISBACK(OnAddAll)); save_files.AutoHideSb(); save_files.AddIndex(); save_files.AddColumn("Jazyk", 10); save_files.AddColumn("Cesta", 40); save_files.WhenLeftDouble = THISBACK(OnBrowse); save_files.AddKey(K_LEFT, remove <<= THISBACK(OnRemove)); save_files.AddKey(K_CTRL_LEFT, remove_all <<= THISBACK(OnRemoveAll)); } bool DlgHelpDirty::Run(VectorMap& f) { files = f; int t; for(t = 0; t < files.GetCount(); t++) { int l = files.GetKey(t); String ln = LNGAsText(l); if(files[t].IsEmpty()) dirty_files.Add(l, ln); else save_files.Add(l, ln, files[t]); } dirty_files.SetCursor(0); save_files.SetCursor(0); ActiveFocus(dirty_files); if(TopWindow::Run() != IDOK) return false; f.Clear(); for(t = 0; t < save_files.GetCount(); t++) f.Add(save_files.Get(t, 0), save_files.Get(t, 2)); return true; } void DlgHelpDirty::UpdateGUI() { add.Enable(dirty_files.IsCursor()); add_all.Enable(dirty_files.GetCount() > 0); remove.Enable(save_files.IsCursor()); remove_all.Enable(save_files.GetCount() > 0); } void DlgHelpDirty::OnBrowse() { if(!save_files.IsCursor()) return; String fn = save_files.Get(2); if(BrowseFile(fn, save_files.Get(0))) save_files.Set(2, fn); } bool DlgHelpDirty::BrowseFile(String& fn, int lang) { FileSelector fsel; fsel.DefaultExt("lng"); fsel.Type("Jazykové soubory (*.lng)", "*.lng"); fsel <<= fn; if(!fsel.ExecuteSaveAs(NFormat("%s - uložit jako...", LNGAsText(lang)))) return false; fn = ~fsel; return true; } bool DlgHelpDirty::DoAdd() { int dc = dirty_files.GetCursor(); if(dc < 0) return false; int l = dirty_files.Get(0); String ln = LNGAsText(l); String fn = files.Get(l); if(fn.IsEmpty()) if(!BrowseFile(fn, l)) return false; files.Get(l) = fn; dirty_files.Remove(dc); dirty_files.SetCursor(dc < dirty_files.GetCount() ? dc : dc - 1); save_files.Add(l, ln, fn); save_files.SetCursor(save_files.GetCount() - 1); UpdateGUI(); return true; } bool DlgHelpDirty::DoRemove() { int sc = save_files.GetCursor(); if(sc < 0) return false; int l = save_files.Get(0); String ln = LNGAsText(l); save_files.Remove(sc); save_files.SetCursor(sc < save_files.GetCount() ? sc : sc - 1); dirty_files.Add(l, ln); dirty_files.SetCursor(dirty_files.GetCount() - 1); UpdateGUI(); return true; } void DlgHelpDirty::OnAdd() { DoAdd(); } void DlgHelpDirty::OnAddAll() { while(DoAdd()) ; } void DlgHelpDirty::OnRemove() { DoRemove(); } void DlgHelpDirty::OnRemoveAll() { while(DoRemove()) ; } static String FromEdit(const String& s) { String out; for(const char *b = s, *p = b; *p; p++) if(*p == '\r') ; else if(*p != '\\') out.Cat(*p); else switch(*++p) { case 'a': out << '\a'; break; case 'b': out << '\b'; break; case 't': out << '\t'; break; case 'v': out << '\v'; break; case 'f': out << '\f'; break; case 'r': out << '\r'; break; case 'n': out << '\n'; break; case '\\': out << '\\'; break; case '\"': out << '\"'; break; case 'x': { int c = ctoi(*++p); if(c < 16) { int c2 = ctoi(*++p); if(c2 < 16) { p++; c = c * 16 + c2; } out.Cat((char)c); } p--; } break; default: if(*p >= '0' && *p <= '7') { // octal sequence int c = *p - '0'; int c2 = *++p - '0'; if(c2 >= 0 && c2 < 8) { c = c * 8 + c2; c2 = *++p - '0'; if(c2 >= 0 && c2 < 8) { c = c * 8 + c2; p++; } } out.Cat((char)c); p--; } break; } return out; } static String ToEdit(const String& s) { String out; for(const char *p = s.Begin(), *e = s.End(); p < e;) { const char *b = p; while(p < e && (*p == '\n' || (byte)*p >= ' ' && *p != '\\' && *p != (char)127 && *p != (char)255)) p++; out.Cat(b, p - b); if(p < e) switch(*p++) { case '\a': out << "\\a"; break; case '\b': out << "\\b"; break; case '\t': out << "\\t"; break; // case '\n': case '\v': out << "\\v"; break; case '\f': out << "\\f"; break; case '\r': out << "\\r"; break; case '\\': out << "\\\\"; break; default: out << "\\" << FormatIntOct((byte)p[-1], 3); break; } } return out; } class DlgHelpEdit : public WithHelpEditLayout { public: typedef DlgHelpEdit CLASSNAME; DlgHelpEdit(); void Run(); virtual bool HotKey(dword key); private: void UpdateLang(); void UpdateModules(const String& mod); void UpdateTexts(const String& key); void UpdateStrings(); void UpdateSrcText(); void UpdateDestText(); void UpdateTitle(); void OnModules(); void OnTexts(); void OnSrcLang(); void OnDestLang(); void OnDestText(); void OnNew(); void OnSave(); void OnLoad(); void OnExit(); void OnExport(); void OnPrevDoubtfulText(); void OnNextDoubtfulText(); String GetModule() const; String GetText() const; bool IsValidLang(int sl, int dl) const { return !IsNull(sl) && !IsNull(dl) && sl != dl; } int GetTextState(const String& key, int sl, int dl) const; void WriteText(const String& key, int lang, const String& text); String ReadText(const String& key, int lang) const; String ReadLoadedText(const String& key, int lang) const; bool CheckDirty(); private: enum { M_KEY, M_NAME, M_COUNT, M_TRAN, M_DIRTY, }; enum { T_KEY, T_TRAN, T_STATE, }; class LangInfo { public: LangInfo() {} public: String filename; VectorMap loaded; VectorMap edited; }; VectorMap all_lang_keys; VectorMap > module_map; Vector file_map; ArrayMap languages; String last_key; int last_lang; bool lock_dest; FrameLeft