1 /* 2 * Copyright 2013-2015 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * John Scipione, jscipione@gmail.com 7 * Ingo Weinhold, ingo_weinhold@gmx.de 8 */ 9 /* 10 Open Tracker License 11 12 Terms and Conditions 13 14 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 15 16 Permission is hereby granted, free of charge, to any person obtaining a copy of 17 this software and associated documentation files (the "Software"), to deal in 18 the Software without restriction, including without limitation the rights to 19 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 20 of the Software, and to permit persons to whom the Software is furnished to do 21 so, subject to the following conditions: 22 23 The above copyright notice and this permission notice applies to all licensees 24 and shall be included in all copies or substantial portions of the Software. 25 26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 30 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 33 Except as contained in this notice, the name of Be Incorporated shall not be 34 used in advertising or otherwise to promote the sale, use or other dealings in 35 this Software without prior written authorization from Be Incorporated. 36 37 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 38 of Be Incorporated in the United States and other countries. Other brand product 39 names are registered trademarks or trademarks of their respective holders. 40 All rights reserved. 41 */ 42 43 44 #include "VirtualDirectoryWindow.h" 45 46 #include <Catalog.h> 47 #include <Locale.h> 48 49 #include <AutoLocker.h> 50 51 #include "Commands.h" 52 #include "VirtualDirectoryManager.h" 53 #include "VirtualDirectoryPoseView.h" 54 55 56 #undef B_TRANSLATION_CONTEXT 57 #define B_TRANSLATION_CONTEXT "VirtualDirectoryWindow" 58 59 60 namespace BPrivate { 61 62 // #pragma mark - VirtualDirectoryWindow 63 64 65 VirtualDirectoryWindow::VirtualDirectoryWindow(LockingList<BWindow>* windowList, 66 uint32 containerWindowFlags, window_look look, window_feel feel, 67 uint32 flags, uint32 workspace) 68 : 69 BContainerWindow(windowList, containerWindowFlags, look, feel, flags, 70 workspace) 71 { 72 } 73 74 75 void 76 VirtualDirectoryWindow::CreatePoseView(Model* model) 77 { 78 fPoseView = NewPoseView(model, kListMode); 79 80 fBorderedView->GroupLayout()->AddView(fPoseView); 81 fBorderedView->EnableBorderHighlight(false); 82 fBorderedView->GroupLayout()->SetInsets(0, 0, 1, 1); 83 } 84 85 86 BPoseView* 87 VirtualDirectoryWindow::NewPoseView(Model* model, 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); 121 } 122 123 124 VirtualDirectoryPoseView* 125 VirtualDirectoryWindow::PoseView() const 126 { 127 return static_cast<VirtualDirectoryPoseView*>(fPoseView); 128 } 129 130 131 void 132 VirtualDirectoryWindow::AddWindowMenu(BMenu* menu) 133 { 134 BMenuItem* item; 135 136 item = new BMenuItem(B_TRANSLATE("Resize to fit"), 137 new BMessage(kResizeToFit), 'Y'); 138 item->SetTarget(this); 139 menu->AddItem(item); 140 141 item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS), 142 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY); 143 item->SetTarget(PoseView()); 144 menu->AddItem(item); 145 146 item = new BMenuItem(B_TRANSLATE("Select all"), 147 new BMessage(B_SELECT_ALL), 'A'); 148 item->SetTarget(PoseView()); 149 menu->AddItem(item); 150 151 item = new BMenuItem(B_TRANSLATE("Invert selection"), 152 new BMessage(kInvertSelection), 'S'); 153 item->SetTarget(PoseView()); 154 menu->AddItem(item); 155 156 item = new BMenuItem(B_TRANSLATE("Open parent"), 157 new BMessage(kOpenParentDir), B_UP_ARROW); 158 item->SetTarget(PoseView()); 159 menu->AddItem(item); 160 161 item = new BMenuItem(B_TRANSLATE("Close"), 162 new BMessage(B_QUIT_REQUESTED), 'W'); 163 item->SetTarget(this); 164 menu->AddItem(item); 165 } 166 167 168 void 169 VirtualDirectoryWindow::AddWindowContextMenus(BMenu* menu) 170 { 171 BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"), 172 new BMessage(kResizeToFit), 'Y'); 173 menu->AddItem(resizeItem); 174 menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS), 175 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY)); 176 menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"), 177 new BMessage(B_SELECT_ALL), 'A')); 178 BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"), 179 new BMessage(B_QUIT_REQUESTED), 'W'); 180 menu->AddItem(closeItem); 181 // target items as needed 182 menu->SetTargetForItems(PoseView()); 183 closeItem->SetTarget(this); 184 resizeItem->SetTarget(this); 185 } 186 187 } // namespace BPrivate 188