-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHistory.cpp
More file actions
104 lines (86 loc) · 2.05 KB
/
History.cpp
File metadata and controls
104 lines (86 loc) · 2.05 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
#include "History.hpp"
#include "App.hpp"
#include "io/Files.hpp"
#include "gui/Tab.hpp"
#include "gui/Table.hpp"
#include "gui/ToolBar.hpp"
namespace cornus {
/// #define CORNUS_DEBUG_HISTORY
History::History(App *app): app_(app) {}
History::~History() {}
void History::Add(const Action action, const QString &s)
{
if (action == Action::Back || action == Action::Forward || action == Action::Reload)
return;
int last = vec_.size() - 1;
if (last >= 0 && last < vec_.size()) {
HistoryItem item = vec_[last];
if (item.dir_path == s) {
index_ = vec_.size() - 1;
#ifdef CORNUS_DEBUG_HISTORY
auto ba = s.toLocal8Bit();
mtl_trace("Not adding %s to index: %d", ba.data(), index_);
#endif
app_->toolbar()->UpdateIcons(this);
return;
}
}
HistoryItem item;
item.dir_path = s;
vec_.append(item);
index_ = vec_.size() - 1;
#ifdef CORNUS_DEBUG_HISTORY
auto ba = s.toLocal8Bit();
mtl_info("added: %s to index: %d", ba.data(), index_);
#endif
if (index_ > 10)
vec_.remove(0, 10);
app_->toolbar()->UpdateIcons(this);
}
QString History::Back()
{
if (index_ > 0)
index_--;
if (index_ < 0 || index_ >= vec_.size()) {
#ifdef CORNUS_DEBUG_HISTORY
mtl_trace("index_: %d, size: %d", index_, vec_.size());
#endif
return QString();
}
app_->toolbar()->UpdateIcons(this);
HistoryItem &item = vec_[index_];
return item.dir_path;
}
QString History::Forward()
{
if (index_ < (vec_.size() - 1))
index_++;
if (index_ >= vec_.size()) {
#ifdef CORNUS_DEBUG_HISTORY
mtl_trace("index_: %d, size: %d", index_, vec_.size());
#endif
return QString();
}
app_->toolbar()->UpdateIcons(this);
HistoryItem &item = vec_[index_];
return item.dir_path;
}
void History::GetSelectedFiles(QVector<QString> &list)
{
if (index_ < 0 || index_ >= vec_.size()) {
return;
}
HistoryItem &item = vec_[index_];
list = item.selected_filenames;
}
void History::Record()
{
int last = index_;
if (last >= 0 && last < vec_.size())
{
app_->tab()->view_files().GetSelectedFileNames(Lock::Yes,
vec_[last].selected_filenames,
Path::OnlyName, StringCase::Lower);
}
}
}