Commit 310df30e authored by Wolfgang Steitz's avatar Wolfgang Steitz Committed by Jim Nelson

Symbolic icons in sidebar rendered selection color: Refs bgo#720771

parent 0ce90683
...@@ -20,7 +20,7 @@ public abstract class FolderList.AbstractFolderEntry : Geary.BaseObject, Sidebar ...@@ -20,7 +20,7 @@ public abstract class FolderList.AbstractFolderEntry : Geary.BaseObject, Sidebar
public abstract string? get_sidebar_tooltip(); public abstract string? get_sidebar_tooltip();
public abstract Icon? get_sidebar_icon(); public abstract string? get_sidebar_icon();
public abstract int get_count(); public abstract int get_count();
......
...@@ -17,8 +17,7 @@ public class FolderList.AccountBranch : Sidebar.Branch { ...@@ -17,8 +17,7 @@ public class FolderList.AccountBranch : Sidebar.Branch {
bool rtl = Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL; bool rtl = Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL;
this.account = account; this.account = account;
user_folder_group = new SpecialGrouping(2, "", user_folder_group = new SpecialGrouping(2, "", rtl ? "tag-rtl-symbolic" : "tag-symbolic");
IconFactory.instance.get_custom_icon(rtl ? "tag-rtl-symbolic" : "tag-symbolic", IconFactory.ICON_SIDEBAR));
folder_entries = new Gee.HashMap<Geary.FolderPath, FolderEntry>(); folder_entries = new Gee.HashMap<Geary.FolderPath, FolderEntry>();
account.information.notify["nickname"].connect(on_nicknamed_changed); account.information.notify["nickname"].connect(on_nicknamed_changed);
......
...@@ -43,39 +43,39 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In ...@@ -43,39 +43,39 @@ public class FolderList.FolderEntry : FolderList.AbstractFolderEntry, Sidebar.In
return _("%s, %s").printf(total_msg, unread_msg); return _("%s, %s").printf(total_msg, unread_msg);
} }
public override Icon? get_sidebar_icon() { public override string? get_sidebar_icon() {
bool rtl = Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL; bool rtl = Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL;
switch (folder.special_folder_type) { switch (folder.special_folder_type) {
case Geary.SpecialFolderType.NONE: case Geary.SpecialFolderType.NONE:
return IconFactory.instance.get_custom_icon(rtl ? "tag-rtl-symbolic" : "tag-symbolic", IconFactory.ICON_SIDEBAR); return rtl ? "tag-rtl-symbolic" : "tag-symbolic";
case Geary.SpecialFolderType.INBOX: case Geary.SpecialFolderType.INBOX:
return new ThemedIcon("inbox-symbolic"); return "inbox-symbolic";
case Geary.SpecialFolderType.DRAFTS: case Geary.SpecialFolderType.DRAFTS:
return new ThemedIcon("accessories-text-editor-symbolic"); return "accessories-text-editor-symbolic";
case Geary.SpecialFolderType.SENT: case Geary.SpecialFolderType.SENT:
return new ThemedIcon(rtl ? "sent-rtl-symbolic" : "sent-symbolic"); return rtl ? "sent-rtl-symbolic" : "sent-symbolic";
case Geary.SpecialFolderType.FLAGGED: case Geary.SpecialFolderType.FLAGGED:
return new ThemedIcon("starred-symbolic"); return "starred-symbolic";
case Geary.SpecialFolderType.IMPORTANT: case Geary.SpecialFolderType.IMPORTANT:
return new ThemedIcon("task-due-symbolic"); return "task-due-symbolic";
case Geary.SpecialFolderType.ALL_MAIL: case Geary.SpecialFolderType.ALL_MAIL:
return IconFactory.instance.get_custom_icon("archive-symbolic", IconFactory.ICON_SIDEBAR); return "archive-symbolic";
case Geary.SpecialFolderType.SPAM: case Geary.SpecialFolderType.SPAM:
return new ThemedIcon(rtl ? "spam-rtl-symbolic" : "spam-symbolic"); return rtl ? "spam-rtl-symbolic" : "spam-symbolic";
case Geary.SpecialFolderType.TRASH: case Geary.SpecialFolderType.TRASH:
return new ThemedIcon("user-trash-symbolic"); return "user-trash-symbolic";
case Geary.SpecialFolderType.OUTBOX: case Geary.SpecialFolderType.OUTBOX:
return new ThemedIcon("outbox-symbolic"); return "outbox-symbolic";
default: default:
assert_not_reached(); assert_not_reached();
......
...@@ -44,8 +44,8 @@ public class FolderList.SearchEntry : FolderList.AbstractFolderEntry { ...@@ -44,8 +44,8 @@ public class FolderList.SearchEntry : FolderList.AbstractFolderEntry {
return ngettext("%d result", "%d results", total).printf(total); return ngettext("%d result", "%d results", total).printf(total);
} }
public override Icon? get_sidebar_icon() { public override string? get_sidebar_icon() {
return new ThemedIcon("edit-find-symbolic"); return "edit-find-symbolic";
} }
public override string to_string() { public override string to_string() {
......
...@@ -11,9 +11,9 @@ public class FolderList.SpecialGrouping : Sidebar.Grouping { ...@@ -11,9 +11,9 @@ public class FolderList.SpecialGrouping : Sidebar.Grouping {
// in the list. If < 0, it comes before non-SpecialGroupings. // in the list. If < 0, it comes before non-SpecialGroupings.
public int position { get; private set; } public int position { get; private set; }
public SpecialGrouping(int position, string name, Icon? open_icon, public SpecialGrouping(int position, string name, string? icon,
Icon? closed_icon = null, string? tooltip = null) { string? tooltip = null) {
base(name, open_icon, closed_icon, tooltip); base(name, icon, tooltip);
this.position = position; this.position = position;
} }
......
...@@ -10,13 +10,11 @@ public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry, ...@@ -10,13 +10,11 @@ public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry,
private string name; private string name;
private string? tooltip; private string? tooltip;
private Icon? open_icon; private string? icon;
private Icon? closed_icon;
public Grouping(string name, Icon? open_icon, Icon? closed_icon = null, string? tooltip = null) { public Grouping(string name, string? icon, string? tooltip = null) {
this.name = name; this.name = name;
this.open_icon = open_icon; this.icon = icon;
this.closed_icon = closed_icon ?? open_icon;
this.tooltip = tooltip; this.tooltip = tooltip;
} }
...@@ -37,16 +35,8 @@ public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry, ...@@ -37,16 +35,8 @@ public class Sidebar.Grouping : Object, Sidebar.Entry, Sidebar.ExpandableEntry,
return tooltip; return tooltip;
} }
public Icon? get_sidebar_icon() { public string? get_sidebar_icon() {
return null; return icon;
}
public Icon? get_sidebar_open_icon() {
return open_icon;
}
public Icon? get_sidebar_closed_icon() {
return closed_icon;
} }
public int get_count() { public int get_count() {
......
...@@ -9,15 +9,13 @@ public interface Sidebar.Entry : Object { ...@@ -9,15 +9,13 @@ public interface Sidebar.Entry : Object {
public signal void sidebar_tooltip_changed(string? tooltip); public signal void sidebar_tooltip_changed(string? tooltip);
public signal void sidebar_icon_changed(Icon? icon);
public signal void sidebar_count_changed(int count); public signal void sidebar_count_changed(int count);
public abstract string get_sidebar_name(); public abstract string get_sidebar_name();
public abstract string? get_sidebar_tooltip(); public abstract string? get_sidebar_tooltip();
public abstract Icon? get_sidebar_icon(); public abstract string? get_sidebar_icon();
public abstract int get_count(); public abstract int get_count();
...@@ -31,12 +29,6 @@ public interface Sidebar.Entry : Object { ...@@ -31,12 +29,6 @@ public interface Sidebar.Entry : Object {
} }
public interface Sidebar.ExpandableEntry : Sidebar.Entry { public interface Sidebar.ExpandableEntry : Sidebar.Entry {
public signal void sidebar_open_closed_icons_changed(Icon? open, Icon? closed);
public abstract Icon? get_sidebar_open_icon();
public abstract Icon? get_sidebar_closed_icon();
public abstract bool expand_on_select(); public abstract bool expand_on_select();
} }
......
...@@ -48,9 +48,7 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -48,9 +48,7 @@ public class Sidebar.Tree : Gtk.TreeView {
NAME, NAME,
TOOLTIP, TOOLTIP,
WRAPPER, WRAPPER,
PIXBUF, ICON,
CLOSED_PIXBUF,
OPEN_PIXBUF,
COUNTER, COUNTER,
N_COLUMNS N_COLUMNS
} }
...@@ -59,9 +57,7 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -59,9 +57,7 @@ public class Sidebar.Tree : Gtk.TreeView {
typeof (string), // NAME typeof (string), // NAME
typeof (string?), // TOOLTIP typeof (string?), // TOOLTIP
typeof (EntryWrapper), // WRAPPER typeof (EntryWrapper), // WRAPPER
typeof (Gdk.Pixbuf?), // PIXBUF typeof (string?), // ICON
typeof (Gdk.Pixbuf?), // CLOSED_PIXBUF
typeof (Gdk.Pixbuf?), // OPEN_PIXBUF
typeof (int) // COUNTER typeof (int) // COUNTER
); );
...@@ -69,7 +65,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -69,7 +65,6 @@ public class Sidebar.Tree : Gtk.TreeView {
private Gtk.CellRendererText text_renderer; private Gtk.CellRendererText text_renderer;
private unowned ExternalDropHandler drop_handler; private unowned ExternalDropHandler drop_handler;
private Gtk.Entry? text_entry = null; private Gtk.Entry? text_entry = null;
private Gee.HashMap<string, Gdk.Pixbuf> icon_cache = new Gee.HashMap<string, Gdk.Pixbuf>();
private Gee.HashMap<Sidebar.Entry, EntryWrapper> entry_map = private Gee.HashMap<Sidebar.Entry, EntryWrapper> entry_map =
new Gee.HashMap<Sidebar.Entry, EntryWrapper>(); new Gee.HashMap<Sidebar.Entry, EntryWrapper>();
private Gee.HashMap<Sidebar.Branch, int> branches = new Gee.HashMap<Sidebar.Branch, int>(); private Gee.HashMap<Sidebar.Branch, int> branches = new Gee.HashMap<Sidebar.Branch, int>();
...@@ -102,10 +97,9 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -102,10 +97,9 @@ public class Sidebar.Tree : Gtk.TreeView {
Gtk.TreeViewColumn text_column = new Gtk.TreeViewColumn(); Gtk.TreeViewColumn text_column = new Gtk.TreeViewColumn();
text_column.set_expand(true); text_column.set_expand(true);
Gtk.CellRendererPixbuf icon_renderer = new Gtk.CellRendererPixbuf(); Gtk.CellRendererPixbuf icon_renderer = new Gtk.CellRendererPixbuf();
icon_renderer.follow_state = true;
text_column.pack_start(icon_renderer, false); text_column.pack_start(icon_renderer, false);
text_column.add_attribute(icon_renderer, "pixbuf", Columns.PIXBUF); text_column.add_attribute(icon_renderer, "icon_name", Columns.ICON);
text_column.add_attribute(icon_renderer, "pixbuf_expander_closed", Columns.CLOSED_PIXBUF);
text_column.add_attribute(icon_renderer, "pixbuf_expander_open", Columns.OPEN_PIXBUF);
text_column.set_cell_data_func(icon_renderer, icon_renderer_function); text_column.set_cell_data_func(icon_renderer, icon_renderer_function);
text_renderer = new Gtk.CellRendererText(); text_renderer = new Gtk.CellRendererText();
text_renderer.editing_canceled.connect(on_editing_canceled); text_renderer.editing_canceled.connect(on_editing_canceled);
...@@ -155,11 +149,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -155,11 +149,6 @@ public class Sidebar.Tree : Gtk.TreeView {
popup_menu.connect(on_context_menu_keypress); popup_menu.connect(on_context_menu_keypress);
if (icon_theme == null)
icon_theme = Gtk.IconTheme.get_default();
icon_theme.changed.connect(on_theme_change);
drag_begin.connect(on_drag_begin); drag_begin.connect(on_drag_begin);
drag_end.connect(on_drag_end); drag_end.connect(on_drag_end);
drag_motion.connect(on_drag_motion); drag_motion.connect(on_drag_motion);
...@@ -168,7 +157,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -168,7 +157,6 @@ public class Sidebar.Tree : Gtk.TreeView {
~Tree() { ~Tree() {
text_renderer.editing_canceled.disconnect(on_editing_canceled); text_renderer.editing_canceled.disconnect(on_editing_canceled);
text_renderer.editing_started.disconnect(on_editing_started); text_renderer.editing_started.disconnect(on_editing_started);
icon_theme.changed.disconnect(on_theme_change);
} }
public void icon_renderer_function(Gtk.CellLayout layout, Gtk.CellRenderer renderer, Gtk.TreeModel model, Gtk.TreeIter iter) { public void icon_renderer_function(Gtk.CellLayout layout, Gtk.CellRenderer renderer, Gtk.TreeModel model, Gtk.TreeIter iter) {
...@@ -492,7 +480,7 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -492,7 +480,7 @@ public class Sidebar.Tree : Gtk.TreeView {
load_entry_icons(assoc_iter); load_entry_icons(assoc_iter);
entry.sidebar_tooltip_changed.connect(on_sidebar_tooltip_changed); entry.sidebar_tooltip_changed.connect(on_sidebar_tooltip_changed);
entry.sidebar_icon_changed.connect(on_sidebar_icon_changed);
entry.sidebar_name_changed.connect(on_sidebar_name_changed); entry.sidebar_name_changed.connect(on_sidebar_name_changed);
entry.sidebar_count_changed.connect(on_sidebar_count_changed); entry.sidebar_count_changed.connect(on_sidebar_count_changed);
...@@ -500,10 +488,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -500,10 +488,6 @@ public class Sidebar.Tree : Gtk.TreeView {
if (emphasizable != null) if (emphasizable != null)
emphasizable.is_emphasized_changed.connect(on_is_emphasized_changed); emphasizable.is_emphasized_changed.connect(on_is_emphasized_changed);
Sidebar.ExpandableEntry? expandable = entry as Sidebar.ExpandableEntry;
if (expandable != null)
expandable.sidebar_open_closed_icons_changed.connect(on_sidebar_open_closed_icons_changed);
entry.grafted(this); entry.grafted(this);
} }
...@@ -607,18 +591,12 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -607,18 +591,12 @@ public class Sidebar.Tree : Gtk.TreeView {
entry.pruned(this); entry.pruned(this);
entry.sidebar_tooltip_changed.disconnect(on_sidebar_tooltip_changed); entry.sidebar_tooltip_changed.disconnect(on_sidebar_tooltip_changed);
entry.sidebar_icon_changed.disconnect(on_sidebar_icon_changed);
entry.sidebar_name_changed.disconnect(on_sidebar_name_changed);
entry.sidebar_count_changed.disconnect(on_sidebar_count_changed); entry.sidebar_count_changed.disconnect(on_sidebar_count_changed);
Sidebar.EmphasizableEntry? emphasizable = entry as Sidebar.EmphasizableEntry; Sidebar.EmphasizableEntry? emphasizable = entry as Sidebar.EmphasizableEntry;
if (emphasizable != null) if (emphasizable != null)
emphasizable.is_emphasized_changed.disconnect(on_is_emphasized_changed); emphasizable.is_emphasized_changed.disconnect(on_is_emphasized_changed);
Sidebar.ExpandableEntry? expandable = entry as Sidebar.ExpandableEntry;
if (expandable != null)
expandable.sidebar_open_closed_icons_changed.disconnect(on_sidebar_open_closed_icons_changed);
bool removed = entry_map.unset(entry); bool removed = entry_map.unset(entry);
assert(removed); assert(removed);
} }
...@@ -748,22 +726,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -748,22 +726,6 @@ public class Sidebar.Tree : Gtk.TreeView {
Geary.HTML.escape_markup(tooltip) : null); Geary.HTML.escape_markup(tooltip) : null);
} }
private void on_sidebar_icon_changed(Sidebar.Entry entry, Icon? icon) {
EntryWrapper? wrapper = get_wrapper(entry);
assert(wrapper != null);
store.set(wrapper.get_iter(), Columns.PIXBUF, fetch_icon_pixbuf(icon));
}
private void on_sidebar_open_closed_icons_changed(Sidebar.ExpandableEntry entry, Icon? open,
Icon? closed) {
EntryWrapper? wrapper = get_wrapper(entry);
assert(wrapper != null);
store.set(wrapper.get_iter(), Columns.OPEN_PIXBUF, fetch_icon_pixbuf(open));
store.set(wrapper.get_iter(), Columns.CLOSED_PIXBUF, fetch_icon_pixbuf(closed));
}
private void rename_entry(Sidebar.Entry entry) { private void rename_entry(Sidebar.Entry entry) {
EntryWrapper? wrapper = get_wrapper(entry); EntryWrapper? wrapper = get_wrapper(entry);
assert(wrapper != null); assert(wrapper != null);
...@@ -786,58 +748,12 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -786,58 +748,12 @@ public class Sidebar.Tree : Gtk.TreeView {
store.set(wrapper.get_iter(), Columns.COUNTER, entry.get_count()); store.set(wrapper.get_iter(), Columns.COUNTER, entry.get_count());
} }
private Gdk.Pixbuf? fetch_icon_pixbuf(GLib.Icon? gicon) {
if (gicon == null)
return null;
try {
Gdk.Pixbuf? icon = icon_cache.get(gicon.to_string());
if (icon != null)
return icon;
Gtk.IconInfo? info = icon_theme.lookup_by_gicon(gicon, ICON_SIZE, 0);
if (info == null)
return null;
icon = info.load_symbolic_for_context(get_style_context());
if (icon == null)
return null;
icon_cache.set(gicon.to_string(), icon);
return icon;
} catch (Error err) {
warning("Unable to load icon %s: %s", gicon.to_string(), err.message);
return null;
}
}
private void load_entry_icons(Gtk.TreeIter iter) { private void load_entry_icons(Gtk.TreeIter iter) {
EntryWrapper? wrapper = get_wrapper_at_iter(iter); EntryWrapper? wrapper = get_wrapper_at_iter(iter);
if (wrapper == null) if (wrapper == null)
return; return;
string? icon = wrapper.entry.get_sidebar_icon();
Icon? icon = wrapper.entry.get_sidebar_icon(); store.set(iter, Columns.ICON, icon);
Icon? open = null;
Icon? closed = null;
Sidebar.ExpandableEntry? expandable = wrapper.entry as Sidebar.ExpandableEntry;
if (expandable != null) {
open = expandable.get_sidebar_open_icon();
closed = expandable.get_sidebar_closed_icon();
}
if (open == null)
open = icon;
if (closed == null)
closed = icon;
store.set(iter, Columns.PIXBUF, fetch_icon_pixbuf(icon));
store.set(iter, Columns.OPEN_PIXBUF, fetch_icon_pixbuf(open));
store.set(iter, Columns.CLOSED_PIXBUF, fetch_icon_pixbuf(closed));
} }
private void load_branch_icons(Gtk.TreeIter iter) { private void load_branch_icons(Gtk.TreeIter iter) {
...@@ -851,15 +767,6 @@ public class Sidebar.Tree : Gtk.TreeView { ...@@ -851,15 +767,6 @@ public class Sidebar.Tree : Gtk.TreeView {
} }
} }
private void on_theme_change() {
Gtk.TreeIter iter;
if (store.get_iter_first(out iter)) {
do {
load_branch_icons(iter);
} while (store.iter_next(ref iter));
}
}
private bool on_selection(Gtk.TreeSelection selection, Gtk.TreeModel model, Gtk.TreePath path, private bool on_selection(Gtk.TreeSelection selection, Gtk.TreeModel model, Gtk.TreePath path,
bool path_currently_selected) { bool path_currently_selected) {
// only allow selection if a page is selectable // only allow selection if a page is selectable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment