MCDE dtfile: the sidebar in groups -- devices, shares, places, searches (t0108)
The sidebar was one flat list of seven places; it is the reference's column
of groups now, each with a head that folds: DEVICES (the mounted drives and
partitions from mcde_sys_disks, the system's own left out, a removable one
marked), SHARED (the computers mcde_sys_net_browse finds, asked for once
200 ms after the window is up so that the browse does not hold the window),
PLACES (the seven places as before) and SEARCH FOR (the reference's saved
searches, insensitive until dtfile's search exists, t0119).
A place goes there, a shared computer opens the network view, a device would
open its mount point. The head folds its entries with the arrow in the
label, as the pane sections do.
Measured under Xvfb: the sidebar shows the four groups
(docs/screenshots/leopard/finder-home-mcde.png, dtfile in $HOME with the
icon view); "No device mounted" here because the host's only disk holds /;
SHARED lists the computers mDNS answered with (N95, KITT, Caroline's
MacBook Air) and a click on one opens the network view ("3 computers
found."); a click on Home goes to ~.
Open: the SEARCH FOR entries do nothing yet (t0119), no eject button beside
a removable device and no drag and drop of a folder into PLACES, the folded
state is not remembered, and the devices are read once when the window is
made (t0162 is the event for a stick that comes later).
This commit is contained in:
1 parent
cbf1edf406
commit
a65cedd58c
1 file changed
+214
-29
+214
-29
@@ -34,6 +34,8 @@
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/List.h>
|
||||
#include <Xm/Frame.h>
|
||||
#include <Xm/PushBG.h>
|
||||
#include <Xm/ScrolledW.h>
|
||||
#include <Xm/Separator.h>
|
||||
|
||||
#include <Dt/Connect.h>
|
||||
@@ -45,6 +47,8 @@
|
||||
#include "Desktop.h"
|
||||
#include "Main.h"
|
||||
#include "Prefs.h"
|
||||
#include <Mcde/McdeSys.h>
|
||||
|
||||
#include "Navigation.h"
|
||||
|
||||
#define SIDEBAR_WIDTH 150
|
||||
@@ -406,11 +410,218 @@ Button(Widget parent, const char *name, const char *label,
|
||||
return b;
|
||||
}
|
||||
|
||||
/* ---- the sidebar: groups of places, devices, shares and searches -------- */
|
||||
|
||||
typedef struct {
|
||||
FileMgrRec *rec;
|
||||
int place; /* >= 0: places[]; -1: path; -2: network */
|
||||
char *path;
|
||||
} SideEntry;
|
||||
|
||||
typedef struct {
|
||||
FileMgrRec *rec;
|
||||
Widget col;
|
||||
Widget placeholder;
|
||||
} SharedFill;
|
||||
|
||||
static void
|
||||
SideGroupToggled(Widget w, XtPointer client, XtPointer call)
|
||||
{
|
||||
XmToggleButtonCallbackStruct *c = (XmToggleButtonCallbackStruct *) call;
|
||||
Widget col = (Widget) client;
|
||||
XmString ls = NULL;
|
||||
char *text = NULL;
|
||||
|
||||
XtVaGetValues(w, XmNlabelString, &ls, NULL);
|
||||
if (ls == NULL || !XmStringGetLtoR(ls, XmFONTLIST_DEFAULT_TAG, &text))
|
||||
return;
|
||||
text[0] = c->set ? 'v' : '>';
|
||||
{
|
||||
XmString s = XmStringCreateLocalized(text);
|
||||
|
||||
XtVaSetValues(w, XmNlabelString, s, NULL);
|
||||
XmStringFree(s);
|
||||
}
|
||||
XtFree(text);
|
||||
if (c->set)
|
||||
XtManageChild(col);
|
||||
else
|
||||
XtUnmanageChild(col);
|
||||
}
|
||||
|
||||
/* a group of the sidebar: the folding head, and the column of its entries */
|
||||
static Widget
|
||||
SideGroup(Widget parent, const char *title)
|
||||
{
|
||||
Widget head, col;
|
||||
XmString s;
|
||||
char label[64];
|
||||
|
||||
(void)snprintf(label, sizeof label, "v %s", title);
|
||||
s = XmStringCreateLocalized(label);
|
||||
head = XtVaCreateManagedWidget("sideGroup", xmToggleButtonWidgetClass,
|
||||
parent, XmNlabelString, s, XmNindicatorOn, False, XmNset, True,
|
||||
XmNalignment, XmALIGNMENT_BEGINNING, XmNmarginTop, 8,
|
||||
XmNmarginBottom, 2, NULL);
|
||||
XmStringFree(s);
|
||||
col = XtVaCreateManagedWidget("sideEntries", xmRowColumnWidgetClass,
|
||||
parent, XmNspacing, 1, XmNmarginWidth, 10, XmNmarginHeight, 0,
|
||||
NULL);
|
||||
XtAddCallback(head, XmNvalueChangedCallback, SideGroupToggled, col);
|
||||
return col;
|
||||
}
|
||||
|
||||
static Widget
|
||||
SideItem(Widget col, const char *label, XtCallbackProc cb, SideEntry *data,
|
||||
Boolean sensitive)
|
||||
{
|
||||
XmString s = XmStringCreateLocalized((char *) label);
|
||||
Widget b = XtVaCreateManagedWidget("sideItem", xmPushButtonGadgetClass,
|
||||
col, XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING,
|
||||
XmNmarginHeight, 1, XmNtraversalOn, False, NULL);
|
||||
|
||||
XmStringFree(s);
|
||||
if (cb != NULL)
|
||||
XtAddCallback(b, XmNactivateCallback, cb, data);
|
||||
if (!sensitive)
|
||||
XtSetSensitive(b, False);
|
||||
return b;
|
||||
}
|
||||
|
||||
static void
|
||||
SideEntryCB(Widget w, XtPointer client, XtPointer call)
|
||||
{
|
||||
SideEntry *e = client;
|
||||
|
||||
(void) w;
|
||||
(void) call;
|
||||
if (e == NULL || e->rec == NULL)
|
||||
return;
|
||||
if (e->place >= 0)
|
||||
PlaceTo(e->rec, e->place);
|
||||
else if (e->place == -1 && e->path != NULL) {
|
||||
_McdeNetShow(e->rec, False);
|
||||
GoTo(e->rec, e->path, False);
|
||||
} else if (e->place == -2)
|
||||
_McdeNetShow(e->rec, True);
|
||||
}
|
||||
|
||||
static SideEntry *
|
||||
SideData(FileMgrRec *rec, int place, const char *path)
|
||||
{
|
||||
SideEntry *e = XtNew(SideEntry);
|
||||
|
||||
e->rec = rec;
|
||||
e->place = place;
|
||||
e->path = path != NULL ? XtNewString(path) : NULL;
|
||||
return e;
|
||||
}
|
||||
|
||||
/* the drives and partitions that are mounted, the system's own left out */
|
||||
static void
|
||||
FillDevices(FileMgrRec *rec, Widget col)
|
||||
{
|
||||
McdeSysDisk disks[32];
|
||||
int n = mcde_sys_disks(disks, 32), i, shown = 0;
|
||||
|
||||
for (i = 0; i < n && shown < 8; i++) {
|
||||
char label[200];
|
||||
|
||||
if (disks[i].mountpoint[0] == '\0' || disks[i].system)
|
||||
continue;
|
||||
(void)snprintf(label, sizeof label, "%s%s",
|
||||
disks[i].label[0] != '\0' ? disks[i].label : disks[i].name,
|
||||
disks[i].removable ? " (removable)" : "");
|
||||
SideItem(col, label, SideEntryCB, SideData(rec, -1,
|
||||
disks[i].mountpoint), True);
|
||||
shown++;
|
||||
}
|
||||
if (shown == 0)
|
||||
(void) SideItem(col, "No device mounted", NULL, NULL, False);
|
||||
}
|
||||
|
||||
/* the computers found on the local network, once, after the window is up */
|
||||
static void
|
||||
FillSharedLater(XtPointer client, XtIntervalId *id)
|
||||
{
|
||||
SharedFill *sf = client;
|
||||
McdeSysNetHost hosts[16];
|
||||
int n, i, shown = 0;
|
||||
|
||||
(void) id;
|
||||
if (sf == NULL)
|
||||
return;
|
||||
n = mcde_sys_net_browse(hosts, 16, 1500);
|
||||
if (sf->placeholder != NULL && XtIsManaged(sf->placeholder)) {
|
||||
XtUnmanageChild(sf->placeholder);
|
||||
XtDestroyWidget(sf->placeholder);
|
||||
}
|
||||
for (i = 0; i < n && shown < 8; i++) {
|
||||
SideItem(sf->col, hosts[i].name[0] != '\0' ? hosts[i].name :
|
||||
hosts[i].host, SideEntryCB, SideData(sf->rec, -2, NULL),
|
||||
True);
|
||||
shown++;
|
||||
}
|
||||
if (shown == 0)
|
||||
(void) SideItem(sf->col, "No computer found", NULL, NULL, False);
|
||||
XtFree((char *) sf);
|
||||
}
|
||||
|
||||
static void
|
||||
MakeSidebar(FileMgrRec *rec, Widget form, Widget bar)
|
||||
{
|
||||
Arg args[8];
|
||||
int n = 0, i;
|
||||
Widget frame, sw, col, group;
|
||||
SharedFill *sf;
|
||||
static const char *const searches[] = { "Today", "Yesterday",
|
||||
"Past Week", "All Images", "All Movies", "All Documents" };
|
||||
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(args[n], XmNtopWidget, bar); n++;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNshadowType, XmSHADOW_IN); n++;
|
||||
XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH + 4); n++;
|
||||
frame = XmCreateFrame(form, "mcdeSidebarFrame", args, n);
|
||||
sw = XtVaCreateManagedWidget("mcdeSidebarScroll",
|
||||
xmScrolledWindowWidgetClass, frame,
|
||||
XmNscrollingPolicy, XmAUTOMATIC,
|
||||
XmNwidth, SIDEBAR_WIDTH, NULL);
|
||||
col = XtVaCreateManagedWidget("mcdeSidebar", xmRowColumnWidgetClass, sw,
|
||||
XmNorientation, XmVERTICAL, XmNpacking, XmPACK_TIGHT, NULL);
|
||||
rec->mcde_sidebar = col;
|
||||
|
||||
group = SideGroup(col, "DEVICES");
|
||||
FillDevices(rec, group);
|
||||
|
||||
group = SideGroup(col, "SHARED");
|
||||
sf = XtNew(SharedFill);
|
||||
sf->rec = rec;
|
||||
sf->col = group;
|
||||
sf->placeholder = SideItem(group, "Looking for computers...", NULL,
|
||||
NULL, False);
|
||||
XtAppAddTimeOut(XtWidgetToApplicationContext(frame), 200, FillSharedLater,
|
||||
sf);
|
||||
|
||||
group = SideGroup(col, "PLACES");
|
||||
for (i = 0; i < (int) NPLACES; i++)
|
||||
(void) SideItem(group, places[i].label, SideEntryCB,
|
||||
SideData(rec, i, NULL), True);
|
||||
|
||||
/* the reference's saved searches wait for dtfile's search (t0119) */
|
||||
group = SideGroup(col, "SEARCH FOR");
|
||||
for (i = 0; i < (int) (sizeof searches / sizeof searches[0]); i++)
|
||||
(void) SideItem(group, searches[i], NULL, NULL, False);
|
||||
|
||||
XtManageChild(frame);
|
||||
rec->mcde_sidebar_frame = frame;
|
||||
}
|
||||
|
||||
Widget
|
||||
_McdeNavCreate(FileMgrRec *rec, Widget parent)
|
||||
{
|
||||
Widget form, bar, views_rc, frame;
|
||||
XmString items[NPLACES];
|
||||
Arg args[12];
|
||||
size_t k;
|
||||
int i, n;
|
||||
@@ -486,34 +697,8 @@ _McdeNavCreate(FileMgrRec *rec, Widget parent)
|
||||
}
|
||||
UpdateButtons(rec);
|
||||
|
||||
/* the sidebar: the places */
|
||||
for (k = 0; k < NPLACES; k++)
|
||||
items[k] = XmStringCreateLocalized((char *)places[k].label);
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
||||
XtSetArg(args[n], XmNtopWidget, bar); n++;
|
||||
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
|
||||
XtSetArg(args[n], XmNshadowType, XmSHADOW_IN); n++;
|
||||
XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH + 4); n++;
|
||||
frame = XmCreateFrame(form, "mcdeSidebarFrame", args, n);
|
||||
n = 0;
|
||||
XtSetArg(args[n], XmNitems, items); n++;
|
||||
XtSetArg(args[n], XmNitemCount, (int)NPLACES); n++;
|
||||
XtSetArg(args[n], XmNvisibleItemCount, (int)NPLACES); n++;
|
||||
XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
|
||||
XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH); n++;
|
||||
XtSetArg(args[n], XmNlistMarginWidth, 6); n++;
|
||||
XtSetArg(args[n], XmNlistMarginHeight, 6); n++;
|
||||
XtSetArg(args[n], XmNshadowThickness, 0); n++;
|
||||
rec->mcde_sidebar = XmCreateList(frame, "mcdeSidebar", args, n);
|
||||
for (k = 0; k < NPLACES; k++)
|
||||
XmStringFree(items[k]);
|
||||
XtAddCallback(rec->mcde_sidebar, XmNbrowseSelectionCallback, PlaceCB,
|
||||
rec);
|
||||
XtManageChild(rec->mcde_sidebar);
|
||||
XtManageChild(frame);
|
||||
rec->mcde_sidebar_frame = frame;
|
||||
/* the sidebar: devices, shares, places and searches (Navigation.c) */
|
||||
MakeSidebar(rec, form, bar);
|
||||
|
||||
XtManageChild(form);
|
||||
SyncViews(rec);
|
||||
|
||||
Reference in new issue
Block a user