Commit 5addd9d7 authored by Allison Barlow's avatar Allison Barlow

Implemented basic event rename, using a dialog.

parent a6e0078c
......@@ -479,7 +479,7 @@ public class CollectionPage : CheckerboardPage {
action_group.add_actions(child_actions, this);
init_ui_bind("/CollectionMenuBar");
init_context_menu("/CollectionContextMenu");
init_item_context_menu("/CollectionContextMenu");
set_layout_comparator(get_sort_comparator());
......@@ -588,11 +588,6 @@ public class CollectionPage : CheckerboardPage {
LibraryWindow.get_app().switch_to_photo_page(this, thumbnail);
}
public override Gtk.Menu? get_context_menu() {
// don't show a context menu if nothing is selected
return (get_selected_count() != 0) ? base.get_context_menu() : null;
}
protected override bool on_context_invoked(Gtk.Menu context_menu) {
bool selected = (get_selected_count() > 0);
bool revert_possible = can_revert_selected();
......@@ -602,7 +597,7 @@ public class CollectionPage : CheckerboardPage {
set_item_sensitive("/CollectionContextMenu/ContextRotateCounterclockwise", selected);
set_item_sensitive("/CollectionContextMenu/ContextMirror", selected);
set_item_sensitive("/CollectionContextMenu/ContextRevert", selected && revert_possible);
return true;
}
......@@ -1128,5 +1123,6 @@ public class CollectionPage : CheckerboardPage {
return new CompareName();
}
}
}
......@@ -1224,15 +1224,28 @@ public class EventTable : DatabaseTable {
return true;
}
public string? get_name(EventID event_id) {
public string? get_raw_name(EventID event_id) {
Sqlite.Statement stmt;
if (!select_by_id(event_id.id, "name, start_time", out stmt))
if (!select_by_id(event_id.id, "name", out stmt))
return null;
// if no name, pretty up the start time
string name = stmt.column_text(0);
if ((name == null) || (name.length == 0)) {
int64 timet = stmt.column_int64(1);
return (name != "") ? name : null;
}
public string get_name(EventID event_id) {
string name = get_raw_name(event_id);
// if no name, pretty up the start time
if (name == null) {
Sqlite.Statement stmt;
if (!select_by_id(event_id.id, "start_time", out stmt))
return "";
int64 timet = stmt.column_int64(0);
assert(timet != 0);
Time start_time = Time.local((time_t) timet);
......
......@@ -219,6 +219,10 @@ public class Event : Object, Queryable, EventSource {
return event_table.get_name(event_id);
}
public string? get_raw_name() {
return event_table.get_raw_name(event_id);
}
public bool rename(string name) {
bool renamed = event_table.rename(event_id, name);
if (renamed)
......
......@@ -134,7 +134,11 @@ public class EventsDirectoryPage : CheckerboardPage {
{ "ViewMenu", null, "_View", null, null, on_view_menu },
{ "HelpMenu", null, "_Help", null, null, null }
{ "HelpMenu", null, "_Help", null, null, null },
{ "EditMenu", null, "_Edit", null, null, on_edit_menu },
{ "Rename", null, "Rename Event...", "F2", "Rename event", on_rename }
};
private Gtk.Toolbar toolbar = new Gtk.Toolbar();
......@@ -157,6 +161,8 @@ public class EventsDirectoryPage : CheckerboardPage {
Gee.ArrayList<Event> events = Event.fetch_all();
foreach (Event event in events)
add_event(event);
init_item_context_menu("/EventsDirectoryContextMenu");
}
public override void realize() {
......@@ -180,6 +186,13 @@ public class EventsDirectoryPage : CheckerboardPage {
LibraryWindow.get_app().switch_to_event(event.event);
}
protected override bool on_context_invoked(Gtk.Menu context_menu) {
set_item_sensitive("/EventsDirectoryContextMenu/ContextRename", get_selected_count() == 1);
return true;
}
private EventDirectoryItem? get_fullscreen_item() {
Gee.Iterable<LayoutItem> iter = null;
......@@ -224,6 +237,19 @@ public class EventsDirectoryPage : CheckerboardPage {
private void on_view_menu() {
set_item_sensitive("/EventsDirectoryMenuBar/ViewMenu/Fullscreen", get_count() > 0);
}
private void on_edit_menu() {
set_item_sensitive("/EventsDirectoryMenuBar/EditMenu/EventRename", get_selected_count() == 1);
}
private void on_rename() {
foreach (LayoutItem item in get_selected()) {
Event event = ((EventDirectoryItem) item).event;
EventRenameDialog rename_dialog = new EventRenameDialog(event.get_raw_name());
event.rename(rename_dialog.execute());
}
}
private void on_added_event(Event event) {
add_event(event);
......@@ -252,7 +278,9 @@ public class EventPage : CollectionPage {
public Event page_event;
private const Gtk.ActionEntry[] ACTIONS = {
{ "MakePrimary", Resources.MAKE_PRIMARY, "Make _Key Photo for Event", null, null, on_make_primary }
{ "MakePrimary", Resources.MAKE_PRIMARY, "Make _Key Photo for Event", null, null, on_make_primary },
{ "Rename", null, "Rename Event...", "F2", "Rename event", on_rename }
};
public EventPage(Event page_event) {
......@@ -264,6 +292,8 @@ public class EventPage : CollectionPage {
Gee.Iterable<PhotoSource> photos = page_event.get_photos();
foreach (PhotoSource source in photos)
add_photo((LibraryPhoto) source);
init_page_context_menu("/EventContextMenu");
}
protected override void on_photos_menu() {
......@@ -282,5 +312,15 @@ public class EventPage : CollectionPage {
break;
}
}
public void rename(string name) {
page_event.rename(name);
set_page_name(page_event.get_name());
}
private void on_rename() {
EventRenameDialog rename_dialog = new EventRenameDialog(page_event.get_raw_name());
rename(rename_dialog.execute());
}
}
......@@ -123,6 +123,18 @@ public class LibraryWindow : AppWindow {
if (page != null)
page.clear_marker();
}
public virtual string get_page_name() {
if (page == null)
return event.get_name();
return page.get_page_name();
}
public Gtk.Menu? get_page_context_menu() {
if (page == null)
get_page();
return page.get_page_context_menu();
}
}
private class CompareEventPageProxy : Comparator<EventPageProxy> {
......@@ -193,6 +205,7 @@ public class LibraryWindow : AppWindow {
// watch for new & removed events
Event.notifier.added += on_added_event;
Event.notifier.removed += on_event_removed;
Event.notifier.altered += on_event_altered;
// add stored events
Gee.ArrayList<Event> events = Event.fetch_all();
......@@ -571,6 +584,20 @@ public class LibraryWindow : AppWindow {
private void on_event_removed(Event event) {
remove_event_page(event);
}
private void on_event_altered(Event event) {
// refresh sidebar
foreach (EventPageProxy proxy in event_list) {
if (proxy.event.equals(event)) {
SidebarMarker marker = proxy.get_marker();
sidebar.rename(marker, event.get_name());
break;
}
}
// refresh basic properties
basic_properties.update_properties(current_page);
}
private void add_event_page(Event event) {
EventPageProxy event_proxy = new EventPageProxy(event);
......
......@@ -53,8 +53,7 @@ public abstract class Page : Gtk.ScrolledWindow, SidebarPage {
private ulong last_configure_ms = 0;
private bool report_move_finished = false;
private bool report_resize_finished = false;
public virtual signal void selection_changed(int count) {
}
......@@ -473,13 +472,18 @@ public abstract class Page : Gtk.ScrolledWindow, SidebarPage {
public abstract int get_selected_queryable_count();
public abstract Gee.Iterable<Queryable>? get_selected_queryables();
public virtual Gtk.Menu? get_page_context_menu() {
return null;
}
}
public abstract class CheckerboardPage : Page {
private const int AUTOSCROLL_PIXELS = 50;
private const int AUTOSCROLL_TICKS_MSEC = 50;
private Gtk.Menu context_menu = null;
private Gtk.Menu item_context_menu = null;
private Gtk.Menu page_context_menu = null;
private CollectionLayout layout = new CollectionLayout();
private Gtk.Viewport viewport = new Gtk.Viewport(null, null);
private Gee.HashSet<LayoutItem> selected_items = new Gee.HashSet<LayoutItem>();
......@@ -510,12 +514,21 @@ public abstract class CheckerboardPage : Page {
add(viewport);
}
public void init_context_menu(string path) {
context_menu = (Gtk.Menu) ui.get_widget(path);
public void init_item_context_menu(string path) {
item_context_menu = (Gtk.Menu) ui.get_widget(path);
}
public virtual Gtk.Menu? get_context_menu() {
return context_menu;
public void init_page_context_menu(string path) {
page_context_menu = (Gtk.Menu) ui.get_widget(path);
}
public Gtk.Menu? get_context_menu() {
// show page context menu if nothing is selected
return (get_selected_count() != 0) ? item_context_menu : page_context_menu;
}
public override Gtk.Menu? get_page_context_menu() {
return page_context_menu;
}
protected virtual void on_item_activated(LayoutItem item) {
......@@ -930,14 +943,14 @@ public abstract class CheckerboardPage : Page {
// clicked in "dead" space, unselect everything
unselect_all();
}
Gtk.Menu context_menu = get_context_menu();
if (context_menu == null)
return false;
if (!on_context_invoked(context_menu))
return false;
context_menu.popup(null, null, null, event.button, event.time);
return true;
......
......@@ -30,11 +30,16 @@ public interface SidebarPage : Object {
public abstract void set_marker(SidebarMarker marker);
public abstract void clear_marker();
public abstract string get_page_name();
public abstract Gtk.Menu? get_page_context_menu();
}
public class Sidebar : Gtk.TreeView {
private Gtk.TreeStore store = new Gtk.TreeStore(1, typeof(string));
private Gee.HashSet<SidebarPage> pages = new Gee.HashSet<SidebarPage>();
private Gtk.Menu context_menu = null;
public Sidebar() {
set_model(store);
......@@ -248,5 +253,82 @@ public class Sidebar : Gtk.TreeView {
// which is unselectable
return locate_page(path) != null;
}
protected Gtk.Menu? get_context_menu(Gdk.EventButton event) {
int x, y, cell_x, cell_y;
Gdk.ModifierType mask;
event.window.get_pointer(out x, out y, out mask);
Gtk.TreePath path;
get_path_at_pos(x, y, out path, null, out cell_x, out cell_y);
SidebarPage page = locate_page(path);
return (page != null) ? page.get_page_context_menu() : null;
}
private override bool button_press_event(Gdk.EventButton event) {
// single right click
if (event.button == 3 && event.type == Gdk.EventType.BUTTON_PRESS) {
context_menu = get_context_menu(event);
if (context_menu == null)
return false;
context_menu.popup(null, null, null, event.button, event.time);
return false;
}
return base.button_press_event(event);
}
public void rename(SidebarMarker marker, string name) {
// set up the columns
Gtk.TreeIter iter;
store.get_iter(out iter, marker.get_path());
store.set(iter, 0, name);
}
}
public class EventRenameDialog : Gtk.Dialog {
Gtk.Entry name_entry;
public EventRenameDialog(string? event_name) {
set_modal(true);
add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK);
set_title("Rename Event");
Gtk.Label name_label = new Gtk.Label("Name:");
name_entry = new Gtk.Entry();
if (event_name != null)
name_entry.set_text(event_name);
name_entry.set_activates_default(true);
Gtk.HBox query = new Gtk.HBox(false, 0);
query.pack_start(name_label, false, false, 3);
query.pack_start(name_entry, false, false, 3);
set_default_response(Gtk.ResponseType.OK);
vbox.pack_start(query, true, false, 6);
}
public string execute() {
show_all();
string event_name = name_entry.get_text();
int response = run();
if (response == Gtk.ResponseType.OK) {
event_name = name_entry.get_text();
}
destroy();
return event_name;
}
}
......@@ -5,12 +5,22 @@
<separator />
<menuitem name="MakePrimary" action="MakePrimary" />
</menu>
<menu name="EditMenu" action="EditMenu">
<separator />
<menuitem name="EventRename" action="Rename" />
</menu>
</menubar>
<popup name="CollectionContextMenu">
<separator />
<menuitem name="ContextMakePrimary" action="MakePrimary" />
</popup>
<popup name="EventContextMenu">
<menuitem name="ContextRename" action="Rename" />
</popup>
</ui>
......@@ -6,6 +6,10 @@
<separator />
<menuitem name="Quit" action="CommonQuit" />
</menu>
<menu name="EditMenu" action="EditMenu">
<menuitem name="EventRename" action="Rename" />
</menu>
<menu name="ViewMenu" action="ViewMenu">
<menuitem name="DisplayBasicProperties" action="CommonDisplayBasicProperties" />
......@@ -25,5 +29,10 @@
</menu>
</menubar>
<popup name="EventsDirectoryContextMenu">
<separator />
<menuitem name="ContextRename" action="Rename" />
</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