• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antonvw / wex / 13091451436

01 Feb 2025 06:48PM UTC coverage: 58.704% (-0.003%) from 58.707%
13091451436

push

github

web-flow
use std::ranges::all_of instead of std::all_of (#833)

16540 of 31034 branches covered (53.3%)

Branch coverage included in aggregate %.

13325 of 19840 relevant lines covered (67.16%)

1217.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.29
/src/ui/toolbar.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
// Name:      toolbar.cpp
3
// Purpose:   Implementation of wex::toolbar class
4
// Author:    Anton van Wezenbeek
5
// Copyright: (c) 2010-2025 Anton van Wezenbeek
6
////////////////////////////////////////////////////////////////////////////////
7

8
#include <wex/core/config.h>
9
#include <wex/core/core.h>
10
#include <wex/factory/bind.h>
11
#include <wex/factory/defs.h>
12
#include <wex/syntax/stc.h>
13
#include <wex/ui/art.h>
14
#include <wex/ui/ex-commandline-input.h>
15
#include <wex/ui/frame.h>
16
#include <wex/ui/frd.h>
17
#include <wex/ui/menu.h>
18
#include <wex/ui/toolbar.h>
19
#include <wx/checkbox.h>
20
#include <wx/stockitem.h>
21

22
#include "findbar.h"
23

24
namespace wex
25
{
26
void find_popup_menu(
×
27
  wxWindow*                             win,
28
  const ex_commandline_input::values_t& l,
29
  const wxPoint&                        pos)
30
{
31
  auto*     menu     = new wex::menu();
×
32
  const int max_size = 25;
×
33

34
  for (int i = 0; const auto& it : l)
×
35
  {
36
    menu->append(
×
37
      {{wex::ID_FIND_FIRST + i++,
×
38
        (it.size() >= max_size - 3 ? it.substr(0, max_size) + "..." : it)}});
×
39

40
    if (i >= wex::FIND_MAX_FINDS)
×
41
    {
42
      break;
×
43
    }
44
  }
45

46
  if (menu->GetMenuItemCount() > 0)
×
47
  {
48
    menu->append({{}, {wex::ID_CLEAR_FINDS, wxGetStockLabel(wxID_CLEAR)}});
×
49
    win->PopupMenu(menu, pos);
×
50
  }
51

52
  delete menu;
×
53
}
×
54

55
wxPoint get_point(wxAuiToolBar* tb, wxAuiToolBarEvent& event)
×
56
{
57
  const auto& rect = tb->GetToolRect(event.GetId());
×
58
  const auto& pt   = tb->ClientToScreen(rect.GetBottomLeft());
×
59
  return tb->ScreenToClient(pt);
×
60
}
61

62
bool prep_dropdown(wxAuiToolBar* tb, wxAuiToolBarEvent& event)
×
63
{
64
  if (!event.IsDropDownClicked())
×
65
  {
66
    event.Skip();
×
67
    return false;
×
68
  }
69

70
  tb->SetToolSticky(event.GetId(), true);
×
71
  return true;
×
72
}
73

74
const wxWindowID ID_VIEW_PROCESS = wxWindowBase::NewControlId();
75
}; // namespace wex
76

77
wex::toolbar::toolbar(wex::frame* frame, const data::window& data)
18✔
78
  : wxAuiToolBar(frame, data.id(), data.pos(), data.size(), data.style())
18✔
79
  , m_frame(frame)
36✔
80
{
81
}
18✔
82

83
void wex::toolbar::add_checkboxes(const checkboxes_t& v, bool realize)
3✔
84
{
85
  // 0   1      2     3       4        5        6
86
  // id, label, name, config, tooltip, default, lambda
87
  for (const auto& it : v)
12✔
88
  {
89
    auto* cb = new wxCheckBox(this, std::get<0>(it), std::get<1>(it));
9!
90

91
    cb->SetToolTip(std::get<4>(it));
9✔
92
    cb->SetValue(config(std::get<3>(it)).get(std::get<5>(it)));
9✔
93
    cb->SetName(std::get<2>(it));
9✔
94

95
    m_checkboxes.emplace_back(cb);
9✔
96

97
    AddControl(cb);
9✔
98

99
    Bind(
27✔
100
      wxEVT_CHECKBOX,
101
      [=, this](wxCommandEvent& event)
9!
102
      {
103
        if (std::get<6>(it) == nullptr)
×
104
        {
105
          config(std::get<3>(it)).set(cb->GetValue());
×
106
        }
107
        else
108
        {
109
          std::get<6>(it)(cb);
×
110
        }
111

112
        if (event.GetId() == ID_VIEW_PROCESS)
×
113
        {
114
          m_frame->pane_show("PROCESS", cb->GetValue());
×
115
        };
116
      },
×
117
      std::get<0>(it));
9✔
118
  }
119

120
  if (realize)
3✔
121
  {
122
    Realize();
1✔
123
  }
124
}
3✔
125

126
void wex::toolbar::add_checkboxes_standard(bool realize)
1✔
127
{
128
  add_checkboxes(
5!
129
    {{ID_VIEW_PROCESS,
130
      _("Process"),
131
      "PROCESS",
132
      "ViewProcess",
133
      _("View process"),
134
      false,
135
      nullptr},
136
     {NewControlId(),
×
137
      "Hex",
138
      "HEX",
139
      "is_hexmode",
140
      _("Open in hex mode"),
141
      false,
142
      nullptr},
143
     {NewControlId(),
×
144
      "Sync",
145
      "SYNC",
146
      "AllowSync",
147
      _("Synchronize modified files"),
148
      true,
149
      nullptr}},
150
    realize);
151
}
2!
152

153
void wex::toolbar::add_find(bool realize)
1✔
154
{
155
  m_find_bar = new find_bar(
×
156
    m_frame,
157
    data::window().parent(this).size(
2✔
158
      wxSize(150, style().default_font_size() + 10)));
3✔
159

160
  AddControl(m_find_bar->control());
1✔
161

162
  add_tool(
4!
163
    {data::toolbar_item(wxID_DOWN)
×
164
       .bitmap(wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_TOOLBAR))
2✔
165
       .help(_("Find next")),
2✔
166
     data::toolbar_item(wxID_UP)
1✔
167
       .bitmap(wxArtProvider::GetBitmap(wxART_GO_UP, wxART_TOOLBAR))
2✔
168
       .help(_("Find previous"))});
2✔
169

170
  add_checkboxes(
5!
171
    {{NewControlId(),
1✔
172
      rfind_after(find_replace_data::get()->text_match_word(), "."),
2✔
173
      "",
174
      "",
175
      _("Search matching words"),
176
      find_replace_data::get()->match_word(),
1✔
177
      [](wxCheckBox* cb)
×
178
      {
179
        find_replace_data::get()->set_match_word(cb->GetValue());
×
180
      }},
×
181
     {NewControlId(),
×
182
      rfind_after(find_replace_data::get()->text_match_case(), "."),
2✔
183
      "",
184
      "",
185
      _("Search case sensitive"),
186
      find_replace_data::get()->match_case(),
1✔
187
      [](wxCheckBox* cb)
×
188
      {
189
        find_replace_data::get()->set_match_case(cb->GetValue());
×
190
      }},
×
191
     {NewControlId(),
×
192
      rfind_after(find_replace_data::get()->text_regex(), "."),
2✔
193
      "",
194
      "",
195
      _("Search using regular expressions"),
196
      find_replace_data::get()->is_regex(),
1✔
197
      [](wxCheckBox* cb)
×
198
      {
199
        find_replace_data::get()->set_regex(cb->GetValue());
×
200
      }}},
×
201
    false);
202

203
  if (realize)
1!
204
  {
205
    Realize();
1✔
206
  }
207

208
  bind(this).command(
5!
209
    {{[=, this](const wxCommandEvent& event)
×
210
      {
211
        find_replace_data::get()->set_search_down(true);
×
212
        m_find_bar->find(false);
×
213
      },
×
214
      wxID_DOWN},
×
215
     {[=, this](const wxCommandEvent& event)
×
216
      {
217
        find_replace_data::get()->set_search_down(false);
×
218
        m_find_bar->find(false);
×
219
      },
×
220
      wxID_UP}});
×
221

222
  bind(this).ui(
5!
223
    {{[=, this](wxUpdateUIEvent& event)
×
224
      {
225
        event.Enable(!m_find_bar->get_text().empty());
×
226
      },
×
227
      wxID_DOWN},
×
228
     {[=, this](wxUpdateUIEvent& event)
×
229
      {
230
        event.Enable(!m_find_bar->get_text().empty());
×
231
      },
×
232
      wxID_UP}});
×
233
}
13!
234

