| 3245 | } |
| 3246 | |
| 3247 | void LLMChatUI::initAttachFile() { |
| 3248 | mLocateBarLayout = findByClass<UIVLinearLayoutCommandExecuter>( "llm_chat_attach" ); |
| 3249 | mLocateInput = findByClass<UITextInput>( "llm_chat_locate_input" ); |
| 3250 | mLocateTable = findByClass<UITableView>( "llm_chat_attach_locate" ); |
| 3251 | mLocateTable->setHeadersVisible( false ); |
| 3252 | |
| 3253 | mLocateTable->on( Event::OnSizeChange, [this]( const Event* ) { updateLocateBarColumns(); } ); |
| 3254 | |
| 3255 | mLocateInput->on( Event::OnTextChanged, [this]( const Event* ) { |
| 3256 | showAttachFile(); |
| 3257 | updateLocateBarColumns(); |
| 3258 | } ); |
| 3259 | mLocateInput->on( Event::OnPressEnter, [this]( const Event* ) { |
| 3260 | KeyEvent keyEvent( mLocateTable, Event::KeyDown, KEY_RETURN, SCANCODE_UNKNOWN, 0, 0 ); |
| 3261 | mLocateTable->forceKeyDown( keyEvent ); |
| 3262 | } ); |
| 3263 | mLocateInput->on( Event::KeyDown, [this]( const Event* event ) { |
| 3264 | const KeyEvent* keyEvent = static_cast<const KeyEvent*>( event ); |
| 3265 | mLocateTable->forceKeyDown( *keyEvent ); |
| 3266 | } ); |
| 3267 | mLocateBarLayout->setCommand( "close-locatebar", [this] { |
| 3268 | hideAttachFile(); |
| 3269 | if ( mChatInput ) |
| 3270 | mChatInput->setFocus(); |
| 3271 | } ); |
| 3272 | mLocateBarLayout->getKeyBindings().addKeybindsString( { |
| 3273 | { "escape", "close-locatebar" }, |
| 3274 | } ); |
| 3275 | mLocateTable->on( Event::KeyDown, [this]( const Event* event ) { |
| 3276 | const KeyEvent* keyEvent = static_cast<const KeyEvent*>( event ); |
| 3277 | if ( keyEvent->getKeyCode() == KEY_ESCAPE ) |
| 3278 | mLocateBarLayout->execute( "close-locatebar" ); |
| 3279 | } ); |
| 3280 | mLocateTable->on( Event::OnModelEvent, [this]( const Event* event ) { |
| 3281 | const ModelEvent* modelEvent = static_cast<const ModelEvent*>( event ); |
| 3282 | if ( modelEvent->getModelEventType() == ModelEventType::Open ) { |
| 3283 | Variant vName( modelEvent->getModel()->data( |
| 3284 | modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 0 ), |
| 3285 | ModelRole::Display ) ); |
| 3286 | Variant vPath( modelEvent->getModel()->data( |
| 3287 | modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 1 ), |
| 3288 | ModelRole::Display ) ); |
| 3289 | |
| 3290 | if ( !vPath.isValid() ) |
| 3291 | return; |
| 3292 | |
| 3293 | std::string path( vPath.toString() ); |
| 3294 | if ( path.empty() ) |
| 3295 | return; |
| 3296 | |
| 3297 | Variant rangeStr( modelEvent->getModel()->data( |
| 3298 | modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 1 ), |
| 3299 | ModelRole::Custom ) ); |
| 3300 | |
| 3301 | auto cdoc = mChatInput->getDocumentRef(); |
| 3302 | |
| 3303 | if ( mLinkMode ) { |
| 3304 | cdoc->resetSelection(); |
nothing calls this directly
no test coverage detected