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