RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / tracker / VirtualDirectoryWindow.cpp
blobb28dc4f814a1ba98a63aa872778174c4843a517d
1 /*
2 * Copyright 2013-2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * John Scipione, jscipione@gmail.com
7 * Ingo Weinhold, ingo_weinhold@gmx.de
8 */
9 /*
10 Open Tracker License
12 Terms and Conditions
14 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
44 #include "VirtualDirectoryWindow.h"
46 #include <Catalog.h>
47 #include <Locale.h>
49 #include <AutoLocker.h>
51 #include "Commands.h"
52 #include "VirtualDirectoryManager.h"
53 #include "VirtualDirectoryPoseView.h"
56 #undef B_TRANSLATION_CONTEXT
57 #define B_TRANSLATION_CONTEXT "VirtualDirectoryWindow"
60 namespace BPrivate {
62 // #pragma mark - VirtualDirectoryWindow
65 VirtualDirectoryWindow::VirtualDirectoryWindow(LockingList<BWindow>* windowList,
66 uint32 containerWindowFlags, window_look look, window_feel feel,
67 uint32 flags, uint32 workspace)
69 BContainerWindow(windowList, containerWindowFlags, look, feel, flags,
70 workspace)
75 void
76 VirtualDirectoryWindow::CreatePoseView(Model* model)
78 fPoseView = NewPoseView(model, kListMode);
79 if (fPoseView == NULL)
80 return;
82 fBorderedView->GroupLayout()->AddView(fPoseView);
83 fBorderedView->EnableBorderHighlight(false);
84 fBorderedView->GroupLayout()->SetInsets(0, 0, 1, 1);
88 BPoseView*
89 VirtualDirectoryWindow::NewPoseView(Model* model, uint32 viewMode)
91 // If the model (or rather the entry_ref to it) came from another
92 // application, it may refer to a subdirectory we cannot use directly. The
93 // manager resolves the given refs to new ones, if necessary.
94 VirtualDirectoryManager* manager = VirtualDirectoryManager::Instance();
95 if (manager == NULL)
96 return NULL;
99 AutoLocker<VirtualDirectoryManager> managerLocker(manager);
100 BStringList directoryPaths;
101 node_ref nodeRef;
102 entry_ref entryRef;
103 if (manager->ResolveDirectoryPaths(*model->NodeRef(),
104 *model->EntryRef(), directoryPaths, &nodeRef, &entryRef)
105 != B_OK) {
106 return NULL;
109 if (nodeRef != *model->NodeRef()) {
110 // Indeed a new file. Create a new model.
111 Model* newModel = new(std::nothrow) Model(&entryRef);
112 if (newModel == NULL || newModel->InitCheck() != B_OK) {
113 delete newModel;
114 return NULL;
117 delete model;
118 model = newModel;
122 return new VirtualDirectoryPoseView(model);
126 VirtualDirectoryPoseView*
127 VirtualDirectoryWindow::PoseView() const
129 return static_cast<VirtualDirectoryPoseView*>(fPoseView);
133 void
134 VirtualDirectoryWindow::AddWindowMenu(BMenu* menu)
136 BMenuItem* item;
137 BMessage* message;
139 BMenu* listViewMenu = new BMenu(B_TRANSLATE("List view"));
141 message = new BMessage(kListMode);
142 message->AddInt32("icon_size", B_MINI_ICON);
143 item = new BMenuItem(listViewMenu, message);
144 item->SetShortcut('3', B_COMMAND_KEY);
145 item->SetTarget(PoseView());
146 menu->AddItem(item);
148 message = new BMessage(kListMode);
149 message->AddInt32("icon_size", B_MINI_ICON);
150 item = new BMenuItem(B_TRANSLATE("Mini"), message);
151 item->SetTarget(PoseView());
152 listViewMenu->AddItem(item);
154 message = new BMessage(kListMode);
155 message->AddInt32("icon_size", B_LARGE_ICON);
156 item = new BMenuItem(B_TRANSLATE("Large"), message);
157 item->SetTarget(PoseView());
158 listViewMenu->AddItem(item);
160 listViewMenu->SetTargetForItems(PoseView());
162 menu->AddSeparatorItem();
164 item = new BMenuItem(B_TRANSLATE("Resize to fit"),
165 new BMessage(kResizeToFit), 'Y');
166 item->SetTarget(this);
167 menu->AddItem(item);
169 item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
170 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY);
171 item->SetTarget(PoseView());
172 menu->AddItem(item);
174 item = new BMenuItem(B_TRANSLATE("Select all"),
175 new BMessage(B_SELECT_ALL), 'A');
176 item->SetTarget(PoseView());
177 menu->AddItem(item);
179 item = new BMenuItem(B_TRANSLATE("Invert selection"),
180 new BMessage(kInvertSelection), 'S');
181 item->SetTarget(PoseView());
182 menu->AddItem(item);
184 item = new BMenuItem(B_TRANSLATE("Open parent"),
185 new BMessage(kOpenParentDir), B_UP_ARROW);
186 item->SetTarget(PoseView());
187 menu->AddItem(item);
189 item = new BMenuItem(B_TRANSLATE("Close"),
190 new BMessage(B_QUIT_REQUESTED), 'W');
191 item->SetTarget(this);
192 menu->AddItem(item);
196 void
197 VirtualDirectoryWindow::AddWindowContextMenus(BMenu* menu)
199 BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"),
200 new BMessage(kResizeToFit), 'Y');
201 menu->AddItem(resizeItem);
202 menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
203 new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
204 menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
205 new BMessage(B_SELECT_ALL), 'A'));
206 BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"),
207 new BMessage(B_QUIT_REQUESTED), 'W');
208 menu->AddItem(closeItem);
209 // target items as needed
210 menu->SetTargetForItems(PoseView());
211 closeItem->SetTarget(this);
212 resizeItem->SetTarget(this);
215 } // namespace BPrivate