| 920 | } |
| 921 | |
| 922 | void ProjectWindow::UpdateStatusWidths() |
| 923 | { |
| 924 | auto pProject = FindProject(); |
| 925 | if (!pProject) |
| 926 | return; |
| 927 | |
| 928 | const auto fieldsCount = |
| 929 | ProjectStatusFieldsRegistry::Count(pProject.get()) + 1; |
| 930 | auto statusBar = GetStatusBar(); |
| 931 | |
| 932 | bool statusBarRecreated = false; |
| 933 | |
| 934 | if (!statusBar || fieldsCount != statusBar->GetFieldsCount()) |
| 935 | { |
| 936 | statusBar = CreateProjectStatusBar(); |
| 937 | statusBarRecreated = true; |
| 938 | } |
| 939 | |
| 940 | const auto& functions = ProjectStatus::GetStatusWidthFunctions(); |
| 941 | |
| 942 | auto& project = *pProject; |
| 943 | |
| 944 | std::vector<int> widths(fieldsCount, 0); |
| 945 | |
| 946 | // The old behavior with zero-width first field is kept |
| 947 | int index = 1; |
| 948 | |
| 949 | ProjectStatusFieldsRegistry::Visit( |
| 950 | [&](const StatusBarFieldItem& field, const auto&) |
| 951 | { |
| 952 | if (!field.IsVisible(project)) |
| 953 | return; |
| 954 | |
| 955 | auto width = field.GetDefaultWidth(project); |
| 956 | |
| 957 | // Negative width indicates that the field is expandable |
| 958 | if (width >= 0) |
| 959 | { |
| 960 | for (const auto& function : functions) |
| 961 | { |
| 962 | auto results = function(project, field.name); |
| 963 | for (const auto& string : results.first) |
| 964 | { |
| 965 | int w; |
| 966 | statusBar->GetTextExtent(string.Translation(), &w, nullptr); |
| 967 | width = std::max<int>(width, w + results.second); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | widths[index++] = width; |
| 973 | }); |
| 974 | |
| 975 | statusBar->SetStatusWidths(fieldsCount, widths.data()); |
| 976 | ProjectStatusFieldsRegistry::OnSize(project); |
| 977 | } |
| 978 | |
| 979 | void ProjectWindow::MacShowUndockedToolbars(bool show) |
no test coverage detected