~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do/src/Do.UI/MainMenu.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 05:57:47 UTC
  • Revision ID: ootz0rz@gmail.com-20090623055747-3srobsuq3q8wbn81
initial adding of Do core stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* MainMenu.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this source distribution.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
using System;
 
21
 
 
22
using Gtk;
 
23
using Mono.Unix;
 
24
 
 
25
using Do;
 
26
using Do.Core;
 
27
using Do.Platform;
 
28
using Do.Universe;
 
29
using Do.Interface;
 
30
 
 
31
namespace Do.UI
 
32
{
 
33
 
 
34
        public class MainMenu : Gtk.Menu
 
35
        {
 
36
 
 
37
                static MainMenu instance;
 
38
 
 
39
                public static MainMenu Instance {
 
40
                        get {
 
41
                                if (instance == null)
 
42
                                        instance = new MainMenu ();
 
43
                                return instance;
 
44
                        }
 
45
                }
 
46
 
 
47
                int mainMenuX, mainMenuY;
 
48
 
 
49
                private MainMenu ()
 
50
                {
 
51
                        foreach (IRunnableItem item in Services.Application.MainMenuItems)
 
52
                                Add (MenuItemFromRunnableItem (item));
 
53
                        ShowAll ();
 
54
                }
 
55
 
 
56
                MenuItem MenuItemFromRunnableItem (IRunnableItem item)
 
57
                {
 
58
                        int iconSize;
 
59
                        Gdk.Pixbuf icon;
 
60
                        ImageMenuItem menuItem;
 
61
                        
 
62
                        menuItem = new ImageMenuItem (item.Name);
 
63
                        Icon.SizeLookup (IconSize.Menu, out iconSize, out iconSize);
 
64
                        icon = IconProvider.PixbufFromIconName (item.Icon, iconSize);
 
65
                        menuItem.Image = new Image (icon);
 
66
                        menuItem.CanFocus = false;
 
67
                        menuItem.Activated += (sender, e) => item.Run ();
 
68
                        return menuItem;
 
69
                }
 
70
 
 
71
                public void PopupAtPosition (int x, int y)
 
72
                {
 
73
                        menuPositioner = null;
 
74
                        mainMenuX = x;
 
75
                        mainMenuY = y;  
 
76
                        Popup (null, null, PositionMainMenu, 3, Gtk.Global.CurrentEventTime);
 
77
                }
 
78
 
 
79
                private void PositionMainMenu (Menu menu, out int x, out int y, out bool push_in)
 
80
                {
 
81
                        if (menuPositioner == null) {
 
82
                                x = mainMenuX;
 
83
                                y = mainMenuY;
 
84
                        } else {
 
85
                                Requisition menuReq = menu.SizeRequest ();
 
86
                                menuPositioner (menuReq.Height, menuReq.Width, out x, out y);
 
87
                        }
 
88
                        push_in = true;
 
89
                }
 
90
 
 
91
                PositionMenu menuPositioner;
 
92
                
 
93
                public void PopupWithPositioner (PositionMenu menuPositioner)
 
94
                {
 
95
                        this.menuPositioner = menuPositioner;
 
96
                        Popup (null, null, PositionMainMenu, 3, Gtk.Global.CurrentEventTime);
 
97
                }
 
98
        }
 
99
}