The following code will not complete the word "two" despite it being on the list and seeing it in the results.
It strangely does complete "tuesday"
Any ideas why?
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include "Stuff.h"
#include <logmanager.h>
#include <cbeditor.h>
#include <cbstyledtextctrl.h>
#include <editormanager.h>
// Register the plugin with Code::Blocks.
// We are using an anonymous namespace so we don't litter the global one.
namespace
{
PluginRegistrant<Stuff> reg(_T("Stuff"));
}
int onCompleteId = wxNewId();
// events handling
BEGIN_EVENT_TABLE(Stuff, cbPlugin)
EVT_MENU(onCompleteId, Stuff::onStuff)
END_EVENT_TABLE()
void Stuff::onStuff(wxCommandEvent &evt)
{
Manager::Get()->GetLogManager()->Log(_("Lols"));
cbEditor* editor = (cbEditor*)Manager::Get()->GetEditorManager()->GetActiveEditor();
cbStyledTextCtrl *control = editor->GetControl();
int pos = control->GetCurrentPos();
int start = control->WordStartPosition(pos, true);
wxArrayString foo;
foo.Add(_("What the heck"));
foo.Add(_("two"));
foo.Add(_("Hello by"));
foo.Add(_("Hels"));
foo.Add(_("Hi"));
foo.Add(_("tuesday"));
foo.Add(_("wednesday"));
wxString final = GetStringFromArray(foo, _T(" "));
final.RemoveLast();
//control->CallTipShow(control->GetCurrentPos(), _("This is confusing"));
control->AutoCompSetIgnoreCase(true);
control->AutoCompSetCancelAtStart(false);
control->AutoCompSetAutoHide(false);
control->AutoCompSetSeparator(' ');
control->AutoCompStops(_(""));
control->AutoCompSetFillUps(_(""));
//final = _("Hello boo");
control->AutoCompShow(pos-start,final );
}
// constructor
Stuff::Stuff()
{
// Make sure our resources are available.
// In the generated boilerplate code we have no resources but when
// we add some, it will be nice that this code is in place already ;)
if(!Manager::LoadResource(_T("Stuff.zip")))
{
NotifyMissingFile(_T("Stuff.zip"));
}
}
// destructor
Stuff::~Stuff()
{
}
void Stuff::OnAttach()
{
// do whatever initialization you need for your plugin
// NOTE: after this function, the inherited member variable
// m_IsAttached will be TRUE...
// You should check for it in other functions, because if it
// is FALSE, it means that the application did *not* "load"
// (see: does not need) this plugin...
}
void Stuff::OnRelease(bool appShutDown)
{
// do de-initialization for your plugin
// if appShutDown is true, the plugin is unloaded because Code::Blocks is being shut down,
// which means you must not use any of the SDK Managers
// NOTE: after this function, the inherited member variable
// m_IsAttached will be FALSE...
}
void Stuff::BuildMenu(wxMenuBar* menuBar)
{
//The application is offering its menubar for your plugin,
//to add any menu items you want...
//Append any items you need in the menu...
//NOTE: Be careful in here... The application's menubar is at your disposal.
wxMenu* menu = menuBar->GetMenu(menuBar->FindMenu(_("&Edit")));
menu->Append(onCompleteId, _("Stuff\tCtrl-F2"));
}
you need to case invariant sort the list of words.
int cmp(const wxString &f,const wxString &s)
{
if(f.Upper()==s.Upper())
return 0;
if(f.Upper()>s.Upper())
return 1;
return -1;
}
//...
foo.Sort(cmp);
//...
(Also why are you using a space separated instead of newline separated?)
control->AutoCompSetSeparator(' ');