Code

clean up redundancies. add a placeholder for Export dialog
[inkscape.git] / src / ui / widget / panel.cpp
index 11235d083948fba78c60b22732a87b6f7bfb9bcb..4ecbda1b8631073db084f372d2f2641e7ab2e569 100644 (file)
 #include <glibmm/i18n.h>
 
 #include "panel.h"
+#include "../../icon-size.h"
 #include "../../prefs-utils.h"
 
 namespace Inkscape {
 namespace UI {
 namespace Widget {
 
+static const int PANEL_SETTING_SIZE = 0;
+static const int PANEL_SETTING_MODE = 1;
+static const int PANEL_SETTING_WRAP = 2;
+static const int PANEL_SETTING_NEXTFREE = 3;
+
 /**
  *    Construct a Panel
  *
  *    \param label Label.
  */
 
-Panel::Panel(const gchar *prefs_path) :
+Panel::Panel() :
     _prefs_path(NULL),
+    _menuDesired(false),
+    _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
+    menu(0),
     _fillable(0)
 {
-    _prefs_path = prefs_path;
     init();
 }
 
-Panel::Panel() :
-    _prefs_path(NULL),
+Panel::Panel( Glib::ustring const &label, gchar const* prefs_path, bool menuDesired ) :
+    _prefs_path(prefs_path),
+    _menuDesired(menuDesired),
+    label(label),
+    _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
+    menu(0),
     _fillable(0)
 {
     init();
 }
 
-Panel::Panel(Glib::ustring const &label) :
-    _prefs_path(NULL),
-    _fillable(0)
+Panel::~Panel()
 {
-    this->label = label;
-    init();
+    delete menu;
 }
 
-Panel::~Panel()
+void Panel::_popper(GdkEventButton* event)
 {
+    if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 1) ) {
+        if (menu) {
+            menu->popup( event->button, event->time );
+        }
+    }
 }
 
 void Panel::init()
@@ -64,20 +78,23 @@ void Panel::init()
 
     guint panel_size = 0;
     if (_prefs_path) {
-        panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
+        panel_size = prefs_get_int_attribute_limited( _prefs_path, "panel_size", 1, 0, 10 );
     }
 
     guint panel_mode = 0;
     if (_prefs_path) {
-        panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
+        panel_mode = prefs_get_int_attribute_limited( _prefs_path, "panel_mode", 1, 0, 10 );
+    }
+
+    guint panel_wrap = 0;
+    if (_prefs_path) {
+        panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 );
     }
 
-    tabButton.set_menu(menu);
-    Gtk::MenuItem* dummy = manage(new Gtk::MenuItem(tmp));
-    menu.append( *dummy );
-    menu.append( *manage(new Gtk::SeparatorMenuItem()) );
+    menu = new Gtk::Menu();
     {
         const char *things[] = {
+            N_("tiny"),
             N_("small"),
             N_("medium"),
             N_("large"),
@@ -87,14 +104,14 @@ void Panel::init()
         for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
             Glib::ustring foo(gettext(things[i]));
             Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, foo));
-            menu.append(*single);
+            menu->append(*single);
             if ( i == panel_size ) {
                 single->set_active(true);
             }
-            single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 0, i) );
+            single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_SIZE, i) );
        }
     }
-    menu.append( *manage(new Gtk::SeparatorMenuItem()) );
+    menu->append( *manage(new Gtk::SeparatorMenuItem()) );
     Gtk::RadioMenuItem::Group group;
     Glib::ustring oneLab(_("List"));
     Glib::ustring twoLab(_("Grid"));
@@ -107,18 +124,50 @@ void Panel::init()
         two->set_active(true);
     }
 
-    menu.append( *one );
-    menu.append( *two );
-    menu.append( *manage(new Gtk::SeparatorMenuItem()) );
-    one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 0) );
-    two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 1) );
+    menu->append( *one );
+    nonHorizontal.push_back( one );
+    menu->append( *two );
+    nonHorizontal.push_back( two );
+    Gtk::MenuItem* sep = manage( new Gtk::SeparatorMenuItem());
+    menu->append( *sep );
+    nonHorizontal.push_back( sep );
+    one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_MODE, 0) );
+    two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_MODE, 1) );
+
+    {
+        Glib::ustring wrapLab(_("Wrap"));
+        Gtk::CheckMenuItem *check = manage(new Gtk::CheckMenuItem(wrapLab));
+        check->set_active( panel_wrap );
+        menu->append( *check );
+        nonVertical.push_back(check);
+
+        check->signal_toggled().connect( sigc::bind<Gtk::CheckMenuItem*>(sigc::mem_fun(*this, &Panel::_wrapToggled), check) );
+
+        sep = manage( new Gtk::SeparatorMenuItem());
+        menu->append( *sep );
+        nonVertical.push_back( sep );
+    }
+
+    menu->show_all_children();
+    for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+        (*iter)->hide();
+    }
 
     //closeButton.set_label("X");
 
     topBar.pack_start(tabTitle);
 
     //topBar.pack_end(closeButton, false, false);
