glom r1535 - in trunk: . glom/libglom glom/mode_data glom/utility_widgets
- From: jhs svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1535 - in trunk: . glom/libglom glom/mode_data glom/utility_widgets
- Date: Tue, 8 Apr 2008 15:09:55 +0100 (BST)
Author: jhs
Date: Tue Apr 8 15:09:54 2008
New Revision: 1535
URL: http://svn.gnome.org/viewvc/glom?rev=1535&view=rev
Log:
2008-04-08 Johannes Schmid <johannes schmid openismus com>
* glom/libglom/sharedptr.h
(operator!): Added operator! for convenience
* glom/mode_data/flowtablewithfields.cc
* glom/mode_data/flowtablewithfields.h:
(FlowTableWithFields): Removed setup_menu()
(on_menu_delete_activate): Added a confirmation dialog
* glom/utility_widgets/Makefile.am:
* glom/utility_widgets/layoutwidgetmenu.cc:
* glom/utility_widgets/layoutwidgetmenu.h:
* glom/utility_widgets/layoutwidgetbase.cc:
* glom/utility_widgets/layoutwidgetbase.h:
Moved menu code from LayoutWidgetBase into it\'s own class
(on_menupopup_activate_delete): Added a menu item to delete fields
* glom/utility_widgets/buttonglom.cc:
* glom/utility_widgets/buttonglom.h:
* glom/utility_widgets/labelglom.cc:
* glom/utility_widgets/labelglom.h:
Derive from LayoutWidgetUtils, removed setup_menu() call in
constructors
* glom/utility_widgets/datawidget.h:
* glom/utility_widgets/notebookglom.h:
* glom/utility_widgets/layoutwidgetfield.h:
Derive from LayoutWidgetMenu
* glom/utility_widgets/layoutwidgetutils.cc:
* glom/utility_widgets/layoutwidgetutils.h:
Derive from LayoutWidgetBase
(on_menu_delete_activate): Added menu item to delete layout items
* glom/utility_widgets/placeholder-glom.cc:
Removed setup_menu() call
Added:
trunk/glom/utility_widgets/layoutwidgetmenu.cc
trunk/glom/utility_widgets/layoutwidgetmenu.h
Modified:
trunk/ChangeLog
trunk/glom/libglom/sharedptr.h
trunk/glom/mode_data/flowtablewithfields.cc
trunk/glom/mode_data/flowtablewithfields.h
trunk/glom/utility_widgets/Makefile.am
trunk/glom/utility_widgets/buttonglom.cc
trunk/glom/utility_widgets/buttonglom.h
trunk/glom/utility_widgets/datawidget.h
trunk/glom/utility_widgets/flowtable_dnd.cc
trunk/glom/utility_widgets/labelglom.cc
trunk/glom/utility_widgets/labelglom.h
trunk/glom/utility_widgets/layoutwidgetbase.cc
trunk/glom/utility_widgets/layoutwidgetbase.h
trunk/glom/utility_widgets/layoutwidgetfield.h
trunk/glom/utility_widgets/layoutwidgetutils.cc
trunk/glom/utility_widgets/layoutwidgetutils.h
trunk/glom/utility_widgets/notebookglom.h
trunk/glom/utility_widgets/placeholder-glom.cc
Modified: trunk/glom/libglom/sharedptr.h
==============================================================================
--- trunk/glom/libglom/sharedptr.h (original)
+++ trunk/glom/libglom/sharedptr.h Tue Apr 8 15:09:54 2008
@@ -108,7 +108,17 @@
*/
inline operator bool() const;
- /** Dynamic cast to derived class.
+ /** Test whether the sharedptr<> points to any underlying instance.
+ *
+ * Mimics usage of ordinary pointers:
+ * @code
+ * if (!ptr)
+ * do_something();
+ * @endcode
+ */
+ inline bool operator!() const;
+
+ /** Dynamic cast to derived class.
*
* The sharedptr can't be cast with the usual notation so instead you can use
* @code
@@ -308,6 +318,12 @@
return (m_pobj != 0);
}
+template <class T_obj>
+inline
+bool sharedptr<T_obj>::operator!() const
+{
+ return (m_pobj == 0);
+}
template <class T_obj>
inline
Modified: trunk/glom/mode_data/flowtablewithfields.cc
==============================================================================
--- trunk/glom/mode_data/flowtablewithfields.cc (original)
+++ trunk/glom/mode_data/flowtablewithfields.cc Tue Apr 8 15:09:54 2008
@@ -59,9 +59,6 @@
m_table_name(table_name)
{
m_refUtilDetails->set_visible(false);
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
}
FlowTableWithFields::~FlowTableWithFields()
@@ -1353,6 +1350,30 @@
}
}
+void FlowTableWithFields::on_menu_delete_activate()
+{
+ Glib::ustring message;
+ if (!get_layout_item()->get_title().empty())
+ {
+ message = Glib::ustring::compose (_("Delete whole group \"%1\"?"),
+ get_layout_item()->get_title());
+ }
+ else
+ {
+ message = _("Delete whole group?");
+ }
+ Gtk::MessageDialog dlg (message, false, Gtk::MESSAGE_QUESTION,
+ Gtk::BUTTONS_YES_NO, true);
+ switch (dlg.run())
+ {
+ case Gtk::RESPONSE_YES:
+ LayoutWidgetUtils::on_menu_delete_activate();
+ break;
+ default:
+ return;
+ }
+}
+
bool FlowTableWithFields::on_button_press_event(GdkEventButton *event)
{
App_Glom* pApp = App_Glom::get_application();
Modified: trunk/glom/mode_data/flowtablewithfields.h
==============================================================================
--- trunk/glom/mode_data/flowtablewithfields.h (original)
+++ trunk/glom/mode_data/flowtablewithfields.h Tue Apr 8 15:09:54 2008
@@ -57,7 +57,6 @@
public FlowTableDnd,
#endif
public View_Composite_Glom,
- public LayoutWidgetBase,
public LayoutWidgetUtils
{
public:
@@ -243,6 +242,7 @@
//menu
virtual void on_menu_properties_activate();
+ virtual void on_menu_delete_activate(); // override this to add a dialog box
virtual bool on_button_press_event(GdkEventButton *event);
};
Modified: trunk/glom/utility_widgets/Makefile.am
==============================================================================
--- trunk/glom/utility_widgets/Makefile.am (original)
+++ trunk/glom/utility_widgets/Makefile.am Tue Apr 8 15:09:54 2008
@@ -38,7 +38,8 @@
layoutwidgetutils.h layoutwidgetutils.cc \
dialog_layoutitem_properties.cc dialog_layoutitem_properties.h \
dialog_flowtable.cc dialog_flowtable.h \
- flowtable_dnd.h flowtable_dnd.cc
+ flowtable_dnd.h flowtable_dnd.cc \
+ layoutwidgetmenu.cc layoutwidgetmenu.h
if !GLOM_ENABLE_CLIENT_ONLY
libutility_widgets_a_SOURCES += filechooserdialog_saveextras.cc filechooserdialog_saveextras.h \
Modified: trunk/glom/utility_widgets/buttonglom.cc
==============================================================================
--- trunk/glom/utility_widgets/buttonglom.cc (original)
+++ trunk/glom/utility_widgets/buttonglom.cc Tue Apr 8 15:09:54 2008
@@ -33,18 +33,11 @@
ButtonGlom::ButtonGlom(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& /* refGlade */)
: Gtk::Button(cobject)
{
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
init();
}
ButtonGlom::ButtonGlom()
{
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
init();
}
Modified: trunk/glom/utility_widgets/buttonglom.h
==============================================================================
--- trunk/glom/utility_widgets/buttonglom.h (original)
+++ trunk/glom/utility_widgets/buttonglom.h Tue Apr 8 15:09:54 2008
@@ -22,7 +22,6 @@
#define GLOM_UTILITY_WIDGETS_BUTTON_GLOM_H
#include <gtkmm.h>
-#include "layoutwidgetbase.h"
#include "layoutwidgetutils.h"
#include <glom/libglom/data_structure/layout/layoutitem_button.h>
#include <libglademm.h>
@@ -34,7 +33,6 @@
class ButtonGlom
: public Gtk::Button,
- public LayoutWidgetBase,
public LayoutWidgetUtils
{
public:
Modified: trunk/glom/utility_widgets/datawidget.h
==============================================================================
--- trunk/glom/utility_widgets/datawidget.h (original)
+++ trunk/glom/utility_widgets/datawidget.h Tue Apr 8 15:09:54 2008
@@ -24,7 +24,7 @@
#include "config.h" // For GLOM_ENABLE_CLIENT_ONLY
#include "placeholder.h"
-#include "layoutwidgetbase.h"
+#include "layoutwidgetmenu.h"
#include <gtkmm/label.h>
#include <glom/libglom/data_structure/field.h>
#include <glom/libglom/document/document_glom.h>
@@ -38,7 +38,7 @@
class DataWidget
: public Gtk::EventBox,
- public LayoutWidgetBase,
+ public LayoutWidgetMenu,
public View_Composite_Glom
{
public:
Modified: trunk/glom/utility_widgets/flowtable_dnd.cc
==============================================================================
--- trunk/glom/utility_widgets/flowtable_dnd.cc (original)
+++ trunk/glom/utility_widgets/flowtable_dnd.cc Tue Apr 8 15:09:54 2008
@@ -31,7 +31,7 @@
{
FlowTableDnd::FlowTableDnd() :
- m_current_dnd_item(0)
+ m_current_dnd_item(0)
{
std::list<Gtk::TargetEntry> drag_targets;
Gtk::TargetEntry drag_target(egg_tool_palette_get_drag_target_item());
Modified: trunk/glom/utility_widgets/labelglom.cc
==============================================================================
--- trunk/glom/utility_widgets/labelglom.cc (original)
+++ trunk/glom/utility_widgets/labelglom.cc Tue Apr 8 15:09:54 2008
@@ -24,6 +24,7 @@
#include <glibmm/i18n.h>
#include "../layout_item_dialogs/dialog_textobject.h"
#include "../libglom/glade_utils.h"
+#include "../mode_data/flowtablewithfields.h"
//#include <sstream> //For stringstream
namespace Glom
@@ -31,20 +32,12 @@
LabelGlom::LabelGlom()
{
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
init();
}
LabelGlom::LabelGlom(const Glib::ustring& label, float xalign, float yalign, bool mnemonic)
: m_label(label, xalign, yalign, mnemonic)
{
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
init();
}
Modified: trunk/glom/utility_widgets/labelglom.h
==============================================================================
--- trunk/glom/utility_widgets/labelglom.h (original)
+++ trunk/glom/utility_widgets/labelglom.h Tue Apr 8 15:09:54 2008
@@ -34,7 +34,6 @@
class LabelGlom
: public Gtk::EventBox,
- public LayoutWidgetBase,
public LayoutWidgetUtils
{
public:
Modified: trunk/glom/utility_widgets/layoutwidgetbase.cc
==============================================================================
--- trunk/glom/utility_widgets/layoutwidgetbase.cc (original)
+++ trunk/glom/utility_widgets/layoutwidgetbase.cc Tue Apr 8 15:09:54 2008
@@ -27,23 +27,10 @@
LayoutWidgetBase::LayoutWidgetBase()
#ifndef GLOM_ENABLE_CLIENT_ONLY
-: m_pLayoutItem(0),
- m_pMenuPopup(0)
+: m_pLayoutItem(0)
#endif // !GLOM_ENABLE_CLIENT_ONLY
{
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- m_refActionGroup = Gtk::ActionGroup::create();
- m_refActionGroup->add(Gtk::Action::create("ContextMenu", "Context Menu") );
- m_refContextLayout = Gtk::Action::create("ContextLayout", _("Choose Field"));
- m_refContextLayoutProperties = Gtk::Action::create("ContextLayoutProperties", _("Field Layout Properties"));
- m_refContextAddField = Gtk::Action::create("ContextAddField", _("Add Field"));
- m_refContextAddRelatedRecords = Gtk::Action::create("ContextAddRelatedRecords", _("Add Related Records"));
- m_refContextAddNotebook = Gtk::Action::create("ContextAddNotebook", _("Add Notebook"));
- m_refContextAddGroup = Gtk::Action::create("ContextAddGroup", _("Add Group"));
- m_refContextAddButton = Gtk::Action::create("ContextAddButton", _("Add Button"));
- m_refContextAddText = Gtk::Action::create("ContextAddText", _("Add Text"));
-#endif // !GLOM_ENABLE_CLIENT_ONLY
}
LayoutWidgetBase::~LayoutWidgetBase()
@@ -66,110 +53,6 @@
return m_pLayoutItem;
}
-#ifndef GLOM_ENABLE_CLIENT_ONLY
-void LayoutWidgetBase::setup_menu()
-{
- m_refActionGroup->add(m_refContextLayout,
- sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_activate_layout) );
-
- m_refActionGroup->add(m_refContextLayoutProperties,
- sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_activate_layout_properties) );
-
- m_refActionGroup->add(m_refContextAddField,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_FIELD ) );
-
- m_refActionGroup->add(m_refContextAddRelatedRecords,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_PORTAL ) );
-
- m_refActionGroup->add(m_refContextAddGroup,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_GROUP ) );
-
- m_refActionGroup->add(m_refContextAddNotebook,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_NOTEBOOK ) );
-
- m_refActionGroup->add(m_refContextAddButton,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_BUTTON ) );
-
- m_refActionGroup->add(m_refContextAddText,
- sigc::bind( sigc::mem_fun(*this, &LayoutWidgetBase::on_menupopup_add_item), TYPE_TEXT ) );
-
- //TODO: This does not work until this widget is in a container in the window:s
- App_Glom* pApp = get_application();
- if(pApp)
- {
- pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
- pApp->add_developer_action(m_refContextLayoutProperties); //So that it can be disabled when not in developer mode.
- pApp->add_developer_action(m_refContextAddField);
- pApp->add_developer_action(m_refContextAddRelatedRecords);
- pApp->add_developer_action(m_refContextAddNotebook);
- pApp->add_developer_action(m_refContextAddGroup);
- pApp->add_developer_action(m_refContextAddButton);
- pApp->add_developer_action(m_refContextAddText);
-
- pApp->update_userlevel_ui(); //Update our action's sensitivity.
- }
-
- m_refUIManager = Gtk::UIManager::create();
-
- m_refUIManager->insert_action_group(m_refActionGroup);
-
- //TODO: add_accel_group(m_refUIManager->get_accel_group());
-
- try
- {
- Glib::ustring ui_info =
- "<ui>"
- " <popup name='ContextMenu'>"
- " <menuitem action='ContextLayout'/>"
- " <menuitem action='ContextLayoutProperties'/>"
- " <menuitem action='ContextAddField'/>"
- " <menuitem action='ContextAddRelatedRecords'/>"
- " <menuitem action='ContextAddNotebook'/>"
- " <menuitem action='ContextAddGroup'/>"
- " <menuitem action='ContextAddButton'/>"
- " <menuitem action='ContextAddText'/>"
- " </popup>"
- "</ui>";
-
- m_refUIManager->add_ui_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << "building menus failed: " << ex.what();
- }
-
- //Get the menu:
- m_pMenuPopup = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/ContextMenu") );
- if(!m_pMenuPopup)
- g_warning("menu not found");
-
-
- if(pApp)
- m_refContextLayout->set_sensitive(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER);
-}
-
-void LayoutWidgetBase::on_menupopup_add_item(enumType item)
-{
- signal_layout_item_added().emit(item);
-}
-
-void LayoutWidgetBase::on_menupopup_activate_layout()
-{
- //finish_editing();
-
- //Ask the parent widget to show the layout dialog:
- signal_user_requested_layout().emit();
-}
-
-void LayoutWidgetBase::on_menupopup_activate_layout_properties()
-{
- //finish_editing();
-
- //Ask the parent widget to show the layout dialog:
- signal_user_requested_layout_properties().emit();
-}
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
App_Glom* LayoutWidgetBase::get_application() const
{
return 0; //override to implement.
Modified: trunk/glom/utility_widgets/layoutwidgetbase.h
==============================================================================
--- trunk/glom/utility_widgets/layoutwidgetbase.h (original)
+++ trunk/glom/utility_widgets/layoutwidgetbase.h Tue Apr 8 15:09:54 2008
@@ -55,14 +55,6 @@
TYPE_TEXT
};
- //Popup-menu:
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- virtual void setup_menu();
- virtual void on_menupopup_activate_layout();
- virtual void on_menupopup_activate_layout_properties();
- virtual void on_menupopup_add_item(enumType item);
-#endif // !GLOM_ENABLE_CLIENT_ONLY
-
#ifndef GLOM_ENABLE_CLIENT_ONLY
typedef sigc::signal<void> type_signal_layout_changed;
@@ -103,14 +95,6 @@
type_signal_user_requested_layout m_signal_user_requested_layout;
type_signal_user_requested_layout_properties m_signal_user_requested_layout_properties;
- Gtk::Menu* m_pMenuPopup;
-
- //TODO_Performance: //Presumably we waste lots of memory by having this in each layout widget. Maybe we can use one shared menu.
- Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
- Glib::RefPtr<Gtk::UIManager> m_refUIManager;
-
- Glib::RefPtr<Gtk::Action> m_refContextLayout, m_refContextLayoutProperties;
- Glib::RefPtr<Gtk::Action> m_refContextAddField, m_refContextAddRelatedRecords, m_refContextAddGroup, m_refContextAddNotebook, m_refContextAddButton, m_refContextAddText;
#endif // !GLOM_ENABLE_CLIENT_ONLY
};
Modified: trunk/glom/utility_widgets/layoutwidgetfield.h
==============================================================================
--- trunk/glom/utility_widgets/layoutwidgetfield.h (original)
+++ trunk/glom/utility_widgets/layoutwidgetfield.h Tue Apr 8 15:09:54 2008
@@ -21,12 +21,12 @@
#ifndef GLOM_MODE_DATA_LAYOUT_WIDGET_FIELD_H
#define GLOM_MODE_DATA_LAYOUT_WIDGET_FIELD_H
-#include "layoutwidgetbase.h"
+#include "layoutwidgetmenu.h"
namespace Glom
{
-class LayoutWidgetField : public LayoutWidgetBase
+class LayoutWidgetField : public LayoutWidgetMenu
{
public:
LayoutWidgetField();
Added: trunk/glom/utility_widgets/layoutwidgetmenu.cc
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/layoutwidgetmenu.cc Tue Apr 8 15:09:54 2008
@@ -0,0 +1,194 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2005 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "layoutwidgetfield.h"
+#include <glibmm/i18n.h>
+#include "../application.h"
+#include "../mode_data/flowtablewithfields.h"
+
+namespace Glom
+{
+
+LayoutWidgetMenu::LayoutWidgetMenu()
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ : m_pMenuPopup(0)
+#endif
+{
+ #ifndef GLOM_ENABLE_CLIENT_ONLY
+ m_refActionGroup = Gtk::ActionGroup::create();
+
+ m_refActionGroup->add(Gtk::Action::create("ContextMenu", "Context Menu") );
+ m_refContextLayout = Gtk::Action::create("ContextLayout", _("Choose Field"));
+ m_refContextLayoutProperties = Gtk::Action::create("ContextLayoutProperties", _("Field Layout Properties"));
+ m_refContextAddField = Gtk::Action::create("ContextAddField", _("Add Field"));
+ m_refContextAddRelatedRecords = Gtk::Action::create("ContextAddRelatedRecords", _("Add Related Records"));
+ m_refContextAddNotebook = Gtk::Action::create("ContextAddNotebook", _("Add Notebook"));
+ m_refContextAddGroup = Gtk::Action::create("ContextAddGroup", _("Add Group"));
+ m_refContextAddButton = Gtk::Action::create("ContextAddButton", _("Add Button"));
+ m_refContextAddText = Gtk::Action::create("ContextAddText", _("Add Text"));
+ m_refContextDelete = Gtk::Action::create("ContextDelete", _("Delete"));
+#endif // !GLOM_ENABLE_CLIENT_ONLY
+}
+
+LayoutWidgetMenu::~LayoutWidgetMenu()
+{
+}
+
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+void LayoutWidgetMenu::setup_menu()
+{
+ m_refActionGroup->add(m_refContextLayout,
+ sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_activate_layout) );
+
+ m_refActionGroup->add(m_refContextLayoutProperties,
+ sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_activate_layout_properties) );
+
+ m_refActionGroup->add(m_refContextAddField,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_FIELD ) );
+
+ m_refActionGroup->add(m_refContextAddRelatedRecords,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_PORTAL ) );
+
+ m_refActionGroup->add(m_refContextAddGroup,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_GROUP ) );
+
+ m_refActionGroup->add(m_refContextAddNotebook,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_NOTEBOOK ) );
+
+ m_refActionGroup->add(m_refContextAddButton,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_BUTTON ) );
+
+ m_refActionGroup->add(m_refContextAddText,
+ sigc::bind( sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_add_item), TYPE_TEXT ) );
+
+ m_refActionGroup->add(m_refContextDelete,
+ sigc::mem_fun(*this, &LayoutWidgetMenu::on_menupopup_activate_delete) );
+
+ //TODO: This does not work until this widget is in a container in the window:s
+ App_Glom* pApp = get_application();
+ if(pApp)
+ {
+ pApp->add_developer_action(m_refContextLayout); //So that it can be disabled when not in developer mode.
+ pApp->add_developer_action(m_refContextLayoutProperties); //So that it can be disabled when not in developer mode.
+ pApp->add_developer_action(m_refContextAddField);
+ pApp->add_developer_action(m_refContextAddRelatedRecords);
+ pApp->add_developer_action(m_refContextAddNotebook);
+ pApp->add_developer_action(m_refContextAddGroup);
+ pApp->add_developer_action(m_refContextAddButton);
+ pApp->add_developer_action(m_refContextAddText);
+
+ pApp->update_userlevel_ui(); //Update our action's sensitivity.
+ }
+
+ m_refUIManager = Gtk::UIManager::create();
+
+ m_refUIManager->insert_action_group(m_refActionGroup);
+
+ //TODO: add_accel_group(m_refUIManager->get_accel_group());
+
+ try
+ {
+ Glib::ustring ui_info =
+ "<ui>"
+ " <popup name='ContextMenu'>"
+ " <menuitem action='ContextLayout'/>"
+ " <menuitem action='ContextLayoutProperties'/>"
+ " <menuitem action='ContextAddField'/>"
+ " <menuitem action='ContextAddRelatedRecords'/>"
+ " <menuitem action='ContextAddNotebook'/>"
+ " <menuitem action='ContextAddGroup'/>"
+ " <menuitem action='ContextAddButton'/>"
+ " <menuitem action='ContextAddText'/>"
+ " <separator />"
+ " <menuitem action='ContextDelete' />"
+ " </popup>"
+ "</ui>";
+
+ m_refUIManager->add_ui_from_string(ui_info);
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << "building menus failed: " << ex.what();
+ }
+
+ //Get the menu:
+ m_pMenuPopup = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/ContextMenu") );
+ if(!m_pMenuPopup)
+ g_warning("menu not found");
+
+
+ if(pApp)
+ m_refContextLayout->set_sensitive(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER);
+}
+
+void LayoutWidgetMenu::on_menupopup_add_item(enumType item)
+{
+ signal_layout_item_added().emit(item);
+}
+
+void LayoutWidgetMenu::on_menupopup_activate_layout()
+{
+ //finish_editing();
+
+ //Ask the parent widget to show the layout dialog:
+ signal_user_requested_layout().emit();
+}
+
+void LayoutWidgetMenu::on_menupopup_activate_layout_properties()
+{
+ //finish_editing();
+
+ //Ask the parent widget to show the layout dialog:
+ signal_user_requested_layout_properties().emit();
+}
+
+void LayoutWidgetMenu::on_menupopup_activate_delete()
+{
+ Gtk::Widget* parent = dynamic_cast<Gtk::Widget*>(this);
+ if (!parent)
+ {
+ // Should never happen!
+ std::cerr << "LayoutWidgetUtils is no Gtk::Widget" << std::endl;
+ return;
+ }
+ LayoutWidgetBase* base = 0;
+ do
+ {
+ parent = parent->get_parent();
+ base = dynamic_cast<LayoutWidgetBase*>(parent);
+ if (base && dynamic_cast<FlowTableWithFields*>(base))
+ {
+ break;
+ }
+ } while (parent);
+ if (base)
+ {
+ sharedptr<LayoutGroup> group =
+ sharedptr<LayoutGroup>::cast_dynamic(base->get_layout_item());
+ if (!group)
+ return;
+ group->remove_item (get_layout_item());
+ base->signal_layout_changed().emit();
+ }
+}
+
+#endif // !GLOM_ENABLE_CLIENT_ONLY
+
+} //namespace Glom
Added: trunk/glom/utility_widgets/layoutwidgetmenu.h
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/layoutwidgetmenu.h Tue Apr 8 15:09:54 2008
@@ -0,0 +1,61 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2005 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_MODE_DATA_LAYOUT_WIDGET_MENU_H
+#define GLOM_MODE_DATA_LAYOUT_WIDGET_MENU_H
+
+#include "layoutwidgetbase.h"
+
+namespace Glom
+{
+
+class LayoutWidgetMenu : public LayoutWidgetBase
+{
+public:
+ LayoutWidgetMenu();
+ virtual ~LayoutWidgetMenu();
+
+ //Popup-menu:
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ virtual void setup_menu();
+ virtual void on_menupopup_activate_layout();
+ virtual void on_menupopup_activate_layout_properties();
+ virtual void on_menupopup_add_item(enumType item);
+ virtual void on_menupopup_activate_delete();
+#endif // !GLOM_ENABLE_CLIENT_ONLY
+
+protected:
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ Gtk::Menu* m_pMenuPopup;
+
+ //TODO_Performance: //Presumably we waste lots of memory by having this in each layout widget. Maybe we can use one shared menu.
+ Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
+ Glib::RefPtr<Gtk::UIManager> m_refUIManager;
+
+ Glib::RefPtr<Gtk::Action> m_refContextLayout, m_refContextLayoutProperties;
+ Glib::RefPtr<Gtk::Action> m_refContextAddField, m_refContextAddRelatedRecords,
+ m_refContextAddGroup, m_refContextAddNotebook, m_refContextAddButton, m_refContextAddText;
+ Glib::RefPtr<Gtk::Action> m_refContextDelete;
+#endif // GLOM_ENABLE_CLIENT_ONLY
+};
+
+} //namespace Glom
+
+#endif //GLOM_MODE_DATA_LAYOUT_WIDGET_MENU_H
Modified: trunk/glom/utility_widgets/layoutwidgetutils.cc
==============================================================================
--- trunk/glom/utility_widgets/layoutwidgetutils.cc (original)
+++ trunk/glom/utility_widgets/layoutwidgetutils.cc Tue Apr 8 15:09:54 2008
@@ -22,6 +22,7 @@
#include "layoutwidgetutils.h"
#include <glibmm/i18n.h>
+#include <gtkmm.h>
#include <iostream>
namespace Glom
@@ -35,6 +36,7 @@
m_refActionGroup->add(Gtk::Action::create("UtilMenu", "Utility Menu") );
m_refUtilProperties = Gtk::Action::create("UtilProperties", _("Properties"));
m_refUtilDetails = Gtk::Action::create("UtilDetails", _("Details"));
+ m_refUtilDelete = Gtk::Action::create("UtilDelete", _("Delete"));
setup_util_menu();
}
@@ -51,6 +53,8 @@
sigc::mem_fun(*this, &LayoutWidgetUtils::on_menu_properties_activate) );
m_refActionGroup->add(m_refUtilDetails,
sigc::mem_fun(*this, &LayoutWidgetUtils::on_menu_details_activate) );
+ m_refActionGroup->add(m_refUtilDelete,
+ sigc::mem_fun(*this, &LayoutWidgetUtils::on_menu_delete_activate) );
m_refUIManager->insert_action_group(m_refActionGroup);
@@ -61,6 +65,8 @@
" <popup name='UtilMenu'>"
" <menuitem action='UtilProperties'/>"
" <menuitem action='UtilDetails'/>"
+ " <separator />"
+ " <menuitem action='UtilDelete' />"
" </popup>"
"</ui>";
@@ -77,5 +83,35 @@
g_warning("menu not found");
}
+void LayoutWidgetUtils::on_menu_delete_activate()
+{
+ Gtk::Widget* parent = dynamic_cast<Gtk::Widget*>(this);
+ if (!parent)
+ {
+ // Should never happen!
+ std::cerr << "LayoutWidgetUtils is no Gtk::Widget" << std::endl;
+ return;
+ }
+ LayoutWidgetBase* base = 0;
+ do
+ {
+ parent = parent->get_parent();
+ base = dynamic_cast<LayoutWidgetBase*>(parent);
+ if (base)
+ {
+ break;
+ }
+ } while (parent);
+ if (base)
+ {
+ sharedptr<LayoutGroup> group =
+ sharedptr<LayoutGroup>::cast_dynamic(base->get_layout_item());
+ if (!group)
+ return;
+ group->remove_item (get_layout_item());
+ signal_layout_changed().emit();
+ }
+}
+
} // namespace Glom
Modified: trunk/glom/utility_widgets/layoutwidgetutils.h
==============================================================================
--- trunk/glom/utility_widgets/layoutwidgetutils.h (original)
+++ trunk/glom/utility_widgets/layoutwidgetutils.h Tue Apr 8 15:09:54 2008
@@ -24,11 +24,12 @@
#define _GLOM_LAYOUT_WIDGET_UTILS_H_
#include <gtkmm.h>
+#include "layoutwidgetbase.h"
namespace Glom
{
-class LayoutWidgetUtils //: public sigc::trackable
+class LayoutWidgetUtils : public LayoutWidgetBase
{
public:
LayoutWidgetUtils();
@@ -40,12 +41,19 @@
virtual void on_menu_properties_activate() = 0;
+ // This one is implemented here
+ virtual void on_menu_delete_activate();
+
// It's not really important to implement this though you should deactivate
// the menu item then. TODO: Does something need to be done here? murrayc.
+ // Some widgets such as buttons have a title and another detailed dialog
+ // in this case to set the script. Others such as labels have no detailed
+ // dialog and as such do not need this menu item. jhs
virtual void on_menu_details_activate() {};
Glib::RefPtr<Gtk::Action> m_refUtilProperties;
Glib::RefPtr<Gtk::Action> m_refUtilDetails;
+ Glib::RefPtr<Gtk::Action> m_refUtilDelete;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
Glib::RefPtr<Gtk::UIManager> m_refUIManager;
};
Modified: trunk/glom/utility_widgets/notebookglom.h
==============================================================================
--- trunk/glom/utility_widgets/notebookglom.h (original)
+++ trunk/glom/utility_widgets/notebookglom.h Tue Apr 8 15:09:54 2008
@@ -22,7 +22,7 @@
#define GLOM_UTILITY_WIDGETS_BUTTON_GLOM_H
#include <gtkmm.h>
-#include "layoutwidgetbase.h"
+#include "layoutwidgetmenu.h"
#include <glom/libglom/data_structure/layout/layoutitem_notebook.h>
#include <libglademm.h>
@@ -33,7 +33,7 @@
class NotebookGlom
: public Gtk::Notebook,
- public LayoutWidgetBase
+ public LayoutWidgetMenu
{
public:
explicit NotebookGlom(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade);
Modified: trunk/glom/utility_widgets/placeholder-glom.cc
==============================================================================
--- trunk/glom/utility_widgets/placeholder-glom.cc (original)
+++ trunk/glom/utility_widgets/placeholder-glom.cc Tue Apr 8 15:09:54 2008
@@ -36,9 +36,6 @@
Gtk::Widget()
{
set_flags(Gtk::NO_WINDOW);
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_menu();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
}
PlaceholderGlom::~PlaceholderGlom()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]