EditorSettingsMiscPanel::EditorSettingsMiscPanel(wxWindow* parent) : EditorSettingsMiscBasePanel(parent) , TreeBookNode<EditorSettingsMiscPanel>() , m_restartRequired(false) { GeneralInfo info = clMainFrame::Get()->GetFrameGeneralInfo(); OptionsConfigPtr options = EditorConfigST::Get()->GetOptions(); if(options->GetIconsSize() == 16) { m_toolbarIconSize->SetSelection(0); } else { m_toolbarIconSize->SetSelection(1); } if(options->GetOptions() & OptionsConfig::Opt_IconSet_FreshFarm) m_choiceIconSet->SetSelection(1); else if(options->GetOptions() & OptionsConfig::Opt_IconSet_Classic_Dark) m_choiceIconSet->SetSelection(2); else m_choiceIconSet->SetSelection(0); // Default m_checkBoxEnableMSWTheme->SetValue(options->GetMswTheme()); m_useSingleToolbar->SetValue(!PluginManager::Get()->AllowToolbar()); m_oldSetLocale = options->GetUseLocale(); m_SetLocale->SetValue(m_oldSetLocale); m_oldpreferredLocale = options->GetPreferredLocale(); // Load the available locales and feed them to the wxchoice int select = FindAvailableLocales(); if(select != wxNOT_FOUND) { m_AvailableLocales->SetSelection(select); } wxArrayString astrEncodings; wxFontEncoding fontEnc; int iCurrSelId = 0; size_t iEncCnt = wxFontMapper::GetSupportedEncodingsCount(); for(size_t i = 0; i < iEncCnt; i++) { fontEnc = wxFontMapper::GetEncoding(i); if(wxFONTENCODING_SYSTEM == fontEnc) { // skip system, it is changed to UTF-8 in optionsconfig continue; } astrEncodings.Add(wxFontMapper::GetEncodingName(fontEnc)); if(fontEnc == options->GetFileFontEncoding()) { iCurrSelId = i; } } m_fileEncoding->Append(astrEncodings); m_fileEncoding->SetSelection(iCurrSelId); m_singleAppInstance->SetValue(clConfig::Get().Read(kConfigSingleInstance, false)); m_versionCheckOnStartup->SetValue(clConfig::Get().Read(kConfigCheckForNewVersion, true)); m_maxItemsFindReplace->ChangeValue(::wxIntToString(clConfig::Get().Read(kConfigMaxItemsInFindReplaceDialog, 15))); m_spinCtrlMaxOpenTabs->ChangeValue(::wxIntToString(clConfig::Get().Read(kConfigMaxOpenedTabs, 15))); m_choice4->SetStringSelection( FileLogger::GetVerbosityAsString(clConfig::Get().Read(kConfigLogVerbosity, FileLogger::Error))); m_checkBoxRestoreSession->SetValue(clConfig::Get().Read(kConfigRestoreLastSession, true)); m_textCtrlPattern->ChangeValue(clConfig::Get().Read(kConfigFrameTitlePattern, wxString("$workspace $fullpath"))); bool showSplash = info.GetFlags() & CL_SHOW_SPLASH ? true : false; m_showSplashScreen->SetValue(showSplash); m_oldMswUseTheme = m_checkBoxEnableMSWTheme->IsChecked(); m_redirectLogOutput->SetValue(clConfig::Get().Read(kConfigRedirectLogOutput, true)); m_checkBoxPromptReleaseOnly->SetValue(clConfig::Get().Read("PromptForNewReleaseOnly", false)); }
bool CodeLiteApp::OnInit() { #if defined(__WXMSW__) && !defined(NDEBUG) SetAppName(wxT("codelite-dbg")); #else SetAppName(wxT("codelite")); #endif #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 clStandardPaths::Get().IgnoreAppSubDir("bin"); #endif // Init resources and add the PNG handler wxSystemOptions::SetOption(_T("msw.remap"), 0); wxSystemOptions::SetOption("msw.notebook.themed-background", 1); wxXmlResource::Get()->InitAllHandlers(); wxImage::AddHandler(new wxPNGHandler); wxImage::AddHandler(new wxCURHandler); wxImage::AddHandler(new wxICOHandler); wxImage::AddHandler(new wxXPMHandler); wxImage::AddHandler(new wxGIFHandler); wxImage::AddHandler(new wxJPEGHandler); 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; } wxString newDataDir(wxEmptyString); if(parser.Found(wxT("d"), &newDataDir)) { clStandardPaths::Get().SetUserDataDir(newDataDir); } // check for single instance if(!IsSingleInstance(parser)) { 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" << CODELITE_VERSION_STRING, "CodeLite"); #else wxPrintf("CodeLite IDE v%s\n", CODELITE_VERSION_STRING); #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 } // Set the log file verbosity. NB Doing this earlier seems to break wxGTK debug output when debugging CodeLite // itself :/ FileLogger::OpenLog("codelite.log", clConfig::Get().Read(kConfigLogVerbosity, FileLogger::Error)); CL_DEBUG(wxT("Starting codelite...")); // 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()) { 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__) 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 = clStandardPaths::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 // Use our persistence manager (which uses wxFileConfig instead of the registry...) m_persistencManager = new clPersistenceManager(); wxPersistenceManager::Set(*m_persistencManager); // 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()); // 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 Manager* mgr = ManagerST::Get(); EditorConfig* cfg = EditorConfigST::Get(); cfg->SetInstallDir(mgr->GetInstallDir()); // Update codelite revision and Version wxString strVersion = CODELITE_VERSION_STRING; cfg->Init(strVersion, wxT("2.0.2")); if(!cfg->Load()) { CL_ERROR(wxT("Failed to load configuration file: %s/config/codelite.xml"), wxGetCwd().c_str()); return false; } #if !defined(__WXMAC__) && defined(NDEBUG) // Now all image handlers have been added, show splash screen; but only when using Release builds of codelite GeneralInfo inf; cfg->ReadObject(wxT("GeneralInfo"), &inf); if(inf.GetFlags() & CL_SHOW_SPLASH) { wxBitmap bitmap; wxString splashName(clStandardPaths::Get().GetDataDir() + wxT("/images/splashscreen.png")); if(bitmap.LoadFile(splashName, wxBITMAP_TYPE_PNG)) { wxString mainTitle = CODELITE_VERSION_STRING; clSplashScreen::g_splashScreen = new clSplashScreen(clSplashScreen::CreateSplashScreenBitmap(bitmap), wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, -1, NULL, wxID_ANY); wxYield(); } } #endif #ifdef __WXGTK__ bool redirect = clConfig::Get().Read(kConfigRedirectLogOutput, 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 //--------------------------------------------------------- // 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 // 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(clStandardPaths::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 } } else { // For proper encoding handling by system libraries it's needed to inialize locale even if UI translation is // turned off m_locale.Init(wxLANGUAGE_ENGLISH, wxLOCALE_DONT_LOAD_DEFAULT); } // 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(clStandardPaths::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(); // Make sure that the colours and fonts manager is instantiated ColoursAndFontsManager::Get().Load(); // 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; }