main.vala 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. namespace Effector {
  2. [GtkTemplate (ui="/de/grindhold/effector/ui/mainwindow.ui")]
  3. public class MainWindow : Gtk.ApplicationWindow {
  4. private GtkFlow.NodeView nv;
  5. public MainWindow() {
  6. this.nv = new GtkFlow.NodeView();
  7. this.nv_scroll.add(this.nv);
  8. Gtk.TreeIter iter;
  9. foreach (var name in Gegl.list_operations() ) {
  10. this.operation_store.append(out iter);
  11. this.operation_store.set(iter, 0, null, 1, name.dup());
  12. }
  13. Gtk.TargetEntry[] empty = {};
  14. this.operation_view.enable_model_drag_source(
  15. Gdk.ModifierType.BUTTON1_MASK,
  16. empty,
  17. Gdk.DragAction.COPY
  18. );
  19. this.operation_view.drag_data_get.connect(this.cb_drag_operation);
  20. Gtk.drag_source_add_text_targets(this.operation_view);
  21. Gtk.drag_dest_set(this.nv, Gtk.DestDefaults.ALL, empty, Gdk.DragAction.COPY);
  22. this.nv.drag_data_received.connect(this.cb_create_node);
  23. Gtk.drag_dest_add_text_targets(this.nv);
  24. this.show_all();
  25. }
  26. private void cb_drag_operation(Gdk.DragContext ctx, Gtk.SelectionData data, uint info, uint time_) {
  27. var selected_path = this.operation_view.get_selected_items().nth_data(0);
  28. var m = this.operation_view.get_model();
  29. Gtk.TreeIter treeiter;
  30. m.get_iter(out treeiter, selected_path);
  31. GLib.Value name;
  32. m.get_value(treeiter, 1, out name);
  33. data.set_text(name.get_string(),-1);
  34. }
  35. private void cb_create_node(Gdk.DragContext ctx, int x, int y, Gtk.SelectionData data, uint info, uint time_) {
  36. var node = new Effector.Node(data.get_text());
  37. this.nv.add_with_child(node,node.grid);
  38. this.nv.set_node_position(node, x, y);
  39. this.nv.show_types = false;
  40. }
  41. [GtkChild]
  42. private Gtk.IconView operation_view;
  43. [GtkChild]
  44. private Gtk.ListStore operation_store;
  45. [GtkChild]
  46. private Gtk.ScrolledWindow nv_scroll;
  47. [GtkCallback]
  48. public bool cb_quit() {
  49. Gtk.main_quit();
  50. return false;
  51. }
  52. public static void run() {
  53. new MainWindow();
  54. Gtk.main();
  55. }
  56. }
  57. public static int main(string[] argv) {
  58. Gtk.init(ref argv);
  59. Gegl.init(ref argv);
  60. MainWindow.run();
  61. return 0;
  62. }
  63. }