Author Topic: Select Word  (Read 5354 times)

Offline IvanBatrakov

  • Single posting newcomer
  • *
  • Posts: 9
Select Word
« on: September 23, 2011, 10:36:37 am »
needed to be added instead of using Ctrl+Left_Mouse_Click

void cbStyledTextCtrl::SelectWord()
{
   const int nPos = GetCurrentPos();
   int nPos_Start = WordStartPosition(nPos, true);
   int nPos_End = WordEndPosition(nPos, true);

   wxScintilla::SetEmptySelection(nPos);

   if((nPos == nPos_Start) || (nPos == nPos_End))
   {
      return;
   }

   wxScintilla::SetSelectionStart(nPos_Start);
   wxScintilla::SetSelectionEnd(nPos_End);
}

//
//main.cpp
int idEditSelectWord = XRCID("idEditSelectWord");
...
EVT_MENU(idEditSelectWord, MainFrame::OnEditSelectWord)
..

void MainFrame::OnEditSelectWord(wxCommandEvent& /*event*/)
{
   if(cbEditor* p_cbEditor = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor())
   {
      p_cbEditor->GetControl()->SelectWord();
   }
}

//main_menu.xrc
      <object class="wxMenuItem" name="idEditSelectWord">
        <label>Select Word</label>
        <accel>Ctrl-P</accel>
        <help>Selects word under keyboard cursor</help>
      </object>


/// paste word

void cbStyledTextCtrl::PasteWord()
{
   if(true == GetSelectedText().IsEmpty())
   {
      SelectWord();
   }

   Paste();
}
« Last Edit: September 23, 2011, 10:47:37 am by IvanBatrakov »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Select Word
« Reply #1 on: September 23, 2011, 10:45:58 am »
        <accel>Ctrl-P</accel>
Are you aware that this is the common shortcut for print? Maybe you can find another (unused) shortcut, or add an accelerator like shift or alike?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline IvanBatrakov

  • Single posting newcomer
  • *
  • Posts: 9
Re: Select Word
« Reply #2 on: September 23, 2011, 10:49:59 am »
shortcut ctrl-P is working now but can be changed to any because anyway main shortcut called from AutoKey program and no matter what shortcut in CodeBlocks is

// making the most powerful tool for migration from windows
// time for Linux now


Alt-A - select word
Alt-S - paste word

using Select Word

void cbStyledTextCtrl::Clear_Selection()
{
   wxScintilla::SetEmptySelection(GetCurrentPos());
}

void cbStyledTextCtrl::CopyWord()
{
   bool bMode_Word = false;

   if(true == GetSelectedText().IsEmpty())
   {
      SelectWord();

      bMode_Word = true;
   }

   Copy();

   if(true == bMode_Word)
   {
      Clear_Selection();
   }
}

void cbStyledTextCtrl::PasteWord()
{
   if(true == GetSelectedText().IsEmpty())
   {
      SelectWord();
   }

   Paste();
}

////////////////
<object class="wxMenu" name="menu_settings">
      <label>Settin&amp;gs</label>
      <object class="wxMenuItem" name="idSettingsEnvironment">
        <label>&amp;Environment...</label>
        <help>Change environment settings</help>
      </object>

// main.cpp
int idEditCopyWord = XRCID("idEditCopyWord");
int idEditPasteWord = XRCID("idEditPasteWord");

    EVT_MENU(idEditCopyWord, MainFrame::OnEditCopyWord)
    EVT_MENU(idEditPasteWord, MainFrame::OnEditPasteWord)


void MainFrame::OnEditCopyWord(wxCommandEvent& /*event*/)
{
   if(cbEditor* p_cbEditor = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor())
   {
      p_cbEditor->GetControl()->CopyWord();
   }
}

void MainFrame::OnEditPasteWord(wxCommandEvent& /*event*/)
{
   if(cbEditor* p_cbEditor = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor())
   {
      p_cbEditor->GetControl()->PasteWord();
   }
}

//////
// menu_main.xrc

      <object class="wxMenuItem" name="idEditCopyWord">
        <label>Copy Word</label>
        <accel>Alt-A</accel>
        <help>Copy word under keyboard cursor</help>
      </object>
      <object class="wxMenuItem" name="idEditPasteWord">
        <label>Paste Word</label>
        <accel>Alt-S</accel>
        <help>Paste word under keyboard cursor</help>
      </object>
« Last Edit: September 23, 2011, 11:01:50 am by IvanBatrakov »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Select Word
« Reply #3 on: September 23, 2011, 11:05:49 am »
/OFF: Would it possible to use code tags for long pastes?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Select Word
« Reply #4 on: September 23, 2011, 01:29:14 pm »
/OFF: Would it possible to use code tags for long pastes?
And please post patches, instead of code-snippets, so it is clear which parts of the code are new.
Makes it also easier to test.