1 /* 2 * Copyright 2004, 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, 0, 0), NULL); 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, new BMessage(B_ABOUT_REQUESTED))); 74 menu->AddSeparatorItem(); 75 76 menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); 77 menu->SetTargetForItems(be_app); 78 item->SetTarget(this); 79 menuBar->AddItem(menu); 80 81 // add our interface widgets 82 83 BRect _rect = Bounds(); 84 _rect.top = menuBar->Bounds().Height() + 1; 85 fProbeView = new ProbeView(_rect, ref, NULL, settings); 86 AddChild(fProbeView); 87 88 fProbeView->AddSaveMenuItems(menu, 4); 89 fProbeView->AddPrintMenuItems(menu, menu->CountItems() - 4); 90 91 fProbeView->UpdateSizeLimits(); 92 } 93 94 95 bool 96 FileWindow::QuitRequested() 97 { 98 bool quit = fProbeView->QuitRequested(); 99 if (!quit) 100 return false; 101 102 return ProbeWindow::QuitRequested(); 103 } 104 105 106 bool 107 FileWindow::Contains(const entry_ref &ref, const char *attribute) 108 { 109 if (attribute != NULL) 110 return false; 111 112 return ref == Ref(); 113 } 114 115