Esempio n. 1
0
bool FindInFilesDialog::Show()
{
    bool res = IsShown() || wxFrame::Show();
    if(res) {

        // update the combobox
        m_findString->Clear();
        m_findString->Append(m_data.GetFindStringArr());
        DoSetFileMask();
        m_findString->SetValue(m_data.GetFindString());

        LEditor* editor = clMainFrame::Get()->GetMainBook()->GetActiveEditor();
        if(editor) {
            // if we have an open editor, and a selected text, make this text the search string
            wxString selText = editor->GetSelectedText();
            if(!selText.IsEmpty()) {
                m_findString->SetValue(selText);
            }
        }

        m_findString->SetSelection(-1, -1); // select all
        m_findString->SetFocus();
    }
    return res;
}
Esempio n. 2
0
FindInFilesDialog::FindInFilesDialog(wxWindow* parent, const wxString& dataName)
    : FindInFilesDialogBase(parent, wxID_ANY)
{
    m_data.SetName(dataName);

    // Store the find-in-files data
    clConfig::Get().ReadItem(&m_data);

    wxArrayString choices;
    size_t count = m_data.GetSearchPaths().GetCount();
    for(size_t i = 0; i < count; ++i) {
        choices.Add(m_data.GetSearchPaths().Item(i));
    }
    DoAddSearchPaths(choices);

    // Search for
    m_findString->Clear();
    m_findString->Append(m_data.GetFindStringArr());
    m_findString->SetValue(m_data.GetFindString());

    m_fileTypes->SetSelection(0);

    m_matchCase->SetValue(m_data.GetFlags() & wxFRD_MATCHCASE);
    m_matchWholeWord->SetValue(m_data.GetFlags() & wxFRD_MATCHWHOLEWORD);
    m_regualrExpression->SetValue(m_data.GetFlags() & wxFRD_REGULAREXPRESSION);
    m_checkBoxSaveFilesBeforeSearching->SetValue(m_data.GetFlags() & wxFRD_SAVE_BEFORE_SEARCH);
    
    // Set encoding
    wxArrayString astrEncodings;
    wxFontEncoding fontEnc;
    int selection(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;
        }
        wxString encodingName = wxFontMapper::GetEncodingName(fontEnc);
        size_t pos = astrEncodings.Add(encodingName);

        if(m_data.GetEncoding() == encodingName) {
            selection = static_cast<int>(pos);
        }
    }

    m_choiceEncoding->Append(astrEncodings);
    if(m_choiceEncoding->IsEmpty() == false) {
        m_choiceEncoding->SetSelection(selection);
    }

    // Set the file mask
    DoSetFileMask();

    GetSizer()->Fit(this);
    CentreOnParent();

    SetName("FindInFilesDialog");
    WindowAttrManager::Load(this);
}
int FindInFilesDialog::ShowDialog()
{
    // Update the combobox
    m_findString->Clear();
    m_findString->Append(m_data.GetFindStringArr());
    DoSetFileMask();
    m_findString->SetValue(m_data.GetFindString());

    LEditor* editor = clMainFrame::Get()->GetMainBook()->GetActiveEditor();
    if(editor) {
        // if we have an open editor, and a selected text, make this text the search string
        wxString selText = editor->GetSelectedText();
        if(!selText.IsEmpty()) {
            m_findString->SetValue(selText);
        }
    }

    m_findString->SetSelection(-1, -1); // select all
    m_findString->CallAfter(&wxTextCtrl::SetFocus);
    return wxDialog::ShowModal();
}
Esempio n. 4
0
FindInFilesDialog::FindInFilesDialog(wxWindow* parent, const wxString& dataName)
    : FindInFilesDialogBase(parent, wxID_ANY)
{
    m_data.SetName(dataName);

    // Store the find-in-files data
    clConfig::Get().ReadItem(&m_data);

    wxArrayString choices;
    size_t count = m_data.GetSearchPaths().GetCount();
    for(size_t i = 0; i < count; ++i) {
        choices.Add(m_data.GetSearchPaths().Item(i));
    }

    // add the default search paths
    if(choices.Index(wxGetTranslation(SEARCH_IN_WORKSPACE)) == wxNOT_FOUND)
        choices.Add(wxGetTranslation(SEARCH_IN_WORKSPACE));

    if(choices.Index(wxGetTranslation(SEARCH_IN_PROJECT)) == wxNOT_FOUND)
        choices.Add(wxGetTranslation(SEARCH_IN_PROJECT));

    if(choices.Index(wxGetTranslation(SEARCH_IN_CURR_FILE_PROJECT)) == wxNOT_FOUND)
        choices.Add(wxGetTranslation(SEARCH_IN_CURR_FILE_PROJECT));

    if(choices.Index(wxGetTranslation(SEARCH_IN_CURRENT_FILE)) == wxNOT_FOUND)
        choices.Add(wxGetTranslation(SEARCH_IN_CURRENT_FILE));

    if(choices.Index(wxGetTranslation(SEARCH_IN_OPEN_FILES)) == wxNOT_FOUND)
        choices.Add(wxGetTranslation(SEARCH_IN_OPEN_FILES));

    int initial = m_data.GetSearchScope();
    if((initial == wxNOT_FOUND) || ((size_t)initial >= count)) {
        initial = 0;
    }

    m_dirPicker->SetValues(choices, initial);

    // Search for
    m_findString->Clear();
    m_findString->Append(m_data.GetFindStringArr());
    m_findString->SetValue(m_data.GetFindString());

    m_fileTypes->SetSelection(0);

    m_matchCase->SetValue(m_data.GetFlags() & wxFRD_MATCHCASE);
    m_matchWholeWord->SetValue(m_data.GetFlags() & wxFRD_MATCHWHOLEWORD);
    m_regualrExpression->SetValue(m_data.GetFlags() & wxFRD_REGULAREXPRESSION);
    m_printScope->SetValue(m_data.GetFlags() & wxFRD_DISPLAYSCOPE);
    m_checkBoxSaveFilesBeforeSearching->SetValue(m_data.GetFlags() & wxFRD_SAVE_BEFORE_SEARCH);
    m_checkBoxSeparateTab->SetValue(m_data.GetFlags() & wxFRD_SEPARATETAB_DISPLAY);
    m_checkBoxSkipMatchesFoundInComments->SetValue(m_data.GetFlags() & wxFRD_SKIP_COMMENTS);
    m_checkBoxSkipMatchesFoundInStrings->SetValue(m_data.GetFlags() & wxFRD_SKIP_STRINGS);
    m_checkBoxHighlighStringComments->SetValue(m_data.GetFlags() & wxFRD_COLOUR_COMMENTS);

    // Set encoding
    wxArrayString astrEncodings;
    wxFontEncoding fontEnc;
    int selection(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;
        }
        wxString encodingName = wxFontMapper::GetEncodingName(fontEnc);
        size_t pos = astrEncodings.Add(encodingName);

        if(m_data.GetEncoding() == encodingName) {
            selection = static_cast<int>(pos);
        }
    }

    m_choiceEncoding->Append(astrEncodings);
    if(m_choiceEncoding->IsEmpty() == false) m_choiceEncoding->SetSelection(selection);

    // Set the file mask
    DoSetFileMask();

    GetSizer()->Fit(this);

    WindowAttrManager::Load(this, "FindInFilesDialog", NULL);
    Centre();
}
FindInFilesDialog::FindInFilesDialog(wxWindow* parent,
                                     const wxString& dataName,
                                     const wxArrayString& additionalSearchPaths)
    : FindInFilesDialogBase(parent, wxID_ANY)
{
    m_data.SetName(dataName);
    m_nonPersistentSearchPaths.insert(additionalSearchPaths.begin(), additionalSearchPaths.end());

    // Store the find-in-files data
    clConfig::Get().ReadItem(&m_data);
    wxArrayString paths = m_data.GetSearchPaths();

    wxStringSet_t persistentSearchPaths, d;
    persistentSearchPaths.insert(m_data.GetSearchPaths().begin(), m_data.GetSearchPaths().end());

    // Create a new set 'd' which contains the elements that appear in 'm_nonPersistentSearchPaths' but not in
    // 'persistentSearchPaths' set
    std::set_difference(m_nonPersistentSearchPaths.begin(),
                        m_nonPersistentSearchPaths.end(),
                        persistentSearchPaths.begin(),
                        persistentSearchPaths.end(),
                        std::inserter(d, d.end()));
    m_nonPersistentSearchPaths.swap(d);

    // At this point, m_nonPersistentSearchPaths contains list of paths that we should not persist
    // Append them to the list of paths to search
    std::for_each(m_nonPersistentSearchPaths.begin(), m_nonPersistentSearchPaths.end(), [&](const wxString& path) {
        paths.Add(path);
    });
    DoAddSearchPaths(paths);

    // Search for
    m_findString->Clear();
    m_findString->Append(m_data.GetFindStringArr());
    m_findString->SetValue(m_data.GetFindString());
    m_replaceString->Append(m_data.GetReplaceStringArr());
    m_replaceString->SetValue(m_data.GetReplaceString());
    m_fileTypes->SetSelection(0);

    m_matchCase->SetValue(m_data.GetFlags() & wxFRD_MATCHCASE);
    m_matchWholeWord->SetValue(m_data.GetFlags() & wxFRD_MATCHWHOLEWORD);
    m_regualrExpression->SetValue(m_data.GetFlags() & wxFRD_REGULAREXPRESSION);
    m_checkBoxSaveFilesBeforeSearching->SetValue(m_data.GetFlags() & wxFRD_SAVE_BEFORE_SEARCH);
    m_checkBoxPipeForGrep->SetValue(m_data.GetFlags() & wxFRD_ENABLE_PIPE_SUPPORT);
    // Set encoding
    wxArrayString astrEncodings;
    wxFontEncoding fontEnc;
    int selection(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;
        }
        wxString encodingName = wxFontMapper::GetEncodingName(fontEnc);
        size_t pos = astrEncodings.Add(encodingName);

        if(m_data.GetEncoding() == encodingName) {
            selection = static_cast<int>(pos);
        }
    }

    m_choiceEncoding->Append(astrEncodings);
    if(m_choiceEncoding->IsEmpty() == false) {
        m_choiceEncoding->SetSelection(selection);
    }

    // Set the file mask
    DoSetFileMask();
    SetName("FindInFilesDialog");

    // Fit the initial size and set it as the default minimum size
    GetSizer()->Fit(this);
    SetMinSize(GetSize());

    // Load the last size and position, but not on GTK
    WindowAttrManager::Load(this);
    CentreOnParent();
}