// Initialize our application bool App::OnInit(void) { // Init resources and add the PNG handler wxSystemOptions::SetOption(wxT("msw.remap"), 0); wxXmlResource::Get()->InitAllHandlers(); wxImage::AddHandler( new wxPNGHandler ); wxImage::AddHandler( new wxCURHandler ); wxImage::AddHandler( new wxBMPHandler ); wxImage::AddHandler( new wxXPMHandler ); InitXmlResource(); pMainFrame = new Frame(NULL, wxT("Frame")); // initialize print data and setup g_printData = new wxPrintData; g_pageSetupData = new wxPageSetupDialogData; // show the main frame pMainFrame->Show(TRUE); // set the main frame to be the main window SetTopWindow(pMainFrame); return TRUE; }
bool Application::OnInit() { wxSocketBase::Initialize(); ::wxInitAllImageHandlers(); wxXmlResource::Get()->InitAllHandlers(); // load resources InitXmlResource(); // create main window and show it MAIN_DIALOG = new dlgMain(0L); if (MAIN_DIALOG) MAIN_DIALOG->Show(); SetTopWindow(MAIN_DIALOG); return true; }
virtual bool OnInit() { // Activate an earlier instance if found, // or quit it if argv[1] == wxT("quit") bool quit = argc>1 && !wxStricmp(argv[1], wxT("quit")); const wxChar* title = wxT("TouchCursor Configuration"); if (quit) { win32funcs::QuitExistingWindow(title); return false; } else { bool found = win32funcs::RaiseExistingWindow(title); if (found) return false; } wxXmlResource::Get()->AddHandler(new wxFrameXmlHandler); wxXmlResource::Get()->AddHandler(new wxDialogXmlHandler); wxXmlResource::Get()->AddHandler(new wxNotebookXmlHandler); wxXmlResource::Get()->AddHandler(new wxPanelXmlHandler); wxXmlResource::Get()->AddHandler(new wxCheckBoxXmlHandler); wxXmlResource::Get()->AddHandler(new wxRadioButtonXmlHandler); wxXmlResource::Get()->AddHandler(new wxChoiceXmlHandler); wxXmlResource::Get()->AddHandler(new wxListBoxXmlHandler); wxXmlResource::Get()->AddHandler(new wxButtonXmlHandler); wxXmlResource::Get()->AddHandler(new wxStaticTextXmlHandler); wxXmlResource::Get()->AddHandler(new wxTextCtrlXmlHandler); wxXmlResource::Get()->AddHandler(new wxSizerXmlHandler); wxXmlResource::Get()->AddHandler(new wxStaticBitmapXmlHandler); wxXmlResource::Get()->AddHandler(new wxStaticLineXmlHandler); wxXmlResource::Get()->AddHandler(new wxHtmlWindowXmlHandler); InitXmlResource(); MainFrame* frame = new MainFrame; frame->SetIcon(wxICON(APP)); assert(frame->GetTitle() == title); frame->Show(); SetTopWindow(frame); return true; }
bool Application::OnInit() { if (BufferedSocket::InitializeSocketAPI() == false) return false; ::wxInitAllImageHandlers(); wxXmlResource::Get()->InitAllHandlers(); // load resources InitXmlResource(); // create main window, get size dimensions and show it MAIN_DIALOG = new dlgMain(0L); if (MAIN_DIALOG) MAIN_DIALOG->Show(); SetTopWindow(MAIN_DIALOG); return true; }
bool PoeditApp::OnInit() { if (!wxApp::OnInit()) return false; #if defined(__WXMAC__) wxSystemOptions::SetOption(wxMAC_TEXTCONTROL_USE_SPELL_CHECKER, 1); #endif #ifdef __WXMAC__ SetExitOnFrameDelete(false); #endif #if defined(__UNIX__) && !defined(__WXMAC__) wxStandardPaths::Get().SetInstallPrefix(POEDIT_PREFIX); wxString home = wxGetHomeDir() + "/"; // create Poedit cfg dir, move ~/.poedit to ~/.poedit/config // (upgrade from older versions of Poedit which used ~/.poedit file) if (!wxDirExists(home + ".poedit")) { if (wxFileExists(home + ".poedit")) wxRenameFile(home + ".poedit", home + ".poedit2"); wxMkdir(home + ".poedit"); if (wxFileExists(home + ".poedit2")) wxRenameFile(home + ".poedit2", home + ".poedit/config"); } #endif SetVendorName("Vaclav Slavik"); SetAppName("Poedit"); #if defined(__WXMAC__) #define CFG_FILE (wxStandardPaths::Get().GetUserConfigDir() + "/net.poedit.Poedit.cfg") #elif defined(__UNIX__) #define CFG_FILE (home + ".poedit/config") #else #define CFG_FILE wxEmptyString #endif #ifdef __WXMAC__ // upgrade from the old location of config file: wxString oldcfgfile = wxStandardPaths::Get().GetUserConfigDir() + "/poedit.cfg"; if (wxFileExists(oldcfgfile) && !wxFileExists(CFG_FILE)) { wxRenameFile(oldcfgfile, CFG_FILE); } #endif wxConfigBase::Set( new wxConfig(wxEmptyString, wxEmptyString, CFG_FILE, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE | wxCONFIG_USE_LOCAL_FILE)); wxConfigBase::Get()->SetExpandEnvVars(false); wxImage::AddHandler(new wxPNGHandler); wxXmlResource::Get()->InitAllHandlers(); #if defined(__WXMAC__) wxXmlResource::Get()->Load(wxStandardPaths::Get().GetResourcesDir() + "/*.xrc"); #elif defined(__WXMSW__) wxStandardPaths::Get().DontIgnoreAppSubDir(); wxXmlResource::Get()->Load(wxStandardPaths::Get().GetResourcesDir() + "\\Resources\\*.xrc"); #else InitXmlResource(); #endif SetDefaultCfg(wxConfig::Get()); #if defined(__WXMAC__) || defined(__WXMSW__) u_setDataDirectory(wxStandardPaths::Get().GetResourcesDir().mb_str()); #endif #ifndef __WXMAC__ wxArtProvider::PushBack(new PoeditArtProvider); #endif SetupLanguage(); #ifdef __WXMAC__ wxMenuBar *bar = wxXmlResource::Get()->LoadMenuBar("mainmenu_mac_global"); TweakOSXMenuBar(bar); wxMenuBar::MacSetCommonMenuBar(bar); // so that help menu is correctly merged with system-provided menu // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1600747&group_id=9863&atid=309863) s_macHelpMenuTitleName = _("&Help"); #endif FileHistory().Load(*wxConfig::Get()); // NB: It's important to do this before TM is used for the first time. if ( !MigrateLegacyTranslationMemory() ) return false; // NB: opening files or creating empty window is handled differently on // Macs, using MacOpenFiles() and MacNewFile(), so don't create empty // window if no files are given on command line; but still support // passing files on command line if (!gs_filesToOpen.empty()) { OpenFiles(gs_filesToOpen); gs_filesToOpen.clear(); } #ifndef __WXMAC__ else { OpenNewFile(); } #endif // !__WXMAC__ #ifdef USE_SPARKLE Sparkle_Initialize(CheckForBetaUpdates()); #endif // USE_SPARKLE #ifdef __WXMSW__ const char *appcast = "http://releases.poedit.net/appcast-win"; if ( CheckForBetaUpdates() ) { // Beta versions use unstable feed. appcast = "http://releases.poedit.net/appcast-win/beta"; } win_sparkle_set_appcast_url(appcast); win_sparkle_init(); #endif return true; }
bool DrawApp::OnInit() { /* Read params from szarp.cfg. */ #if wxUSE_UNICODE libpar_read_cmdline_w(&argc, argv); #else libpar_read_cmdline(&argc, argv); #endif #if BOOST_FILESYSTEM_VERSION == 3 boost::filesystem::wpath::imbue(std::locale("C")); #else boost::filesystem::wpath_traits::imbue(std::locale("C")); #endif if (!DrawGLApp::OnInit()) return false; SetProgName(_T("Draw 3")); //signal(SIGINT, INThandler); if (m_just_print_version) { std::cout << SZARP_VERSION << std::endl; return false; } m_server = NULL; m_db_queue = NULL; m_executor = NULL; m_remarks_handler = NULL; #ifdef __WXGTK__ libpar_init(); char *base = NULL; if (m_base == wxEmptyString) { base = libpar_getpar("", "config_prefix", 1); m_base = SC::L2S(base); free(base); } { if (m_base_type != IKS_BASE) { char *iks_server = libpar_getpar("draw3", "iks_server", 0); if (iks_server) { m_iks_server = SC::L2S(iks_server); m_base_type = IKS_BASE; free(iks_server); } char *iks_port = libpar_getpar("draw3", "iks_server_port", 0); if (iks_port) { m_iks_port = SC::L2S(iks_port); free(iks_port); } } } m_probers_from_szarp_cfg = get_probers_addresses(); #endif #ifdef MINGW32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif /* Set logging to stderr. */ wxLog *logger = new wxLogStderr(); //wxLog *logger = new wxLogGui(); wxLog::SetActiveTarget(logger); m_instance = new szSingleInstanceChecker(_T(".szarp_m_instance_lock"), wxEmptyString, _T("draw3")); if (m_instance->IsAnotherRunning()) { if (!m_url.IsEmpty()) { if (m_url_open_in_existing) SendToRunningInstance(_T("START_URL"), m_url.c_str()); else SendToRunningInstance(_T("START_URL_EXISTING"), m_url.c_str()); } else if (!m_base.IsEmpty()) { SendToRunningInstance(_T("START_BASE"), m_base.c_str()); } else { wxLogError(_T("base not given")); return false; } return false; } InitGL(); SplashScreen *splash = NULL; wxBitmap bitmap; // this loads draw64_xpm under Linux, or draw64 icon resource under Windows szFrame::setDefaultIcon(wxICON(draw64)); wxString splashimage = GetSzarpDir(); #ifndef MINGW32 splashimage += _T("resources/wx/images/szarp-logo.png"); #else splashimage += _T("resources\\wx\\images\\szarp-logo.png"); #endif #if wxUSE_LIBPNG /* Activate PNG image handler. */ wxImage::AddHandler( new wxPNGHandler ); #endif if (bitmap.LoadFile(splashimage, wxBITMAP_TYPE_PNG)) splash = new SplashScreen(&bitmap); else splash = new SplashScreen(); splash->Show(true); splash->PushStatusText(_("Setting locale...")); /* Set locale. */ this->InitializeLocale(_T("draw3"), locale); splash->PushStatusText(_("Reading params from szarp.cfg...")); wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE); if (_lang == AUTO_LANGUAGE) _lang = DEFAULT_LANGUAGE; splash->PushStatusText(_("Initializing IPKContainer...")); IPKContainer::Init(GetSzarpDataDir().c_str(), GetSzarpDir().c_str(), _lang.c_str()); m_cfg_mgr = new ConfigManager(GetSzarpDataDir(), IPKContainer::GetObject()); m_cfg_mgr->SetSplashScreen(splash); splash->PushStatusText(_("Initializing szbase...")); splash->PushStatusText(_("Initializing XML Resources...")); InitXmlResource(); splash->PushStatusText(_("Starting database query mechanism...")); m_db_queue = new DatabaseQueryQueue(); m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr); m_db_queue->SetDatabaseManager(m_dbmgr); m_dbmgr->SetProbersAddresses(GetProbersAddresses()); Draw3Base* draw_base; switch (m_base_type) { case SZBASE_BASE: draw_base = new SzbaseBase(m_dbmgr, GetSzarpDataDir().c_str(), &ConfigurationFileChangeHandler::handle, wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L)); break; case SZ4_BASE: draw_base = new Sz4Base(m_dbmgr, GetSzarpDataDir().c_str(), IPKContainer::GetObject()); break; case IKS_BASE: draw_base = new Sz4ApiBase(m_dbmgr, m_iks_server.c_str(), m_iks_port.c_str(), IPKContainer::GetObject()); break; } m_executor = new QueryExecutor(m_db_queue, m_dbmgr, draw_base); m_executor->Create(); m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2); m_executor->Run(); m_cfg_mgr->SetDatabaseManager(m_dbmgr); ConfigurationFileChangeHandler::database_manager = m_dbmgr; /* default config */ wxString defid; DrawsSets *config = NULL; splash->PushStatusText(_("Loading configuration...")); /* init activity logger with base name as server name. This assumes that * server has written basename to /etc/hosts on linux machines and probably * doesn't work on windows. */ UDPLogger::SetAppName( "draw3" ); UDPLogger::SetAddress( (const char*)m_base.mb_str(wxConvUTF8) ); UDPLogger::SetPort ( "7777" ); UDPLogger::LogEvent ( "drawapp:start" ); wxString prefix, window; PeriodType pt = PERIOD_T_YEAR; time_t time = -1; int selected_draw = 0; if (!m_url.IsEmpty()) { if (!decode_url(m_url, prefix, window, pt, time, selected_draw)) { wxLogError(_T("Invalid URL")); StopThreads(); return FALSE; } } else if (!m_base.IsEmpty()) { if ((config = m_cfg_mgr->LoadConfig(m_base,std::wstring(),m_show_logparams)) == NULL) { wxLogError(_("Error occurred while loading default configuration. Check your szarp.cfg file.")); StopThreads(); return FALSE; } prefix = m_base; } else { wxLogError(_("Missing starting base specification.")); StopThreads(); return FALSE; } #ifndef MINGW32 libpar_done(); #endif m_help = new szHelpController; #ifndef MINGW32 m_help->AddBook(wxGetApp().GetSzarpDir() + L"/resources/documentation/new/draw3/html/draw3.hhp"); #else m_help->AddBook(wxGetApp().GetSzarpDir() + L"\\resources\\documentation\\new\\draw3\\html\\draw3.hhp"); #endif szHelpControllerHelpProvider* provider = new szHelpControllerHelpProvider; wxHelpProvider::Set(provider); provider->SetHelpController(m_help); splash->PushStatusText(_("Initizalizing remarks...")); m_remarks_handler = new RemarksHandler(m_cfg_mgr); m_remarks_handler->Start(); splash->PushStatusText(_("Creating Frame Manager...")); VersionChecker* version_checker = new VersionChecker(argv[0]); version_checker->Start(); FrameManager *fm = new FrameManager(m_dbmgr, m_cfg_mgr, m_remarks_handler); /*@michal */ if (!fm->CreateFrame(prefix, window, pt, time, wxSize(width, height), wxPoint(x, y), selected_draw, m_url.IsEmpty(), m_full_screen)) { StopThreads(); wxLogError(_T("Unable to load base: %s"), prefix.c_str()); return FALSE; } StartInstanceServer(fm, m_cfg_mgr); wxToolTip::SetDelay(1000); SetAppName(_T("SZARPDRAW3")); splash->Destroy(); m_cfg_mgr->ResetSplashScreen(); #ifndef NO_GSTREAMER if (!gst_init_check(NULL, NULL, NULL)) return 1; #endif return TRUE; }
bool CodeLiteApp::OnInit() { // Set the log file verbosity FileLogger::OpenLog("codelite.log", clConfig::Get().Read("LogVerbosity", FileLogger::Error)); CL_DEBUG(wxT("Starting codelite...")); #if defined(__WXGTK__) || defined(__WXMAC__) // block signal pipe sigset_t mask_set; sigemptyset(&mask_set); sigaddset(&mask_set, SIGPIPE); sigprocmask(SIG_SETMASK, &mask_set, NULL); // Handle sigchld CodeLiteBlockSigChild(); #ifdef __WXGTK__ // Insall signal handlers signal(SIGSEGV, WaitForDebugger); signal(SIGABRT, WaitForDebugger); #endif #endif wxSocketBase::Initialize(); // #if wxUSE_ON_FATAL_EXCEPTION // //trun on fatal exceptions handler // wxHandleFatalExceptions(true); // #endif #ifdef __WXMSW__ // as described in http://jrfonseca.dyndns.org/projects/gnu-win32/software/drmingw/ // load the exception handler dll so we will get Dr MinGW at runtime m_handler = LoadLibrary(wxT("exchndl.dll")); // Enable this process debugging priviliges // EnableDebugPriv(); #endif #ifdef USE_POSIX_LAYOUT wxStandardPaths::Get().IgnoreAppSubDir("bin"); #endif // Init resources and add the PNG handler wxSystemOptions::SetOption(_T("msw.remap"), 0); wxSystemOptions::SetOption("msw.notebook.themed-background", 0); wxXmlResource::Get()->InitAllHandlers(); wxImage::AddHandler(new wxPNGHandler); wxImage::AddHandler(new wxCURHandler); wxImage::AddHandler(new wxICOHandler); wxImage::AddHandler(new wxXPMHandler); wxImage::AddHandler(new wxGIFHandler); InitXmlResource(); wxLog::EnableLogging(false); wxString homeDir(wxEmptyString); // parse command line wxCmdLineParser parser; parser.SetDesc(cmdLineDesc); parser.SetCmdLine(wxAppBase::argc, wxAppBase::argv); if(parser.Parse() != 0) { return false; } if(parser.Found(wxT("h"))) { // print usage parser.Usage(); return false; } if(parser.Found(wxT("v"))) { // print version #ifdef __WXMSW__ ::wxMessageBox(wxString() << "CodeLite IDE v" << clGitRevision, "CodeLite"); #else wxPrintf("CodeLite IDE v%s\n", clGitRevision); #endif return false; } if(parser.Found(wxT("n"))) { // Load codelite without plugins SetPluginLoadPolicy(PP_None); } wxString plugins; if(parser.Found(wxT("p"), &plugins)) { wxArrayString pluginsArr = ::wxStringTokenize(plugins, wxT(",")); // Trim and make lower case for(size_t i = 0; i < pluginsArr.GetCount(); i++) { pluginsArr.Item(i).Trim().Trim(false).MakeLower(); } // Load codelite without plugins SetAllowedPlugins(pluginsArr); SetPluginLoadPolicy(PP_FromList); } wxString newBaseDir(wxEmptyString); if(parser.Found(wxT("b"), &newBaseDir)) { #if defined(__WXMSW__) homeDir = newBaseDir; #else wxLogDebug("Ignoring the Windows-only --basedir option as not running Windows"); #endif } wxString newDataDir(wxEmptyString); if(parser.Found(wxT("d"), &newDataDir)) { clStandardPaths::Get().SetUserDataDir(newDataDir); } // Copy gdb pretty printers from the installation folder to a writeable location // this is needed because python complies the files and in most cases the user // running codelite has no write permissions to /usr/share/codelite/... DoCopyGdbPrinters(); // Since GCC 4.8.2 gcc has a default colored output // which breaks codelite output parsing // to disable this, we need to set GCC_COLORS to an empty // string. // https://sourceforge.net/p/codelite/bugs/946/ // http://gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html ::wxSetEnv("GCC_COLORS", ""); #if defined(__WXGTK__) if(homeDir.IsEmpty()) { SetAppName(wxT("codelite")); homeDir = clStandardPaths::Get() .GetUserDataDir(); // By default, ~/Library/Application Support/codelite or ~/.codelite if(!wxFileName::Exists(homeDir)) { wxLogNull noLog; wxFileName::Mkdir(homeDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); wxCHECK_MSG(wxFileName::DirExists(homeDir), false, "Failed to create the requested data dir"); } // Create the directory structure wxLogNull noLog; wxMkdir(homeDir); wxMkdir(homeDir + wxT("/lexers/")); wxMkdir(homeDir + wxT("/rc/")); wxMkdir(homeDir + wxT("/images/")); wxMkdir(homeDir + wxT("/templates/")); wxMkdir(homeDir + wxT("/config/")); wxMkdir(homeDir + wxT("/tabgroups/")); // copy the settings from the global location if needed wxString installPath(INSTALL_DIR, wxConvUTF8); if(!CopySettings(homeDir, installPath)) return false; ManagerST::Get()->SetInstallDir(installPath); } else { wxFileName fn(homeDir); fn.MakeAbsolute(); ManagerST::Get()->SetInstallDir(fn.GetFullPath()); } #elif defined(__WXMAC__) SetAppName(wxT("codelite")); homeDir = clStandardPaths::Get().GetUserDataDir(); if(!wxFileName::Exists(homeDir)) { wxLogNull noLog; wxFileName::Mkdir(homeDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); wxCHECK_MSG(wxFileName::DirExists(homeDir), false, "Failed to create the requested data dir"); } { wxLogNull noLog; // Create the directory structure wxMkdir(homeDir); wxMkdir(homeDir + wxT("/lexers/")); wxMkdir(homeDir + wxT("/rc/")); wxMkdir(homeDir + wxT("/images/")); wxMkdir(homeDir + wxT("/templates/")); wxMkdir(homeDir + wxT("/config/")); wxMkdir(homeDir + wxT("/tabgroups/")); } wxString installPath(MacGetBasePath()); ManagerST::Get()->SetInstallDir(installPath); // copy the settings from the global location if needed CopySettings(homeDir, installPath); #else //__WXMSW__ if(homeDir.IsEmpty()) { // did we got a basedir from user? # ifdef USE_POSIX_LAYOUT homeDir = wxStandardPaths::Get().GetDataDir() + wxT(INSTALL_DIR); # else homeDir = ::wxGetCwd(); # endif } wxFileName fnHomdDir(homeDir + wxT("/")); // try to locate the menu/rc.xrc file wxFileName fn(homeDir + wxT("/rc"), wxT("menu.xrc")); if(!fn.FileExists()) { // we got wrong home directory wxFileName appFn(wxAppBase::argv[0]); homeDir = appFn.GetPath(); } if(fnHomdDir.IsRelative()) { fnHomdDir.MakeAbsolute(); homeDir = fnHomdDir.GetPath(); } ManagerST::Get()->SetInstallDir(homeDir); #endif // Update codelite revision and Version EditorConfigST::Get()->Init(clGitRevision, wxT("2.0.2")); // Make sure we have an instance if the keyboard manager allocated before we create the main frame class // (the keyboard manager needs to connect to the main frame events) clKeyboardManager::Get(); ManagerST::Get()->SetOriginalCwd(wxGetCwd()); ::wxSetWorkingDirectory(homeDir); // Load all of the XRC files that will be used. You can put everything // into one giant XRC file if you wanted, but then they become more // diffcult to manage, and harder to reuse in later projects. // The menubar if(!wxXmlResource::Get()->Load(DoFindMenuFile(ManagerST::Get()->GetInstallDir(), wxT("2.0")))) return false; // keep the startup directory ManagerST::Get()->SetStartupDirectory(::wxGetCwd()); // set the performance output file name PERF_OUTPUT(wxString::Format(wxT("%s/codelite.perf"), wxGetCwd().c_str()).mb_str(wxConvUTF8)); // Initialize the configuration file locater ConfFileLocator::Instance()->Initialize(ManagerST::Get()->GetInstallDir(), ManagerST::Get()->GetStartupDirectory()); Manager* mgr = ManagerST::Get(); // set the CTAGS_REPLACEMENT environment variable wxSetEnv(wxT("CTAGS_REPLACEMENTS"), ManagerST::Get()->GetStartupDirectory() + wxT("/ctags.replacements")); long style = wxSIMPLE_BORDER; #if defined(__WXMSW__) || defined(__WXGTK__) style |= wxFRAME_NO_TASKBAR; #else // Mac wxUnusedVar(style); #endif // read the last frame size from the configuration file // Initialise editor configuration files #ifdef __WXMSW__ { wxLogNull noLog; wxFileName::Mkdir(clStandardPaths::Get().GetUserDataDir(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); } #endif EditorConfigST::Get()->SetInstallDir(mgr->GetInstallDir()); EditorConfig* cfg = EditorConfigST::Get(); if(!cfg->Load()) { CL_ERROR(wxT("Failed to load configuration file: %s/config/codelite.xml"), wxGetCwd().c_str()); return false; } ColoursAndFontsManager::Get().Load(); #ifdef __WXGTK__ bool redirect = clConfig::Get().Read("RedirectLogOutput", true); if(redirect) { // Redirect stdout/error to a file wxFileName stdout_err(clStandardPaths::Get().GetUserDataDir(), "codelite-stdout-stderr.log"); FILE* new_stdout = ::freopen(stdout_err.GetFullPath().mb_str(wxConvISO8859_1).data(), "a+b", stdout); FILE* new_stderr = ::freopen(stdout_err.GetFullPath().mb_str(wxConvISO8859_1).data(), "a+b", stderr); wxUnusedVar(new_stderr); wxUnusedVar(new_stdout); } #endif // check for single instance if(!IsSingleInstance(parser, ManagerST::Get()->GetOriginalCwd())) { return false; } //--------------------------------------------------------- // Set environment variable for CodeLiteDir (make it first // on the list so it can be used by other variables) //--------------------------------------------------------- EvnVarList vars; EnvironmentConfig::Instance()->Load(); EnvironmentConfig::Instance()->ReadObject(wxT("Variables"), &vars); vars.InsertVariable(wxT("Default"), wxT("CodeLiteDir"), ManagerST::Get()->GetInstallDir()); EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars); //--------------------------------------------------------- #ifdef __WXMSW__ // Read registry values MSWReadRegistry(); #endif GeneralInfo inf; cfg->ReadObject(wxT("GeneralInfo"), &inf); // Set up the locale if appropriate if(EditorConfigST::Get()->GetOptions()->GetUseLocale()) { int preferredLocale = wxLANGUAGE_ENGLISH; // The locale had to be saved as the canonical locale name, as the wxLanguage enum wasn't consistent between wx // versions wxString preferredLocalename = EditorConfigST::Get()->GetOptions()->GetPreferredLocale(); if(!preferredLocalename.IsEmpty()) { const wxLanguageInfo* info = wxLocale::FindLanguageInfo(preferredLocalename); if(info) { preferredLocale = info->Language; if(preferredLocale == wxLANGUAGE_UNKNOWN) { preferredLocale = wxLANGUAGE_ENGLISH; } } } #if defined(__WXGTK__) // Cater for a --prefix= build. This gets added automatically to the search path for catalogues. // So hack in the standard ones too, otherwise wxstd.mo will be missed wxLocale::AddCatalogLookupPathPrefix(wxT("/usr/share/locale")); wxLocale::AddCatalogLookupPathPrefix(wxT("/usr/local/share/locale")); #elif defined(__WXMSW__) # ifdef USE_POSIX_LAYOUT wxLocale::AddCatalogLookupPathPrefix(wxStandardPaths::Get().GetDataDir() + wxT("/share/locale")); # else wxLocale::AddCatalogLookupPathPrefix(ManagerST::Get()->GetInstallDir() + wxT("\\locale")); # endif #endif // This has to be done before the catalogues are added, as otherwise the wrong one (or none) will be found m_locale.Init(preferredLocale); bool codelitemo_found = m_locale.AddCatalog(wxT("codelite")); if(!codelitemo_found) { m_locale.AddCatalog(wxT("CodeLite")); // Hedge bets re our spelling } if(!codelitemo_found) { // I wanted to 'un-init' the locale if no translations were found // as otherwise, in a RTL locale, menus, dialogs etc will be displayed RTL, in English... // However I couldn't find a way to do this } } // Append the binary's dir to $PATH. This makes codelite-cc available even for a --prefix= installation #if defined(__WXMSW__) wxChar pathsep(wxT(';')); #else wxChar pathsep(wxT(':')); #endif wxString oldpath; wxGetEnv(wxT("PATH"), &oldpath); wxFileName execfpath(wxStandardPaths::Get().GetExecutablePath()); wxSetEnv(wxT("PATH"), oldpath + pathsep + execfpath.GetPath()); wxString newpath; wxGetEnv(wxT("PATH"), &newpath); // If running under Cygwin terminal, adjust the environment variables AdjustPathForCygwinIfNeeded(); // If running under Cygwin terminal, adjust the environment variables AdjustPathForMSYSIfNeeded(); // Create the main application window clMainFrame::Initialize(parser.GetParamCount() == 0); m_pMainFrame = clMainFrame::Get(); m_pMainFrame->Show(TRUE); SetTopWindow(m_pMainFrame); long lineNumber(0); parser.Found(wxT("l"), &lineNumber); if(lineNumber > 0) { lineNumber--; } else { lineNumber = 0; } for(size_t i = 0; i < parser.GetParamCount(); i++) { wxString argument = parser.GetParam(i); // convert to full path and open it wxFileName fn(argument); fn.MakeAbsolute(ManagerST::Get()->GetOriginalCwd()); if(fn.GetExt() == wxT("workspace")) { ManagerST::Get()->OpenWorkspace(fn.GetFullPath()); } else { clMainFrame::Get()->GetMainBook()->OpenFile(fn.GetFullPath(), wxEmptyString, lineNumber); } } wxLogMessage(wxString::Format(wxT("Install path: %s"), ManagerST::Get()->GetInstallDir().c_str())); wxLogMessage(wxString::Format(wxT("Startup Path: %s"), ManagerST::Get()->GetStartupDirectory().c_str())); #ifdef __WXGTK__ // Needed on GTK if(clMainFrame::Get()->GetMainBook()->GetActiveEditor() == NULL) { clMainFrame::Get()->GetOutputPane()->GetBuildTab()->SetFocus(); } #endif // Especially with the OutputView open, CodeLite was consuming 50% of a cpu, mostly in updateui // The next line limits the frequency of UpdateUI events to every 100ms wxUpdateUIEvent::SetUpdateInterval(100); return TRUE; }
bool HTMLButcherApp::OnInit() { if (!wxApp::OnInit()) return false; #if defined(__WXMSW__) || !defined(HTMLBUTCHER_DEMO) SetAppName(wxT("HTMLButcher")); #else SetAppName(wxT("HTMLButcher-Demo")); #endif #ifdef HTMLBUTCHER_DEBUG wxFileName kf(wxStandardPaths::Get().GetExecutablePath()); kf.SetFullName(wxT("default.po")); kf.AppendDir(wxT("..")); kf.AppendDir(wxT("..")); kf.AppendDir(wxT("locale")); kf.Normalize(); locale_.AddCatalogLookupPathPrefix(kf.GetPath()); #endif locale_.AddCatalogLookupPathPrefix(wxStandardPaths::Get().GetDataDir() + wxT("/share/locale")); locale_.Init(GetUILanguage()); locale_.AddCatalog(wxT("htmlbutcher")); #ifdef __WXGTK__ wxFileName::Mkdir(wxStandardPaths::Get().GetUserDataDir(), 0777, wxPATH_MKDIR_FULL); // must create dir for wxConfig wxConfig::Set(new wxFileConfig(wxString::Format(wxT("%s/config"), wxTheApp->GetAppName().c_str()))); #endif extern void InitXmlResource(); // defined in htmlbutcher_resources.cpp wxXmlResource::Get()->InitAllHandlers(); InitXmlResource(); wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxArchiveFSHandler); //::wxHandleFatalExceptions(true); wxFreeImage::Initialize(); #ifdef BUTCHER_USE_HELP // help wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider; wxHelpProvider::Set(provider); provider->SetHelpController(&help_); #ifdef __WXMSW__ wxFileName fn(wxStandardPaths::Get().GetExecutablePath()); fn.SetFullName(wxT("htmlbutcher.chm")); #else #ifdef HTMLBUTCHER_DEBUG wxFileName fn(wxStandardPaths::Get().GetExecutablePath()); fn.SetFullName(wxT("htmlbutcher.htb")); #else wxFileName fn(wxStandardPaths::Get().GetResourcesDir().Lower(), wxEmptyString); fn.SetFullName(wxT("htmlbutcher.htb")); if (!fn.FileExists()) { fn.AssignDir(wxString::Format(wxT("/usr/share/%s"), wxTheApp->GetAppName().Lower().c_str())); fn.SetFullName(wxT("htmlbutcher.htb")); } #endif #endif if (!help_.Initialize(fn.GetFullPath())) { wxLogError(wxT("Cannot initialize the help system, aborting.")); return false; } #endif // main frame HTMLButcherFrame* frame = new HTMLButcherFrame(0L, wxT("HTMLButcher")); // splash screen { wxLogNull logNo; wxBitmap rbitmap(wxXmlResource::Get()->LoadBitmap(wxT("b_splash"))); wxImage simage(rbitmap.ConvertToImage()); simage.ConvertAlphaToMask(); wxBitmap bitmap(simage); HTMLButcherSplashScreen *splash = new HTMLButcherSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 4000, frame, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxSPLASH_CENTRE_ON_SCREEN|wxFRAME_SHAPED); splash->Update(); } //wxYield(); #ifdef __WXMSW__ frame->SetIcon(wxICON(HTMLBUTCHERICON)); // To Set App Icon #elif defined(__WXGTK__) frame->SetIcon(wxICON(htmlbutcher)); // To Set App Icon #endif //__WXMSW__ frame->Show(); SetTopWindow(frame); //#ifndef __WXMAC__ frame->Maximize(); //#endif #ifndef HTMLBUTCHER_DEMO if (!openfile_.IsEmpty()) frame->DoOpenProject(openfile_); #endif return true; }