Skip to content

Commit 243e30e

Browse files
committed
implement form_collection and use it
1 parent 7f076bc commit 243e30e

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/xtd.forms/include/xtd/forms/form_collection.hpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55
#include "form.hpp"
66
#include <xtd/ref>
7-
#include <vector>
7+
#include <xtd/collections/generic/list>
88

99
/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
1010
namespace xtd {
@@ -21,6 +21,53 @@ namespace xtd {
2121
/// xtd.forms
2222
/// @ingroup xtd_forms
2323
/// @remarks form_collection is used by the application object to list the currently open forms in an application through the open_forms property.
24-
using form_collection = std::vector<xtd::ref<form>>;
24+
class form_collection : public xtd::collections::generic::list<xtd::ref<form>> {
25+
public:
26+
/// @name Public Aliases
27+
28+
/// @{
29+
/// @brief Represents the base type of the collection.
30+
using base_type = xtd::collections::generic::list<xtd::ref<form>>;
31+
/// @}
32+
33+
/// @name Public Constructors
34+
35+
/// @{
36+
/// @brief Creates a new object xtd::forms::form_collection with specified allocator (optional).
37+
/// @remarks If allocator not specified, the std::allocator<value_type> is used.
38+
explicit form_collection() = default;
39+
/// @}
40+
41+
/// @cond
42+
form_collection(form_collection&&) = default;
43+
form_collection(const form_collection& collection) = default;
44+
auto operator =(form_collection&& collection) -> form_collection& = default;
45+
auto operator =(const form_collection& collection) -> form_collection& = default;
46+
/// @endcond
47+
48+
/// @name Operators
49+
50+
/// @{
51+
using base_type::operator [];
52+
/// @brief Gets the first xtd::forms::form_collection in the list with the specified name.
53+
/// @param name The name of the xtd::forms::control to get from the list.
54+
/// @return The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
55+
/// @remarks The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.
56+
auto operator [](const xtd::string& name) const -> value_type {
57+
for (auto item : self_)
58+
if (item.get().name() == name) return item;
59+
return {};
60+
}
61+
/// @brief Gets the first xtd::forms::form_collection in the list with the specified name.
62+
/// @param name The name of the xtd::forms::control to get from the list.
63+
/// @return The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
64+
/// @remarks The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.
65+
auto operator [](const xtd::string& name) -> value_type {
66+
for (auto item : self_)
67+
if (item.get().name() == name) return item;
68+
return {};
69+
}
70+
/// @}
71+
};
2572
}
2673
}

src/xtd.forms/src/xtd/forms/application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ const form_collection application::open_forms() noexcept {
241241
auto forms = form_collection {};
242242
if (keep_cloned_controls()) {
243243
for (auto control : top_level_forms_)
244-
forms.push_back(dynamic_cast<form&>(*control));
244+
forms.add(dynamic_cast<form&>(*control));
245245
return forms;
246246
}
247247

248248
for (auto control : control::top_level_controls_)
249-
forms.push_back(dynamic_cast<form&>(control.get()));
249+
forms.add(dynamic_cast<form&>(control.get()));
250250
return forms;
251251

252252
/*

0 commit comments

Comments
 (0)