News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Trouble with wxscintilla autocompletion

Started by Lalaland, November 22, 2011, 06:24:15 PM

Previous topic - Next topic

Lalaland

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"));

}

dmoore

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(' ');
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

Lalaland

You are right, I need to case sort the words and then it works perfectly.
I was planning on sorted them by a "priority" too, but I guess that is no longer a valid option.

I used a space separator because the place where I found the rest of the code(the current code completion plugin) used a space separator.
I am going to switch to a newline separator now.

dmoore

Quote from: Lalaland on November 22, 2011, 09:35:23 PM
I was planning on sorted them by a "priority" too, but I guess that is no longer a valid option.

I guess you could roll your own completion combo box and then you can do whatever you want. (This may be a faulty memory, but I vaguely recall a handwritten completion control in older versions of the C::B CC plugin)
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]