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

antonvw / wex / 14789787688

27 Apr 2025 01:43PM UTC coverage: 58.788% (+0.003%) from 58.785%
14789787688

push

github

web-flow
use fold_left instead of accumulate (#933)

16624 of 31138 branches covered (53.39%)

Branch coverage included in aggregate %.

13365 of 19874 relevant lines covered (67.25%)

1223.7 hits per line

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

0.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-2025 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 idShowHidden = wxWindow::NewControlId();
23

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

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

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

85
        build(path_lexer(files[0]));
×
86
      },
×
87
      ID_TREE_RUN_BUILD},
×
88
     {[=, this](const wxCommandEvent& event)
×
89
      {
90
        frame->find_in_files(
×
91
          to_vector_path(*this).get(),
×
92
          tool((wex::window_id)event.GetId()));
×
93
      },
×
94
      ID_TOOL_REPORT_FIND},
×
95
     {[=, this](const wxCommandEvent& event)
×
96
      {
97
        frame->find_in_files(
×
98
          to_vector_path(*this).get(),
×
99
          tool((wex::window_id)event.GetId()));
×
100
      },
×
101
      ID_TOOL_REPLACE},
×
102
     {[=, this](const wxCommandEvent& event)
×
103
      {
104
        ShowHidden(!config(_("Show hidden")).get(false));
×
105
        config(_("Show hidden")).set(!config(_("Show hidden")).get(false));
×
106
      },
×
107
      idShowHidden}});
108

109
  Bind(
×
110
    wxEVT_TREE_ITEM_ACTIVATED,
111
    [=, this](wxTreeEvent& event)
×
112
    {
113
      GET_VECTOR_FILES
×
114

115
      if (const auto& fn(files[0]); !fn.file_exists() && fn.dir_exists())
×
116
      {
117
        if (!GetTreeCtrl()->IsExpanded(event.GetItem()))
×
118
        {
119
          expand_and_select_path(fn);
×
120
        }
121
        else
122
        {
123
          CollapsePath(fn.string());
×
124
        }
125
      }
126
      else
127
      {
128
        open_files(
×
129
          frame,
130
          files,
131
          data::stc(),
×
132
          data::dir::type_t().set(data::dir::FILES));
×
133
      }
134
    });
×
135

136
  Bind(
×
137
    wxEVT_TREE_ITEM_MENU,
138
    [=, this](wxTreeEvent& event)
×
139
    {
140
      GET_VECTOR_FILES
×
141

142
      const wex::path_lexer filename(files[0]);
×
143

144
      wex::menu menu(
145
        menu::menu_t_def().set(menu::IS_POPUP).set(menu::IS_VISUAL));
×
146

147
      if (filename.file_exists())
×
148
      {
149
        menu.append({{ID_EDIT_OPEN, _("&Open")}, {}});
×
150
      }
151

152
      menu.append(
×
153
        {{ID_TREE_COPY,
154
          wxGetStockLabel(wxID_COPY),
×
155
          data::menu().art(wxART_COPY)}});
×
156

157
      // If the filename is under vcs append vcs submenu.
158
      if (vcs::dir_exists(filename))
×
159
      {
160
        menu.append({{}, {filename, frame}});
×
161
      }
162

163
      if (filename.is_build())
×
164
      {
165
        menu.append({{}, {ID_TREE_RUN_BUILD, "&Build"}});
×
166
      }
167

168
      menu.append(
×
169
        {{},
170
         {ID_TOOL_REPORT_FIND,
171
          ellipsed(frame->find_in_files_title(ID_TOOL_REPORT_FIND))},
×
172
         {ID_TOOL_REPLACE,
173
          ellipsed(frame->find_in_files_title(ID_TOOL_REPLACE))},
×
174
         {}});
175

176
      if (auto* item = menu.AppendCheckItem(idShowHidden, _("Show hidden"));
×
177
          config(_("Show hidden")).get(false))
×
178
      {
179
        item->Check();
×
180
      }
181

182
      PopupMenu(&menu);
×
183
    });
×
184

185
  Bind(
×
186
    wxEVT_TREE_SEL_CHANGED,
187
    [=, this](wxTreeEvent& event)
×
188
    {
189
      GET_VECTOR_FILES
×
190
      log::status() << files[0];
×
191
    });
×
192
}
×
193

194
void wex::del::dirctrl::expand_and_select_path(const wex::path& path)
×
195
{
196
  ExpandPath(path.string());
×
197
  SelectPath(path.string());
×
198
}
×
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