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

antonvw / wex / 24955860718

26 Apr 2026 11:47AM UTC coverage: 64.21% (-0.07%) from 64.281%
24955860718

push

github

web-flow
added compare to dirctrl (#1237)

* added compare to dirctrl

* changes after review

18754 of 32095 branches covered (58.43%)

Branch coverage included in aggregate %.

14955 of 20403 relevant lines covered (73.3%)

1457.37 hits per line

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

10.82
/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 (files.size() == 2 && !config(_("list.Comparator")).get().empty())
×
162
        {
163
          menu.append({{id_compare, _("&Compare")}, {}});
×
164
        }
165
      }
166

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

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

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

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

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

198
      PopupMenu(&menu);
×
199
    });
×
200

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

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