[blam/gtk-builder: 56/56] Start binding the channel popup menu



commit 87ed2774be007e660fe0a7e59465ee2c08e53bbf
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Sun Oct 6 19:37:32 2013 +0200

    Start binding the channel popup menu

 blam.csproj              |    6 ++
 src/Blam.cs              |    2 +-
 src/BuilderExtensions.cs |   16 ++++
 src/Channel.cs           |    2 +-
 src/ChannelDialog.cs     |   28 ++++++-
 src/ChannelList.cs       |   51 +++++++++++
 src/Makefile.am          |    3 +-
 src/blam.ui              |  215 ++++++++++++++++++++++++++++++++++++++++++++
 src/edit-channel.ui      |  224 ++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 543 insertions(+), 4 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index da31d49..382a59b 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -136,6 +136,12 @@
     <EmbeddedResource Include="gtk-gui\gui.stetic">
       <LogicalName>gui.stetic</LogicalName>
     </EmbeddedResource>
+    <EmbeddedResource Include="src\edit-channel.ui">
+      <LogicalName>edit-channel.ui</LogicalName>
+    </EmbeddedResource>
+    <EmbeddedResource Include="src\blam.ui">
+      <LogicalName>blam.ui</LogicalName>
+    </EmbeddedResource>
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>
diff --git a/src/Blam.cs b/src/Blam.cs
index fb337f3..7fd2884 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -28,7 +28,7 @@ namespace Blam
                        ItemStore.Load();
 
                        var bld = new Builder();
-                       bld.AddFromFile("/home/carlos/progs/blam/blam/src/blam.ui");
+                       bld.AddFromResource("blam.ui");
 
                        MainWindow = bld.GetObject<Window>("main-window");
                        MainWindow.DeleteEvent += OnDelete;
diff --git a/src/BuilderExtensions.cs b/src/BuilderExtensions.cs
index 13ccc5d..5b0b231 100644
--- a/src/BuilderExtensions.cs
+++ b/src/BuilderExtensions.cs
@@ -10,5 +10,21 @@ namespace Blam
                {
                        return (T) builder.GetObject(name);
                }
+
+               public static void AddFromResource(this Builder builder, string name)
+               {
+                       var assembly = System.Reflection.Assembly.GetCallingAssembly();
+
+                       System.IO.Stream s = assembly.GetManifestResourceStream(name);
+                       if (s == null)
+                               throw new ArgumentException("No resource named " + name);
+
+                       int size = (int) s.Length;
+                       byte[] buffer = new byte[size];
+                       s.Read(buffer, 0, size);
+                       s.Close();
+
+                       builder.AddFromString(System.Text.Encoding.UTF8.GetString(buffer));
+               }
        }
 }
diff --git a/src/Channel.cs b/src/Channel.cs
index 76f9207..1ccc5cf 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -327,7 +327,7 @@ namespace Imendio.Blam {
 
                                return Update(feed);
                        } catch (Exception e) {
-                               Console.WriteLine("Failed to get feed {0}: {1}", Name, e.Message);
+                               Console.WriteLine("Failed to get feed {0}: {1}\n{2}", Name, e.Message, 
e.StackTrace);
                                return false;
                        }
                }
diff --git a/src/ChannelDialog.cs b/src/ChannelDialog.cs
index dc3728b..4c5d5c6 100644
--- a/src/ChannelDialog.cs
+++ b/src/ChannelDialog.cs
@@ -5,12 +5,38 @@
 // (C) 2004 Imendio HB
 //
 
-using Gdk;
 using Gtk;
+using Gdk;
 using Glade;
 using System;
 using System.Text;
 
