1 /* 2 * Copyright 2013 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold, ingo_weinhold@gmx.de 7 */ 8 /* 9 Open Tracker License 10 11 Terms and Conditions 12 13 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 14 15 Permission is hereby granted, free of charge, to any person obtaining a copy of 16 this software and associated documentation files (the "Software"), to deal in 17 the Software without restriction, including without limitation the rights to 18 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 of the Software, and to permit persons to whom the Software is furnished to do 20 so, subject to the following conditions: 21 22 The above copyright notice and this permission notice applies to all licensees 23 and shall be included in all copies or substantial portions of the Software. 24 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 29 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 30 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 32 Except as contained in this notice, the name of Be Incorporated shall not be 33 used in advertising or otherwise to promote the sale, use or other dealings in 34 this Software without prior written authorization from Be Incorporated. 35 36 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 37 of Be Incorporated in the United States and other countries. Other brand product 38 names are registered trademarks or trademarks of their respective holders. 39 All rights reserved. 40 */ 41 42 43 #include "VirtualDirectoryWindow.h" 44 45 #include <Catalog.h> 46 #include <Locale.h> 47 48 #include <AutoLocker.h> 49 50 #include "Commands.h" 51 #include "VirtualDirectoryManager.h" 52 #include "VirtualDirectoryPoseView.h" 53 54 55 #undef B_TRANSLATION_CONTEXT 56 #define B_TRANSLATION_CONTEXT "VirtualDirectoryWindow" 57 58 59 namespace BPrivate { 60 61 // #pragma mark - VirtualDirectoryWindow 62 63 64 VirtualDirectoryWindow::VirtualDirectoryWindow(LockingList<BWindow>* windowList, 65 uint32 containerWindowFlags, window_look look, window_feel feel, 66 uint32 flags, uint32 workspace) 67 : 68 BContainerWindow(windowList, containerWindowFlags, look, feel, flags, 69 workspace) 70 { 71 } 72 73 74 void 75 VirtualDirectoryWindow::CreatePoseView(Model* model) 76 { 77 BRect rect(Bounds()); 78 rect.right -= B_V_SCROLL_BAR_WIDTH; 79 rect.bottom -= B_H_SCROLL_BAR_HEIGHT; 80 fPoseView = NewPoseView(model, rect, kListMode); 81 82 AddChild(fPoseView); 83 } 84 85 86 BPoseView* 87 VirtualDirectoryWindow::NewPoseView(Model* model, BRect rect, uint32 viewMode) 88 { 89 // If the model (or rather the entry_ref to it) came from another 90 // application, it may refer to a subdirectory we cannot use directly. The 91 // manager resolves the given refs to new ones, if necessary. 92 VirtualDirectoryManager* manager = VirtualDirectoryManager::Instance(); 93 if (manager == NULL) 94 return NULL; 95 96 { 97 AutoLocker<VirtualDirectoryManager> managerLocker(manager); 98 BStringList directoryPaths; 99 node_ref nodeRef; 100 entry_ref entryRef; 101 if (manager->ResolveDirectoryPaths(*model->NodeRef(), 102 *model->EntryRef(), directoryPaths, &nodeRef, &entryRef) 103 != B_OK) { 104 return NULL; 105 } 106 107 if (nodeRef != *model->NodeRef()) { 108 // Indeed a new file. Create a new model. 109 Model* newModel = new(std::nothrow) Model(&entryRef); 110 if (newModel == NULL || newModel->InitCheck() != B_OK) { 111 delete newModel; 112 return NULL; 113 } 114 115 delete model; 116 model = newModel; 117 } 118 } 119 120 return new VirtualDirectoryPoseView(model, rect); 121 } 122 123 124 void 125 VirtualDirectoryWindow::AddWindowMenu(BMenu* menu) 126 { 127 BMenuItem* item; 128 129 item = new BMenuItem(B_TRANSLATE("Resize to fit"), 130 new BMessage(kResizeToFit), 'Y'); 131 item->SetTarget(this); 132 menu->AddItem(item); 133 134 item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS), 135 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY); 136 item->SetTarget(PoseView()); 137 menu->AddItem(item); 138 139 item = new BMenuItem(B_TRANSLATE("Select all"), 140 new BMessage(B_SELECT_ALL), 'A'); 141 item->SetTarget(PoseView()); 142 menu->AddItem(item); 143 144 item = new BMenuItem(B_TRANSLATE("Invert selection"), 145 new BMessage(kInvertSelection), 'S'); 146 item->SetTarget(PoseView()); 147 menu->AddItem(item); 148 149 item = new BMenuItem(B_TRANSLATE("Open parent"), 150 new BMessage(kOpenParentDir), B_UP_ARROW); 151 item->SetTarget(PoseView()); 152 menu->AddItem(item); 153 154 item = new BMenuItem(B_TRANSLATE("Close"), 155 new BMessage(B_QUIT_REQUESTED), 'W'); 156 item->SetTarget(this); 157 menu->AddItem(item); 158 } 159 160 161 void 162 VirtualDirectoryWindow::AddWindowContextMenus(BMenu* menu) 163 { 164 BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"), 165 new BMessage(kResizeToFit), 'Y'); 166 menu->AddItem(resizeItem); 167 menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS), 168 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY)); 169 menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"), 170 new BMessage(B_SELECT_ALL), 'A')); 171 BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"), 172 new BMessage(B_QUIT_REQUESTED), 'W'); 173 menu->AddItem(closeItem); 174 // target items as needed 175 menu->SetTargetForItems(PoseView()); 176 closeItem->SetTarget(this); 177 resizeItem->SetTarget(this); 178 } 179 180 } // namespace BPrivate 181