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