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) 35 || S_ISCHR(stat.st_mode))) { 36 BPath path(ref); 37 SetTitle(path.Path()); 38 } else if (entry.IsDirectory()) { 39 BDirectory directory(&entry); 40 if (directory.InitCheck() == B_OK && directory.IsRootDirectory()) { 41 // use the volume name for root directories 42 BVolume volume(stat.st_dev); 43 if (volume.InitCheck() == B_OK) { 44 char name[B_FILE_NAME_LENGTH]; 45 if (volume.GetName(name) == B_OK) 46 SetTitle(name); 47 } 48 } 49 } 50 51 // add the menu 52 53 BMenuBar *menuBar = new BMenuBar(BRect(0, 0, Bounds().Width(), 8), 54 "menu bar"); 55 AddChild(menuBar); 56 57 BMenu *menu = new BMenu(B_TRANSLATE("File")); 58 menu->AddItem(new BMenuItem(B_TRANSLATE("New" B_UTF8_ELLIPSIS), 59 new BMessage(kMsgOpenOpenWindow), 'N', B_COMMAND_KEY)); 60 61 BMenu *devicesMenu = new BMenu(B_TRANSLATE("Open device")); 62 OpenWindow::CollectDevices(devicesMenu); 63 devicesMenu->SetTargetForItems(be_app); 64 menu->AddItem(new BMenuItem(devicesMenu)); 65 66 BMenu *recentsMenu = BRecentFilesList::NewFileListMenu( 67 B_TRANSLATE("Open file" B_UTF8_ELLIPSIS), 68 NULL, NULL, be_app, 10, false, NULL, kSignature); 69 BMenuItem *item; 70 menu->AddItem(item = new BMenuItem(recentsMenu, 71 new BMessage(kMsgOpenFilePanel))); 72 item->SetShortcut('O', B_COMMAND_KEY); 73 menu->AddSeparatorItem(); 74 75 // the ProbeView save menu items will be inserted here 76 item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_CLOSE_REQUESTED), 77 'W', B_COMMAND_KEY); 78 menu->AddItem(item); 79 menu->AddSeparatorItem(); 80 81 // the ProbeView print menu items will be inserted here 82 83 menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), 84 new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); 85 menu->SetTargetForItems(be_app); 86 item->SetTarget(this); 87 menuBar->AddItem(menu); 88 89 // add our interface widgets 90 91 rect = Bounds(); 92 rect.top = menuBar->Bounds().Height() + 1; 93 fProbeView = new ProbeView(rect, ref, NULL, settings); 94 AddChild(fProbeView); 95 96 fProbeView->AddSaveMenuItems(menu, 4); 97 fProbeView->AddPrintMenuItems(menu, menu->CountItems() - 4); 98 fProbeView->AddViewAsMenuItems(); 99 100 fProbeView->UpdateSizeLimits(); 101 } 102 103 104 bool 105 FileWindow::QuitRequested() 106 { 107 bool quit = fProbeView->QuitRequested(); 108 if (!quit) 109 return false; 110 111 return ProbeWindow::QuitRequested(); 112 } 113 114 115 bool 116 FileWindow::Contains(const entry_ref &ref, const char *attribute) 117 { 118 if (attribute != NULL) 119 return false; 120 121 return ref == Ref(); 122 } 123 124