src/tracks/labeltrack/ui/LabelTrackView.cpp
/// OnChar is called for incoming characters -- that's any keypress not handled
/// by OnKeyDown.
OnChar is called for incoming characters -- that's any keypress not handled
by OnKeyDown.
OnChar is called for incoming characters -- that ' s any keypress not handled by OnKeyDown .
bool LabelTrackView::DoChar(
   AudacityProject &project, NotifyingSelectedRegion &WXUNUSED(newSel),
   wxKeyEvent & event)
{
    We still need to check this or we will eat the top level menu accelerators
    on Windows if our capture or key down handlers skipped the event.
   const int mods = event.GetModifiers();
   if (mods != wxMOD_NONE && mods != wxMOD_SHIFT) {
      event.Skip();
      return false;
   }
    Only track true changes to the label
   bool updated = false;
    Cache the character
   wxChar charCode = event.GetUnicodeKey();
    Skip if it's not a valid unicode character or a control character
   if (charCode == 0 || wxIscntrl(charCode)) {
      event.Skip();
      return false;
   }
    If we've reached this point and aren't currently editing, add NEW label
   const auto pTrack = FindLabelTrack();
   if (!IsValidIndex(mTextEditIndex, project)) {
       Don't create a NEW label for a space
      if (wxIsspace(charCode)) {
         event.Skip();
         return false;
      }
      bool useDialog;
      gPrefs->Read(wxT("/GUI/DialogForNameNewLabel"), &useDialog, false);
      auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
      if (useDialog) {
         wxString title;
         if (DialogForLabelName(
            project, selectedRegion, charCode, title) ==
             wxID_CANCEL) {
            return false;
         }
         pTrack->SetSelected(true);
         pTrack->AddLabel(selectedRegion, title);
         ProjectHistory::Get( project )
            .PushState(XO("Added label"), XO("Label"));
         return false;
      }
      else {
         pTrack->SetSelected(true);
         AddLabel( selectedRegion );
         ProjectHistory::Get( project )
            .PushState(XO("Added label"), XO("Label"));
      }
   }
   if (!IsValidIndex(mTextEditIndex, project))
      return false;
    Now we are definitely in a label; append the incoming character
    Test if cursor is in the end of string or not
   if (mInitialCursorPos != mCurrentCursorPos)
      RemoveSelectedText();
   const auto& mLabels = pTrack->GetLabels();
   auto labelStruct = mLabels[mTextEditIndex];
   auto& title = labelStruct.title;
   if (mCurrentCursorPos < (int)title.length()) {
       Get substring on the righthand side of cursor
      wxString rightPart = title.Mid(mCurrentCursorPos);
       Set title to substring on the lefthand side of cursor
      title = title.Left(mCurrentCursorPos);
      append charcode
      title += charCode;
      append the right part substring
      title += rightPart;
   }
   else
      append charCode
      title += charCode;
   pTrack->SetLabel(mTextEditIndex, labelStruct );
   moving cursor position forward
   mInitialCursorPos = ++mCurrentCursorPos;
   return true;
}
bool LabelTrackView :: DoChar ( AudacityProject & project , NotifyingSelectedRegion & WXUNUSED ( newSel ) , wxKeyEvent & event ) { const int mods = event . GetModifiers ( ) ; if ( mods != wxMOD_NONE && mods != wxMOD_SHIFT ) { event . Skip ( ) ; return false ; } wxChar charCode = event . GetUnicodeKey ( ) ; if ( charCode == 0 || wxIscntrl ( charCode ) ) { event . Skip ( ) ; return false ; } const auto pTrack = FindLabelTrack ( ) ; if ( ! IsValidIndex ( mTextEditIndex , project ) ) { if ( wxIsspace ( charCode ) ) { event . Skip ( ) ; return false ; } bool useDialog ; gPrefs -> Read ( wxT ( " " ) , & useDialog , false ) ; auto & selectedRegion = ViewInfo :: Get ( project ) . selectedRegion ; if ( useDialog ) { wxString title ; if ( DialogForLabelName ( project , selectedRegion , charCode , title ) == wxID_CANCEL ) { return false ; } pTrack -> SetSelected ( true ) ; pTrack -> AddLabel ( selectedRegion , title ) ; ProjectHistory :: Get ( project ) . PushState ( XO ( " " ) , XO ( " " ) ) ; return false ; } else { pTrack -> SetSelected ( true ) ; AddLabel ( selectedRegion ) ; ProjectHistory :: Get ( project ) . PushState ( XO ( " " ) , XO ( " " ) ) ; } } if ( ! IsValidIndex ( mTextEditIndex , project ) ) return false ; if ( mInitialCursorPos != mCurrentCursorPos ) RemoveSelectedText ( ) ; const auto & mLabels = pTrack -> GetLabels ( ) ; auto labelStruct = mLabels [ mTextEditIndex ] ; auto & title = labelStruct . title ; if ( mCurrentCursorPos < ( int ) title . length ( ) ) { wxString rightPart = title . Mid ( mCurrentCursorPos ) ; title = title . Left ( mCurrentCursorPos ) ; title += charCode ; title += rightPart ; } else title += charCode ; pTrack -> SetLabel ( mTextEditIndex , labelStruct ) ; mInitialCursorPos = ++ mCurrentCursorPos ; return true ; }
OnChar is called for incoming characters -- that's any keypress not handled
by OnKeyDown.
OnChar is called for incoming characters -- that ' s any keypress not handled by OnKeyDown .
// Check for modifiers and only allow shift. // // We still need to check this or we will eat the top level menu accelerators // on Windows if our capture or key down handlers skipped the event. // Only track true changes to the label //bool updated = false; // Cache the character // Skip if it's not a valid unicode character or a control character // If we've reached this point and aren't currently editing, add NEW label // Don't create a NEW label for a space // // Now we are definitely in a label; append the incoming character // // Test if cursor is in the end of string or not // Get substring on the righthand side of cursor // Set title to substring on the lefthand side of cursor //append charcode //append the right part substring //append charCode //moving cursor position forward