-    topBar.pack_end(tabButton, false, false);
+
+
+    if ( _menuDesired ) {
+        topBar.pack_end(menuPopper, false, false);
+        Gtk::Frame* outliner = manage(new Gtk::Frame());
+        outliner->set_shadow_type( Gtk::SHADOW_ETCHED_IN );
+        outliner->add( _tempArrow );
+        menuPopper.add( *outliner );
+        menuPopper.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &Panel::_popper) );
+    }
 
     pack_start( topBar, false, false );
 
@@ -131,8 +180,9 @@ void Panel::init()
 
     show_all_children();
 
-    bounceCall (0, panel_size);
-    bounceCall (1, panel_mode);
+    bounceCall( PANEL_SETTING_SIZE, panel_size );
+    bounceCall( PANEL_SETTING_MODE, panel_mode );
+    bounceCall( PANEL_SETTING_WRAP, panel_wrap );
 }
 
 void Panel::setLabel(Glib::ustring const &label)
@@ -151,25 +201,45 @@ void Panel::setOrientation( Gtk::AnchorType how )
             case Gtk::ANCHOR_NORTH:
             case Gtk::ANCHOR_SOUTH:
             {
-                tabButton.reference();
-                topBar.remove(tabButton);
-                rightBar.pack_start(tabButton, false, false);
-                tabButton.unreference();
-
+                if ( _menuDesired ) {
+                    menuPopper.reference();
+                    topBar.remove(menuPopper);
+                    rightBar.pack_start(menuPopper, false, false);
+                    menuPopper.unreference();
+
+                    for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
+                        (*iter)->hide();
+                    }
+                    for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+                        (*iter)->show();
+                    }
+                }
+                // Ensure we are not in "list" mode
+                bounceCall( PANEL_SETTING_MODE, 1 );
                 topBar.remove(tabTitle);
             }
             break;
 
             default:
-                ; // nothing for now
+            {
+                if ( _menuDesired ) {
+                    for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
+                        (*iter)->show();
+                    }
+                    for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+                        (*iter)->hide();
+                    }
+                }
+            }
         }
     }
 }
 
 void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
 {
-    menu.append( *item );
-    item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + 2, id) );
+    menu->append( *item );
+    item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + PANEL_SETTING_NEXTFREE, id) );
+    item->show();
 }
 
 void Panel::restorePanelPrefs()
@@ -182,37 +252,49 @@ void Panel::restorePanelPrefs()
     if (_prefs_path) {
         panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
     }
-    bounceCall (0, panel_size);
-    bounceCall (1, panel_mode);
+    guint panel_wrap = 0;
+    if (_prefs_path) {
+        panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 );
+    }
+    bounceCall( PANEL_SETTING_SIZE, panel_size );
+    bounceCall( PANEL_SETTING_MODE, panel_mode );
+    bounceCall( PANEL_SETTING_WRAP, panel_wrap );
 }
 
 void Panel::bounceCall(int i, int j)
 {
-    menu.set_active(0);
+    menu->set_active(0);
     switch ( i ) {
-    case 0:
-        if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_size", j);
+    case PANEL_SETTING_SIZE:
+        if (_prefs_path) {
+            prefs_set_int_attribute( _prefs_path, "panel_size", j );
+        }
         if ( _fillable ) {
             ViewType currType = _fillable->getPreviewType();
             switch ( j ) {
             case 0:
             {
-                _fillable->setStyle(Gtk::ICON_SIZE_MENU, currType);
+                _fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, currType);
             }
             break;
             case 1:
             {
-                _fillable->setStyle(Gtk::ICON_SIZE_SMALL_TOOLBAR, currType);
+                _fillable->setStyle(Inkscape::ICON_SIZE_MENU, currType);
             }
             break;
             case 2:
             {
-                _fillable->setStyle(Gtk::ICON_SIZE_BUTTON, currType);
+                _fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, currType);
             }
             break;
             case 3:
             {
-                _fillable->setStyle(Gtk::ICON_SIZE_DIALOG, currType);
+                _fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, currType);
+            }
+            break;
+            case 4:
+            {
+                _fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, currType);
             }
             break;
             default:
@@ -220,10 +302,12 @@ void Panel::bounceCall(int i, int j)
             }
         }
         break;
-    case 1:
-        if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_mode", j);
+    case PANEL_SETTING_MODE:
+        if (_prefs_path) {
+            prefs_set_int_attribute (_prefs_path, "panel_mode", j);
+        }
         if ( _fillable ) {
-            Gtk::BuiltinIconSize currSize = _fillable->getPreviewSize();
+            Inkscape::IconSize currSize = _fillable->getPreviewSize();
             switch ( j ) {
             case 0:
             {
@@ -240,8 +324,24 @@ void Panel::bounceCall(int i, int j)
             }
         }
         break;
+    case PANEL_SETTING_WRAP:
+        if (_prefs_path) {
+            prefs_set_int_attribute (_prefs_path, "panel_wrap", j ? 1 : 0);
+        }
+        if ( _fillable ) {
+            _fillable->setWrap( j );
+        }
+        break;
     default:
-        _handleAction( i - 2, j );
+        _handleAction( i - PANEL_SETTING_NEXTFREE, j );
+    }
+}
+
+
+void Panel::_wrapToggled(Gtk::CheckMenuItem* toggler)
+{
+    if ( toggler ) {
+        bounceCall( PANEL_SETTING_WRAP, toggler->get_active() ? 1 : 0 );
     }
 }