235
void wex::toolbar::add_standard(bool realize)
2✔
236
{
237
  add_tool(
24!
238
    {{wxID_NEW},
239
     {wxID_OPEN},
240
     {wxID_BACKWARD},
241
     {wxID_FORWARD},
242
     {wxID_SAVE},
243
     {wxID_PRINT},
244
     {wxID_UNDO},
245
     {wxID_REDO},
246
     {wxID_FIND},
247
     {wxID_EXECUTE}},
248
    false);
249

250
  SetToolDropDown(wxID_FIND, true);
2✔
251
  SetToolDropDown(wxID_OPEN, true);
2✔
252

253
  Bind(
2✔
254
    wxEVT_AUITOOLBAR_TOOL_DROPDOWN,
255
    [=, this](wxAuiToolBarEvent& event)
2✔
256
    {
257
      if (!prep_dropdown(this, event))
×
258
      {
259
        return;
×
260
      }
261

262
      find_popup_menu(
×
263
        this,
264
        find_replace_data::get()->get_find_strings(),
×
265
        get_point(this, event));
×
266

267
      SetToolSticky(event.GetId(), false);
×
268
    },
269
    wxID_FIND);
270

271
  Bind(
2✔
272
    wxEVT_AUITOOLBAR_TOOL_DROPDOWN,
273
    [=, this](wxAuiToolBarEvent& event)
2✔
274
    {
275
      if (!prep_dropdown(this, event))
×
276
      {
277
        return;
×
278
      }
279

280
      m_frame->file_history().popup_menu(
×
281
        this,
282
        ID_CLEAR_FILES,
283
        get_point(this, event));
×
284

285
      SetToolSticky(event.GetId(), false);
×
286
    },
287
    wxID_OPEN);
288

289
  bind(this).command(
8!
290
    {{[=, this](wxCommandEvent& event)
×
291
      {
292
        m_frame->browse(event);
×
293
      },
×
294
      wxID_FORWARD,
×
295
      wxID_BACKWARD}});
×
296

297
  if (realize)
2✔
298
  {
299
    Realize();
1✔
300
  }
301
}
6!
302

