Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / interface.cpp
index 8a318210396331e78530b17e987c0f7bf88c3747..96c8c10ba41a700fa75c1e5577971466233d0aab 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <glib.h>
 #include "inkscape-private.h"
 #include "extension/effect.h"
 #include "widgets/icon.h"
@@ -129,7 +130,7 @@ static void sp_ui_drag_leave( GtkWidget *widget,
 static void sp_ui_menu_item_set_sensitive(SPAction *action,
                                           unsigned int sensitive,
                                           void *data);
-static void sp_ui_menu_item_set_name(SPAction *action, 
+static void sp_ui_menu_item_set_name(SPAction *action,
                                      Glib::ustring name,
                                      void *data);
 static void sp_recent_open(GtkRecentChooser *, gpointer);
@@ -158,21 +159,21 @@ sp_create_window(SPViewWidget *vw, gboolean editable)
 
     if (editable) {
                g_object_set_data(G_OBJECT(vw), "window", win);
-               
+
                SPDesktopWidget *desktop_widget = reinterpret_cast<SPDesktopWidget*>(vw);
                SPDesktop* desktop = desktop_widget->desktop;
-               
+
                desktop_widget->window = win;
 
         win->set_data("desktop", desktop);
         win->set_data("desktopwidget", desktop_widget);
-               
+
         win->signal_delete_event().connect(sigc::mem_fun(*(SPDesktop*)vw->view, &SPDesktop::onDeleteUI));
                win->signal_window_state_event().connect(sigc::mem_fun(*desktop, &SPDesktop::onWindowStateEvent));
                win->signal_focus_in_event().connect(sigc::mem_fun(*desktop_widget, &SPDesktopWidget::onFocusInEvent));
-       
+
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-        gint prefs_geometry = 
+        gint prefs_geometry =
             (2==prefs->getInt("/options/savewindowgeometry/value", 0));
         if (prefs_geometry) {
             gint pw = prefs->getInt("/desktop/geometry/width", -1);
@@ -826,6 +827,8 @@ sp_ui_checkboxes_menus(GtkMenu *m, Inkscape::UI::View::View *view)
     //                                       checkitem_toggled, checkitem_update, 0);
     sp_ui_menu_append_check_item_from_verb(m, view, _("Commands Bar"), _("Show or hide the Commands bar (under the menu)"), "commands",
                                            checkitem_toggled, checkitem_update, 0);
+    sp_ui_menu_append_check_item_from_verb(m, view, _("Snap controls Bar"), _("Show or hide the snapping controls"), "snaptoolbox",
+                                                                                  checkitem_toggled, checkitem_update, 0);
     sp_ui_menu_append_check_item_from_verb(m, view, _("Tool Controls Bar"), _("Show or hide the Tool Controls bar"), "toppanel",
                                            checkitem_toggled, checkitem_update, 0);
     sp_ui_menu_append_check_item_from_verb(m, view, _("_Toolbox"), _("Show or hide the main toolbox (on the left)"), "toolbox",
@@ -840,6 +843,25 @@ sp_ui_checkboxes_menus(GtkMenu *m, Inkscape::UI::View::View *view)
                                            checkitem_toggled, checkitem_update, 0);
 }
 
+/** @brief Observer that updates the recent list's max document count */
+class MaxRecentObserver : public Inkscape::Preferences::Observer {
+public:
+    MaxRecentObserver(GtkWidget *recent_menu) :
+        Observer("/options/maxrecentdocuments/value"),
+        _rm(recent_menu)
+    {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        prefs->addObserver(*this);
+    }
+    virtual void notify(Inkscape::Preferences::Entry const &e) {
+        gtk_recent_chooser_set_limit(GTK_RECENT_CHOOSER(_rm), e.getInt());
+        // hack: the recent menu doesn't repopulate after changing the limit, so we force it
+        g_signal_emit_by_name((gpointer) gtk_recent_manager_get_default(), "changed");
+    }
+private:
+    GtkWidget *_rm;
+};
+
 /** \brief  This function turns XML into a menu
     \param  menus  This is the XML that defines the menu
     \param  menu   Menu to be added to
@@ -923,16 +945,18 @@ sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI:
             // sort most recently used documents first to preserve previous behavior
             gtk_recent_chooser_set_sort_type(GTK_RECENT_CHOOSER(recent_menu), GTK_RECENT_SORT_MRU);
             g_signal_connect(G_OBJECT(recent_menu), "item-activated", G_CALLBACK(sp_recent_open), (gpointer) NULL);
-            
+
             // add filter to only open files added by Inkscape
             GtkRecentFilter *inkscape_only_filter = gtk_recent_filter_new();
-            gtk_recent_filter_add_application(inkscape_only_filter, "inkscape");
+            gtk_recent_filter_add_application(inkscape_only_filter, g_get_prgname());
             gtk_recent_chooser_add_filter(GTK_RECENT_CHOOSER(recent_menu), inkscape_only_filter);
 
             GtkWidget *recent_item = gtk_menu_item_new_with_mnemonic(_("Open _Recent"));
             gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent_item), recent_menu);
-            
+
             gtk_menu_append(GTK_MENU(menu), GTK_WIDGET(recent_item));
+            // this will just sit and update the list's item count
+            static MaxRecentObserver *mro = new MaxRecentObserver(recent_menu);
             continue;
         }
         if (!strcmp(menu_pntr->name(), "objects-checkboxes")) {
@@ -1128,7 +1152,7 @@ sp_ui_drag_data_received(GtkWidget *widget,
                     sp_desktop_apply_css_recursive( item, css, true );
                     item->updateRepr();
 
-                    sp_document_done( doc , SP_VERB_NONE, 
+                    sp_document_done( doc , SP_VERB_NONE,
                                       _("Drop color"));
 
                     if ( srgbProf ) {
@@ -1145,9 +1169,9 @@ sp_ui_drag_data_received(GtkWidget *widget,
             int destX = 0;
             int destY = 0;
             gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY );
-            NR::Point where( sp_canvas_window_to_world( desktop->canvas, NR::Point( destX, destY ) ) );
-            NR::Point const button_dt(desktop->w2d(where));
-            NR::Point const button_doc(desktop->dt2doc(button_dt));
+            Geom::Point where( sp_canvas_window_to_world( desktop->canvas, Geom::Point( destX, destY ) ) );
+            Geom::Point const button_dt(desktop->w2d(where));
+            Geom::Point const button_doc(desktop->dt2doc(button_dt));
 
             if ( data->length == 8 ) {
                 gchar c[64] = {0};
@@ -1182,15 +1206,15 @@ sp_ui_drag_data_received(GtkWidget *widget,
 
                 if (!consumed && item) {
                     bool fillnotstroke = (drag_context->action != GDK_ACTION_MOVE);
-                    if (fillnotstroke && 
+                    if (fillnotstroke &&
                         (SP_IS_SHAPE(item) || SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))) {
                         Path *livarot_path = Path_for_item(item, true, true);
                         livarot_path->ConvertWithBackData(0.04);
 
                         boost::optional<Path::cut_position> position = get_nearest_position_on_Path(livarot_path, button_doc);
                         if (position) {
-                            NR::Point nearest = get_point_on_Path(livarot_path, position->piece, position->t);
-                            NR::Point delta = nearest - button_doc;
+                            Geom::Point nearest = get_point_on_Path(livarot_path, position->piece, position->t);
+                            Geom::Point delta = nearest - button_doc;
                             Inkscape::Preferences *prefs = Inkscape::Preferences::get();
                             delta = desktop->d2w(delta);
                             double stroke_tolerance =
@@ -1199,9 +1223,9 @@ sp_ui_drag_data_received(GtkWidget *widget,
                                   SP_OBJECT_STYLE (item)->stroke_width.computed *
                                   to_2geom(sp_item_i2d_affine(item)).descrim() * 0.5
                                   : 0.0)
-                                + prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); 
+                                + prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
 
-                            if (NR::L2 (delta) < stroke_tolerance) {
+                            if (Geom::L2 (delta) < stroke_tolerance) {
                                 fillnotstroke = false;
                             }
                         }
@@ -1214,7 +1238,7 @@ sp_ui_drag_data_received(GtkWidget *widget,
                     sp_desktop_apply_css_recursive( item, css, true );
                     item->updateRepr();
 
-                    sp_document_done( doc , SP_VERB_NONE, 
+                    sp_document_done( doc , SP_VERB_NONE,
                                       _("Drop color"));
                 }
             }
@@ -1261,7 +1285,7 @@ sp_ui_drag_data_received(GtkWidget *widget,
                 bool const saved_pref = prefs->getBool("/options/transform/pattern", true);
                 prefs->setBool("/options/transform/pattern", true);
                 sp_document_ensure_up_to_date(sp_desktop_document(desktop));
-                boost::optional<Geom::Rect> sel_bbox = selection->bounds();
+                Geom::OptRect sel_bbox = selection->bounds();
                 if (sel_bbox) {
                     Geom::Point m( desktop->point() - sel_bbox->midpoint() );
                     sp_selection_move_relative(selection, m);
@@ -1270,7 +1294,7 @@ sp_ui_drag_data_received(GtkWidget *widget,
             }
 
             Inkscape::GC::release(newgroup);
-            sp_document_done(doc, SP_VERB_NONE, 
+            sp_document_done(doc, SP_VERB_NONE,
                              _("Drop SVG"));
             break;
         }
@@ -1328,7 +1352,7 @@ sp_ui_drag_data_received(GtkWidget *widget,
             desktop->currentLayer()->appendChildRepr(newImage);
 
             Inkscape::GC::release(newImage);
-            sp_document_done( doc , SP_VERB_NONE, 
+            sp_document_done( doc , SP_VERB_NONE,
                               _("Drop bitmap image"));
             break;
         }
@@ -1465,7 +1489,7 @@ sp_ui_menu_item_set_name(SPAction */*action*/, Glib::ustring name, void *data)
         gtk_label_set_markup_with_mnemonic(GTK_LABEL (child), name.c_str());
     } else if (GTK_IS_HBOX(child)) {
         gtk_label_set_markup_with_mnemonic(
-        GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (child))->data), 
+        GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (child))->data),
         name.c_str());
     }//else sp_ui_menu_append_item_from_verb has been modified and can set
     //a menu item in yet another way...