ContentAssistantPopup::ContentAssistantPopup(
  wxWindow *parent,
  EditorCell* editor,
  AutoComplete * autocomplete,
  AutoComplete::autoCompletionType type
  ) : wxPopupTransientWindow(parent,-1)
{
  m_autocomplete = autocomplete;
  m_editor       = editor;
  m_type         = type;
  m_length       = 0;
  m_autocompletions = new wxListBox(this, -1);
  
  m_autocompletions->Connect(wxEVT_LISTBOX,
                             wxCommandEventHandler(ContentAssistantPopup::OnClick),
                             NULL, this);
  m_autocompletions->Connect(wxEVT_CHAR,
                             wxKeyEventHandler(ContentAssistantPopup::OnKeyPress),
                             NULL, this);
wxFlexGridSizer *box = new wxFlexGridSizer(1);
  UpdateResults();
  box->AddGrowableCol(0);
  box->AddGrowableRow(0);
  box->Add(m_autocompletions, 0, wxEXPAND | wxALL, 0);
  SetSizerAndFit(box);
}
예제 #2
0
AutocompletePopup::AutocompletePopup(
  EditorCell* editor,
  AutoComplete * autocomplete,
  AutoComplete::autoCompletionType type
  ) : wxMenu()
{
  m_autocomplete = autocomplete;
  m_editor       = editor;
  m_type         = type;
  m_length       = 0;
  UpdateResults();
}
예제 #3
0
void wxStfChildFrame::UpdateChannels( ) {

    wxStfDoc* pDoc=(wxStfDoc*)GetDocument();

    if ( pDoc != NULL && pDoc->size() > 1) {
        try {
            if (pActChannel->GetCurrentSelection() >= 0 ||
                pActChannel->GetCurrentSelection() <  (int)pDoc->size())
            {
                pDoc->SetCurChIndex( pActChannel->GetCurrentSelection() );
                if (pInactChannel->GetCurrentSelection() >= 0 ||
                    pInactChannel->GetCurrentSelection() <  (int)pDoc->size())
                {
                    pDoc->SetSecChIndex( pInactChannel->GetCurrentSelection() );
                } else {
                    pDoc->SetCurChIndex(0);
                    pDoc->SetSecChIndex(1);
                }
            } else {
                pDoc->SetCurChIndex(0);
                pDoc->SetSecChIndex(1);
            }
        }
        catch (const std::out_of_range& e) {
            wxString msg(wxT("Error while changing channels\nPlease close file\n"));
            msg += wxString( e.what(), wxConvLocal );
            wxGetApp().ExceptMsg(msg);
            return;
        }

        // Update measurements:
        wxGetApp().OnPeakcalcexecMsg();
        UpdateResults();
        wxStfView* pView=(wxStfView*)GetView();
        if ( pView == NULL ) {
            wxGetApp().ErrorMsg( wxT("View is zero in wxStfDoc::SwapChannels"));
            return;
        }
        if (pView->GetGraph() != NULL) {
            pView->GetGraph()->Refresh();
            pView->GetGraph()->Enable();
            pView->GetGraph()->SetFocus();
        }
    }
}
void ContentAssistantPopup::OnKeyPress(wxKeyEvent& event)
{
#if wxUSE_UNICODE
  wxChar key = event.GetUnicodeKey();
#else
  wxChar key = wxString::Format(wxT("%c"), ChangeNumpadToChar(event.GetKeyCode()));
#endif
  
  switch (event.GetKeyCode()) {
  case WXK_TAB:
    if(m_completions.GetCount()>0)
    {
      wxChar ch;
      bool addChar = true;
      wxString word=m_editor->GetSelectionString();
      int index=word.Length();
      do
      {
        if(m_completions[0].Length()<=index)
          addChar = false;
        else
        {
          ch = m_completions[0][index];
          for(size_t i=0;i<m_completions.GetCount();i++)
            if((m_completions[i].Length()<index + 1)||(m_completions[i][index]!=ch))
              addChar = false;
        }
        
        if(addChar)
        {
          index++;
          word += ch;
        }
      }
      while(addChar);
      m_editor->ReplaceSelection(m_editor->GetSelectionString(),word,true);
    }
    break;
  case WXK_RETURN:
  case WXK_RIGHT:
  case WXK_NUMPAD_ENTER:
  {
    int selection = m_autocompletions->GetSelection();
    if(selection<0)
      selection = 0;

    if(m_completions.GetCount()>0)
      m_editor->ReplaceSelection(
        m_editor->GetSelectionString(),
        m_completions[selection]
        );
    this->GetParent()->GetParent()->Refresh();
    if(!m_editor->IsActive())
      m_editor->ActivateCell();
    Dismiss();
  }
  break;
  case WXK_LEFT:
  case WXK_ESCAPE:
    this->GetParent()->GetParent()->Refresh();
    if(!m_editor->IsActive())
      m_editor->ActivateCell();
    Dismiss();
    break;
  case WXK_UP:
  {
    int selection = m_autocompletions->GetSelection();
    if(selection > 0)
      m_autocompletions->SetSelection(selection-1);
    else
    {
      if(m_completions.GetCount()>0)
        m_autocompletions->SetSelection(0);
    }
    break;
  }
  case WXK_DOWN:
  {
    int selection = m_autocompletions->GetSelection();
    if(selection<0) selection = 0;
    selection++;
    if(selection >= m_completions.GetCount())
      selection--;
    if(m_completions.GetCount()>0)
      m_autocompletions->SetSelection(selection);
    break;
  }
  case WXK_BACK:
  {
    wxString oldString=m_editor->GetSelectionString();
    if(oldString!=wxEmptyString)
    {
      m_editor->ReplaceSelection(
        oldString,
        oldString.Left(oldString.Length()-1),
        true
        );
      UpdateResults();
    }
    else
      this->GetParent()->GetParent()->Refresh();
    if(!m_editor->IsActive())
      m_editor->ActivateCell();
    
    Dismiss();
    break;
  }
  default:
  {
    if((wxIsalpha(key))||(key==wxT('_')))
    {
      wxString oldString=m_editor->GetSelectionString();
      m_editor->ReplaceSelection(
        oldString,
        oldString+wxString(key),
        true
        );
      UpdateResults();
    }
    else if(wxIsprint(key))
    {
      int selection = m_autocompletions->GetSelection();
      if(selection<0)
        selection = 0;
      
      m_editor->ReplaceSelection(
        m_editor->GetSelectionString(),
        m_completions[selection]+key
        );
      this->GetParent()->GetParent()->Refresh();
      if(!m_editor->IsActive())
        m_editor->ActivateCell();
      Dismiss();
      
    } else
      event.Skip();
  }
  }
  this->GetParent()->GetParent()->Refresh();
}