| 134 | std::string SignList::default_name; |
| 135 | |
| 136 | struct SignListWindow : Window, SignList { |
| 137 | QueryString filter_editbox; ///< Filter editbox; |
| 138 | int text_offset = 0; ///< Offset of the sign text relative to the left edge of the WID_SIL_LIST widget. |
| 139 | Scrollbar *vscroll = nullptr; |
| 140 | |
| 141 | SignListWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc), filter_editbox(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS) |
| 142 | { |
| 143 | this->CreateNestedTree(); |
| 144 | this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR); |
| 145 | this->FinishInitNested(window_number); |
| 146 | this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); |
| 147 | |
| 148 | /* Initialize the text edit widget */ |
| 149 | this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox; |
| 150 | this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR; |
| 151 | |
| 152 | /* Initialize the filtering variables */ |
| 153 | this->SetFilterString(""); |
| 154 | |
| 155 | /* Create initial list. */ |
| 156 | this->signs.ForceRebuild(); |
| 157 | this->signs.ForceResort(); |
| 158 | this->BuildSortSignList(); |
| 159 | } |
| 160 | |
| 161 | void OnInit() override |
| 162 | { |
| 163 | /* Default sign name, used if Sign::name is nullptr. */ |
| 164 | SignList::default_name = GetString(STR_DEFAULT_SIGN_NAME); |
| 165 | this->signs.ForceResort(); |
| 166 | this->SortSignsList(); |
| 167 | this->SetDirty(); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * This function sets the filter string of the sign list. The contents of |
| 172 | * the edit widget is not updated by this function. Depending on if the |
| 173 | * new string is zero-length or not the clear button is made |
| 174 | * disabled/enabled. The sign list is updated according to the new filter. |
| 175 | */ |
| 176 | void SetFilterString(std::string_view new_filter_string) |
| 177 | { |
| 178 | /* check if there is a new filter string */ |
| 179 | this->string_filter.SetFilterTerm(new_filter_string); |
| 180 | |
| 181 | /* Rebuild the list of signs */ |
| 182 | this->InvalidateData(); |
| 183 | } |
| 184 | |
| 185 | void OnPaint() override |
| 186 | { |
| 187 | if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList(); |
| 188 | this->DrawWidgets(); |
| 189 | } |
| 190 | |
| 191 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 192 | { |
| 193 | switch (widget) { |
nothing calls this directly
no test coverage detected