1/*
2 * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "FileWindow.h"
8#include "OpenWindow.h"
9#include "DiskProbe.h"
10#include "ProbeView.h"
11
12#include <Application.h>
13#include <Catalog.h>
14#include <Directory.h>
15#include <GroupLayout.h>
16#include <Locale.h>
17#include <MenuBar.h>
18#include <MenuItem.h>
19#include <Path.h>
20#include <Volume.h>
21#include <be_apps/Tracker/RecentItems.h>
22
23
24#undef B_TRANSLATION_CONTEXT
25#define B_TRANSLATION_CONTEXT "FileWindow"
26
27
28FileWindow::FileWindow(BRect rect, entry_ref *ref, const BMessage *settings)
29	: ProbeWindow(rect, ref)
30{
31	SetLayout(new BGroupLayout(B_VERTICAL, 0));
32	// Set alternative window title for devices
33
34	BEntry entry(ref);
35	struct stat stat;
36	if (entry.GetStat(&stat) == B_OK && (S_ISBLK(stat.st_mode)
37		|| S_ISCHR(stat.st_mode))) {
38		BPath path(ref);
39		SetTitle(path.Path());
40	} else if (entry.IsDirectory()) {
41		BDirectory directory(&entry);
42		if (directory.InitCheck() == B_OK && directory.IsRootDirectory()) {
43			// use the volume name for root directories
44			BVolume volume(stat.st_dev);
45			if (volume.InitCheck() == B_OK) {
46				char name[B_FILE_NAME_LENGTH];
47				if (volume.GetName(name) == B_OK)
48					SetTitle(name);
49			}
50		}
51	}
52
53	// add the menu
54
55	BMenuBar *menuBar = new BMenuBar("menu bar");
56	AddChild(menuBar);
57
58	BMenu *menu = new BMenu(B_TRANSLATE("File"));
59	menu->AddItem(new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS),
60		new BMessage(kMsgOpenOpenWindow), 'N', B_COMMAND_KEY));
61
62	BMenu *devicesMenu = new BMenu(B_TRANSLATE("Open device"));
63	OpenWindow::CollectDevices(devicesMenu);
64	devicesMenu->SetTargetForItems(be_app);
65	menu->AddItem(new BMenuItem(devicesMenu));
66
67	BMenu *recentsMenu = BRecentFilesList::NewFileListMenu(
68		B_TRANSLATE("Open file" B_UTF8_ELLIPSIS),
69		NULL, NULL, be_app, 10, false, NULL, kSignature);
70	BMenuItem *item;
71	menu->AddItem(item = new BMenuItem(recentsMenu,
72		new BMessage(kMsgOpenFilePanel)));
73	item->SetShortcut('O', B_COMMAND_KEY);
74	menu->AddSeparatorItem();
75
76	// the ProbeView save menu items will be inserted here
77	item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_CLOSE_REQUESTED),
78		'W', B_COMMAND_KEY);
79	menu->AddItem(item);
80	menu->AddSeparatorItem();
81
82	// the ProbeView print menu items will be inserted here
83
84	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
85		new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY));
86	menu->SetTargetForItems(be_app);
87	item->SetTarget(this);
88	menuBar->AddItem(menu);
89
90	// add our interface widgets
91
92	fProbeView = new ProbeView(ref, NULL, settings);
93	AddChild(fProbeView);
94
95	fProbeView->AddSaveMenuItems(menu, 4);
96	fProbeView->AddPrintMenuItems(menu, menu->CountItems() - 4);
97	fProbeView->AddViewAsMenuItems();
98}
99
100
101bool
102FileWindow::QuitRequested()
103{
104	bool quit = fProbeView->QuitRequested();
105	if (!quit)
106		return false;
107
108	return ProbeWindow::QuitRequested();
109}
110
111
112bool
113FileWindow::Contains(const entry_ref &ref, const char *attribute)
114{
115	if (attribute != NULL)
116		return false;
117
118	return ref == Ref();
119}
120
121