1 /* 2 * Copyright 2013, Haiku, Inc. 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 62 VirtualDirectoryWindow::VirtualDirectoryWindow(LockingList<BWindow>* windowList, 63 uint32 containerWindowFlags, window_look look, window_feel feel, 64 uint32 flags, uint32 workspace) 65 : 66 BContainerWindow(windowList, containerWindowFlags, look, feel, flags, 67 workspace) 68 { 69 } 70 71 72 void 73 VirtualDirectoryWindow::CreatePoseView(Model* model) 74 { 75 BRect rect(Bounds()); 76 rect.right -= B_V_SCROLL_BAR_WIDTH; 77 rect.bottom -= B_H_SCROLL_BAR_HEIGHT; 78 fPoseView = NewPoseView(model, rect, kListMode); 79 80 AddChild(fPoseView); 81 } 82 83 84 BPoseView* 85 VirtualDirectoryWindow::NewPoseView(Model* model, BRect rect, uint32 viewMode) 86 { 87 // If the model (or rather the entry_ref to it) came from another 88 // application, it may refer to a subdirectory we cannot use directly. The 89 // manager resolves the given refs to new ones, if necessary. 90 VirtualDirectoryManager* manager = VirtualDirectoryManager::Instance(); 91 if (manager == NULL) 92 return NULL; 93 94 { 95 AutoLocker<VirtualDirectoryManager> managerLocker(manager); 96 BStringList directoryPaths; 97 node_ref nodeRef; 98 entry_ref entryRef; 99 if (manager->ResolveDirectoryPaths(*model->NodeRef(), 100 *model->EntryRef(), directoryPaths, &nodeRef, &entryRef) 101 != B_OK) { 102 return NULL; 103 } 104 105 if (nodeRef != *model->NodeRef()) { 106 // Indeed a new file. Create a new model. 107 Model* newModel = new(std::nothrow) Model(&entryRef); 108 if (newModel == NULL || newModel->InitCheck() != B_OK) { 109 delete newModel; 110 return NULL; 111 } 112 113 delete model; 114 model = newModel; 115 } 116 } 117 118 return new VirtualDirectoryPoseView(model, rect); 119 } 120 121 122 void 123 VirtualDirectoryWindow::AddWindowMenu(BMenu* menu) 124 { 125 BMenuItem* item; 126 127 item = new BMenuItem(B_TRANSLATE("Resize to fit"), 128 new BMessage(kResizeToFit), 'Y'); 129 item->SetTarget(this); 130 menu->AddItem(item); 131 132 item = new BMenuItem(B_TRANSLATE("Select"B_UTF8_ELLIPSIS), 133 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY); 134 item->SetTarget(PoseView()); 135 menu->AddItem(item); 136 137 item = new BMenuItem(B_TRANSLATE("Select all"), 138 new BMessage(B_SELECT_ALL), 'A'); 139 item->SetTarget(PoseView()); 140 menu->AddItem(item); 141 142 item = new BMenuItem(B_TRANSLATE("Invert selection"), 143 new BMessage(kInvertSelection), 'S'); 144 item->SetTarget(PoseView()); 145 menu->AddItem(item); 146 147 item = new BMenuItem(B_TRANSLATE("Open parent"), 148 new BMessage(kOpenParentDir), B_UP_ARROW); 149 item->SetTarget(PoseView()); 150 menu->AddItem(item); 151 152 item = new BMenuItem(B_TRANSLATE("Close"), 153 new BMessage(B_QUIT_REQUESTED), 'W'); 154 item->SetTarget(this); 155 menu->AddItem(item); 156 } 157 158 159 void 160 VirtualDirectoryWindow::AddWindowContextMenus(BMenu* menu) 161 { 162 BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"), 163 new BMessage(kResizeToFit), 'Y'); 164 menu->AddItem(resizeItem); 165 menu->AddItem(new BMenuItem(B_TRANSLATE("Select"B_UTF8_ELLIPSIS), 166 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY)); 167 menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"), 168 new BMessage(B_SELECT_ALL), 'A')); 169 BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"), 170 new BMessage(B_QUIT_REQUESTED), 'W'); 171 menu->AddItem(closeItem); 172 // target items as needed 173 menu->SetTargetForItems(PoseView()); 174 closeItem->SetTarget(this); 175 resizeItem->SetTarget(this); 176 } 177 178 179 } // namespace BPrivate 180