Browse files

HistoryView: add a "show" button which activates the selected row

  • Loading branch information...
1 parent 4987809 commit cac2e7e75a8dea45b867d8d7c1dac64b67ac9494 @stfacc committed Oct 14, 2011
Showing with 60 additions and 10 deletions.
  1. +39 −8 data/pixasso-history-view.ui
  2. +18 −1 src/pixasso-history-view.cpp
  3. +3 −1 src/pixasso-history-view.h
View
47 data/pixasso-history-view.ui
@@ -19,6 +19,45 @@
<class name="inline-toolbar"/>
</style>
<child>
+ <object class="GtkToolItem" id="snippet-button-group">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox" id="snippet-button-box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkButton" id="show-button">
+ <property name="tooltip_markup" translatable="yes">Show selected snippet in editor</property>
+ <property name="tooltip_text">Show selected snippet in editor</property>
+ <property name="label" translatable="yes">Show</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="remove-button">
+ <property name="visible">True</property>
+ <property name="tooltip_markup" translatable="yes">Permanently delete selected snippets</property>
+ <property name="tooltip_text">Permanently delete selected snippets</property>
+ <child>
+ <object class="GtkImage" id="remove-button-image">
+ <property name="icon_size">1</property>
+ <property name="icon_name">user-trash-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorToolItem" id="separator-item">
+ <property name="draw">False</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkToolItem" id="clear-button-item">
<property name="visible">True</property>
<property name="tooltip_markup" translatable="yes">Permanently delete all snippets</property>
@@ -30,13 +69,5 @@
</child>
</object>
</child>
- <child>
- <object class="GtkToolButton" id="remove-button">
- <property name="visible">True</property>
- <property name="icon_name">user-trash-symbolic</property>
- <property name="tooltip_markup" translatable="yes">Permanently delete selected snippets</property>
- <property name="tooltip_text">Permanently delete selected snippets</property>
- </object>
- </child>
</object>
</interface>
View
19 src/pixasso-history-view.cpp
@@ -111,6 +111,11 @@ HistoryView::HistoryView (Glib::RefPtr<History> &history)
((Gtk::Button *) widget)->signal_clicked ()
.connect (sigc::mem_fun (*this, &HistoryView::on_clear_button_clicked));
+ refBuilder->get_widget ("show-button", show_button);
+ show_button->set_sensitive (false);
+ show_button->signal_clicked ()
+ .connect (sigc::mem_fun (*this, &HistoryView::on_show_button_clicked));
+
refBuilder->get_widget ("remove-button", remove_button);
remove_button->set_sensitive (false);
remove_button->signal_clicked ()
@@ -128,7 +133,10 @@ HistoryView::get_treeview ()
void
HistoryView::on_selection_changed ()
{
- remove_button->set_sensitive (m_TreeView.get_selection ()->count_selected_rows () > 0);
+ gint selected_rows = m_TreeView.get_selection ()->count_selected_rows ();
+
+ remove_button->set_sensitive (selected_rows > 0);
+ show_button->set_sensitive (selected_rows == 1);
}
void
@@ -153,6 +161,15 @@ HistoryView::on_clear_button_clicked ()
}
void
+HistoryView::on_show_button_clicked ()
+{
+ // The button activating this callback is sensitive
+ // only when the selection contains exactly one element
+ std::vector<Gtk::TreeModel::Path> row_paths = m_TreeView.get_selection ()->get_selected_rows ();
+ m_TreeView.row_activated (row_paths[0], *(m_TreeView.get_column (0)));
+}
+
+void
HistoryView::on_remove_button_clicked ()
{
Gtk::Window *parent = (Gtk::Window *) get_toplevel ();
View
4 src/pixasso-history-view.h
@@ -41,11 +41,13 @@ class HistoryView : public Gtk::Grid
protected:
Gtk::TreeView m_TreeView;
- Gtk::ToolButton *remove_button;
+ Gtk::Button *show_button;
+ Gtk::Button *remove_button;
Glib::RefPtr<History> history_model;
void on_selection_changed ();
void on_clear_button_clicked ();
+ void on_show_button_clicked ();
void on_remove_button_clicked ();
};

0 comments on commit cac2e7e

Please sign in to comment.