summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2017-06-27 22:04:40 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2017-06-27 22:04:40 +0000
commit58928f3ed2adc05902c3fb2daf15b27a100c14f3 (patch)
tree360e3fa26dcd2c2d60f1389d38c7f90d75ddaad6 /src
parentcolor wheel: Temp fix for Gtk+ style properties (diff)
downloadinkscape-58928f3ed2adc05902c3fb2daf15b27a100c14f3.tar.gz
inkscape-58928f3ed2adc05902c3fb2daf15b27a100c14f3.zip
Partial fix for menu items and split contextmenu into separate file
Diffstat (limited to 'src')
-rw-r--r--src/helper/pixbuf-ops.cpp2
-rw-r--r--src/helper/png-write.h2
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/contextmenu.cpp932
-rw-r--r--src/ui/contextmenu.h218
-rw-r--r--src/ui/interface.cpp929
-rw-r--r--src/ui/interface.h189
-rw-r--r--src/ui/tools/tool-base.cpp1
8 files changed, 1194 insertions, 1081 deletions
diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp
index bab998fdb..bb33f7b15 100644
--- a/src/helper/pixbuf-ops.cpp
+++ b/src/helper/pixbuf-ops.cpp
@@ -30,6 +30,8 @@
#include "helper/pixbuf-ops.h"
+#include <gdk/gdk.h>
+
// TODO look for copy-n-paste duplication of this function:
/**
* Hide all items that are not listed in list, recursively, skipping groups and defs.
diff --git a/src/helper/png-write.h b/src/helper/png-write.h
index 06498f46e..b886158c9 100644
--- a/src/helper/png-write.h
+++ b/src/helper/png-write.h
@@ -16,8 +16,8 @@
#include <2geom/forward.h>
-
class SPDocument;
+class SPItem;
enum ExportResult {
EXPORT_ERROR = 0,
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 389e8902a..c253daed9 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -1,5 +1,6 @@
set(ui_SRC
clipboard.cpp
+ contextmenu.cpp
control-manager.cpp
dialog-events.cpp
draw-anchor.cpp
@@ -173,6 +174,7 @@ set(ui_SRC
# -------
# Headers
clipboard.h
+ contextmenu.h
control-manager.h
control-types.h
dialog-events.h
diff --git a/src/ui/contextmenu.cpp b/src/ui/contextmenu.cpp
new file mode 100644
index 000000000..cd61d3872
--- /dev/null
+++ b/src/ui/contextmenu.cpp
@@ -0,0 +1,932 @@
+/**
+ * @file
+ * Context menu
+ */
+/* Authors:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * Frank Felfe <innerspace@iname.com>
+ * bulia byak <buliabyak@users.sf.net>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
+ *
+ * Copyright (C) 2012 Kris De Gussem
+ * Copyright (C) 2010 authors
+ * Copyright (C) 1999-2005 authors
+ * Copyright (C) 2004 David Turner
+ * Copyright (C) 2001-2002 Ximian, Inc.
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "contextmenu.h"
+
+#include <glibmm/i18n.h>
+#include <glibmm/miscutils.h>
+
+#include <gtkmm/box.h>
+#include <gtkmm/image.h>
+#include <gtkmm/separatormenuitem.h>
+
+#include "desktop.h"
+#include "document.h"
+#include "document-undo.h"
+#include "helper/action.h"
+#include "helper/action-context.h"
+#include "inkscape.h"
+#include "message-context.h"
+#include "message-stack.h"
+#include "selection.h"
+#include "selection-chemistry.h"
+#include "shortcuts.h"
+#include "sp-anchor.h"
+#include "sp-clippath.h"
+#include "sp-image.h"
+#include "sp-item.h"
+#include "sp-mask.h"
+#include "sp-shape.h"
+#include "sp-text.h"
+#include "ui/dialog/dialog-manager.h"
+#include "ui/dialog/layer-properties.h"
+#include "verbs.h"
+
+static bool temporarily_block_actions = false;
+
+ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) :
+ _item(item),
+ MIGroup(),
+ MIParent(_("Go to parent"))
+{
+// g_message("ContextMenu");
+ _object = static_cast<SPObject *>(item);
+ _desktop = desktop;
+
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_UNDO));
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_REDO));
+ AddSeparator();
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_CUT));
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_COPY));
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_PASTE));
+ AddSeparator();
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DUPLICATE));
+ AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DELETE));
+
+ positionOfLastDialog = 10; // 9 in front + 1 for the separator in the next if; used to position the dialog menu entries below each other
+ /* Item menu */
+ if (item!=NULL) {
+ AddSeparator();
+ MakeObjectMenu();
+ }
+ AddSeparator();
+ /* Lock/Unock Hide/Unhide*/
+ Geom::Rect b(_desktop->point(),_desktop->point() + Geom::Point(1,1));
+ std::vector< SPItem * > down_items = _desktop->getDocument()->getItemsPartiallyInBox( _desktop->dkey, b, true, true);
+ bool has_down_hidden = false;
+ bool has_down_locked = false;
+ for(std::vector< SPItem * >::iterator down = down_items.begin(); down != down_items.end(); ++down){
+ if((*down)->isHidden()) {
+ has_down_hidden = true;
+ }
+ if((*down)->isLocked()) {
+ has_down_locked = true;
+ }
+ }
+ Gtk::MenuItem* mi;
+
+ mi = Gtk::manage(new Gtk::MenuItem(_("Hide selected objects"),1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::HideSelected));
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(false);
+ }
+ mi->show();
+ append(*mi);//insert(*mi,positionOfLastDialog++);
+
+ mi = Gtk::manage(new Gtk::MenuItem(_("Unhide objects below"),1));
+ mi->signal_activate().connect(sigc::bind<std::vector< SPItem * > >(sigc::mem_fun(*this, &ContextMenu::UnHideBelow), down_items));
+ if (!has_down_hidden) {
+ mi->set_sensitive(false);
+ }
+ mi->show();
+ append(*mi);//insert(*mi,positionOfLastDialog++);
+
+ mi = Gtk::manage(new Gtk::MenuItem(_("Lock selected objects"),1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LockSelected));
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(false);
+ }
+ mi->show();
+ append(*mi);//insert(*mi,positionOfLastDialog++);
+
+ mi = Gtk::manage(new Gtk::MenuItem(_("Unlock objects below"),1));
+ mi->signal_activate().connect(sigc::bind<std::vector< SPItem * > >(sigc::mem_fun(*this, &ContextMenu::UnLockBelow), down_items));
+ if (!has_down_locked) {
+ mi->set_sensitive(false);
+ }
+ mi->show();
+ append(*mi);//insert(*mi,positionOfLastDialog++);
+ /* layer menu */
+ SPGroup *group=NULL;
+ if (item) {
+ if (SP_IS_GROUP(item)) {
+ group = SP_GROUP(item);
+ } else if ( item != _desktop->currentRoot() && SP_IS_GROUP(item->parent) ) {
+ group = SP_GROUP(item->parent);
+ }
+ }
+
+ if (( group && group != _desktop->currentLayer() ) ||
+ ( _desktop->currentLayer() != _desktop->currentRoot() && _desktop->currentLayer()->parent != _desktop->currentRoot() ) ) {
+ AddSeparator();
+ }
+
+ if ( group && group != _desktop->currentLayer() ) {
+ /* TRANSLATORS: #%1 is the id of the group e.g. <g id="#g7">, not a number. */
+ MIGroup.set_label (Glib::ustring::compose(_("Enter group #%1"), group->getId()));
+ MIGroup.set_data("group", group);
+ MIGroup.signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &ContextMenu::EnterGroup),&MIGroup));
+ MIGroup.show();
+ append(MIGroup);
+ }
+
+ if ( _desktop->currentLayer() != _desktop->currentRoot() ) {
+ if ( _desktop->currentLayer()->parent != _desktop->currentRoot() ) {
+ MIParent.signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LeaveGroup));
+ MIParent.show();
+ append(MIParent);
+
+ /* Pop selection out of group */
+ Gtk::MenuItem* miu = Gtk::manage(new Gtk::MenuItem(_("_Pop selection out of group"), 1));
+ miu->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroupPopSelection));
+ miu->show();
+ append(*miu);
+ }
+ }
+}
+
+ContextMenu::~ContextMenu(void)
+{
+}
+
+Gtk::SeparatorMenuItem* ContextMenu::AddSeparator(void)
+{
+ Gtk::SeparatorMenuItem* sep = Gtk::manage(new Gtk::SeparatorMenuItem());
+ sep->show();
+ append(*sep);
+ return sep;
+}
+
+void ContextMenu::EnterGroup(Gtk::MenuItem* mi)
+{
+ _desktop->setCurrentLayer(reinterpret_cast<SPObject *>(mi->get_data("group")));
+ _desktop->selection->clear();
+}
+
+void ContextMenu::LeaveGroup(void)
+{
+ _desktop->setCurrentLayer(_desktop->currentLayer()->parent);
+}
+
+void ContextMenu::LockSelected(void)
+{
+ auto itemlist = _desktop->selection->items();
+ for(auto i=itemlist.begin();i!=itemlist.end(); ++i) {
+ (*i)->setLocked(true);
+ }
+}
+
+void ContextMenu::HideSelected(void)
+{
+ auto itemlist =_desktop->selection->items();
+ for(auto i=itemlist.begin();i!=itemlist.end(); ++i) {
+ (*i)->setHidden(true);
+ }
+}
+
+void ContextMenu::UnLockBelow(std::vector<SPItem *> items)
+{
+ _desktop->selection->clear();
+ for(auto i=items.begin();i!=items.end(); ++i) {
+ if ((*i)->isLocked()) {
+ (*i)->setLocked(false);
+ _desktop->selection->add(*i);
+ }
+ }
+}
+
+void ContextMenu::UnHideBelow(std::vector<SPItem *> items)
+{
+ _desktop->selection->clear();
+ for(auto i=items.begin();i!=items.end(); ++i) {
+ if ((*i)->isHidden()) {
+ (*i)->setHidden(false);
+ _desktop->selection->add(*i);
+ }
+ }
+}
+
+/*
+ * Some day when the right-click menus are ready to start working
+ * smarter with the verbs, we'll need to change this NULL being
+ * sent to sp_action_perform to something useful, or set some kind
+ * of global "right-clicked position" variable for actions to
+ * investigate when they're called.
+ */
+static void
+context_menu_item_on_my_activate(void */*object*/, SPAction *action)
+{
+ if (!temporarily_block_actions) {
+ sp_action_perform(action, NULL);
+ }
+}
+
+static void
+context_menu_item_on_my_select(void */*object*/, SPAction *action)
+{
+ sp_action_get_view(action)->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, action->tip);
+}
+
+static void
+context_menu_item_on_my_deselect(void */*object*/, SPAction *action)
+{
+ sp_action_get_view(action)->tipsMessageContext()->clear();
+}
+
+
+// TODO: Update this to allow radio items to be used
+void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)//, bool radio, GSList *group)
+{
+ SPAction *action;
+ SPDesktop *view = _desktop;
+
+ if (verb->get_code() == SP_VERB_NONE) {
+ Gtk::MenuItem *item = AddSeparator();
+ item->show();
+ append(*item);
+ } else {
+ action = verb->get_action(Inkscape::ActionContext(view));
+ if (!action) {
+ return;
+ }
+
+ // Create a box to contain all the widgets (icon, label, accelerator)
+ // that will go inside the menu item
+ auto const box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 6));
+
+ // If there is an image associated with the action, then we can add it as an
+ // icon for the menu item
+ if (action->image) {
+ auto const icon = Gtk::manage(new Gtk::Image());
+ icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU);
+ box->add(*icon);
+ }
+
+ // Now create the label and add it to the menu item (with mnemonic
+ auto const label = Gtk::manage(new Gtk::Label(action->name, true));
+ box->add(*label);
+
+ // Create the menu item itself, either as a radio menu item, or just
+ // a regular menu item depending on whether the "radio" flag is set
+ auto const item = Gtk::manage(new Gtk::MenuItem(*box));
+
+ sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb));
+
+ action->signal_set_sensitive.connect(sigc::mem_fun(*this, &ContextMenu::set_sensitive));
+ action->signal_set_name.connect(sigc::mem_fun(*item, &ContextMenu::set_name));
+
+ if (!action->sensitive) {
+ item->set_sensitive(FALSE);
+ }
+
+ item->set_events(Gdk::KEY_PRESS_MASK);
+ item->signal_activate().connect(sigc::bind(sigc::ptr_fun(context_menu_item_on_my_activate),item,action));
+ item->signal_select().connect(sigc::bind(sigc::ptr_fun(context_menu_item_on_my_select),item,action));
+ item->signal_deselect().connect(sigc::bind(sigc::ptr_fun(context_menu_item_on_my_deselect),item,action));
+ item->show_all();
+ append(*item);
+ }
+}
+
+void ContextMenu::MakeObjectMenu(void)
+{
+ if (SP_IS_ITEM(_object)) {
+ MakeItemMenu();
+ }
+
+ if (SP_IS_GROUP(_object)) {
+ MakeGroupMenu();
+ }
+
+ if (SP_IS_ANCHOR(_object)) {
+ MakeAnchorMenu();
+ }
+
+ if (SP_IS_IMAGE(_object)) {
+ MakeImageMenu();
+ }
+
+ if (SP_IS_SHAPE(_object)) {
+ MakeShapeMenu();
+ }
+
+ if (SP_IS_TEXT(_object)) {
+ MakeTextMenu();
+ }
+}
+
+void ContextMenu::MakeItemMenu (void)
+{
+ Gtk::MenuItem* mi;
+
+ /* Item dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Object Properties..."),1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemProperties));
+ mi->show();
+ append(*mi);//insert(*mi,positionOfLastDialog++);
+
+ AddSeparator();
+
+ /* Select item */
+ if (Inkscape::Verb::getbyid( "org.inkscape.followlink" )) {
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Select This"), 1));
+ if (_desktop->selection->includes(_item)) {
+ mi->set_sensitive(FALSE);
+ } else {
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemSelectThis));
+ }
+ mi->show();
+ append(*mi);
+ }
+
+
+ mi = Gtk::manage(new Gtk::MenuItem(_("Select Same")));
+ mi->show();
+ Gtk::Menu *select_same_submenu = Gtk::manage(new Gtk::Menu());
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(FALSE);
+ }
+ mi->set_submenu(*select_same_submenu);
+ append(*mi);
+
+ /* Select same fill and stroke */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Fill and Stroke"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillStroke));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ select_same_submenu->append(*mi);
+
+ /* Select same fill color */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Fill Color"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillColor));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ select_same_submenu->append(*mi);
+
+ /* Select same stroke color */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Color"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeColor));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ select_same_submenu->append(*mi);
+
+ /* Select same stroke style */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Style"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeStyle));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ select_same_submenu->append(*mi);
+
+ /* Select same stroke style */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Object type"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameObjectType));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ select_same_submenu->append(*mi);
+
+ /* Move to layer */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Move to layer ..."), 1));
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(FALSE);
+ } else {
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemMoveTo));
+ }
+ mi->show();
+ append(*mi);
+
+ /* Create link */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Create _Link"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemCreateLink));
+ mi->set_sensitive(!SP_IS_ANCHOR(_item));
+ mi->show();
+ append(*mi);
+
+ bool ClipRefOK=false;
+ bool MaskRefOK=false;
+ if (_item){
+ if (_item->clip_ref){
+ if (_item->clip_ref->getObject()){
+ ClipRefOK=true;
+ }
+ }
+ }
+ if (_item){
+ if (_item->mask_ref){
+ if (_item->mask_ref->getObject()){
+ MaskRefOK=true;
+ }
+ }
+ }
+ /* Set mask */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Set Mask"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetMask));
+ if (ClipRefOK || MaskRefOK) {
+ mi->set_sensitive(FALSE);
+ } else {
+ mi->set_sensitive(TRUE);
+ }
+ mi->show();
+ append(*mi);
+
+ /* Release mask */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Release Mask"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseMask));
+ if (MaskRefOK) {
+ mi->set_sensitive(TRUE);
+ } else {
+ mi->set_sensitive(FALSE);
+ }
+ mi->show();
+ append(*mi);
+
+ /*SSet Clip Group */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Create Clip G_roup"),1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::CreateGroupClip));
+ mi->set_sensitive(TRUE);
+ mi->show();
+ append(*mi);
+
+ /* Set Clip */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Set Cl_ip"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetClip));
+ if (ClipRefOK || MaskRefOK) {
+ mi->set_sensitive(FALSE);
+ } else {
+ mi->set_sensitive(TRUE);
+ }
+ mi->show();
+ append(*mi);
+
+ /* Release Clip */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Release C_lip"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseClip));
+ if (ClipRefOK) {
+ mi->set_sensitive(TRUE);
+ } else {
+ mi->set_sensitive(FALSE);
+ }
+ mi->show();
+ append(*mi);
+
+ /* Group */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Group"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateGroup));
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(FALSE);
+ } else {
+ mi->set_sensitive(TRUE);
+ }
+ mi->show();
+ append(*mi);
+}
+
+void ContextMenu::SelectSameFillStroke(void)
+{
+ sp_select_same_fill_stroke_style(_desktop, true, true, true);
+}
+
+void ContextMenu::SelectSameFillColor(void)
+{
+ sp_select_same_fill_stroke_style(_desktop, true, false, false);
+}
+
+void ContextMenu::SelectSameStrokeColor(void)
+{
+ sp_select_same_fill_stroke_style(_desktop, false, true, false);
+}
+
+void ContextMenu::SelectSameStrokeStyle(void)
+{
+ sp_select_same_fill_stroke_style(_desktop, false, false, true);
+}
+
+void ContextMenu::SelectSameObjectType(void)
+{
+ sp_select_same_object_type(_desktop);
+}
+
+void ContextMenu::ItemProperties(void)
+{
+ _desktop->selection->set(_item);
+ _desktop->_dlg_mgr->showDialog("ObjectProperties");
+}
+
+void ContextMenu::ItemSelectThis(void)
+{
+ _desktop->selection->set(_item);
+}
+
+void ContextMenu::ItemMoveTo(void)
+{
+ Inkscape::UI::Dialogs::LayerPropertiesDialog::showMove(_desktop, _desktop->currentLayer());
+}
+
+
+
+void ContextMenu::ItemCreateLink(void)
+{
+ Inkscape::XML::Document *xml_doc = _desktop->doc()->getReprDoc();
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:a");
+ _item->parent->getRepr()->addChild(repr, _item->getRepr());
+ SPObject *object = _item->document->getObjectByRepr(repr);
+ g_return_if_fail(SP_IS_ANCHOR(object));
+
+ const char *id = _item->getRepr()->attribute("id");
+ Inkscape::XML::Node *child = _item->getRepr()->duplicate(xml_doc);
+ _item->deleteObject(false);
+ repr->addChild(child, NULL);
+ child->setAttribute("id", id);
+
+ Inkscape::GC::release(repr);
+ Inkscape::GC::release(child);
+
+ Inkscape::DocumentUndo::done(object->document, SP_VERB_NONE, _("Create link"));
+
+ _desktop->selection->set(SP_ITEM(object));
+ _desktop->_dlg_mgr->showDialog("ObjectAttributes");
+}
+
+void ContextMenu::SetMask(void)
+{
+ _desktop->selection->setMask(false, false);
+}
+
+void ContextMenu::ReleaseMask(void)
+{
+ _desktop->selection->unsetMask(false);
+}
+
+void ContextMenu::CreateGroupClip(void)
+{
+ _desktop->selection->setClipGroup();
+}
+
+void ContextMenu::SetClip(void)
+{
+ _desktop->selection->setMask(true, false);
+}
+
+
+void ContextMenu::ReleaseClip(void)
+{
+ _desktop->selection->unsetMask(true);
+}
+
+void ContextMenu::MakeGroupMenu(void)
+{
+ /* Ungroup */
+ Gtk::MenuItem* mi = Gtk::manage(new Gtk::MenuItem(_("_Ungroup"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroup));
+ mi->show();
+ append(*mi);
+}
+
+void ContextMenu::ActivateGroup(void)
+{
+ _desktop->selection->group();
+}
+
+void ContextMenu::ActivateUngroup(void)
+{
+ std::vector<SPItem*> children;
+
+ sp_item_group_ungroup(static_cast<SPGroup*>(_item), children);
+ _desktop->selection->setList(children);
+}
+
+void ContextMenu::ActivateUngroupPopSelection(void)
+{
+ _desktop->selection->popFromGroup();
+}
+
+
+void ContextMenu::MakeAnchorMenu(void)
+{
+ Gtk::MenuItem* mi;
+
+ /* Link dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Link _Properties..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkProperties));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+
+ /* Select item */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Follow Link"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkFollow));
+ mi->show();
+ append(*mi);
+
+ /* Reset transformations */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Remove Link"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkRemove));
+ mi->show();
+ append(*mi);
+}
+
+void ContextMenu::AnchorLinkProperties(void)
+{
+ _desktop->_dlg_mgr->showDialog("ObjectAttributes");
+}
+
+void ContextMenu::AnchorLinkFollow(void)
+{
+
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+ // Opening the selected links with a python extension
+ Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.inkscape.followlink" );
+ if (verb) {
+ SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
+ if (action) {
+ sp_action_perform(action, NULL);
+ }
+ }
+}
+
+void ContextMenu::AnchorLinkRemove(void)
+{
+ std::vector<SPItem*> children;
+ sp_item_group_ungroup(static_cast<SPAnchor*>(_item), children, false);
+ Inkscape::DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link"));
+}
+
+void ContextMenu::MakeImageMenu (void)
+{
+ Gtk::MenuItem* mi;
+ Inkscape::XML::Node *ir = _object->getRepr();
+ const gchar *href = ir->attribute("xlink:href");
+
+ /* Image properties */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Image _Properties..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageProperties));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+
+ /* Edit externally */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Edit Externally..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEdit));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+ if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
+ mi->set_sensitive( FALSE );
+ }
+
+ /* Trace Bitmap */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Trace Bitmap..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTraceBitmap));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(FALSE);
+ }
+
+ /* Trace Pixel Art */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Trace Pixel Art"), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTracePixelArt));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+ if (_desktop->selection->isEmpty()) {
+ mi->set_sensitive(FALSE);
+ }
+
+ /* Embed image */
+ if (Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" )) {
+ mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Embed Image")));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEmbed));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+ if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
+ mi->set_sensitive( FALSE );
+ }
+ }
+
+ /* Extract image */
+ if (Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" )) {
+ mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Extract Image...")));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageExtract));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+ if ( (!href) || ((strncmp(href, "data:", 5) != 0)) ) {
+ mi->set_sensitive( FALSE );
+ }
+ }
+}
+
+void ContextMenu::ImageProperties(void)
+{
+ _desktop->_dlg_mgr->showDialog("ObjectAttributes");
+}
+
+Glib::ustring ContextMenu::getImageEditorName() {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Glib::ustring value;
+ Glib::ustring choices = prefs->getString("/options/bitmapeditor/value");
+ if (!choices.empty()) {
+ value = choices;
+ }
+ else {
+ value = "gimp";
+ }
+ return value;
+}
+
+void ContextMenu::ImageEdit(void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ GError* errThing = 0;
+ Glib::ustring cmdline = getImageEditorName();
+ Glib::ustring name;
+ Glib::ustring fullname;
+
+#ifdef WIN32
+ // g_spawn_command_line_sync parsing is done according to Unix shell rules,
+ // not Windows command interpreter rules. Thus we need to enclose the
+ // executable path with single quotes.
+ int index = cmdline.find(".exe");
+ if ( index < 0 ) index = cmdline.find(".bat");
+ if ( index < 0 ) index = cmdline.find(".com");
+ if ( index >= 0 ) {
+ Glib::ustring editorBin = cmdline.substr(0, index + 4).c_str();
+ Glib::ustring args = cmdline.substr(index + 4, cmdline.length()).c_str();
+ editorBin.insert(0, "'");
+ editorBin.append("'");
+ cmdline = editorBin;
+ cmdline.append(args);
+ } else {
+ // Enclose the whole command line if no executable path can be extracted.
+ cmdline.insert(0, "'");
+ cmdline.append("'");
+ }
+#endif
+
+ auto itemlist= _desktop->selection->items();
+ for(auto i=itemlist.begin();i!=itemlist.end();++i){
+ Inkscape::XML::Node *ir = (*i)->getRepr();
+ const gchar *href = ir->attribute("xlink:href");
+
+ if (strncmp (href,"file:",5) == 0) {
+ // URI to filename conversion
+ name = g_filename_from_uri(href, NULL, NULL);
+ } else {
+ name.append(href);
+ }
+
+ if (Glib::path_is_absolute(name)) {
+ fullname = name;
+ } else if (SP_ACTIVE_DOCUMENT->getBase()) {
+ fullname = Glib::build_filename(SP_ACTIVE_DOCUMENT->getBase(), name);
+ } else {
+ fullname = Glib::build_filename(Glib::get_current_dir(), name);
+ }
+
+ cmdline.append(" '");
+ cmdline.append(fullname.c_str());
+ cmdline.append("'");
+ }
+
+ //g_warning("##Command line: %s\n", cmdline.c_str());
+
+ g_spawn_command_line_async(cmdline.c_str(), &errThing);
+
+ if ( errThing ) {
+ g_warning("Problem launching editor (%d). %s", errThing->code, errThing->message);
+ (_desktop->messageStack())->flash(Inkscape::ERROR_MESSAGE, errThing->message);
+ g_error_free(errThing);
+ errThing = 0;
+ }
+}
+
+void ContextMenu::ImageTraceBitmap(void)
+{
+ INKSCAPE.dialogs_unhide();
+ _desktop->_dlg_mgr->showDialog("Trace");
+}
+
+void ContextMenu::ImageTracePixelArt(void)
+{
+ INKSCAPE.dialogs_unhide();
+ _desktop->_dlg_mgr->showDialog("PixelArt");
+}
+
+void ContextMenu::ImageEmbed(void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" );
+ if (verb) {
+ SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
+ if (action) {
+ sp_action_perform(action, NULL);
+ }
+ }
+}
+
+void ContextMenu::ImageExtract(void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" );
+ if (verb) {
+ SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
+ if (action) {
+ sp_action_perform(action, NULL);
+ }
+ }
+}
+
+void ContextMenu::MakeShapeMenu (void)
+{
+ Gtk::MenuItem* mi;
+
+ /* Item dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+}
+
+void ContextMenu::FillSettings(void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ _desktop->_dlg_mgr->showDialog("FillAndStroke");
+}
+
+void ContextMenu::MakeTextMenu (void)
+{
+ Gtk::MenuItem* mi;
+
+ /* Fill and Stroke dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+
+ /* Edit Text dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("_Text and Font..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::TextSettings));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+
+ /* Spellcheck dialog */
+ mi = Gtk::manage(new Gtk::MenuItem(_("Check Spellin_g..."), 1));
+ mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SpellcheckSettings));
+ mi->show();
+ insert(*mi,positionOfLastDialog++);
+}
+
+void ContextMenu::TextSettings (void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ _desktop->_dlg_mgr->showDialog("TextFont");
+}
+
+void ContextMenu::SpellcheckSettings (void)
+{
+ if (_desktop->selection->isEmpty()) {
+ _desktop->selection->set(_item);
+ }
+
+ _desktop->_dlg_mgr->showDialog("SpellCheck");
+}
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/contextmenu.h b/src/ui/contextmenu.h
new file mode 100644
index 000000000..faae6358f
--- /dev/null
+++ b/src/ui/contextmenu.h
@@ -0,0 +1,218 @@
+#ifndef SEEN_CONTEXTMENU_H
+#define SEEN_CONTEXTMENU_H
+
+/*
+ * Context menu
+ *
+ * Authors:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * Frank Felfe <innerspace@iname.com>
+ * Abhishek Sharma
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
+ *
+ * Copyright (C) 2012 Kris De Gussem
+ * Copyright (C) 1999-2002 authors
+ * Copyright (C) 2001-2002 Ximian, Inc.
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <gtkmm/menu.h>
+
+class SPDesktop;
+class SPItem;
+class SPObject;
+
+namespace Gtk {
+class SeparatorMenuItem;
+}
+
+namespace Inkscape {
+class Verb;
+}
+
+/**
+ * Implements the Inkscape context menu.
+ *
+ * For the context menu implementation, the ContextMenu class stores the object
+ * that was selected in a private data member. This should be farely safe to do
+ * and a pointer to the SPItem as well as SPObject class are kept.
+ * All callbacks of the context menu entries are implemented as private
+ * functions.
+ *
+ * @todo add callbacks to destroy the context menu when it is closed (=key or mouse button pressed out of the scope of the context menu)
+ */
+class ContextMenu : public Gtk::Menu
+{
+ public:
+ /**
+ * The ContextMenu constructor contains all code to create and show the
+ * menu entries (aka child widgets).
+ *
+ * @param desktop pointer to the desktop the user is currently working on.
+ * @param item SPItem pointer to the object selected at the time the ContextMenu is created.
+ */
+ ContextMenu(SPDesktop *desktop, SPItem *item);
+ ~ContextMenu(void);
+
+ private:
+ SPItem *_item; // pointer to the object selected at the time the ContextMenu is created
+ SPObject *_object; // pointer to the object selected at the time the ContextMenu is created
+ SPDesktop *_desktop; //pointer to the desktop the user was currently working on at the time the ContextMenu is created
+
+ int positionOfLastDialog;
+
+ Gtk::MenuItem MIGroup; //menu entry to enter a group
+ Gtk::MenuItem MIParent; //menu entry to leave a group
+
+ /**
+ * auxiliary function that adds a separator line in the context menu
+ */
+ Gtk::SeparatorMenuItem* AddSeparator(void);
+
+ /**
+ * c++ified version of sp_ui_menu_append_item.
+ *
+ * @see sp_ui_menu_append_item_from_verb and synchronize/drop that function when c++ifying other code in interface.cpp
+ */
+ void AppendItemFromVerb(Inkscape::Verb *verb);
+
+ /**
+ * main function which is responsible for creating the context sensitive menu items,
+ * calls subfunctions below to create the menu entry widgets.
+ */
+ void MakeObjectMenu (void);
+ /**
+ * creates menu entries for an SP_TYPE_ITEM object
+ */
+ void MakeItemMenu (void);
+ /**
+ * creates menu entries for a grouped object
+ */
+ void MakeGroupMenu (void);
+ /**
+ * creates menu entries for an anchor object
+ */
+ void MakeAnchorMenu (void);
+ /**
+ * creates menu entries for a bitmap image object
+ */
+ void MakeImageMenu (void);
+ /**
+ * creates menu entries for a shape object
+ */
+ void MakeShapeMenu (void);
+ /**
+ * creates menu entries for a text object
+ */
+ void MakeTextMenu (void);
+
+ void EnterGroup(Gtk::MenuItem* mi);
+ void LeaveGroup(void);
+ void LockSelected(void);
+ void HideSelected(void);
+ void UnLockBelow(std::vector<SPItem *> items);
+ void UnHideBelow(std::vector<SPItem *> items);
+ //////////////////////////////////////////
+ //callbacks for the context menu entries of an SP_TYPE_ITEM object
+ void ItemProperties(void);
+ void ItemSelectThis(void);
+ void ItemMoveTo(void);
+ void SelectSameFillStroke(void);
+ void SelectSameFillColor(void);
+ void SelectSameStrokeColor(void);
+ void SelectSameStrokeStyle(void);
+ void SelectSameObjectType(void);
+ void ItemCreateLink(void);
+ void CreateGroupClip(void);
+ void SetMask(void);
+ void ReleaseMask(void);
+ void SetClip(void);
+ void ReleaseClip(void);
+ //////////////////////////////////////////
+
+
+ /**
+ * callback, is executed on clicking the anchor "Group" and "Ungroup" menu entry
+ */
+ void ActivateUngroupPopSelection(void);
+ void ActivateUngroup(void);
+ void ActivateGroup(void);
+
+ void AnchorLinkProperties(void);
+ /**
+ * placeholder for callback to be executed on clicking the anchor "Follow link" context menu entry
+ * @todo add code to follow link externally
+ */
+ void AnchorLinkFollow(void);
+
+ /**
+ * callback, is executed on clicking the anchor "Link remove" menu entry
+ */
+ void AnchorLinkRemove(void);
+
+
+ /**
+ * callback, opens the image properties dialog and is executed on clicking the context menu entry with similar name
+ */
+ void ImageProperties(void);
+
+ /**
+ * callback, is executed on clicking the image "Edit Externally" menu entry
+ */
+ void ImageEdit(void);
+
+ /**
+ * auxiliary function that loads the external image editor name from the settings.
+ */
+ Glib::ustring getImageEditorName();
+
+ /**
+ * callback, is executed on clicking the "Embed Image" menu entry
+ */
+ void ImageEmbed(void);
+
+ /**
+ * callback, is executed on clicking the "Trace Bitmap" menu entry
+ */
+ void ImageTraceBitmap(void);
+
+ /**
+ * callback, is executed on clicking the "Trace Pixel Art" menu entry
+ */
+ void ImageTracePixelArt(void);
+
+ /**
+ * callback, is executed on clicking the "Extract Image" menu entry
+ */
+ void ImageExtract(void);
+
+
+ /**
+ * callback, is executed on clicking the "Fill and Stroke" menu entry
+ */
+ void FillSettings(void);
+
+
+ /**
+ * callback, is executed on clicking the "Text and Font" menu entry
+ */
+ void TextSettings(void);
+
+ /**
+ * callback, is executed on clicking the "Check spelling" menu entry
+ */
+ void SpellcheckSettings(void);
+};
+#endif // SEEN_CONTEXT_MENU_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index 6c95c65a3..c2ce9e568 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -27,8 +27,6 @@
#include <gtkmm/icontheme.h>
#include "file.h"
#include <glibmm/miscutils.h>
-#include <gtkmm/imagemenuitem.h>
-#include <gtkmm/separatormenuitem.h>
#if WITH_GTKMM_3_22
# include <gdkmm/monitor.h>
@@ -447,45 +445,55 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb
// Just create a menu separator if this isn't a real action.
// Otherwise, create a real menu item
if (verb->get_code() == SP_VERB_NONE) {
-
item = gtk_separator_menu_item_new();
-
} else {
SPAction *action = verb->get_action(Inkscape::ActionContext(view));
if (!action) return NULL;
+ // Create the menu item itself, either as a radio menu item, or just
+ // a regular menu item depending on whether the "radio" flag is set
+ if (radio) {
+ item = gtk_radio_menu_item_new(group);
+ } else {
+ item = gtk_menu_item_new();
+ }
+
// Create a box to contain all the widgets (icon, label, accelerator)
// that will go inside the menu item
- GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
+ GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+
+ // Now create the label and add it to the menu item
+ GtkWidget *label = gtk_accel_label_new(action->name);
+ gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name);
+ gtk_label_set_use_underline(GTK_LABEL(label), true);
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0);
+
+ GtkAccelGroup *accel_group = sp_shortcut_get_accel_group();
+ gtk_menu_set_accel_group(menu, accel_group);
+
+ sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb));
+ gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item);
// If there is an image associated with the action, then we can add it as an
- // icon for the menu item
+ // icon for the menu item. If not, give the label a bit more space
if(action->image) {
GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU);
- gtk_container_add(GTK_CONTAINER(box), icon);
+ gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0);
+ }
+ else {
+ GtkWidget *fake_icon = gtk_label_new("");
+ gtk_widget_set_size_request(label, 16, 16);
+ gtk_widget_set_hexpand(label, true);
+ gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16);
}
- // Now create the label and add it to the menu item
- GtkWidget *label = gtk_label_new_with_mnemonic(action->name);
- gtk_label_set_markup_with_mnemonic( GTK_LABEL(label), action->name);
- gtk_container_add(GTK_CONTAINER(box), label);
+ gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
- // Create the menu item itself, either as a radio menu item, or just
- // a regular menu item depending on whether the "radio" flag is set
- if (radio) {
- item = gtk_radio_menu_item_new(group);
- } else {
- item = gtk_menu_item_new();
- }
// Finally, pack all the widgets into the menu item
gtk_container_add(GTK_CONTAINER(item), box);
- GtkAccelGroup *accel_group = sp_shortcut_get_accel_group();
- gtk_menu_set_accel_group(menu, accel_group);
-
- sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb));
action->signal_set_sensitive.connect(
sigc::bind<0>(
@@ -1398,8 +1406,13 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name)
if (GTK_IS_LABEL(child)) {
gtk_label_set_markup_with_mnemonic(GTK_LABEL (child), name.c_str());
} else if (GTK_IS_BOX(child)) {
+ GList *children = gtk_container_get_children(GTK_CONTAINER(child));
+
+ // Label is second child in list
+ GtkWidget *label = GTK_WIDGET(children->next->data);
+
gtk_label_set_markup_with_mnemonic(
- GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (child))->data),
+ GTK_LABEL (label),
name.c_str());
}//else sp_ui_menu_append_item_from_verb has been modified and can set
//a menu item in yet another way...
@@ -1433,876 +1446,6 @@ void injectRenamedIcons()
}
}
-
-ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) :
- _item(item),
- MIGroup(),
- MIParent(_("Go to parent"))
-{
-// g_message("ContextMenu");
- _object = static_cast<SPObject *>(item);
- _desktop = desktop;
-
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_UNDO));
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_REDO));
- AddSeparator();
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_CUT));
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_COPY));
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_PASTE));
- AddSeparator();
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DUPLICATE));
- AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DELETE));
-
- positionOfLastDialog = 10; // 9 in front + 1 for the separator in the next if; used to position the dialog menu entries below each other
- /* Item menu */
- if (item!=NULL) {
- AddSeparator();
- MakeObjectMenu();
- }
- AddSeparator();
- /* Lock/Unock Hide/Unhide*/
- Geom::Rect b(_desktop->point(),_desktop->point() + Geom::Point(1,1));
- std::vector< SPItem * > down_items = _desktop->getDocument()->getItemsPartiallyInBox( _desktop->dkey, b, true, true);
- bool has_down_hidden = false;
- bool has_down_locked = false;
- for(std::vector< SPItem * >::iterator down = down_items.begin(); down != down_items.end(); ++down){
- if((*down)->isHidden()) {
- has_down_hidden = true;
- }
- if((*down)->isLocked()) {
- has_down_locked = true;
- }
- }
- Gtk::MenuItem* mi;
-
- mi = Gtk::manage(new Gtk::MenuItem(_("Hide selected objects"),1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::HideSelected));
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(false);
- }
- mi->show();
- append(*mi);//insert(*mi,positionOfLastDialog++);
-
- mi = Gtk::manage(new Gtk::MenuItem(_("Unhide objects below"),1));
- mi->signal_activate().connect(sigc::bind<std::vector< SPItem * > >(sigc::mem_fun(*this, &ContextMenu::UnHideBelow), down_items));
- if (!has_down_hidden) {
- mi->set_sensitive(false);
- }
- mi->show();
- append(*mi);//insert(*mi,positionOfLastDialog++);
-
- mi = Gtk::manage(new Gtk::MenuItem(_("Lock selected objects"),1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LockSelected));
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(false);
- }
- mi->show();
- append(*mi);//insert(*mi,positionOfLastDialog++);
-
- mi = Gtk::manage(new Gtk::MenuItem(_("Unlock objects below"),1));
- mi->signal_activate().connect(sigc::bind<std::vector< SPItem * > >(sigc::mem_fun(*this, &ContextMenu::UnLockBelow), down_items));
- if (!has_down_locked) {
- mi->set_sensitive(false);
- }
- mi->show();
- append(*mi);//insert(*mi,positionOfLastDialog++);
- /* layer menu */
- SPGroup *group=NULL;
- if (item) {
- if (SP_IS_GROUP(item)) {
- group = SP_GROUP(item);
- } else if ( item != _desktop->currentRoot() && SP_IS_GROUP(item->parent) ) {
- group = SP_GROUP(item->parent);
- }
- }
-
- if (( group && group != _desktop->currentLayer() ) ||
- ( _desktop->currentLayer() != _desktop->currentRoot() && _desktop->currentLayer()->parent != _desktop->currentRoot() ) ) {
- AddSeparator();
- }
-
- if ( group && group != _desktop->currentLayer() ) {
- /* TRANSLATORS: #%1 is the id of the group e.g. <g id="#g7">, not a number. */
- MIGroup.set_label (Glib::ustring::compose(_("Enter group #%1"), group->getId()));
- MIGroup.set_data("group", group);
- MIGroup.signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &ContextMenu::EnterGroup),&MIGroup));
- MIGroup.show();
- append(MIGroup);
- }
-
- if ( _desktop->currentLayer() != _desktop->currentRoot() ) {
- if ( _desktop->currentLayer()->parent != _desktop->currentRoot() ) {
- MIParent.signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::LeaveGroup));
- MIParent.show();
- append(MIParent);
-
- /* Pop selection out of group */
- Gtk::MenuItem* miu = Gtk::manage(new Gtk::MenuItem(_("_Pop selection out of group"), 1));
- miu->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroupPopSelection));
- miu->show();
- append(*miu);
- }
- }
-}
-
-ContextMenu::~ContextMenu(void)
-{
-}
-
-Gtk::SeparatorMenuItem* ContextMenu::AddSeparator(void)
-{
- Gtk::SeparatorMenuItem* sep = Gtk::manage(new Gtk::SeparatorMenuItem());
- sep->show();
- append(*sep);
- return sep;
-}
-
-void ContextMenu::EnterGroup(Gtk::MenuItem* mi)
-{
- _desktop->setCurrentLayer(reinterpret_cast<SPObject *>(mi->get_data("group")));
- _desktop->selection->clear();
-}
-
-void ContextMenu::LeaveGroup(void)
-{
- _desktop->setCurrentLayer(_desktop->currentLayer()->parent);
-}
-
-void ContextMenu::LockSelected(void)
-{
- auto itemlist = _desktop->selection->items();
- for(auto i=itemlist.begin();i!=itemlist.end(); ++i) {
- (*i)->setLocked(true);
- }
-}
-
-void ContextMenu::HideSelected(void)
-{
- auto itemlist =_desktop->selection->items();
- for(auto i=itemlist.begin();i!=itemlist.end(); ++i) {
- (*i)->setHidden(true);
- }
-}
-
-void ContextMenu::UnLockBelow(std::vector<SPItem *> items)
-{
- _desktop->selection->clear();
- for(auto i=items.begin();i!=items.end(); ++i) {
- if ((*i)->isLocked()) {
- (*i)->setLocked(false);
- _desktop->selection->add(*i);
- }
- }
-}
-
-void ContextMenu::UnHideBelow(std::vector<SPItem *> items)
-{
- _desktop->selection->clear();
- for(auto i=items.begin();i!=items.end(); ++i) {
- if ((*i)->isHidden()) {
- (*i)->setHidden(false);
- _desktop->selection->add(*i);
- }
- }
-}
-
-// TODO: Update this to allow radio items to be used
-void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)//, bool radio, GSList *group)
-{
- SPAction *action;
- SPDesktop *view = _desktop;
-
- if (verb->get_code() == SP_VERB_NONE) {
- Gtk::MenuItem *item = AddSeparator();
- item->show();
- append(*item);
- } else {
- action = verb->get_action(Inkscape::ActionContext(view));
- if (!action) {
- return;
- }
-
- // Create a box to contain all the widgets (icon, label, accelerator)
- // that will go inside the menu item
- auto const box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 6));
-
- // If there is an image associated with the action, then we can add it as an
- // icon for the menu item
- if (action->image) {
- auto const icon = Gtk::manage(new Gtk::Image());
- icon->set_from_icon_name(action->image, Gtk::ICON_SIZE_MENU);
- box->add(*icon);
- }
-
- // Now create the label and add it to the menu item (with mnemonic
- auto const label = Gtk::manage(new Gtk::Label(action->name, true));
- box->add(*label);
-
- // Create the menu item itself, either as a radio menu item, or just
- // a regular menu item depending on whether the "radio" flag is set
- auto const item = Gtk::manage(new Gtk::MenuItem(*box));
-
- sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb));
-
- action->signal_set_sensitive.connect(sigc::mem_fun(*this, &ContextMenu::set_sensitive));
- action->signal_set_name.connect(sigc::mem_fun(*item, &ContextMenu::set_name));
-
- if (!action->sensitive) {
- item->set_sensitive(FALSE);
- }
-
-
- item->set_events(Gdk::KEY_PRESS_MASK);
- item->signal_activate().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_activate),item,action));
- item->signal_select().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_select_action),item,action));
- item->signal_deselect().connect(sigc::bind(sigc::ptr_fun(sp_ui_menu_deselect_action),item,action));
- item->show_all();
- append(*item);
- }
-}
-
-void ContextMenu::MakeObjectMenu(void)
-{
-// GObjectClass *klass = G_OBJECT_GET_CLASS(_object); //to deduce the object's type from its class
-//
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_ITEM))
-// {
-// MakeItemMenu ();
-// }
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_GROUP))
-// {
-// MakeGroupMenu();
-// }
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_ANCHOR))
-// {
-// MakeAnchorMenu();
-// }
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_IMAGE))
-// {
-// MakeImageMenu();
-// }
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_SHAPE))
-// {
-// MakeShapeMenu();
-// }
-// if (G_TYPE_CHECK_CLASS_TYPE(klass, SP_TYPE_TEXT))
-// {
-// MakeTextMenu();
-// }
-
- if (SP_IS_ITEM(_object)) {
- MakeItemMenu();
- }
-
- if (SP_IS_GROUP(_object)) {
- MakeGroupMenu();
- }
-
- if (SP_IS_ANCHOR(_object)) {
- MakeAnchorMenu();
- }
-
- if (SP_IS_IMAGE(_object)) {
- MakeImageMenu();
- }
-
- if (SP_IS_SHAPE(_object)) {
- MakeShapeMenu();
- }
-
- if (SP_IS_TEXT(_object)) {
- MakeTextMenu();
- }
-}
-
-void ContextMenu::MakeItemMenu (void)
-{
- Gtk::MenuItem* mi;
-
- /* Item dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Object Properties..."),1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemProperties));
- mi->show();
- append(*mi);//insert(*mi,positionOfLastDialog++);
-
- AddSeparator();
-
- /* Select item */
- if (Inkscape::Verb::getbyid( "org.inkscape.followlink" )) {
- mi = Gtk::manage(new Gtk::MenuItem(_("_Select This"), 1));
- if (_desktop->selection->includes(_item)) {
- mi->set_sensitive(FALSE);
- } else {
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemSelectThis));
- }
- mi->show();
- append(*mi);
- }
-
-
- mi = Gtk::manage(new Gtk::MenuItem(_("Select Same")));
- mi->show();
- Gtk::Menu *select_same_submenu = Gtk::manage(new Gtk::Menu());
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(FALSE);
- }
- mi->set_submenu(*select_same_submenu);
- append(*mi);
-
- /* Select same fill and stroke */
- mi = Gtk::manage(new Gtk::MenuItem(_("Fill and Stroke"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillStroke));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- select_same_submenu->append(*mi);
-
- /* Select same fill color */
- mi = Gtk::manage(new Gtk::MenuItem(_("Fill Color"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillColor));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- select_same_submenu->append(*mi);
-
- /* Select same stroke color */
- mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Color"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeColor));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- select_same_submenu->append(*mi);
-
- /* Select same stroke style */
- mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Style"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeStyle));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- select_same_submenu->append(*mi);
-
- /* Select same stroke style */
- mi = Gtk::manage(new Gtk::MenuItem(_("Object type"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameObjectType));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- select_same_submenu->append(*mi);
-
- /* Move to layer */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Move to layer ..."), 1));
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(FALSE);
- } else {
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemMoveTo));
- }
- mi->show();
- append(*mi);
-
- /* Create link */
- mi = Gtk::manage(new Gtk::MenuItem(_("Create _Link"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemCreateLink));
- mi->set_sensitive(!SP_IS_ANCHOR(_item));
- mi->show();
- append(*mi);
-
- bool ClipRefOK=false;
- bool MaskRefOK=false;
- if (_item){
- if (_item->clip_ref){
- if (_item->clip_ref->getObject()){
- ClipRefOK=true;
- }
- }
- }
- if (_item){
- if (_item->mask_ref){
- if (_item->mask_ref->getObject()){
- MaskRefOK=true;
- }
- }
- }
- /* Set mask */
- mi = Gtk::manage(new Gtk::MenuItem(_("Set Mask"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetMask));
- if (ClipRefOK || MaskRefOK) {
- mi->set_sensitive(FALSE);
- } else {
- mi->set_sensitive(TRUE);
- }
- mi->show();
- append(*mi);
-
- /* Release mask */
- mi = Gtk::manage(new Gtk::MenuItem(_("Release Mask"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseMask));
- if (MaskRefOK) {
- mi->set_sensitive(TRUE);
- } else {
- mi->set_sensitive(FALSE);
- }
- mi->show();
- append(*mi);
-
- /*SSet Clip Group */
- mi = Gtk::manage(new Gtk::MenuItem(_("Create Clip G_roup"),1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::CreateGroupClip));
- mi->set_sensitive(TRUE);
- mi->show();
- append(*mi);
-
- /* Set Clip */
- mi = Gtk::manage(new Gtk::MenuItem(_("Set Cl_ip"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetClip));
- if (ClipRefOK || MaskRefOK) {
- mi->set_sensitive(FALSE);
- } else {
- mi->set_sensitive(TRUE);
- }
- mi->show();
- append(*mi);
-
- /* Release Clip */
- mi = Gtk::manage(new Gtk::MenuItem(_("Release C_lip"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseClip));
- if (ClipRefOK) {
- mi->set_sensitive(TRUE);
- } else {
- mi->set_sensitive(FALSE);
- }
- mi->show();
- append(*mi);
-
- /* Group */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Group"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateGroup));
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(FALSE);
- } else {
- mi->set_sensitive(TRUE);
- }
- mi->show();
- append(*mi);
-}
-
-void ContextMenu::SelectSameFillStroke(void)
-{
- sp_select_same_fill_stroke_style(_desktop, true, true, true);
-}
-
-void ContextMenu::SelectSameFillColor(void)
-{
- sp_select_same_fill_stroke_style(_desktop, true, false, false);
-}
-
-void ContextMenu::SelectSameStrokeColor(void)
-{
- sp_select_same_fill_stroke_style(_desktop, false, true, false);
-}
-
-void ContextMenu::SelectSameStrokeStyle(void)
-{
- sp_select_same_fill_stroke_style(_desktop, false, false, true);
-}
-
-void ContextMenu::SelectSameObjectType(void)
-{
- sp_select_same_object_type(_desktop);
-}
-
-void ContextMenu::ItemProperties(void)
-{
- _desktop->selection->set(_item);
- _desktop->_dlg_mgr->showDialog("ObjectProperties");
-}
-
-void ContextMenu::ItemSelectThis(void)
-{
- _desktop->selection->set(_item);
-}
-
-void ContextMenu::ItemMoveTo(void)
-{
- Inkscape::UI::Dialogs::LayerPropertiesDialog::showMove(_desktop, _desktop->currentLayer());
-}
-
-
-
-void ContextMenu::ItemCreateLink(void)
-{
- Inkscape::XML::Document *xml_doc = _desktop->doc()->getReprDoc();
- Inkscape::XML::Node *repr = xml_doc->createElement("svg:a");
- _item->parent->getRepr()->addChild(repr, _item->getRepr());
- SPObject *object = _item->document->getObjectByRepr(repr);
- g_return_if_fail(SP_IS_ANCHOR(object));
-
- const char *id = _item->getRepr()->attribute("id");
- Inkscape::XML::Node *child = _item->getRepr()->duplicate(xml_doc);
- _item->deleteObject(false);
- repr->addChild(child, NULL);
- child->setAttribute("id", id);
-
- Inkscape::GC::release(repr);
- Inkscape::GC::release(child);
-
- DocumentUndo::done(object->document, SP_VERB_NONE, _("Create link"));
-
- _desktop->selection->set(SP_ITEM(object));
- _desktop->_dlg_mgr->showDialog("ObjectAttributes");
-}
-
-void ContextMenu::SetMask(void)
-{
- _desktop->selection->setMask(false, false);
-}
-
-void ContextMenu::ReleaseMask(void)
-{
- _desktop->selection->unsetMask(false);
-}
-
-void ContextMenu::CreateGroupClip(void)
-{
- _desktop->selection->setClipGroup();
-}
-
-void ContextMenu::SetClip(void)
-{
- _desktop->selection->setMask(true, false);
-}
-
-
-void ContextMenu::ReleaseClip(void)
-{
- _desktop->selection->unsetMask(true);
-}
-
-void ContextMenu::MakeGroupMenu(void)
-{
- /* Ungroup */
- Gtk::MenuItem* mi = Gtk::manage(new Gtk::MenuItem(_("_Ungroup"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroup));
- mi->show();
- append(*mi);
-}
-
-void ContextMenu::ActivateGroup(void)
-{
- _desktop->selection->group();
-}
-
-void ContextMenu::ActivateUngroup(void)
-{
- std::vector<SPItem*> children;
-
- sp_item_group_ungroup(static_cast<SPGroup*>(_item), children);
- _desktop->selection->setList(children);
-}
-
-void ContextMenu::ActivateUngroupPopSelection(void)
-{
- _desktop->selection->popFromGroup();
-}
-
-
-void ContextMenu::MakeAnchorMenu(void)
-{
- Gtk::MenuItem* mi;
-
- /* Link dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("Link _Properties..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkProperties));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-
- /* Select item */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Follow Link"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkFollow));
- mi->show();
- append(*mi);
-
- /* Reset transformations */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Remove Link"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkRemove));
- mi->show();
- append(*mi);
-}
-
-void ContextMenu::AnchorLinkProperties(void)
-{
- _desktop->_dlg_mgr->showDialog("ObjectAttributes");
-}
-
-void ContextMenu::AnchorLinkFollow(void)
-{
-
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
- // Opening the selected links with a python extension
- Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.inkscape.followlink" );
- if (verb) {
- SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
- if (action) {
- sp_action_perform(action, NULL);
- }
- }
-}
-
-void ContextMenu::AnchorLinkRemove(void)
-{
- std::vector<SPItem*> children;
- sp_item_group_ungroup(static_cast<SPAnchor*>(_item), children, false);
- DocumentUndo::done(_desktop->doc(), SP_VERB_NONE, _("Remove link"));
-}
-
-void ContextMenu::MakeImageMenu (void)
-{
- Gtk::MenuItem* mi;
- Inkscape::XML::Node *ir = _object->getRepr();
- const gchar *href = ir->attribute("xlink:href");
-
- /* Image properties */
- mi = Gtk::manage(new Gtk::MenuItem(_("Image _Properties..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageProperties));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-
- /* Edit externally */
- mi = Gtk::manage(new Gtk::MenuItem(_("Edit Externally..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEdit));
- mi->show();
- insert(*mi,positionOfLastDialog++);
- if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
- mi->set_sensitive( FALSE );
- }
-
- /* Trace Bitmap */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Trace Bitmap..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTraceBitmap));
- mi->show();
- insert(*mi,positionOfLastDialog++);
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(FALSE);
- }
-
- /* Trace Pixel Art */
- mi = Gtk::manage(new Gtk::MenuItem(_("Trace Pixel Art"), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTracePixelArt));
- mi->show();
- insert(*mi,positionOfLastDialog++);
- if (_desktop->selection->isEmpty()) {
- mi->set_sensitive(FALSE);
- }
-
- /* Embed image */
- if (Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" )) {
- mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Embed Image")));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEmbed));
- mi->show();
- insert(*mi,positionOfLastDialog++);
- if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) {
- mi->set_sensitive( FALSE );
- }
- }
-
- /* Extract image */
- if (Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" )) {
- mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Extract Image...")));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageExtract));
- mi->show();
- insert(*mi,positionOfLastDialog++);
- if ( (!href) || ((strncmp(href, "data:", 5) != 0)) ) {
- mi->set_sensitive( FALSE );
- }
- }
-}
-
-void ContextMenu::ImageProperties(void)
-{
- _desktop->_dlg_mgr->showDialog("ObjectAttributes");
-}
-
-Glib::ustring ContextMenu::getImageEditorName() {
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- Glib::ustring value;
- Glib::ustring choices = prefs->getString("/options/bitmapeditor/value");
- if (!choices.empty()) {
- value = choices;
- }
- else {
- value = "gimp";
- }
- return value;
-}
-
-void ContextMenu::ImageEdit(void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- GError* errThing = 0;
- Glib::ustring cmdline = getImageEditorName();
- Glib::ustring name;
- Glib::ustring fullname;
-
-#ifdef WIN32
- // g_spawn_command_line_sync parsing is done according to Unix shell rules,
- // not Windows command interpreter rules. Thus we need to enclose the
- // executable path with single quotes.
- int index = cmdline.find(".exe");
- if ( index < 0 ) index = cmdline.find(".bat");
- if ( index < 0 ) index = cmdline.find(".com");
- if ( index >= 0 ) {
- Glib::ustring editorBin = cmdline.substr(0, index + 4).c_str();
- Glib::ustring args = cmdline.substr(index + 4, cmdline.length()).c_str();
- editorBin.insert(0, "'");
- editorBin.append("'");
- cmdline = editorBin;
- cmdline.append(args);
- } else {
- // Enclose the whole command line if no executable path can be extracted.
- cmdline.insert(0, "'");
- cmdline.append("'");
- }
-#endif
-
- auto itemlist= _desktop->selection->items();
- for(auto i=itemlist.begin();i!=itemlist.end();++i){
- Inkscape::XML::Node *ir = (*i)->getRepr();
- const gchar *href = ir->attribute("xlink:href");
-
- if (strncmp (href,"file:",5) == 0) {
- // URI to filename conversion
- name = g_filename_from_uri(href, NULL, NULL);
- } else {
- name.append(href);
- }
-
- if (Glib::path_is_absolute(name)) {
- fullname = name;
- } else if (SP_ACTIVE_DOCUMENT->getBase()) {
- fullname = Glib::build_filename(SP_ACTIVE_DOCUMENT->getBase(), name);
- } else {
- fullname = Glib::build_filename(Glib::get_current_dir(), name);
- }
-
- cmdline.append(" '");
- cmdline.append(fullname.c_str());
- cmdline.append("'");
- }
-
- //g_warning("##Command line: %s\n", cmdline.c_str());
-
- g_spawn_command_line_async(cmdline.c_str(), &errThing);
-
- if ( errThing ) {
- g_warning("Problem launching editor (%d). %s", errThing->code, errThing->message);
- (_desktop->messageStack())->flash(Inkscape::ERROR_MESSAGE, errThing->message);
- g_error_free(errThing);
- errThing = 0;
- }
-}
-
-void ContextMenu::ImageTraceBitmap(void)
-{
- INKSCAPE.dialogs_unhide();
- _desktop->_dlg_mgr->showDialog("Trace");
-}
-
-void ContextMenu::ImageTracePixelArt(void)
-{
- INKSCAPE.dialogs_unhide();
- _desktop->_dlg_mgr->showDialog("PixelArt");
-}
-
-void ContextMenu::ImageEmbed(void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" );
- if (verb) {
- SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
- if (action) {
- sp_action_perform(action, NULL);
- }
- }
-}
-
-void ContextMenu::ImageExtract(void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- Inkscape::Verb *verb = Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" );
- if (verb) {
- SPAction *action = verb->get_action(Inkscape::ActionContext(_desktop));
- if (action) {
- sp_action_perform(action, NULL);
- }
- }
-}
-
-void ContextMenu::MakeShapeMenu (void)
-{
- Gtk::MenuItem* mi;
-
- /* Item dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-}
-
-void ContextMenu::FillSettings(void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- _desktop->_dlg_mgr->showDialog("FillAndStroke");
-}
-
-void ContextMenu::MakeTextMenu (void)
-{
- Gtk::MenuItem* mi;
-
- /* Fill and Stroke dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-
- /* Edit Text dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("_Text and Font..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::TextSettings));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-
- /* Spellcheck dialog */
- mi = Gtk::manage(new Gtk::MenuItem(_("Check Spellin_g..."), 1));
- mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SpellcheckSettings));
- mi->show();
- insert(*mi,positionOfLastDialog++);
-}
-
-void ContextMenu::TextSettings (void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- _desktop->_dlg_mgr->showDialog("TextFont");
-}
-
-void ContextMenu::SpellcheckSettings (void)
-{
- if (_desktop->selection->isEmpty()) {
- _desktop->selection->set(_item);
- }
-
- _desktop->_dlg_mgr->showDialog("SpellCheck");
-}
-
/*
Local Variables:
mode:c++
diff --git a/src/ui/interface.h b/src/ui/interface.h
index a41c36cc3..6e95c161c 100644
--- a/src/ui/interface.h
+++ b/src/ui/interface.h
@@ -17,23 +17,13 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-//#ifdef HAVE_CONFIG_H
-//# include <config.h>
-//#endif
+#include <glibmm/ustring.h>
-#include <gtkmm/menu.h>
-
-class SPItem;
-class SPObject;
-class SPDesktop;
class SPViewWidget;
-namespace Gtk {
-class SeparatorMenuItem;
-}
+typedef struct _GtkWidget GtkWidget;
namespace Inkscape {
-
class Verb;
namespace UI {
@@ -93,181 +83,6 @@ Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view );
void sp_ui_error_dialog (char const* message);
bool sp_ui_overwrite_file (char const* filename);
-
-/**
- * Implements the Inkscape context menu.
- *
- * For the context menu implementation, the ContextMenu class stores the object
- * that was selected in a private data member. This should be farely safe to do
- * and a pointer to the SPItem as well as SPObject class are kept.
- * All callbacks of the context menu entries are implemented as private
- * functions.
- *
- * @todo add callbacks to destroy the context menu when it is closed (=key or mouse button pressed out of the scope of the context menu)
- */
-class ContextMenu : public Gtk::Menu
-{
- public:
- /**
- * The ContextMenu constructor contains all code to create and show the
- * menu entries (aka child widgets).
- *
- * @param desktop pointer to the desktop the user is currently working on.
- * @param item SPItem pointer to the object selected at the time the ContextMenu is created.
- */
- ContextMenu(SPDesktop *desktop, SPItem *item);
- ~ContextMenu(void);
-
- private:
- SPItem *_item; // pointer to the object selected at the time the ContextMenu is created
- SPObject *_object; // pointer to the object selected at the time the ContextMenu is created
- SPDesktop *_desktop; //pointer to the desktop the user was currently working on at the time the ContextMenu is created
-
- int positionOfLastDialog;
-
- Gtk::MenuItem MIGroup; //menu entry to enter a group
- Gtk::MenuItem MIParent; //menu entry to leave a group
-
- /**
- * auxiliary function that adds a separator line in the context menu
- */
- Gtk::SeparatorMenuItem* AddSeparator(void);
-
- /**
- * c++ified version of sp_ui_menu_append_item.
- *
- * @see sp_ui_menu_append_item_from_verb and synchronize/drop that function when c++ifying other code in interface.cpp
- */
- void AppendItemFromVerb(Inkscape::Verb *verb);
-
- /**
- * main function which is responsible for creating the context sensitive menu items,
- * calls subfunctions below to create the menu entry widgets.
- */
- void MakeObjectMenu (void);
- /**
- * creates menu entries for an SP_TYPE_ITEM object
- */
- void MakeItemMenu (void);
- /**
- * creates menu entries for a grouped object
- */
- void MakeGroupMenu (void);
- /**
- * creates menu entries for an anchor object
- */
- void MakeAnchorMenu (void);
- /**
- * creates menu entries for a bitmap image object
- */
- void MakeImageMenu (void);
- /**
- * creates menu entries for a shape object
- */
- void MakeShapeMenu (void);
- /**
- * creates menu entries for a text object
- */
- void MakeTextMenu (void);
-
- void EnterGroup(Gtk::MenuItem* mi);
- void LeaveGroup(void);
- void LockSelected(void);
- void HideSelected(void);
- void UnLockBelow(std::vector<SPItem *> items);
- void UnHideBelow(std::vector<SPItem *> items);
- //////////////////////////////////////////
- //callbacks for the context menu entries of an SP_TYPE_ITEM object
- void ItemProperties(void);
- void ItemSelectThis(void);
- void ItemMoveTo(void);
- void SelectSameFillStroke(void);
- void SelectSameFillColor(void);
- void SelectSameStrokeColor(void);
- void SelectSameStrokeStyle(void);
- void SelectSameObjectType(void);
- void ItemCreateLink(void);
- void CreateGroupClip(void);
- void SetMask(void);
- void ReleaseMask(void);
- void SetClip(void);
- void ReleaseClip(void);
- //////////////////////////////////////////
-
-
- /**
- * callback, is executed on clicking the anchor "Group" and "Ungroup" menu entry
- */
- void ActivateUngroupPopSelection(void);
- void ActivateUngroup(void);
- void ActivateGroup(void);
-
- void AnchorLinkProperties(void);
- /**
- * placeholder for callback to be executed on clicking the anchor "Follow link" context menu entry
- * @todo add code to follow link externally
- */
- void AnchorLinkFollow(void);
-
- /**
- * callback, is executed on clicking the anchor "Link remove" menu entry
- */
- void AnchorLinkRemove(void);
-
-
- /**
- * callback, opens the image properties dialog and is executed on clicking the context menu entry with similar name
- */
- void ImageProperties(void);
-
- /**
- * callback, is executed on clicking the image "Edit Externally" menu entry
- */
- void ImageEdit(void);
-
- /**
- * auxiliary function that loads the external image editor name from the settings.
- */
- Glib::ustring getImageEditorName();
-
- /**
- * callback, is executed on clicking the "Embed Image" menu entry
- */
- void ImageEmbed(void);
-
- /**
- * callback, is executed on clicking the "Trace Bitmap" menu entry
- */
- void ImageTraceBitmap(void);
-
- /**
- * callback, is executed on clicking the "Trace Pixel Art" menu entry
- */
- void ImageTracePixelArt(void);
-
- /**
- * callback, is executed on clicking the "Extract Image" menu entry
- */
- void ImageExtract(void);
-
-
- /**
- * callback, is executed on clicking the "Fill and Stroke" menu entry
- */
- void FillSettings(void);
-
-
- /**
- * callback, is executed on clicking the "Text and Font" menu entry
- */
- void TextSettings(void);
-
- /**
- * callback, is executed on clicking the "Check spelling" menu entry
- */
- void SpellcheckSettings(void);
-};
-
#endif // SEEN_SP_INTERFACE_H
/*
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 3d755eadc..9231db7c8 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -23,6 +23,7 @@
#include "shortcuts.h"
#include "file.h"
+#include "ui/contextmenu.h"
#include "ui/interface.h"
#include "ui/event-debug.h"
#include "ui/tool/control-point.h"