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