[longomatch] Create a new menu class to reuse it in widgets
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Create a new menu class to reuse it in widgets
- Date: Mon, 7 Jul 2014 11:30:24 +0000 (UTC)
commit b549e7c3f853c8522d62c4adab3b9ad5b9cd008e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Jun 19 14:48:17 2014 +0200
Create a new menu class to reuse it in widgets
LongoMatch.GUI/Gui/Component/Timeline.cs | 48 +-----------
LongoMatch.GUI/Gui/GtkGlue.cs | 35 +++++++++
LongoMatch.GUI/Gui/Menu/PlaysMenu.cs | 123 ++++++++++++++++++++++++++++++
LongoMatch.GUI/LongoMatch.GUI.mdp | 3 +
4 files changed, 164 insertions(+), 45 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/Timeline.cs b/LongoMatch.GUI/Gui/Component/Timeline.cs
index a036343..45e8e1f 100644
--- a/LongoMatch.GUI/Gui/Component/Timeline.cs
+++ b/LongoMatch.GUI/Gui/Component/Timeline.cs
@@ -42,6 +42,7 @@ namespace LongoMatch.Gui.Component
double secondsPerPixel;
uint timeoutID;
Time currentTime, nextCurrentTime;
+ PlaysMenu menu;
public Timeline ()
{
@@ -61,6 +62,7 @@ namespace LongoMatch.Gui.Component
scrolledwindow1.Vadjustment.ValueChanged += HandleScrollEvent;
scrolledwindow1.Hadjustment.ValueChanged += HandleScrollEvent;
timeoutID = 0;
+ menu = new PlaysMenu ();
}
public TimeNode SelectedTimeNode {
@@ -158,51 +160,7 @@ namespace LongoMatch.Gui.Component
void HandleShowMenu (List<Play> plays, Category cat, Time time)
{
- Menu menu;
- MenuItem newPlay, del, tag, addPLN, snapshot, render;
-
- menu = new Menu();
-
- newPlay = new MenuItem(String.Format ("{0} in {1}",
- Catalog.GetString("Add new play"), cat.Name));
- menu.Append(newPlay);
- newPlay.Activated += (sender, e) => Config.EventsBroker.EmitNewTagAtPos (cat, time);
-
- if (plays != null) {
- if (plays.Count == 1) {
- tag = new MenuItem(Catalog.GetString("Edit tags"));
- snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
- tag.Activated += (sender, e) => Config.EventsBroker.EmitTagPlay
(plays[0]);
- snapshot.Activated += (sender, e) =>
Config.EventsBroker.EmitSnapshotSeries (plays[0]);
- menu.Add (tag);
- menu.Add (snapshot);
- }
- if (plays.Count > 0 ) {
- del = new MenuItem (String.Format ("{0} ({1})",
- Catalog.GetString("Delete"), plays.Count));
- del.Activated += (sender, e) => Config.EventsBroker.EmitPlaysDeleted
(plays);
- menu.Add (del);
- addPLN = new MenuItem (String.Format ("{0} ({1})",
- Catalog.GetString("Add to playlist"),
plays.Count));
- addPLN.Activated += (sender, e) =>
Config.EventsBroker.EmitPlayListNodeAdded (plays);
- menu.Add (addPLN);
- render = new MenuItem (String.Format ("{0} ({1})",
- Catalog.GetString("Export to video file"),
plays.Count));
- render.Activated += (sender, e) => EmitRenderPlaylist (plays);
- menu.Add (render);
- }
- }
- menu.ShowAll();
- menu.Popup();
- }
-
- void EmitRenderPlaylist (List<Play> plays)
- {
- PlayList pl = new PlayList();
- foreach (Play p in plays) {
- pl.Add (new PlayListPlay (p, projectFile, true));
- }
- Config.EventsBroker.EmitRenderPlaylist (pl);
+ menu.ShowMenu (plays, cat, time, projectFile);
}
}
}
diff --git a/LongoMatch.GUI/Gui/GtkGlue.cs b/LongoMatch.GUI/Gui/GtkGlue.cs
new file mode 100644
index 0000000..99e659b
--- /dev/null
+++ b/LongoMatch.GUI/Gui/GtkGlue.cs
@@ -0,0 +1,35 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using Gtk;
+using System.Runtime.InteropServices;
+
+namespace LongoMatch
+{
+ public class GtkGlue
+ {
+
+ [DllImport("libgtk-2.0.dll") /* willfully unmapped */ ]
+ static extern void gtk_menu_item_set_label (IntPtr menu, IntPtr label);
+
+ public static void MenuItemSetLabel (MenuItem menu, string label) {
+ gtk_menu_item_set_label (menu.Handle, GLib.Marshaller.StringToFilenamePtr (label));
+ }
+ }
+}
+
diff --git a/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs b/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs
new file mode 100644
index 0000000..954be6b
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Menu/PlaysMenu.cs
@@ -0,0 +1,123 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using Gtk;
+using LongoMatch.Store;
+using LongoMatch.Handlers;
+using Mono.Unix;
+using LongoMatch.Common;
+
+namespace LongoMatch.Gui.Menus
+{
+ public class PlaysMenu: Gtk.Menu
+ {
+
+ MenuItem newPlay, del, tag, addPLN, snapshot, render;
+ List<Play> plays;
+ Category cat;
+ Time time;
+ MediaFile projectFile;
+
+
+ public PlaysMenu ()
+ {
+ CreateMenu ();
+ }
+
+ public void ShowMenu (List<Play> plays) {
+ ShowMenu (plays, null, null, null);
+ }
+
+ public void ShowMenu (List<Play> plays, Category cat, Time time,
+ MediaFile projectFile) {
+ this.plays = plays;
+ this.cat = cat;
+ this.time = time;
+ this.projectFile = projectFile;
+
+ if (cat != null) {
+ string label = String.Format ("{0} in {1}", Catalog.GetString("Add new
play"), cat.Name);
+ GtkGlue.MenuItemSetLabel (newPlay, label);
+ newPlay.Visible = true;
+ } else {
+ newPlay.Visible = false;
+ }
+
+ if (plays == null)
+ plays = new List<Play> ();
+
+ tag.Visible = plays.Count == 1;
+ snapshot.Visible = plays.Count == 1;
+ del.Visible = plays.Count > 0;;
+ addPLN.Visible = plays.Count > 0;;
+ render.Visible = plays.Count > 0;;
+
+ if (plays.Count > 0 ) {
+ string label = String.Format ("{0} ({1})",Catalog.GetString("Delete"),
plays.Count);
+ GtkGlue.MenuItemSetLabel (del, label);
+ label = String.Format ("{0} ({1})",Catalog.GetString("Add to playlist"),
plays.Count);
+ GtkGlue.MenuItemSetLabel (addPLN, label);
+ label = String.Format ("{0} ({1})", Catalog.GetString("Export to video
file"), plays.Count);
+ GtkGlue.MenuItemSetLabel (render, label);
+ }
+ Popup();
+ }
+
+ void CreateMenu () {
+ newPlay = new MenuItem("");
+ Add (newPlay);
+ newPlay.Activated += HandleNePlayActivated;
+
+ tag = new MenuItem(Catalog.GetString("Edit tags"));
+ tag.Activated += (sender, e) => Config.EventsBroker.EmitTagPlay (plays[0]);
+ Add (tag);
+
+ snapshot = new MenuItem(Catalog.GetString("Export to PGN images"));
+ snapshot.Activated += (sender, e) => Config.EventsBroker.EmitSnapshotSeries
(plays[0]);
+ Add (snapshot);
+
+ del = new MenuItem ("");
+ del.Activated += (sender, e) => Config.EventsBroker.EmitPlaysDeleted (plays);
+ Add (del);
+
+ addPLN = new MenuItem ("");
+ addPLN.Activated += (sender, e) => Config.EventsBroker.EmitPlayListNodeAdded (plays);
+ Add (addPLN);
+
+ render = new MenuItem ("");
+ render.Activated += (sender, e) => EmitRenderPlaylist (plays);
+ Add (render);
+ ShowAll ();
+ }
+
+ void HandleNePlayActivated (object sender, EventArgs e)
+ {
+ Config.EventsBroker.EmitNewTagAtPos (cat, time);
+ }
+
+ void EmitRenderPlaylist (List<Play> plays)
+ {
+ PlayList pl = new PlayList();
+ foreach (Play p in plays) {
+ pl.Add (new PlayListPlay (p, projectFile, true));
+ }
+ Config.EventsBroker.EmitRenderPlaylist (pl);
+ }
+ }
+}
diff --git a/LongoMatch.GUI/LongoMatch.GUI.mdp b/LongoMatch.GUI/LongoMatch.GUI.mdp
index e96014e..ebb36b5 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.mdp
+++ b/LongoMatch.GUI/LongoMatch.GUI.mdp
@@ -174,6 +174,9 @@
<File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Component.PeriodsRecoder.cs" />
<File subtype="Code" buildaction="Compile" name="Gui/Component/PlaysPositionViewer.cs" />
<File subtype="Code" buildaction="Compile"
name="gtk-gui/LongoMatch.Gui.Component.PlaysPositionViewer.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Gui/Menu" />
+ <File subtype="Code" buildaction="Compile" name="Gui/Menu/PlaysMenu.cs" />
+ <File subtype="Code" buildaction="Compile" name="Gui/GtkGlue.cs" />
</Contents>
<References>
<ProjectReference type="Package" localcopy="True" refto="atk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]