| 2036 | } |
| 2037 | |
| 2038 | UIWindow* DebuggerPlugin::processPicker() { |
| 2039 | static constexpr auto PROCESS_PICKER_LAYOUT = R"html( |
| 2040 | <window id="process_picker" lw="450dp" lh="450dp" padding="4dp" window-title="@string(list_of_processes, List of Processes)"> |
| 2041 | <vbox lw="mp" lh="mp"> |
| 2042 | <hbox lw="mp" lh="wc" margin-bottom="4dp"> |
| 2043 | <TextView text="@string(filter_colon, Filter:)" lh="mp" margin-right="8dp" /> |
| 2044 | <TextInput id="processes_filter" lw="0dp" lw8="1" /> |
| 2045 | </hbox> |
| 2046 | <TableView id="processes_list" lw="mp" lh="0dp" lw8="1" /> |
| 2047 | <hbox class="buttons" lw="mp" lh="wc" margin-top="4dp"> |
| 2048 | <PushButton id="pick_process" text="@string(pick_process, Pick Process)" enabled="false" /> |
| 2049 | <PushButton id="update_process_list" text="@string(update_list, Update List)" margin-left="4dp" /> |
| 2050 | <Widget lw="0dp" lw8="1" /> |
| 2051 | <PushButton id="cancel_pick" text="@string(cancel, Cancel)" /> |
| 2052 | </hbox> |
| 2053 | </vbox> |
| 2054 | </window> |
| 2055 | )html"; |
| 2056 | UIWindow* win = |
| 2057 | getUISceneNode()->loadLayoutFromString( PROCESS_PICKER_LAYOUT )->asType<UIWindow>(); |
| 2058 | UITextInput* uiFilter = win->find( "processes_filter" )->asType<UITextInput>(); |
| 2059 | UITableView* uiTableView = win->find( "processes_list" )->asType<UITableView>(); |
| 2060 | UIPushButton* uiPickBut = win->find( "pick_process" )->asType<UIPushButton>(); |
| 2061 | UIPushButton* uiUpdateList = win->find( "update_process_list" )->asType<UIPushButton>(); |
| 2062 | UIPushButton* uiCancel = win->find( "cancel_pick" )->asType<UIPushButton>(); |
| 2063 | auto model = std::make_shared<ProcessesModel>( std::vector<std::pair<Uint64, std::string>>{}, |
| 2064 | getUISceneNode() ); |
| 2065 | uiTableView->setAutoColumnsWidth( true ); |
| 2066 | uiTableView->setFitAllColumnsToWidget( true ); |
| 2067 | uiTableView->setMainColumn( 1 ); |
| 2068 | uiTableView->setModel( model ); |
| 2069 | uiTableView->onModelEvent( [win]( const ModelEvent* event ) { |
| 2070 | if ( event->getModelEventType() == ModelEventType::Open ) |
| 2071 | win->sendCommonEvent( Event::OnConfirm ); |
| 2072 | } ); |
| 2073 | uiTableView->setOnSelectionChange( [uiTableView, uiPickBut]() { |
| 2074 | uiPickBut->setEnabled( !uiTableView->getSelection().isEmpty() ); |
| 2075 | } ); |
| 2076 | uiFilter->on( Event::OnValueChange, [uiFilter, uiTableView, model]( auto ) { |
| 2077 | model->setFilter( uiFilter->getText() ); |
| 2078 | uiTableView->setSelection( model->index( 0 ) ); |
| 2079 | } ); |
| 2080 | uiFilter->on( Event::OnPressEnter, [uiTableView, win]( auto ) { |
| 2081 | if ( !uiTableView->getSelection().isEmpty() ) |
| 2082 | win->sendCommonEvent( Event::OnConfirm ); |
| 2083 | } ); |
| 2084 | uiUpdateList->onClick( [this, model]( auto ) { |
| 2085 | mThreadPool->run( [model] { model->setProcesses( Sys::listProcesses() ); } ); |
| 2086 | } ); |
| 2087 | mThreadPool->run( [model, uiTableView] { |
| 2088 | model->setProcesses( Sys::listProcesses() ); |
| 2089 | uiTableView->scrollToBottom(); |
| 2090 | } ); |
| 2091 | uiCancel->onClick( [win]( auto ) { win->closeWindow(); } ); |
| 2092 | uiPickBut->onClick( [win]( auto ) { win->sendCommonEvent( Event::OnConfirm ); } ); |
| 2093 | win->on( Event::OnWindowReady, [uiFilter]( auto ) { uiFilter->setFocus(); } ); |
| 2094 | win->setKeyBindingCommand( "close-window", [win]() { win->closeWindow(); } ); |
| 2095 | win->addKeyBinding( { KEY_ESCAPE }, "close-window" ); |
nothing calls this directly
no test coverage detected