This repository was archived by the owner on Jul 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMetalinkEditor.cpp
More file actions
125 lines (105 loc) · 2.29 KB
/
MetalinkEditor.cpp
File metadata and controls
125 lines (105 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "MetalinkEditor.hpp"
MetalinkEditor::MetalinkEditor()
{
selection_ = 0;
}
bool MetalinkEditor::is_empty() const
{
return metalink_.is_empty();
}
int MetalinkEditor::num_files() const
{
return metalink_.num_files();
}
const wxString& MetalinkEditor::get_filename(int file) const
{
return metalink_.get_file(file).get_filename();
}
void MetalinkEditor::add_file(const wxString& filename)
{
add_file(MetalinkFile(filename));
}
void MetalinkEditor::add_file(const MetalinkFile& file)
{
metalink_.add_file(file);
selection_ = metalink_.num_files() - 1;
update();
}
void MetalinkEditor::add_listener(MetalinkEditorListener* listener)
{
listeners_.push_back(listener);
}
void MetalinkEditor::select(int file)
{
if(file < 0 || file >= metalink_.num_files()) return;
selection_ = file;
update();
}
int MetalinkEditor::get_selection() const
{
return selection_;
}
void MetalinkEditor::remove_file()
{
// Remove the file
metalink_.remove_file(selection_);
// Update
update();
}
const MetalinkFile& MetalinkEditor::get_file() const
{
return metalink_.get_file(selection_);
}
const std::vector<MetalinkFile>& MetalinkEditor::get_files() const
{
return metalink_.get_files();
}
void MetalinkEditor::set_file(const MetalinkFile& file)
{
metalink_.set_file(selection_, file);
update();
}
const wxString& MetalinkEditor::get_filename() const
{
return filename_;
}
const Metalink& MetalinkEditor::get_metalink() const
{
return metalink_;
}
void MetalinkEditor::set_filename(const wxString& filename)
{
filename_ = filename;
}
void MetalinkEditor::update()
{
// Fix selection, if needed.
if(metalink_.is_empty()) {
selection_ = 0;
} else if(selection_ >= metalink_.num_files()) {
selection_ = metalink_.num_files() - 1;
}
// Notify listeners
for(int i = 0; i < listeners_.size(); i++) {
listeners_.at(i)->update();
}
}
void MetalinkEditor::save()
{
if(filename_.empty()) return;
metalink_.save(filename_);
}
void MetalinkEditor::open(const wxString& filename)
{
metalink_ = Metalink::load(filename);
filename_ = filename;
selection_ = 0;
update();
}
void MetalinkEditor::clear()
{
metalink_.clear();
filename_.clear();
selection_ = 0;
update();
}