예제 #1
0
void EditorSettingsLocal::DisplayHigherValues(const OptionsConfigPtr options)
{
    // There should be 'global' (or workspace if this will be a project setting) values for each setting
    // Insert them all, but leave the enabling checkboxes ticked, so the items will be disabled
    m_indentsUsesTabs->SetValue(options->GetIndentUsesTabs());
    m_indentWidth->SetValue(options->GetIndentWidth());
    m_tabWidth->SetValue(options->GetTabWidth());
    m_displayLineNumbers->SetValue(options->GetDisplayLineNumbers());
    m_showIndentationGuideLines->SetValue(options->GetShowIndentationGuidelines());

    m_highlightCaretLine->SetValue(options->GetHighlightCaretLine());
    m_checkBoxTrimLine->SetValue(options->GetTrimLine());
    m_checkBoxAppendLF->SetValue(options->GetAppendLF());

    m_checkBoxHideChangeMarkerMargin->SetValue(options->GetHideChangeMarkerMargin());
    m_checkBoxDisplayFoldMargin->SetValue(options->GetDisplayFoldMargin());
    m_displayBookmarkMargin->SetValue(options->GetDisplayBookmarkMargin());

    const wxString WhitespaceStyle[] = { wxTRANSLATE("Invisible"), wxTRANSLATE("Visible always"),
        wxTRANSLATE("Visible after indentation"), wxTRANSLATE("Indentation only") };
    wxString currentWhitespace;
    switch(options->GetShowWhitspaces()) {
    case wxSTC_WS_VISIBLEALWAYS:
        currentWhitespace = wxT("Visible always");
        break;
    case wxSTC_WS_VISIBLEAFTERINDENT:
        currentWhitespace = wxT("Visible after indentation");
        break;
    default:
        currentWhitespace = wxT("Invisible");
        break;
    }
    m_WSstringManager.AddStrings(
        sizeof(WhitespaceStyle) / sizeof(wxString), WhitespaceStyle, currentWhitespace, m_whitespaceStyle);

    const wxString EOLChoices[] = { wxTRANSLATE("Default"), wxT("Mac (CR)"), wxT("Windows (CRLF)"), wxT("Unix (LF)") };
    m_EOLstringManager.AddStrings(
        sizeof(EOLChoices) / sizeof(wxString), EOLChoices, options->GetEolMode(), m_choiceEOL);

    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);
}
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));
}
void EditorSettingsMiscPanel::Save(OptionsConfigPtr options)
{

    if(m_showSplashScreen->IsChecked()) {
        clMainFrame::Get()->SetFrameFlag(true, CL_SHOW_SPLASH);
    } else {
        clMainFrame::Get()->SetFrameFlag(false, CL_SHOW_SPLASH);
    }

    // Set the theme support.
    // This option requires a restart of codelite
    options->SetMswTheme(m_checkBoxEnableMSWTheme->IsChecked());
    if(m_oldMswUseTheme != m_checkBoxEnableMSWTheme->IsChecked()) {
        m_restartRequired = true;
    }

    clConfig::Get().Write(kConfigSingleInstance, m_singleAppInstance->IsChecked());
    clConfig::Get().Write(kConfigCheckForNewVersion, m_versionCheckOnStartup->IsChecked());
    clConfig::Get().Write(kConfigMaxItemsInFindReplaceDialog, ::wxStringToInt(m_maxItemsFindReplace->GetValue(), 15));
    clConfig::Get().Write(kConfigMaxOpenedTabs, ::wxStringToInt(m_spinCtrlMaxOpenTabs->GetValue(), 15));
    clConfig::Get().Write(kConfigRestoreLastSession, m_checkBoxRestoreSession->IsChecked());
    clConfig::Get().Write(kConfigFrameTitlePattern, m_textCtrlPattern->GetValue());

    bool oldUseSingleToolbar = !PluginManager::Get()->AllowToolbar();
    EditorConfigST::Get()->SetInteger(wxT("UseSingleToolbar"), m_useSingleToolbar->IsChecked() ? 1 : 0);

    // check to see of the icon size was modified
    int oldIconSize(24);

    OptionsConfigPtr oldOptions = EditorConfigST::Get()->GetOptions();
    if(oldOptions) {
        oldIconSize = oldOptions->GetIconsSize();
    }

    int iconSize(24);
    if(m_toolbarIconSize->GetSelection() == 0) {
        iconSize = 16;
    }
    options->SetIconsSize(iconSize);

    bool setlocale = m_SetLocale->IsChecked();
    options->SetUseLocale(setlocale);
    wxString newLocaleString = m_AvailableLocales->GetStringSelection();
    // I don't think we should check if newLocaleString is empty; that's still useful information
    newLocaleString = newLocaleString.BeforeFirst(wxT(':')); // Store it as "fr_FR", not "fr_FR: French"
    options->SetPreferredLocale(newLocaleString);
    if((setlocale != m_oldSetLocale) || (newLocaleString != m_oldpreferredLocale)) {
        m_restartRequired = true;
    }

    // save file font encoding
    options->SetFileFontEncoding(m_fileEncoding->GetStringSelection());
    TagsManagerST::Get()->SetEncoding(options->GetFileFontEncoding());

    if(oldIconSize != iconSize || oldUseSingleToolbar != m_useSingleToolbar->IsChecked()) {
        EditorConfigST::Get()->SetInteger(wxT("LoadSavedPrespective"), 0);
        // notify the user
        m_restartRequired = true;
    } else {
        EditorConfigST::Get()->SetInteger(wxT("LoadSavedPrespective"), 1);
    }

    size_t flags = options->GetOptions();
    size_t oldFlags = oldOptions->GetOptions();

    // Keep the old icon-set flags, this is done for deciding whether we should
    // prompt the user for possible restart
    size_t oldIconFlags(0);
    size_t newIconFlags(0);

    if(oldFlags & OptionsConfig::Opt_IconSet_Classic) oldIconFlags |= OptionsConfig::Opt_IconSet_Classic;

    if(oldFlags & OptionsConfig::Opt_IconSet_FreshFarm) oldIconFlags |= OptionsConfig::Opt_IconSet_FreshFarm;

    if(oldFlags & OptionsConfig::Opt_IconSet_Classic_Dark) oldIconFlags |= OptionsConfig::Opt_IconSet_Classic_Dark;

    if(oldIconFlags == 0) oldIconFlags = OptionsConfig::Opt_IconSet_Classic;

    // Clear old settings
    flags &= ~(OptionsConfig::Opt_IconSet_Classic);
    flags &= ~(OptionsConfig::Opt_IconSet_FreshFarm);
    flags &= ~(OptionsConfig::Opt_IconSet_Classic_Dark);

    if(m_choiceIconSet->GetSelection() == 0) {
        newIconFlags |= OptionsConfig::Opt_IconSet_Classic;
        flags |= OptionsConfig::Opt_IconSet_Classic;

    } else if(m_choiceIconSet->GetSelection() == 2) {
        newIconFlags |= OptionsConfig::Opt_IconSet_Classic_Dark;
        flags |= OptionsConfig::Opt_IconSet_Classic_Dark;

    } else { // 1
        newIconFlags |= OptionsConfig::Opt_IconSet_FreshFarm;
        flags |= OptionsConfig::Opt_IconSet_FreshFarm;
    }

    clConfig::Get().Write("RedirectLogOutput", m_redirectLogOutput->IsChecked());
    clConfig::Get().Write("PromptForNewReleaseOnly", m_checkBoxPromptReleaseOnly->IsChecked());
    options->SetOptions(flags);
    m_restartRequired = ((oldIconFlags != newIconFlags) || m_restartRequired);
}