5
// Lluis Sanchez Gual <lluis@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
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;
42
namespace MonoDevelop.Ide.WelcomePage
44
class WelcomePageFrame: EventBox
46
WelcomePageProjectBar projectBar;
48
public WelcomePageFrame (Gtk.Widget w)
50
VBox box = new VBox ();
52
projectBar = new WelcomePageProjectBar ();
53
box.PackStart (projectBar, false, false, 0);
55
box.PackStart (w, true, true, 0);
63
public void UpdateProjectBar ()
65
if (IdeApp.Workspace.IsOpen || IdeApp.Workbench.Documents.Count > 0) {
66
projectBar.UpdateContent ();
67
projectBar.ShowAll ();
73
protected override bool OnKeyPressEvent (EventKey evnt)
75
if (evnt.Key == Gdk.Key.Escape && IdeApp.Workspace.IsOpen)
76
WelcomePageService.HideWelcomePage (true);
77
return base.OnKeyPressEvent (evnt);
80
void HandleLastWorkspaceItemClosed (object sender, EventArgs e)
85
void HandleDocumentClosed (object sender, MonoDevelop.Ide.Gui.DocumentEventArgs e)
90
protected override void OnParentSet (Widget previous_parent)
92
base.OnParentSet (previous_parent);
94
IdeApp.Workspace.LastWorkspaceItemClosed -= HandleLastWorkspaceItemClosed;
95
IdeApp.Workbench.DocumentClosed -= HandleDocumentClosed;
97
IdeApp.Workspace.LastWorkspaceItemClosed += HandleLastWorkspaceItemClosed;
98
IdeApp.Workbench.DocumentClosed += HandleDocumentClosed;
103
class WelcomePageProjectBar: HeaderBox
105
Gtk.Label messageLabel;
106
Gtk.Button closeButton;
107
Gtk.Button backButton;
109
public WelcomePageProjectBar ()
111
SetPadding (3, 3, 12, 12);
112
GradientBackround = true;
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);
121
closeButton.Clicked += delegate {
122
if (IdeApp.Workspace.IsOpen)
123
IdeApp.Workspace.Close ();
125
IdeApp.Workbench.CloseAllDocuments (false);
127
backButton.Clicked += delegate {
128
WelcomePageService.HideWelcomePage (true);
134
public void UpdateContent ()
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");
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");
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");
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");
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");
171
//this is used to style like a tooltip
172
bool changeStyle = false;
174
protected override void OnStyleSet (Gtk.Style previous_style)
179
var surrogate = new TooltipStyleSurrogate ();
180
surrogate.EnsureStyle ();
181
this.Style = surrogate.Style;
182
surrogate.Destroy ();
184
base.OnStyleSet (previous_style);
188
class TooltipStyleSurrogate : TooltipWindow {}