Commit ee5ecac9 authored by Allison Barlow's avatar Allison Barlow

fixes tickets #1556 (don't allow Page Up/Down to affect zoom slider) and #1576...

fixes tickets #1556 (don't allow Page Up/Down to affect zoom slider) and #1576 (Right click support for import from camera).
parent 49e72d98
......@@ -573,6 +573,14 @@ public abstract class CollectionPage : CheckerboardPage {
bool handled = true;
switch (Gdk.keyval_name(event.keyval)) {
case "Page_Up":
on_page_up();
break;
case "Page_Down":
on_page_down();
break;
case "equal":
case "plus":
case "KP_Add":
......@@ -592,6 +600,17 @@ public abstract class CollectionPage : CheckerboardPage {
return handled ? true : base.on_app_key_pressed(event);
}
protected void on_page_up() {
Gtk.Adjustment vadjustment = get_vadjustment();
vadjustment.set_value(vadjustment.get_value() - vadjustment.get_page_increment());
}
protected void on_page_down() {
Gtk.Adjustment vadjustment = get_vadjustment();
vadjustment.set_value((vadjustment.get_value() + vadjustment.get_page_increment()).clamp(
vadjustment.get_lower(), vadjustment.get_upper() - vadjustment.get_page_size()));
}
public void increase_thumb_size() {
set_thumb_size(scale + MANUAL_STEPPING);
......
......@@ -287,6 +287,8 @@ public class ImportPage : CheckerboardPage {
init_ui("import.ui", "/ImportMenuBar", "ImportActionGroup", create_actions(),
create_toggle_actions());
init_item_context_menu("/ImportContextMenu");
init_page_context_menu("/ImportContextMenu");
// Set up toolbar
Gtk.Toolbar toolbar = get_toolbar();
......@@ -1044,6 +1046,15 @@ public class ImportPage : CheckerboardPage {
if (action != null)
action.set_active(display);
}
public override bool on_context_invoked() {
set_item_sensitive("/ImportContextMenu/ContextImportSelected", !busy &&
get_view().get_selected_count() > 0);
set_item_sensitive("/ImportContextMenu/ContextImportAll", !busy &&
get_view().get_count() > 0);
return base.on_context_invoked();
}
}
#endif
......
......@@ -174,6 +174,12 @@ public class LibraryWindow : AppWindow {
get_page();
return page.get_page_context_menu();
}
public bool popup_context_menu(Gtk.Menu? context_menu, Gdk.EventButton? event = null) {
if (page == null)
get_page();
return page.popup_context_menu(context_menu, event);
}
}
private class SubEventsDirectoryPageStub : PageStub {
......
......@@ -747,9 +747,8 @@ public abstract class Page : Gtk.ScrolledWindow, SidebarPage {
protected bool popup_context_menu(Gtk.Menu? context_menu,
Gdk.EventButton? event = null) {
on_context_invoked();
if (context_menu == null)
if (context_menu == null || !on_context_invoked())
return false;
if (event == null)
......@@ -815,7 +814,8 @@ public abstract class CheckerboardPage : Page {
public Gtk.Menu? get_context_menu() {
// show page context menu if nothing is selected
return (get_view().get_selected_count() != 0) ? get_item_context_menu() : get_page_context_menu();
return (get_view().get_selected_count() != 0) ? get_item_context_menu() :
get_page_context_menu();
}
public virtual Gtk.Menu? get_item_context_menu() {
......@@ -1117,15 +1117,7 @@ public abstract class CheckerboardPage : Page {
}
Gtk.Menu context_menu = get_context_menu();
if (context_menu == null)
return false;
if (!on_context_invoked())
return false;
context_menu.popup(null, null, null, event.button, event.time);
return true;
return popup_context_menu(context_menu, event);
}
protected virtual bool on_mouse_over(CheckerboardItem? item, int x, int y, Gdk.ModifierType mask) {
......
......@@ -34,6 +34,8 @@ public interface SidebarPage : Object {
public abstract string get_page_name();
public abstract Gtk.Menu? get_page_context_menu();
public abstract bool popup_context_menu(Gtk.Menu? context_menu, Gdk.EventButton? event = null);
}
public class Sidebar : Gtk.TreeView {
......@@ -314,42 +316,32 @@ public class Sidebar : Gtk.TreeView {
return path;
}
private bool popup_context_menu(Gtk.Menu? context_menu, Gdk.EventButton? event = null) {
// TODO: share this code with Page, possibly through a contextable interface
if (context_menu == null)
return false;
if (event == null)
context_menu.popup(null, null, null, 0, Gtk.get_current_event_time());
else
context_menu.popup(null, null, null, event.button, event.time);
return true;
}
private bool on_context_menu_keypress() {
Gtk.TreePath path = get_selection().get_selected_rows(null).data;
Gtk.Menu context_menu = get_context_menu(path);
scroll_to_cell(path, null, false, 0, 0);
popup_context_menu(context_menu);
popup_context_menu(path);
return true;
}
protected Gtk.Menu? get_context_menu(Gtk.TreePath path) {
protected bool popup_context_menu(Gtk.TreePath path, Gdk.EventButton? event = null) {
SidebarPage page = locate_page(path);
return (page != null) ? page.get_page_context_menu() : null;
if (page == null)
return false;
Gtk.Menu context_menu = page.get_page_context_menu();
return (context_menu != null) ? page.popup_context_menu(context_menu, event) : false;
}
private override bool button_press_event(Gdk.EventButton event) {
if (event.button == 3 && event.type == Gdk.EventType.BUTTON_PRESS) {
// single right click
popup_context_menu(get_context_menu(get_path_from_event(event)), event);
popup_context_menu(get_path_from_event(event), event);
} else if (event.button == 1 && event.type == Gdk.EventType.2BUTTON_PRESS) {
// double left click
......
......@@ -34,5 +34,10 @@
<menuitem name="About" action="CommonAbout" />
</menu>
</menubar>
<popup name="ImportContextMenu">
<menuitem name="ContextImportSelected" action="ImportSelected" />
<menuitem name="ContextImportAll" action="ImportAll" />
</popup>
</ui>
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