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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/VersionInformationTabPage.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:
35
35
using System.IO;
36
36
using MonoDevelop.Ide.Fonts;
37
37
using Mono.Addins;
 
38
using System.Collections.Generic;
 
39
using System.Linq;
38
40
 
39
41
 
40
42
namespace MonoDevelop.Ide.Gui.Dialogs
45
47
                
46
48
                public VersionInformationTabPage ()
47
49
                {
 
50
                        BorderWidth = 6;
48
51
                        SetLabel (GettextCatalog.GetString ("Loading..."));
49
52
                        
50
53
                        new System.Threading.Thread (() => {
51
54
                                try {
52
 
                                        var text = SystemInformation.ToText ();
 
55
                                        var info = SystemInformation.GetDescription ().ToArray ();
53
56
                                        Gtk.Application.Invoke (delegate {
54
57
                                                if (destroyed)
55
58
                                                        return;
56
 
                                                SetText (text);
 
59
                                                SetText (info);
57
60
                                        });
58
61
                                } catch (Exception ex) {
59
62
                                        LoggingService.LogError ("Failed to load version information", ex);
81
84
                        ShowAll ();
82
85
                }
83
86
 
84
 
                void SetText (string text)
 
87
                void SetText (IEnumerable<ISystemInformationProvider> text)
85
88
                {
86
89
                        Clear ();
87
 
                        var buf = new TextBuffer (null);
88
 
                        buf.Text = text;
89
 
                        
 
90
 
 
91
                        var buf = new Gtk.Label ();
 
92
                        buf.Selectable = true;
 
93
                        buf.Xalign = 0;
 
94
 
 
95
                        StringBuilder sb = new StringBuilder ();
 
96
 
 
97
                        foreach (var info in text) {
 
98
                                sb.Append ("<b>").Append (GLib.Markup.EscapeText (info.Title)).Append ("</b>\n");
 
99
                                sb.Append (GLib.Markup.EscapeText (info.Description.Trim ())).Append ("\n\n");
 
100
                        }
 
101
 
 
102
                        buf.Markup = sb.ToString ().Trim () + "\n";
 
103
 
 
104
                        var contentBox = new VBox ();
 
105
                        contentBox.BorderWidth = 4;
 
106
                        contentBox.PackStart (buf, false, false, 0);
 
107
 
 
108
                        var asmButton = new Gtk.Button ("Show loaded assemblies");
 
109
                        asmButton.Clicked += (sender, e) => {
 
110
                                asmButton.Hide ();
 
111
                                contentBox.PackStart (CreateAssembliesTable (), false, false, 0);
 
112
                        };
 
113
                        var hb = new Gtk.HBox ();
 
114
                        hb.PackStart (asmButton, false, false, 0);
 
115
                        contentBox.PackStart (hb, false, false, 0);
 
116
 
90
117
                        var sw = new MonoDevelop.Components.CompactScrolledWindow () {
91
118
                                ShowBorderLine = true,
92
 
                                BorderWidth = 2,
93
 
                                Child = new TextView (buf) {
94
 
                                        Editable = false,
95
 
                                        LeftMargin = 4,
96
 
                                        RightMargin = 4,
97
 
                                        PixelsAboveLines = 4,
98
 
                                        PixelsBelowLines = 4
99
 
                                }
 
119
                                BorderWidth = 2
100
120
                        };
101
 
                        
102
 
                        sw.Child.ModifyFont (Pango.FontDescription.FromString (DesktopService.DefaultMonospaceFont));
 
121
                        sw.AddWithViewport (contentBox);
 
122
                        sw.ShadowType = ShadowType.None;
 
123
                        ((Gtk.Viewport)sw.Child).ShadowType = ShadowType.None;
 
124
 
103
125
                        PackStart (sw, true, true, 0);
104
 
                        var hb = new HBox (false, 0) {
105
 
                                BorderWidth = 2,
106
 
                        };
107
 
                        var copyButton = new Button () { Label = GettextCatalog.GetString ("Copy Version Information") };
108
 
                        copyButton.Clicked += (sender, e) => CopyBufferToClipboard (buf);
109
 
                        hb.PackStart (copyButton, true, true, 0);
110
 
                        PackEnd (hb, false, false, 0);
111
126
                        ShowAll ();
112
127
                }
113
128
 
114
 
                static void CopyBufferToClipboard (TextBuffer buf)
 
129
                Gtk.Widget CreateAssembliesTable ()
115
130
                {
116
 
                        //get current cursor state
117
 
                        TextIter s, e;
118
 
                        TextIter cursorIter = TextIter.Zero;
119
 
                        var hadSel = buf.GetSelectionBounds (out s, out e);
120
 
                        if (!hadSel) {
121
 
                                cursorIter = buf.GetIterAtOffset (buf.CursorPosition);
122
 
                        }
123
 
 
124
 
                        //copy text to clipboard, let the buffer handle the details
125
 
                        buf.SelectRange (buf.StartIter, buf.EndIter);
126
 
                        Clipboard clipboard = Clipboard.Get (Mono.TextEditor.ClipboardActions.CopyOperation.CLIPBOARD_ATOM);
127
 
                        buf.CopyClipboard (clipboard);
128
 
 
129
 
                        //restore cursor state
130
 
                        if (hadSel) {
131
 
                                buf.SelectRange (s, e);
132
 
                        } else {
133
 
                                buf.PlaceCursor (cursorIter);
134
 
                        }
 
131
                        var box = new Gtk.VBox ();
 
132
                        box.PackStart (new Gtk.Label () {
 
133
                                Markup = "<b>LoadedAssemblies</b>",
 
134
                                Xalign = 0
 
135
                        });
 
136
                        var table = new Gtk.Table (0, 0, false);
 
137
                        table.ColumnSpacing = 3;
 
138
                        uint line = 0;
 
139
                        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies ().Where (a => !a.IsDynamic).OrderBy (a => a.FullName)) {
 
140
                                try {
 
141
                                        var assemblyName = assembly.GetName ();
 
142
                                        table.Attach (new Gtk.Label (assemblyName.Name) { Xalign = 0 }, 0, 1, line, line + 1);
 
143
                                        table.Attach (new Gtk.Label (assemblyName.Version.ToString ()) { Xalign = 0 }, 1, 2, line, line + 1);
 
144
                                        table.Attach (new Gtk.Label (System.IO.Path.GetFullPath (assembly.Location)) { Xalign = 0 }, 2, 3, line, line + 1);
 
145
                                } catch {
 
146
                                }
 
147
                                line++;
 
148
                        }
 
149
                        box.PackStart (table, false, false, 0);
 
150
                        box.ShowAll ();
 
151
                        return box;
135
152
                }
136
 
                
 
153
 
137
154
                public override void Destroy ()
138
155
                {
139
156
                        base.Destroy ();