File indexing completed on 2024-05-12 16:39:35

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KEXI_ACTION_CATEGORIES_H
0021 #define KEXI_ACTION_CATEGORIES_H
0022 
0023 #include "kexipart.h"
0024 
0025 #include <QSharedData>
0026 
0027 namespace Kexi
0028 {
0029 
0030 enum ActionCategory {
0031     NoActionCategory = 0,      //!< no category at all
0032     GlobalActionCategory = 1,  //!< global application action like editcopy;
0033                                //!< can be applied to focused widget (of many types)
0034     PartItemActionCategory = 2,//!< action related to part item, e.g. data_execute;
0035                                //!< requires context, used only in the navigator
0036     WindowActionCategory = 4   //!< action related to active window, which can display
0037                                //!< table, query, form, report...
0038 };
0039 
0040 //! @short A set of functions used to declare action categories
0041 /*! Note: we do not declare actions used in design/text view modes,
0042  because the categories are used in the data view,
0043  for now in the 'assign action to a push button' function. */
0044 class KEXICORE_EXPORT ActionCategories : public QSharedData
0045 {
0046 public:
0047     ActionCategories();
0048     ~ActionCategories();
0049 
0050     /*! Declares action \a name for categories \a category (a combination of ActionCategory enum values).
0051      The categories is merged with the previous declaration (if any).
0052      \a supportedObjectTypes can be specified for ActionCategory::WindowAction to declare what object types
0053      the action allows, it is a combination of KexiPart::ObjectType enum values. */
0054     void addAction(const char* name, int categories,
0055                    KexiPart::ObjectType supportedObjectType1 = KexiPart::UnknownObjectType,
0056                    KexiPart::ObjectType supportedObjectType2 = KexiPart::UnknownObjectType,
0057                    KexiPart::ObjectType supportedObjectType3 = KexiPart::UnknownObjectType,
0058                    KexiPart::ObjectType supportedObjectType4 = KexiPart::UnknownObjectType,
0059                    KexiPart::ObjectType supportedObjectType5 = KexiPart::UnknownObjectType,
0060                    KexiPart::ObjectType supportedObjectType6 = KexiPart::UnknownObjectType,
0061                    KexiPart::ObjectType supportedObjectType7 = KexiPart::UnknownObjectType,
0062                    KexiPart::ObjectType supportedObjectType8 = KexiPart::UnknownObjectType);
0063 
0064     void addGlobalAction(const char* name) {
0065         addAction(name, Kexi::GlobalActionCategory);
0066     }
0067 
0068     //! Convenience function for adding action of category "part item", uses \ref addAction().
0069     void addPartItemAction(const char* name) {
0070         addAction(name, Kexi::PartItemActionCategory);
0071     }
0072 
0073     /*! Convenience function for adding action of category "window", uses \ref addAction().
0074      \a supportedObjectTypes is a combination of KexiPart::ObjectType enum values describing
0075      object types supported by the action. */
0076     void addWindowAction(const char* name,
0077                          KexiPart::ObjectType supportedObjectType1 = KexiPart::UnknownObjectType,
0078                          KexiPart::ObjectType supportedObjectType2 = KexiPart::UnknownObjectType,
0079                          KexiPart::ObjectType supportedObjectType3 = KexiPart::UnknownObjectType,
0080                          KexiPart::ObjectType supportedObjectType4 = KexiPart::UnknownObjectType,
0081                          KexiPart::ObjectType supportedObjectType5 = KexiPart::UnknownObjectType,
0082                          KexiPart::ObjectType supportedObjectType6 = KexiPart::UnknownObjectType,
0083                          KexiPart::ObjectType supportedObjectType7 = KexiPart::UnknownObjectType,
0084                          KexiPart::ObjectType supportedObjectType8 = KexiPart::UnknownObjectType)
0085     {
0086         addAction(name, Kexi::WindowActionCategory, supportedObjectType1, supportedObjectType2,
0087                   supportedObjectType3, supportedObjectType4, supportedObjectType5, supportedObjectType6,
0088                   supportedObjectType7, supportedObjectType8);
0089     }
0090 
0091     /*! If \a set is true, action with name \a name will support any possible object type
0092      that can be checked by actionSupportsObjectType().
0093      Makes sense for action of category Kexi::WindowActionCategory. */
0094     void setAllObjectTypesSupported(const char* name, bool set);
0095 
0096     //! \return categories for action \a name (a combination of ActionCategory enum values).
0097     //! If there is no such actions declared at all, -1 is returned.
0098     int actionCategories(const char* name) const;
0099 
0100     /*! \return true if action \a name supports \a objectType.
0101      Only works for actions of WindowAction category. */
0102     bool actionSupportsObjectType(const char* name, KexiPart::ObjectType objectType) const;
0103 protected:
0104     class Private;
0105     Private * const d;
0106 };
0107 
0108 //! \return ActionCategories singleton object
0109 KEXICORE_EXPORT ActionCategories *actionCategories();
0110 
0111 }
0112 
0113 #endif