version 0.5.0_alpha
git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -2,21 +2,189 @@
|
||||
#include "shared.h"
|
||||
|
||||
|
||||
FileManager::FileManager() {
|
||||
setName("FileManager");
|
||||
offset = cur = height = 0;
|
||||
enabled = del_commit = false;
|
||||
CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
|
||||
FileManager::TileDir::TileDir(): TileList() {
|
||||
label_path = 0;
|
||||
selection_mode = TileList::MultiSelection;
|
||||
dir = PIDir::current();
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
dir.setDir("/home/peri4");
|
||||
updateDir();
|
||||
resized = false;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::keyEvent(char key) {
|
||||
if (!enabled) return;
|
||||
if (key == 'D') {
|
||||
bool FileManager::TileDir::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (key.key == PIKbdListener::Return) {
|
||||
if (cur < entries.size_s() && cur >= 0) {
|
||||
//piCout << entries[cur];
|
||||
if (entries[cur].isDir()) {
|
||||
prev_pos[dir.path()] = PIPair<int, int>(cur, offset);
|
||||
dir.cd(entries[cur].name());
|
||||
PIPair<int, int> cp = prev_pos.value(dir.path());
|
||||
cur = cp.first;
|
||||
offset = cp.second;
|
||||
selected.clear();
|
||||
updateDir();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return TileList::keyEvent(key);
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::lock() {
|
||||
if (screen && !resized) ((PIScreen*)screen)->lock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::unlock() {
|
||||
if (screen && !resized) ((PIScreen*)screen)->unlock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::updateDir() {
|
||||
//if (!enabled) return;
|
||||
entries.clear();
|
||||
lock();
|
||||
int pc = cur, po = offset;
|
||||
cur = -1;
|
||||
offset = 0;
|
||||
content.resize(1);
|
||||
content[0] = Row("... Reading ...", CellFormat());
|
||||
unlock();
|
||||
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
|
||||
if (el.isEmpty()) {
|
||||
PIFile::FileInfo fi;
|
||||
fi.path = "..";
|
||||
fi.flags |= PIFile::FileInfo::DotDot | PIFile::FileInfo::Dir;
|
||||
entries << fi;
|
||||
} else {
|
||||
for (int i = 0; i < el.size_s(); ++i) {
|
||||
if (el[i].name() == ".") continue;
|
||||
if (el[i].name() == "..") {
|
||||
dl.push_front(el[i]);
|
||||
continue;
|
||||
}
|
||||
if (el[i].isDir()) dl << el[i];
|
||||
else fl << el[i];
|
||||
}
|
||||
entries << dl << fl;
|
||||
}
|
||||
if (label_path) {
|
||||
label_path->content.resize(1);
|
||||
label_path->content[0].first = dir.absolutePath();
|
||||
}
|
||||
cur = pc;
|
||||
offset = po;
|
||||
buildNames();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::buildNames() {
|
||||
//if (!enabled) return;
|
||||
lock();
|
||||
content.clear();
|
||||
PIChar t;
|
||||
CharFlags cf = 0;
|
||||
Color cc = Default;
|
||||
PIString fcol, scol;
|
||||
piForeachC (PIFile::FileInfo & e, entries) {
|
||||
if (e.isDir()) {
|
||||
t = '/';
|
||||
cf = Bold;
|
||||
scol = " dir";
|
||||
} else {
|
||||
if (e.perm_user.exec || e.perm_group.exec || e.perm_other.exec) {
|
||||
cf = Bold;
|
||||
cc = Green;
|
||||
t = '*';
|
||||
} else {
|
||||
t = ' ';
|
||||
cf = 0;
|
||||
}
|
||||
scol = PIString::readableSize(e.size);
|
||||
}
|
||||
if (e.isSymbolicLink() && (t != '*')) t = '~';
|
||||
scol = scol.expandRightTo(9, ' ') + "| " + e.time_modification.toString("dd.MM hh:mm:ss") + " | "
|
||||
+ e.perm_user.toString() + " " + e.perm_group.toString() + " " + e.perm_other.toString();
|
||||
fcol = t + e.name();
|
||||
if (fcol.size_s() >= width - 2 - scol.size_s())
|
||||
fcol = fcol.left(width - 5 - scol.size_s()) + "...";
|
||||
fcol.expandRightTo(width - 1 - scol.size_s(), ' ');
|
||||
content << Row(fcol + scol, CellFormat(cc, Transparent, cf));
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::sizeHint(int & w, int & h) const {
|
||||
w = h = 4;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::resizeEvent(int w, int h) {
|
||||
resized = true;
|
||||
buildNames();
|
||||
resized = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FileManager::FileManager() {
|
||||
setName("FileManager");
|
||||
enabled = del_commit = false;
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
TileSimple * tl;
|
||||
|
||||
tile_root = new PIScreenTile();
|
||||
tile_root->direction = Vertical;
|
||||
PIScreenTile * pt = new PIScreenTile();
|
||||
pt->direction = Horizontal;
|
||||
pt->spacing = 1;
|
||||
pt->back_format.color_back = Cyan;
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
PIScreenTile * panel = new PIScreenTile();
|
||||
TileSimple * plabel = new TileSimple();
|
||||
plabel->size_policy = Fixed;
|
||||
plabel->maximumWidth = 1;
|
||||
panel->direction = Vertical;
|
||||
panels[i] = new TileDir();
|
||||
panels[i]->name = "file panel " + PIString(i);
|
||||
panels[i]->label_path = plabel;
|
||||
panel->addTile(plabel);
|
||||
panel->addTile(panels[i]);
|
||||
panels[i]->updateDir();
|
||||
pt->addTile(panel);
|
||||
}
|
||||
tile_root->addTile(pt);
|
||||
|
||||
PIScreenTile * labels = new PIScreenTile();
|
||||
labels->size_policy = Fixed;
|
||||
labels->direction = Horizontal;
|
||||
PIVector<SSPair> ll;
|
||||
ll << SSPair(" Esc", "Exit") << SSPair(" F5", "Copy") << SSPair(" F6", "Move") << SSPair(" F8", "Delete");
|
||||
piForeachC (SSPair & l, ll) {
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->content << TileSimple::Row(l.first, CellFormat(White, Transparent, Bold));
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->content << TileSimple::Row(l.second, CellFormat(Black, Cyan));
|
||||
}
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->size_policy = Expanding;
|
||||
tile_root->addTile(labels);
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile * FileManager::tile() const {
|
||||
return tile_root;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
/*if (!enabled) return;
|
||||
if (key.key == 'D') {
|
||||
if (cur >= files.size_s() || cur < 0) return;
|
||||
if (del_commit) {
|
||||
piForeachC (PIString & f, selected) {
|
||||
@@ -38,7 +206,7 @@ void FileManager::keyEvent(char key) {
|
||||
console.clearCustomStatus();
|
||||
del_commit = false;
|
||||
PIStringList nsel;
|
||||
switch (key) {
|
||||
switch (key.key) {
|
||||
case PIKbdListener::UpArrow:
|
||||
cur--;
|
||||
if (cur < 0) cur = 0;
|
||||
@@ -103,80 +271,20 @@ void FileManager::keyEvent(char key) {
|
||||
menuRequest();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void FileManager::updateConsole() {
|
||||
if (!enabled) return;
|
||||
/*if (!enabled) return;
|
||||
startTab(2);
|
||||
console.addString("File manager", 1, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addString("Path: " + dir.absolutePath(), 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
console.addString("Name", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
|
||||
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
|
||||
console.addString("File manager", 1, Yellow | Inverse);
|
||||
console.addString("Path: " + dir.absolutePath(), 1, Green | Inverse | Bold);
|
||||
console.addString("Name", 1, Green | Inverse | Bold);
|
||||
console.addString(" ", 2, Yellow | Inverse);
|
||||
console.addString(" ", 2, Green | Inverse);
|
||||
console.addString(" ", 2, Green | Inverse);
|
||||
buildNames();
|
||||
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
finishTab();
|
||||
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, Green | Inverse | Bold);
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void FileManager::buildNames() {
|
||||
if (!enabled) return;
|
||||
height = console.windowHeight() - 10;
|
||||
int is = piClampi(offset, 0, piMaxi(0, files.size_s() - 1)), ie = piClampi(offset + height, 0, files.size_s());
|
||||
console.addString((is > 0) ? (PIString(" /\\ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
|
||||
console.addString(" ", 2);
|
||||
PIChar t;
|
||||
PIConsole::FormatFlags f = 0;
|
||||
PIString scol;
|
||||
piCout << cur;
|
||||
for (int i = is; i < ie; ++i) {
|
||||
if (files[i].isDir()) {
|
||||
t = '/';
|
||||
f = PIConsole::Bold;
|
||||
scol = " dir";
|
||||
} else {
|
||||
if (files[i].perm_user.exec || files[i].perm_group.exec || files[i].perm_other.exec) {
|
||||
f = PIConsole::Green | PIConsole::Bold;
|
||||
t = '*';
|
||||
} else {
|
||||
t = ' ';
|
||||
f = 0;
|
||||
}
|
||||
scol = PIString::readableSize(files[i].size);
|
||||
}
|
||||
if (files[i].isSymbolicLink() && (t != '*')) t = '~';
|
||||
scol = scol.expandRightTo(9, ' ') + "| " + files[i].time_modification.toString("dd.MM hh:mm:ss") + " | "
|
||||
+ files[i].perm_user.toString() + " " + files[i].perm_group.toString() + " " + files[i].perm_other.toString();
|
||||
if (i == cur) f |= PIConsole::BackBlue;
|
||||
if (selected.contains(files[i].path)) f |= PIConsole::Yellow | PIConsole::Bold;
|
||||
console.addString(t + files[i].name(), 1, f);
|
||||
console.addString(scol, 2, f);
|
||||
}
|
||||
console.addString((ie < files.size_s()) ? (PIString(" \\/ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
|
||||
console.addString(" ", 2);
|
||||
}
|
||||
|
||||
|
||||
void FileManager::updateDir() {
|
||||
if (!enabled) return;
|
||||
files.clear();
|
||||
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
|
||||
for (int i = 0; i < el.size_s(); ++i) {
|
||||
if (el[i].path == ".") continue;
|
||||
if (el[i].path == "..") {
|
||||
dl.push_front(el[i]);
|
||||
continue;
|
||||
}
|
||||
if (el[i].isDir()) dl << el[i];
|
||||
else fl << el[i];
|
||||
}
|
||||
files << dl << fl;
|
||||
if (cur >= files.size_s()) cur = files.size_s() - 1;
|
||||
if (offset >= files.size_s() - height) offset = files.size_s() - height;
|
||||
if (cur < 0) cur = 0;
|
||||
if (offset < 0) offset = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user