wxExCTags::wxExCTags(wxExFrame* frame, const std::string& filename) : m_Frame(frame) { tagFileInfo info; for (const auto & it : std::vector < std::string > { "./", wxExConfigDir() + "/"}) { if ((m_File = tagsOpen(std::string(it + filename).c_str(), &info)) != nullptr) { return; // finish, we found a file } } }
bool wxExViMacros::ExpandTemplate( wxExEx* ex, const wxExVariable& v, std::string& expanded) { if (v.GetValue().empty()) { return false; } if (!m_IsExpand) { m_IsExpand = true; AskForInput(); } // Read the file (file name is in v.GetValue()), expand // all macro variables in it, and set expanded. const wxExFileName filename(wxExConfigDir(), v.GetValue()); std::ifstream ifs(filename.GetFullPath()); if (!ifs.is_open()) { wxLogError("Could not open template file: %s", filename.GetFullPath().c_str()); return false; } // Keep current macro, in case you cancel expanding, // this one is restored. std::string macro = m_Macro; while (ifs.good() && !ifs.eof()) { const char c = ifs.get(); if (c != '@') { expanded += c; } else { std::string variable; bool completed = false; while (ifs.good() && !ifs.eof() && !completed) { const char c = ifs.get(); if (c != '@') { variable += c; } else { completed = true; } } if (!completed) { m_Macro = macro; return false; } // Prevent recursion. if (variable == v.GetName()) { m_Macro = macro; return false; } std::string value; if (!Expand(ex, variable, value)) { m_Macro = macro; return false; } expanded += value; } } m_IsExpand = false; // Set back to normal value. AskForInput(); if (!m_IsRecording) { m_Macro = v.GetName(); } return true; }
const wxFileName wxExViMacros::GetFileName() { return wxFileName(wxExConfigDir(), "macros.xml"); }
bool wxExApp::OnInit() { // This should be before first use of wxConfigBase::Get(). wxConfigBase::Set(new wxFileConfig(wxEmptyString, wxEmptyString, wxFileName(wxExConfigDir(), GetAppName().Lower() + #ifdef __WXMSW__ ".ini" #else ".conf" #endif ).GetFullPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE)); const wxLanguageInfo* info = nullptr; if (wxConfigBase::Get()->Exists("LANG")) { info = wxLocale::FindLanguageInfo(wxConfigBase::Get()->Read("LANG")); if (info == nullptr) { std::cout << "Unknown language: " << wxConfigBase::Get()->Read("LANG").ToStdString() << "\n";; } } const int lang = (info != nullptr ? info->Language: wxLANGUAGE_DEFAULT); // Init the localization, from now on things will be translated. // Do not load wxstd, we load all files ourselved, // and do not want messages about loading non existing wxstd files. if (!m_Locale.Init(lang, wxLOCALE_DONT_LOAD_DEFAULT)) { std::cout << "Could not init locale for: " << std::to_string(lang) << "\n"; } // If there are catalogs in the catalog_dir, then add them to the m_Locale. // README: We use the canonical name, also for windows, not sure whether that is // the best. m_CatalogDir = wxStandardPaths::Get().GetLocalizedResourcesDir( m_Locale.GetCanonicalName(), // This seems to be necessary for wxGTK. For wxMSW it isn't used. wxStandardPaths::ResourceCat_Messages); if (wxFileName::DirExists(m_CatalogDir)) { wxArrayString files; wxDir::GetAllFiles(m_CatalogDir, &files, "*.mo"); for (const auto& it : files) { if (!m_Locale.AddCatalog(wxFileName(it).GetName())) { std::cout << "Could not add catalog: " << wxFileName(it).GetName(). ToStdString() << "\n";; } } } else if (info != nullptr) { std::cout << "Missing locale files for: " << GetLocale().GetName() << "\n"; } wxExVCS::LoadDocument(); return true; // wxApp::OnInit(); // we have our own cmd line processing }