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