1/*
2 * Copyright 2018, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "TypeHandlerMenuItem.h"
8
9#include "TypeHandler.h"
10
11
12TypeHandlerMenuItem::TypeHandlerMenuItem(const char* label,	BMessage* message,
13	char shortcut, uint32 modifiers)
14	:
15	ActionMenuItem(label, message, shortcut, modifiers),
16	fTypeHandler(NULL)
17{
18}
19
20
21TypeHandlerMenuItem::~TypeHandlerMenuItem()
22{
23	if (fTypeHandler != NULL)
24		fTypeHandler->ReleaseReference();
25}
26
27
28void
29TypeHandlerMenuItem::ItemSelected()
30{
31	// if the item was selected, acquire a reference
32	// on behalf of the message target, as ours will be released
33	// when our menu item is freed.
34	fTypeHandler->AcquireReference();
35}
36
37
38status_t
39TypeHandlerMenuItem::SetTypeHandler(TypeHandler* handler)
40{
41	status_t error = Message()->AddPointer("handler", handler);
42	if (error != B_OK)
43		return error;
44
45	fTypeHandler = handler;
46	return B_OK;
47}
48