~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageFrame.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// WelcomePageFrame.cs
 
3
//
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@xamarin.com>
 
6
//
 
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.IO;
 
29
using System.Xml;
 
30
using System.Linq;
 
31
using Gdk;
 
32
using Gtk;
 
33
using Mono.Addins;
 
34
using MonoDevelop.Core;
 
35
using MonoDevelop.Ide;
 
36
using MonoDevelop.Projects;
 
37
using MonoDevelop.Ide.Desktop;
 
38
using System.Reflection;
 
39
using System.Xml.Linq;
 
40
using MonoDevelop.Components;
 
41
 
 
42
namespace MonoDevelop.Ide.WelcomePage
 
43
{
 
44
        class WelcomePageFrame: EventBox
 
45
        {
 
46
                WelcomePageProjectBar projectBar;
 
47
 
 
48
                public WelcomePageFrame (Gtk.Widget w)
 
49
                {
 
50
                        VBox box = new VBox ();
 
51
                        box.Show ();
 
52
                        projectBar = new WelcomePageProjectBar ();
 
53
                        box.PackStart (projectBar, false, false, 0);
 
54
 
 
55
                        box.PackStart (w, true, true, 0);
 
56
                        CanFocus = true;
 
57
 
 
58
                        Add (box);
 
59
                        Show ();
 
60
                        UpdateProjectBar ();
 
61
                }
 
62
 
 
63
                public void UpdateProjectBar ()
 
64
                {
 
65
                        if (IdeApp.Workspace.IsOpen || IdeApp.Workbench.Documents.Count > 0) {
 
66
                                projectBar.UpdateContent ();
 
67
                                projectBar.ShowAll ();
 
68
                        }
 
69
                        else
 
70
                                projectBar.Hide ();
 
71
                }
 
72
 
 
73
                protected override bool OnKeyPressEvent (EventKey evnt)
 
74
                {
 
75
                        if (evnt.Key == Gdk.Key.Escape && IdeApp.Workspace.IsOpen)
 
76
                                WelcomePageService.HideWelcomePage (true);
 
77
                        return base.OnKeyPressEvent (evnt);
 
78
                }
 
79
 
 
80
                void HandleLastWorkspaceItemClosed (object sender, EventArgs e)
 
81
                {
 
82
                        UpdateProjectBar ();
 
83
                }
 
84
 
 
85
                void HandleDocumentClosed (object sender, MonoDevelop.Ide.Gui.DocumentEventArgs e)
 
86
                {
 
87
                        UpdateProjectBar ();
 
88
                }
 
89
 
 
90
                protected override void OnParentSet (Widget previous_parent)
 
91
                {
 
92
                        base.OnParentSet (previous_parent);
 
93
                        if (Parent == null) {
 
94
                                IdeApp.Workspace.LastWorkspaceItemClosed -= HandleLastWorkspaceItemClosed;
 
95
                                IdeApp.Workbench.DocumentClosed -= HandleDocumentClosed;
 
96
                        } else {
 
97
                                IdeApp.Workspace.LastWorkspaceItemClosed += HandleLastWorkspaceItemClosed;
 
98
                                IdeApp.Workbench.DocumentClosed += HandleDocumentClosed;
 
99
                        }
 
100
                }
 
101
        }
 
102
 
 
103
        class WelcomePageProjectBar: HeaderBox
 
104
        {
 
105
                Gtk.Label messageLabel;
 
106
                Gtk.Button closeButton;
 
107
                Gtk.Button backButton;
 
108
 
 
109
                public WelcomePageProjectBar ()
 
110
                {
 
111
                        SetPadding (3, 3, 12, 12);
 
112
                        GradientBackround = true;
 
113
 
 
114
                        HBox box = new HBox (false, 6);
 
115
                        box.PackStart (messageLabel = new Gtk.Label () { Xalign = 0 }, true, true, 0);
 
116
                        backButton = new Gtk.Button ();
 
117
                        box.PackEnd (backButton, false, false, 0);
 
118
                        closeButton = new Gtk.Button ();
 
119
                        box.PackEnd (closeButton, false, false, 0);
 
120
 
 
121
                        closeButton.Clicked += delegate {
 
122
                                if (IdeApp.Workspace.IsOpen)
 
123
                                        IdeApp.Workspace.Close ();
 
124
                                else
 
125
                                        IdeApp.Workbench.CloseAllDocuments (false);
 
126
                        };
 
127
                        backButton.Clicked += delegate {
 
128
                                WelcomePageService.HideWelcomePage (true);
 
129
                        };
 
130
                        Add (box);
 
131
                        UpdateContent ();
 
132
                }
 
133
 
 
134
                public void UpdateContent ()
 
135
                {
 
136
                        if (IdeApp.Workspace.Items.Count > 0) {
 
137
                                var sols = IdeApp.Workspace.GetAllSolutions ().ToArray ();
 
138
                                if (sols.Length == 1) {
 
139
                                        messageLabel.Text = GettextCatalog.GetString ("Solution '{0}' is currently open", sols [0].Name);
 
140
                                        backButton.Label = GettextCatalog.GetString ("Go Back to Solution");
 
141
                                        closeButton.Label = GettextCatalog.GetString ("Close Solution");
 
142
                                }
 
143
                                else if (sols.Length > 1) {
 
144
                                        messageLabel.Text = GettextCatalog.GetString ("Solution '{0}' and others are currently open", sols [0].Name);
 
145
                                        backButton.Label = GettextCatalog.GetString ("Go Back to Solutions");
 
146
                                        closeButton.Label = GettextCatalog.GetString ("Close all Solutions");
 
147
                                }
 
148
                                else {
 
149
                                        messageLabel.Text = GettextCatalog.GetString ("A workspace is currently open");
 
150
                                        backButton.Label = GettextCatalog.GetString ("Go Back to Workspace");
 
151
                                        closeButton.Label = GettextCatalog.GetString ("Close Workspace");
 
152
                                }
 
153
                        } else if (IdeApp.Workbench.Documents.Count> 0) {
 
154
                                var files = IdeApp.Workbench.Documents.Where (d => d.IsFile).ToArray ();
 
155
                                if (files.Length == 1) {
 
156
                                        messageLabel.Text = GettextCatalog.GetString ("The file '{0}' is currently open", files[0].FileName.FileName);
 
157
                                        backButton.Label = GettextCatalog.GetString ("Go Back to File");
 
158
                                        closeButton.Label = GettextCatalog.GetString ("Close File");
 
159
                                } else if (files.Length > 1) {
 
160
                                        messageLabel.Text = GettextCatalog.GetString ("The file '{0}' and other are currently open", files[0].FileName.FileName);
 
161
                                        backButton.Label = GettextCatalog.GetString ("Go Back to Files");
 
162
                                        closeButton.Label = GettextCatalog.GetString ("Close Files");
 
163
                                } else {
 
164
                                        messageLabel.Text = GettextCatalog.GetString ("Some documents are currently open");
 
165
                                        backButton.Label = GettextCatalog.GetString ("Go Back to Documents");
 
166
                                        closeButton.Label = GettextCatalog.GetString ("Close Documents");
 
167
                                }
 
168
                        }
 
169
                }
 
170
                
 
171
                //this is used to style like a tooltip
 
172
                bool changeStyle = false;
 
173
                
 
174
                protected override void OnStyleSet (Gtk.Style previous_style)
 
175
                {
 
176
                        if (changeStyle)
 
177
                                return;
 
178
                        changeStyle = true;
 
179
                        var surrogate = new TooltipStyleSurrogate ();
 
180
                        surrogate.EnsureStyle ();
 
181
                        this.Style = surrogate.Style;
 
182
                        surrogate.Destroy ();
 
183
 
 
184
                        base.OnStyleSet (previous_style);
 
185
                        changeStyle = false;
 
186
                }
 
187
                
 
188
                class TooltipStyleSurrogate : TooltipWindow {}
 
189
        }
 
190
}