+namespace Blam
+{
+       using Channel = Imendio.Blam.Channel;
+
+       public class ChannelDialog
+       {
+               Dialog Dialog;
+
+               public ChannelDialog()
+               {
+                       var bld = new Builder();
+                       bld.AddFromResource("edit-channel.ui");
+
+                       Dialog = bld.GetObject<Dialog>("edit-channel");
+
+                       var image = bld.GetObject<Gtk.Image>("edit-channel-image");
+                       image.Pixbuf = Pixbuf.LoadFromResource("blam-edit-news.png");
+               }
+
+               public void Show (Channel channel)
+               {
+                       Dialog.ShowAll();
+               }
+       }
+}
+
 namespace Imendio.Blam {
     public class ChannelDialog {
     [Widget] Gtk.Dialog channelDialog = null;
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index 574b2f6..f8f9370 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -21,10 +21,12 @@ namespace Blam
        using Channel = Imendio.Blam.Channel;
        using IChannel = Imendio.Blam.IChannel;
        using ChannelGroup = Imendio.Blam.ChannelGroup;
+       using ChannelMenu = Imendio.Blam.ChannelMenu;
 
        public class FeedList : Gtk.TreeView
        {
                TreeViewColumn name_col;
+               ChannelMenu Popup;
 
                public FeedList(IEnumerable<Channel> channels, IEnumerable<ChannelGroup> groups)
                {
@@ -59,6 +61,18 @@ namespace Blam
                                foreach(IChannel chan in group.Channels)
                                        chan.Iter = model.AppendValues(group.Iter, chan);
                        }
+
+                       Popup = new ChannelMenu();
+                       Popup.RefreshSelected += () => GetSelected().RefreshAsync();
+                       Popup.MarkAsReadSelected += () => GetSelected().MarkAsRead();
+                       Popup.EditSelected += () => {
+                               var chan = GetSelected();
+                               if (chan is ChannelGroup)
+                                       return;
+
+                               var diag = new ChannelDialog();
+                               diag.Show((Channel)chan);
+                       };
                }
 
                void NamesCellDataFunc(TreeViewColumn col, CellRenderer _cell, TreeModel model, TreeIter iter)
@@ -83,6 +97,43 @@ namespace Blam
                        cell.Weight = (int)weight;
                }
 
+               public IChannel GetSelected ()
+               {
+                       TreeModel model;
+                       TreeIter  iter;
+
+                       if (!this.Selection.GetSelected(out model, out iter)) {
+                               return null;
+                       }
+
+                       return(IChannel)model.GetValue(iter, 0);
+               }
+
+               protected override bool OnButtonPressEvent (EventButton bEvent)
+               {
+                       switch (bEvent.Button) {
+                               case 1:
+                                       if (bEvent.Type == EventType.TwoButtonPress) {
+                                               //EditChannelCb();
+                                       } else {
+                                               return base.OnButtonPressEvent (bEvent);
+                                       }
+                                       break;
+                                       case 3:
+                                       TreePath path;
+
+                                       if (!GetPathAtPos ((int) bEvent.X, (int) bEvent.Y, out path)) {
+                                               return false;
+                                       }
+
+                                       this.Selection.SelectPath (path);
+
+                                       Popup.Activate (bEvent);
+                                       return false;
+                       }
+
+                       return false;
+               }
        }
 }
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 816525b..cf44157 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,8 @@ GLADE_BUILD = $(srcdir)/blam.glade
 RESOURCES = \
            -resource:$(GLADE_BUILD),blam.glade                                  \
            -resource:$(top_srcdir)/icons/blam-add-news.png,blam-add-news.png      \
-           -resource:$(top_srcdir)/icons/blam-edit-news.png,blam-edit-news.png
+           -resource:$(top_srcdir)/icons/blam-edit-news.png,blam-edit-news.png \
+           -resource:blam.ui,edit-channel.ui
 
 ASSEMBLIES = \
             -r:System.Web   \
diff --git a/src/blam.ui b/src/blam.ui
index 39830ef..b5c96db 100644
--- a/src/blam.ui
+++ b/src/blam.ui
@@ -2,6 +2,221 @@
 <interface>
   <requires lib="gtk+" version="2.24"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkDialog" id="edit-channel">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel-button">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok-button">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkImage" id="edit-channel-image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="stock">gtk-missing-image</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Change the fields to update channel 
information</property>
+                <property name="single_line_mode">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="n_rows">4</property>
+            <property name="n_columns">2</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Name</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">URL</property>
+              </object>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Username</property>
+              </object>
+              <packing>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label5">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Password</property>
+              </object>
+              <packing>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry3">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry4">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">cancel-button</action-widget>
+      <action-widget response="0">ok-button</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkWindow" id="main-window">
     <property name="can_focus">False</property>
     <child>
diff --git a/src/edit-channel.ui b/src/edit-channel.ui
new file mode 100644
index 0000000..5ca2178
--- /dev/null
+++ b/src/edit-channel.ui
@@ -0,0 +1,224 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.24"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkDialog" id="edit-channel">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox3">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel-button">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok-button">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox1">
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkImage" id="edit-channel-image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="stock">gtk-missing-image</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Change the fields to update channel 
information</property>
+                <property name="single_line_mode">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="n_rows">4</property>
+            <property name="n_columns">2</property>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Name</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">URL</property>
+              </object>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Username</property>
+              </object>
+              <packing>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label5">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Password</property>
+              </object>
+              <packing>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="invisible_char_set">True</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry2">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="invisible_char_set">True</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry3">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="invisible_char_set">True</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="entry4">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+                <property name="invisible_char_set">True</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="secondary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">True</property>
+                <property name="secondary_icon_sensitive">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">cancel-button</action-widget>
+      <action-widget response="0">ok-button</action-widget>
+    </action-widgets>
+  </object>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]