reference: DropTree example

git-svn-id: svn://ultimatepp.org/upp/trunk@1602 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-10-02 12:51:36 +00:00
parent cedbea2d15
commit 89e2137cb2
3 changed files with 103 additions and 8 deletions

View file

@ -0,0 +1,9 @@
uses
CtrlLib;
file
main.cpp;
mainconfig
"" = "GUI";

View file

@ -0,0 +1,21 @@
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
GUI_APP_MAIN
{
TopWindow win;
DropTree dt;
dt->SetRoot(CtrlImg::Home(), "Home");
for(int i = 0; i < 10; i++) {
int id = dt->Add(0, CtrlImg::Computer(), "Computer " + AsString(i + 1));
for(int j = 0; j < i; j++)
dt->Add(id, CtrlImg::File(), "File " + AsString(j + 1));
}
dt.AutoResize();
win.Add(dt.HSizePos().TopPos(0, Ctrl::STDSIZE));
win.Run();
}

View file

@ -3,20 +3,85 @@
using namespace Upp;
struct App : TopWindow {
TreeCtrl tree;
Splitter horz;
TreeCtrl tree1;
TreeCtrl tree2;
OptionTree optree;
Option x[10];
StatusBar info;
Array<EditString> edit;
typedef App CLASSNAME;
virtual bool Key(dword key, int count) {
if(key == K_DELETE)
tree.Clear();
return false;
void OpenDir(int id) {
String path = tree1[id];
for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next()) {
String n = ff.GetName();
if(n != "." && n != "..")
tree1.Add(id, ff.IsFolder() ? CtrlImg::error() : CtrlImg::File(),
AppendFileName(path, n), n, ff.IsFolder());
}
}
void CloseDir(int id) {
tree1.RemoveChildren(id);
}
void LoadTree(int parent, const String& path, Progress& pi)
{
pi.SetText(DeFormat(path));
for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next()) {
if(pi.StepCanceled())
return;
String n = ff.GetName();
if(n != "." && n != "..") {
edit.Add();
edit.Top() <<= n;
int q;
static int x;
if(++x & 1)
q = tree2.Add(parent, ff.IsFolder() ? CtrlImg::Dir() : CtrlImg::File(),
edit.Top(), 150);
else
q = tree2.Add(parent, ff.IsFolder() ? CtrlImg::Dir() : CtrlImg::File(), n);
if(ff.IsFolder())
LoadTree(q, AppendFileName(path, n), pi);
}
}
}
void ShowPath() {
info = ~tree1;
}
App() {
Add(tree.SizePos());
tree.Add(0, CtrlImg::cut(), edit.Add());
horz.Add(tree1);
horz.Add(tree2);
horz.Add(optree);
Add(horz.Horz().SizePos());
optree.SetRoot("everything");
for(int i = 0; i < 10; i++)
optree.Add(i ? rand() % i : 0, x[i], AsString(i));
// tree1.MultiSelect();
tree1.WhenOpen = THISBACK(OpenDir);
tree1.WhenClose = THISBACK(CloseDir);
#ifdef PLATFORM_WIN32
String dir = String(GetExeFilePath()[0], 1) + ":\\";
#else
String dir = "/usr";
#endif
tree1.SetRoot(CtrlImg::Dir(), dir);
tree2.SetRoot(CtrlImg::Dir(), dir);
Progress pi;
pi.AlignText(ALIGN_LEFT);
LoadTree(0, dir, pi);
tree2.NoCursor().NoRoot();
tree2.SortDeep(0);
Sizeable();
tree1.WhenCursor = THISBACK(ShowPath);
tree1.AddFrame(info);
}
};