303
bool wex::toolbar::add_tool(
4✔
304
  const std::vector<data::toolbar_item>& v,
305
  bool                                   realize)
306
{
307
  if (!std::ranges::all_of(
4!
308
        v,
309
        [this](const auto& it)
26✔
310
        {
311
          // If the id has a bitmap from our art.
312
          if (const art art(it.id()); art.get_bitmap(wxART_TOOLBAR).IsOk())
26✔
313
          {
314
            if (!AddTool(
6✔
315
                  it.id(),
316
                  wxEmptyString, // no label
317
#ifdef __WXGTK__
318
                  art.get_bitmap(wxART_TOOLBAR),
4✔
319
#else
320
                  art.get_bitmap(wxART_MENU, wxSize(16, 16)),
321
#endif
322
                  wxIsStockID(it.id()) ?
4!
323
                    wxGetStockLabel(it.id(), wxSTOCK_NOFLAGS).ToStdString() :
4!
324
                    it.help(),
×
325
                  it.kind()))
326
            {
327
              return false;
×
328
            }
329
          }
330
          // If the it has a bitmap on it's own.
331
          else if (it.bitmap().IsOk())
24✔
332
          {
333
            if (!AddTool(
2!
334
                  it.id(),
335
                  it.label(),
336
                  it.bitmap(),
337
                  it.help(),
338
                  it.kind()))
339
            {
340
              return false;
×
341
            }
342
          }
343
          return true;
26✔
344
        }))
345
  {
346
    return false;
×
347
  }
348

349
  if (realize)
4✔
350
  {
351
    Realize();
2✔
352
  }
353

354
  return true;
4✔
355
}
356

357
bool wex::toolbar::Destroy()
×
358
{
359
  delete m_find_bar;
×
360

361
  return wxAuiToolBar::Destroy();
×
362
}
363

364
bool wex::toolbar::set_checkbox(const std::string& name, bool show) const
35✔
365
{
366
  for (auto& it : m_checkboxes)
68✔
367
  {
368
    if (it->GetName() == name)
34✔
369
    {
370
      it->SetValue(show);
1✔
371
      return true;
1✔
372
    }
373
  }
374

375
  return false;
34✔
376
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc