BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / diskprobe / FileWindow.cpp
blobd05473ffd9d353b3d1189e3404d7fa5d70ea93af
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 */
7 #include "FileWindow.h"
8 #include "OpenWindow.h"
9 #include "DiskProbe.h"
10 #include "ProbeView.h"
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>
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "FileWindow"
28 FileWindow::FileWindow(BRect rect, entry_ref *ref, const BMessage *settings)
29 : ProbeWindow(rect, ref)
31 SetLayout(new BGroupLayout(B_VERTICAL, 0));
32 // Set alternative window title for devices
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);
53 // add the menu
55 BMenuBar *menuBar = new BMenuBar("menu bar");
56 AddChild(menuBar);
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));
62 BMenu *devicesMenu = new BMenu(B_TRANSLATE("Open device"));
63 OpenWindow::CollectDevices(devicesMenu);
64 devicesMenu->SetTargetForItems(be_app);
65 menu->AddItem(new BMenuItem(devicesMenu));
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();
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();
82 // the ProbeView print menu items will be inserted here
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);
90 // add our interface widgets
92 fProbeView = new ProbeView(ref, NULL, settings);
93 AddChild(fProbeView);
95 fProbeView->AddSaveMenuItems(menu, 4);
96 fProbeView->AddPrintMenuItems(menu, menu->CountItems() - 4);
97 fProbeView->AddViewAsMenuItems();
101 bool
102 FileWindow::QuitRequested()
104 bool quit = fProbeView->QuitRequested();
105 if (!quit)
106 return false;
108 return ProbeWindow::QuitRequested();
112 bool
113 FileWindow::Contains(const entry_ref &ref, const char *attribute)
115 if (attribute != NULL)
116 return false;
118 return ref == Ref();