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

antonvw / wex / 26389842410

25 May 2026 07:53AM UTC coverage: 64.89% (+0.03%) from 64.86%
26389842410

push

github

web-flow
1265 improve dirctrl (#1266)

* improve dirctrl

* fixed test

18909 of 31956 branches covered (59.17%)

Branch coverage included in aggregate %.

15111 of 20471 relevant lines covered (73.82%)

1529.84 hits per line

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

10.0
/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
#include <numeric>
12

13
const int id_compare     = wxWindow::NewControlId();
14
const int id_show_hidden = wxWindow::NewControlId();
15

16
wex::del::dirctrl::dirctrl(frame* frame, const data::window& data)
2✔
17
  : wxGenericDirCtrl(
18
      data.parent(),
19
      data.id(),
20
      wxDirDialogDefaultFolderStr,
21
      data.pos(),
22
      data.size(),
23
      data.style(),
24
      "*", // filter
25
      0,   // filter index
26
      data.name())
2✔
27
{
28
  if (config(_("Show hidden")).get(false))
2!
29
  {
30
    ShowHidden(true);
×
31
  }
32

33
  lexers::get()->apply_default_style(
4✔
34
    [=, this](const std::string& back)
×
35
    {
36
      GetTreeCtrl()->SetBackgroundColour(wxColour(back));
×
37
    },
×
38
    [=, this](const std::string& fore)
×
39
    {
40
      GetTreeCtrl()->SetForegroundColour(wxColour(fore));
×
41
    });
×
42

43
  bind(this).command(
22!
44
    {{[=, this](const wxCommandEvent& event)
×
45
      {
46
        vcs_execute(
×
47
          frame,
48
          event.GetId() - ID_EDIT_VCS_LOWEST - 1,
×
49
          to_vector_path(*this).get());
×
50
      },
×
51
      ID_EDIT_VCS_LOWEST},
×
52
     {[=, this](const wxCommandEvent& event)
×
53
      {
54
        const auto v(to_vector_string(*this).get());
×
55
        clipboard_add(
×
56
          std::ranges::fold_left(
×
57
            v,
58
            std::string(),
×
59
            [](const std::string& a, const std::string& b)
×
60
            {
61
              return a + b + "\n";
×
62
            }));
63
      },
×
64
      ID_TREE_COPY},
×
65
     {[=, this](const wxCommandEvent& event)
×
66
      {
67
        open_files(
×
68
          frame,
69
          to_vector_path(*this).get(),
×
70
          data::stc(),
×
71
          data::dir::type_t().set(data::dir::FILES));
×
72
      },
×
73
      ID_EDIT_OPEN},
×
74
     {[=, this](wxCommandEvent& event)
×
75
      {
76
        on_selected_paths(
×
77
          [=, this](const std::vector<path> p)
×
78
          {
79
            build(path_lexer(p[0]));
×
80
          });
×
81
      },
×
82
      ID_TREE_RUN_BUILD},
×
83
     {[=, this](const wxCommandEvent& event)
×
84
      {
85
        frame->find_in_files(
×
86
          to_vector_path(*this).get(),
×
87
          tool((wex::window_id)event.GetId()));
×
88
      },
×
89
      ID_TOOL_REPORT_FIND},
×
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_REPLACE},
×
97
     {[=, this](const wxCommandEvent& event)
×
98
      {
99
        if (const auto v(to_vector_path(*this).get()); v.size() == 2)
×
100
        {
101
          compare_file(v[0], v[1]);
×
102
        }
×
103
      },
×
104
      id_compare},
105
     {[=, this](const wxCommandEvent& event)
×
106
      {
107
        ShowHidden(!config(_("Show hidden")).get(false));
×
108
        config(_("Show hidden")).set(!config(_("Show hidden")).get(false));
×
109
      },
×
110
      id_show_hidden}});
111

112
  Bind(
2✔
113
    wxEVT_TREE_ITEM_ACTIVATED,
114
    [=, this](wxTreeEvent& event)
2✔
115
    {
116
      on_selected_paths(
×
117
        [=, this](const std::vector<path> p)
×
118
        {
119
          if (const auto& fn(p[0]); !fn.file_exists() && fn.dir_exists())
×
120
          {
121
            if (!GetTreeCtrl()->IsExpanded(event.GetItem()))
×
122
            {
123
              expand_and_select_path(fn);
×
124
            }
125
            else
126
            {
127
              CollapsePath(fn.string());
×
128
            }
129
          }
130
          else
131
          {
132
            open_files(
×
133
              frame,
134
              p,
135
              data::stc(),
×
136
              data::dir::type_t().set(data::dir::FILES));
×
137
          }
138
        });
×
139
    });
×
140

141
  Bind(
2✔
142
    wxEVT_TREE_ITEM_MENU,
143
    [=, this](wxTreeEvent& event)
2✔
144
    {
145
      on_selected_paths(
×
146
        [=, this](const std::vector<path> p)
×
147
        {
148
          const wex::path_lexer filename(p[0]);
×
149

150
          wex::menu menu(
151
            menu::menu_t_def().set(menu::IS_POPUP).set(menu::IS_VISUAL));
×
152

153
          if (filename.file_exists())
×
154
          {
155
            menu.append({{ID_EDIT_OPEN, _("&Open")}, {}});
×
156

157
            if (
×
158
              p.size() == 2 &&
×
159
              !config(_("list.Comparator")).get_first_of().empty())
×
160
            {
161
              menu.append({{id_compare, _("&Compare")}, {}});
×
162
            }
163
          }
164

165
          menu.append(
×
166
            {{ID_TREE_COPY,
167
              wxGetStockLabel(wxID_COPY),
×
168
              data::menu().art(wxART_COPY)}});
×
169

170
          // If the filename is under vcs append vcs submenu.
171
          if (vcs::dir_exists(filename))
×
172
          {
173
            menu.append({{}, {filename, frame}});
×
174
          }
175

176
          if (filename.is_build())
×
177
          {
178
            menu.append({{}, {ID_TREE_RUN_BUILD, "&Build"}});
×
179
          }
180

181
          menu.append(
×
182
            {{},
183
             {ID_TOOL_REPORT_FIND,
184
              ellipsed(frame->find_in_files_title(ID_TOOL_REPORT_FIND))},
×
185
             {ID_TOOL_REPLACE,
186
              ellipsed(frame->find_in_files_title(ID_TOOL_REPLACE))},
×
187
             {}});
188

189
          if (
×
190
            auto* item = menu.AppendCheckItem(id_show_hidden, _("Show hidden"));
×
191
            config(_("Show hidden")).get(false))
×
192
          {
193
            item->Check();
×
194
          }
195

196
          PopupMenu(&menu);
×
197
        });
×
198
    });
×
199

200
  Bind(
2✔
201
    wxEVT_TREE_SEL_CHANGED,
202
    [=, this](wxTreeEvent& event)
2✔
203
    {
204
      on_selected_paths(
×
205
        [=, this](const std::vector<path> p)
×
206
        {
207
          log::status() << p[0];
×
208
        });
×
209
    });
×
210
}
4!
211

212
bool wex::del::dirctrl::expand_and_select_path(const wex::path& path)
2✔
213
{
214
  if (!ExpandPath(path.string()))
2!
215
  {
216
    return false;
2✔
217
  }
218

219
  SelectPath(path.string());
×
220

221
  return true;
×
222
}
223

224
std::vector<wex::path> wex::del::dirctrl::on_selected_paths(
×
225
  std::function<void(std::vector<path> p)> f) const
226
{
227
  const auto v(wex::to_vector_path(*this).get());
×
228

229
  if (!v.empty())
×
230
  {
231
    f(v);
×
232
  }
233

234
  return v;
×
235
}
×
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