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

antonvw / wex / 25880257505

14 May 2026 07:15PM UTC coverage: 64.688% (-0.08%) from 64.766%
25880257505

push

github

web-flow
make comparator a combobox (#1253)

* make comparator a combobox

* changes after review

18925 of 32141 branches covered (58.88%)

Branch coverage included in aggregate %.

15104 of 20464 relevant lines covered (73.81%)

1529.5 hits per line

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

10.76
/src/del/dirctrl.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
// Name:      dirctrl.cpp
3
// Purpose:   Implementation of class wex::del::dirctrl
4
// Author:    Anton van Wezenbeek
5
// Copyright: (c) 2010-2026 Anton van Wezenbeek
6
////////////////////////////////////////////////////////////////////////////////
7

8
#include <wex/wex.h>
9
#include <wx/stockitem.h> // for wxGetStockLabel
10

11
#define GET_VECTOR_FILES                                                       \
12
  const auto files(wex::to_vector_path(*this).get());                          \
13
  /* NOLINTNEXTLINE */                                                         \
14
  if (files.empty())                                                           \
15
  {                                                                            \
16
    event.Skip();                                                              \
17
    return;                                                                    \
18
  }
19

20
#include <numeric>
21

22
const int id_compare     = wxWindow::NewControlId();
23
const int id_show_hidden = wxWindow::NewControlId();
24

25
wex::del::dirctrl::dirctrl(frame* frame, const data::window& data)
2✔
26
  : wxGenericDirCtrl(
27
      data.parent(),
28
      data.id(),
29
      wxDirDialogDefaultFolderStr,
30
      data.pos(),
31
      data.size(),
32
      data.style(),
33
      "*", // filter
34
      0,   // filter index
35
      data.name())
2✔
36
{
37
  if (config(_("Show hidden")).get(false))
2!
38
  {
39
    ShowHidden(true);
×
40
  }
41

42
  lexers::get()->apply_default_style(
4✔
43
    [=, this](const std::string& back)
×
44
    {
45
      GetTreeCtrl()->SetBackgroundColour(wxColour(back));
×
46
    },
×
47
    [=, this](const std::string& fore)
×
48
    {
49
      GetTreeCtrl()->SetForegroundColour(wxColour(fore));
×
50
    });
×
51

52
  bind(this).command(
22!
53
    {{[=, this](const wxCommandEvent& event)
×
54
      {
55
        vcs_execute(
×
56
          frame,
57
          event.GetId() - ID_EDIT_VCS_LOWEST - 1,
×
58
          to_vector_path(*this).get());
×
59
      },
×
60
      ID_EDIT_VCS_LOWEST},
×
61
     {[=, this](const wxCommandEvent& event)
×
62
      {
63
        const auto v(to_vector_string(*this).get());
×
64
        clipboard_add(
×
65
          std::ranges::fold_left(
×
66
            v,
67
            std::string(),
×
68
            [](const std::string& a, const std::string& b)
×
69
            {
70
              return a + b + "\n";
×
71
            }));
72
      },
×
73
      ID_TREE_COPY},
×
74
     {[=, this](const wxCommandEvent& event)
×
75
      {
76
        open_files(
×
77
          frame,
78
          to_vector_path(*this).get(),
×
79
          data::stc(),
×
80
          data::dir::type_t().set(data::dir::FILES));
×
81
      },
×
82
      ID_EDIT_OPEN},
×
83
     {[=, this](wxCommandEvent& event)
×
84
      {
85
        GET_VECTOR_FILES
×
86

87
        build(path_lexer(files[0]));
×
88
      },
×
89
      ID_TREE_RUN_BUILD},
×
90
     {[=, this](const wxCommandEvent& event)
×
91
      {
92
        frame->find_in_files(
×
93
          to_vector_path(*this).get(),
×
94
          tool((wex::window_id)event.GetId()));
×
95
      },
×
96
      ID_TOOL_REPORT_FIND},
×
97
     {[=, this](const wxCommandEvent& event)
×
98
      {
99
        frame->find_in_files(
×
100
          to_vector_path(*this).get(),
×
101
          tool((wex::window_id)event.GetId()));
×
102
      },
×
103
      ID_TOOL_REPLACE},
×
104
     {[=, this](const wxCommandEvent& event)
×
105
      {
106
        if (const auto v(to_vector_path(*this).get()); v.size() == 2)
×
107
        {
108
          compare_file(v[0], v[1]);
×
109
        }
×
110
      },
×
111
      id_compare},
112
     {[=, this](const wxCommandEvent& event)
×
113
      {
114
        ShowHidden(!config(_("Show hidden")).get(false));
×
115
        config(_("Show hidden")).set(!config(_("Show hidden")).get(false));
×
116
      },
×
117
      id_show_hidden}});
118

119
  Bind(
2✔
120
    wxEVT_TREE_ITEM_ACTIVATED,
121
    [=, this](wxTreeEvent& event)
2✔
122
    {
123
      GET_VECTOR_FILES
×
124

125
      if (const auto& fn(files[0]); !fn.file_exists() && fn.dir_exists())
×
126
      {
127
        if (!GetTreeCtrl()->IsExpanded(event.GetItem()))
×
128
        {
129
          expand_and_select_path(fn);
×
130
        }
131
        else
132
        {
133
          CollapsePath(fn.string());
×
134
        }
135
      }
136
      else
137
      {
138
        open_files(
×
139
          frame,
140
          files,
141
          data::stc(),
×
142
          data::dir::type_t().set(data::dir::FILES));
×
143
      }
144
    });
×
145

146
  Bind(
2✔
147
    wxEVT_TREE_ITEM_MENU,
148
    [=, this](wxTreeEvent& event)
2✔
149
    {
150
      GET_VECTOR_FILES
×
151

152
      const wex::path_lexer filename(files[0]);
×
153

154
      wex::menu menu(
155
        menu::menu_t_def().set(menu::IS_POPUP).set(menu::IS_VISUAL));
×
156

157
      if (filename.file_exists())
×
158
      {
159
        menu.append({{ID_EDIT_OPEN, _("&Open")}, {}});
×
160

161
        if (
×
162
          files.size() == 2 &&
×
163
          !config(_("list.Comparator")).get_first_of().empty())
×
164
        {
165
          menu.append({{id_compare, _("&Compare")}, {}});
×
166
        }
167
      }
168

169
      menu.append(
×
170
        {{ID_TREE_COPY,
171
          wxGetStockLabel(wxID_COPY),
×
172
          data::menu().art(wxART_COPY)}});
×
173

174
      // If the filename is under vcs append vcs submenu.
175
      if (vcs::dir_exists(filename))
×
176
      {
177
        menu.append({{}, {filename, frame}});
×
178
      }
179

180
      if (filename.is_build())
×
181
      {
182
        menu.append({{}, {ID_TREE_RUN_BUILD, "&Build"}});
×
183
      }
184

185
      menu.append(
×
186
        {{},
187
         {ID_TOOL_REPORT_FIND,
188
          ellipsed(frame->find_in_files_title(ID_TOOL_REPORT_FIND))},
×
189
         {ID_TOOL_REPLACE,
190
          ellipsed(frame->find_in_files_title(ID_TOOL_REPLACE))},
×
191
         {}});
192

193
      if (
×
194
        auto* item = menu.AppendCheckItem(id_show_hidden, _("Show hidden"));
×
195
        config(_("Show hidden")).get(false))
×
196
      {
197
        item->Check();
×
198
      }
199

200
      PopupMenu(&menu);
×
201
    });
×
202

203
  Bind(
2✔
204
    wxEVT_TREE_SEL_CHANGED,
205
    [=, this](wxTreeEvent& event)
2✔
206
    {
207
      GET_VECTOR_FILES
×
208
      log::status() << files[0];
×
209
    });
×
210
}
4!
211

212
void wex::del::dirctrl::expand_and_select_path(const wex::path& path)
2✔
213
{
214
  ExpandPath(path.string());
2✔
215
  SelectPath(path.string());
2✔
216
}
2✔
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