xref: /haiku/src/kits/tracker/QueryContainerWindow.cpp (revision e661df29804f2703a65e23f5789c3c87c0915298)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 
36 #include <Catalog.h>
37 #include <Locale.h>
38 #include <Menu.h>
39 #include <MenuItem.h>
40 #include <Path.h>
41 #include <PopUpMenu.h>
42 #include <MenuItem.h>
43 #include <Query.h>
44 
45 #include "Attributes.h"
46 #include "Commands.h"
47 #include "QueryContainerWindow.h"
48 #include "QueryPoseView.h"
49 
50 
51 //	#pragma mark - BQueryContainerWindow
52 
53 
54 #undef B_TRANSLATION_CONTEXT
55 #define B_TRANSLATION_CONTEXT "QueryContainerWindow"
56 
57 
58 BQueryContainerWindow::BQueryContainerWindow(LockingList<BWindow>* windowList,
59 	uint32 containerWindowFlags)
60 	:
61 	BContainerWindow(windowList, containerWindowFlags)
62 {
63 }
64 
65 
66 BPoseView*
67 BQueryContainerWindow::NewPoseView(Model* model, uint32)
68 {
69 	return new BQueryPoseView(model);
70 }
71 
72 
73 BQueryPoseView*
74 BQueryContainerWindow::PoseView() const
75 {
76 	return static_cast<BQueryPoseView*>(fPoseView);
77 }
78 
79 
80 void
81 BQueryContainerWindow::CreatePoseView(Model* model)
82 {
83 	fPoseView = NewPoseView(model, kListMode);
84 
85 	fBorderedView->GroupLayout()->AddView(fPoseView);
86 	fBorderedView->EnableBorderHighlight(false);
87 	fBorderedView->GroupLayout()->SetInsets(0, 0, 1, 1);
88 }
89 
90 
91 void
92 BQueryContainerWindow::AddWindowMenu(BMenu* menu)
93 {
94 	BMenuItem* item;
95 
96 	item = new BMenuItem(B_TRANSLATE("Resize to fit"),
97 		new BMessage(kResizeToFit), 'Y');
98 	item->SetTarget(this);
99 	menu->AddItem(item);
100 
101 	item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
102 		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY);
103 	item->SetTarget(PoseView());
104 	menu->AddItem(item);
105 
106 	item = new BMenuItem(B_TRANSLATE("Select all"),
107 		new BMessage(B_SELECT_ALL), 'A');
108 	item->SetTarget(PoseView());
109 	menu->AddItem(item);
110 
111 	item = new BMenuItem(B_TRANSLATE("Invert selection"),
112 		new BMessage(kInvertSelection), 'S');
113 	item->SetTarget(PoseView());
114 	menu->AddItem(item);
115 
116 	item = new BMenuItem(B_TRANSLATE("Close"),
117 		new BMessage(B_QUIT_REQUESTED), 'W');
118 	item->SetTarget(this);
119 	menu->AddItem(item);
120 }
121 
122 
123 void
124 BQueryContainerWindow::AddWindowContextMenus(BMenu* menu)
125 {
126 	BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"),
127 		new BMessage(kResizeToFit), 'Y');
128 	menu->AddItem(resizeItem);
129 	menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
130 		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
131 	menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
132 		new BMessage(B_SELECT_ALL), 'A'));
133 	BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"),
134 		new BMessage(B_QUIT_REQUESTED), 'W');
135 	menu->AddItem(closeItem);
136 
137 	// target items as needed
138 	menu->SetTargetForItems(PoseView());
139 	closeItem->SetTarget(this);
140 	resizeItem->SetTarget(this);
141 }
142 
143 
144 void
145 BQueryContainerWindow::SetUpDefaultState()
146 {
147 	BNode defaultingNode;
148 
149 	WindowStateNodeOpener opener(this, true);
150 		// this is our destination node, whatever it is for this window
151 	if (opener.StreamNode() == NULL)
152 		return;
153 
154 	BString defaultStatePath(kQueryTemplates);
155 	BString sanitizedType(PoseView()->SearchForType());
156 
157 	defaultStatePath += '/';
158 	int32 length = sanitizedType.Length();
159 	char* buf = sanitizedType.LockBuffer(length);
160 	for (int32 index = length - 1; index >= 0; index--)
161 		if (buf[index] == '/')
162 			buf[index] = '_';
163 	sanitizedType.UnlockBuffer(length);
164 
165 	defaultStatePath += sanitizedType;
166 
167 	PRINT(("looking for default query state at %s\n",
168 		defaultStatePath.String()));
169 
170 	if (!DefaultStateSourceNode(defaultStatePath.String(), &defaultingNode,
171 			false)) {
172 		TRACE();
173 		return;
174 	}
175 
176 	// copy over the attributes
177 
178 	// set up a filter of the attributes we want copied
179 	const char* allowAttrs[] = {
180 		kAttrWindowFrame,
181 		kAttrViewState,
182 		kAttrViewStateForeign,
183 		kAttrColumns,
184 		kAttrColumnsForeign,
185 		0
186 	};
187 
188 	// do it
189 	AttributeStreamMemoryNode memoryNode;
190 	NamesToAcceptAttrFilter filter(allowAttrs);
191 	AttributeStreamFileNode fileNode(&defaultingNode);
192 	*opener.StreamNode() << memoryNode << filter << fileNode;
193 }
194 
195 
196 bool
197 BQueryContainerWindow::ActiveOnDevice(dev_t device) const
198 {
199 	return PoseView()->ActiveOnDevice(device);
200 }
201