Esempio n. 1
0
void CscopeTab::DoItemActivated(const wxDataViewItem& item )
{
    CscopeTabClientData *data = dynamic_cast<CscopeTabClientData*>(m_dataviewModel->GetClientObject(item));
    if (data) {
        wxString wsp_path = clCxxWorkspaceST::Get()->GetPrivateFolder();
        //a single entry was activated, open the file
        //convert the file path to absolut path. We do it here, to improve performance
        wxFileName fn(data->GetEntry().GetFile());

        if ( !fn.MakeAbsolute(wsp_path) ) {
            wxLogMessage(wxT("failed to convert file to absolute path"));
        }

        if(m_mgr->OpenFile(fn.GetFullPath(), wxEmptyString, data->GetEntry().GetLine()-1)) {
            IEditor *editor = m_mgr->GetActiveEditor();
            if( editor && editor->GetFileName().GetFullPath() == fn.GetFullPath() && !GetFindWhat().IsEmpty()) {
                // We can't use data->GetEntry().GetPattern() as the line to search for as any appended comments have been truncated
                // For some reason LEditor::DoFindAndSelect checks it against the whole current line
                // and won't believe a match unless their lengths are the same
                int line = data->GetEntry().GetLine() - 1;
                int start = editor->PosFromLine(line);	// PosFromLine() returns the line start position
                int end = editor->LineEnd(line);
                wxString searchline(editor->GetTextRange(start, end));
                // Find and select the entry in the file
                editor->FindAndSelectV(searchline, GetFindWhat(), start); // The async version of FindAndSelect()
                editor->DelayedSetActive(); // We need to SetActive() editor. At least in wxGTK, this won't work synchronously
            }
        }
    } else {
        // Parent item, expand it
        m_dataview->Expand( item );
    }
}
void OpenResourceDialog::OpenSelection(const OpenResourceDialogItemData& selection, IManager* manager)
{
    // send event to the plugins to see if they want
    // to open this file
    wxString file_path = selection.m_file;
    clCommandEvent activateEvent(wxEVT_TREE_ITEM_FILE_ACTIVATED);
    activateEvent.SetFileName(file_path);
    if(EventNotifier::Get()->ProcessEvent(activateEvent)) return;

    if(manager && manager->OpenFile(selection.m_file, wxEmptyString, selection.m_line - 1)) {
        IEditor* editor = manager->GetActiveEditor();
        if(editor && !selection.m_name.IsEmpty() && !selection.m_pattern.IsEmpty()) {
            editor->FindAndSelectV(selection.m_pattern, selection.m_name);
        }
    }
}