News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Select Word

Started by IvanBatrakov, September 23, 2011, 10:36:37 AM

Previous topic - Next topic

IvanBatrakov

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();
}

MortenMacFly

Quote from: IvanBatrakov on September 23, 2011, 10:36:37 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

IvanBatrakov

#2
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>

oBFusCATed

/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!]

Jenna

Quote from: oBFusCATed on September 23, 2011, 11:05:49 AM
/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.