summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexiactioncategories.h
blob: 6e672133c23bdbebf8c9e0da57eba5d8cf5acd10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* This file is part of the KDE project
   Copyright (C) 2006 Jaroslaw Staniek <[email protected]>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KEXI_ACTION_CATEGORIES_H
#define KEXI_ACTION_CATEGORIES_H

#include <ksharedptr.h>
#include "kexipart.h"

namespace Kexi {

enum ActionCategory
{
	NoActionCategory = 0,      //!< no category at all
	GlobalActionCategory = 1,  //!< global application action like editcopy; 
	                           //!< can be applied to focused widget (of many types)
	PartItemActionCategory = 2,//!< action related to part item, e.g. data_execute; 
	                           //!< requires context, used only in the navigator
	WindowActionCategory = 4   //!< action related to active window, which can display 
	                           //!< table, query, form, report...
};

//! @short A set of functions used to declare action categories
/*! Note: we do not declare actions used in design/text view modes, 
 because the categories are used in the data view, 
 for now in the 'assign action to a push button' function. */
class KEXICORE_EXPORT ActionCategories : public KShared
{
	public:
		ActionCategories();
		~ActionCategories();

		/*! Declares action \a name for categories \a category (a combination of ActionCategory enum values). 
		 The categories is merged with the previous declaration (if any).
		 \a supportedObjectTypes can be specified for ActionCategory::WindowAction to declare what object types
		 the action allows, it is a combination of KexiPart::ObjectTypes enum values. */
		void addAction(const char* name, int categories,
			KexiPart::ObjectTypes supportedObjectType1 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType2 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType3 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType4 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType5 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType6 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType7 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType8 = (KexiPart::ObjectTypes)0);

		void addGlobalAction(const char* name)
			{ addAction(name, Kexi::GlobalActionCategory); }

		//! Convenience function for adding action of category "part item", uses \ref addAction().
		void addPartItemAction(const char* name)
			{ addAction(name, Kexi::PartItemActionCategory); }

		/*! Convenience function for adding action of category "window", uses \ref addAction().
		 \a supportedObjectTypes is a combination of KexiPart::ObjectTypes enum values describing 
		 object types supported by the action. */
		void addWindowAction(const char* name,
			KexiPart::ObjectTypes supportedObjectType1 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType2 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType3 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType4 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType5 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType6 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType7 = (KexiPart::ObjectTypes)0,
			KexiPart::ObjectTypes supportedObjectType8 = (KexiPart::ObjectTypes)0)
			{ addAction(name, Kexi::WindowActionCategory, supportedObjectType1, supportedObjectType2,
				supportedObjectType3, supportedObjectType4, supportedObjectType5, supportedObjectType6,
				supportedObjectType7, supportedObjectType8); }

		/*! If \a set is true, action with name \a name will support any possible object type
		 that can be checked by actionSupportsObjectType(). 
		 Makes sense for action of category Kexi::WindowActionCategory. */
		void setAllObjectTypesSupported(const char* name, bool set);

		//! \return categories for action \a name (a combination of ActionCategory enum values).
		//! If there is no such actions declared at all, -1 is returned.
		int actionCategories(const char* name) const;

		/*! \return true if action \a name supports \a objectType.
		 Only works for actions of WindowAction category. */
		bool actionSupportsObjectType(const char* name, KexiPart::ObjectTypes objectType) const;
	protected:
		class Private;
		Private *d;
};

//! \return ActionCategories singleton object
KEXICORE_EXPORT ActionCategories *actionCategories();

}

#endif