1 // VersionInformationTabPage.cs 2 // 3 // Author: 4 // Viktoria Dudka (viktoriad@remobjects.com) 5 // 6 // Copyright (c) 2009 RemObjects Software 7 // 8 // Permission is hereby granted, free of charge, to any person obtaining a copy 9 // of this software and associated documentation files (the "Software"), to deal 10 // in the Software without restriction, including without limitation the rights 11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 // copies of the Software, and to permit persons to whom the Software is 13 // furnished to do so, subject to the following conditions: 14 // 15 // The above copyright notice and this permission notice shall be included in 16 // all copies or substantial portions of the Software. 17 // 18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 // THE SOFTWARE. 25 // 26 // 27 28 using System; 29 using Gtk; 30 using System.Reflection; 31 using Mono.Unix; 32 using System.Text; 33 using System.Diagnostics; 34 35 namespace Pinta 36 { 37 internal class VersionInformationTabPage : VBox 38 { 39 private ListStore data = null; 40 private CellRenderer cellRenderer = new CellRendererText (); 41 TreeView treeView = null; 42 VersionInformationTabPage()43 public VersionInformationTabPage () 44 { 45 treeView = new TreeView (); 46 47 TreeViewColumn treeViewColumnTitle = new TreeViewColumn (Catalog.GetString ("Title"), cellRenderer, "text", 0); 48 treeViewColumnTitle.FixedWidth = 200; 49 treeViewColumnTitle.Sizing = TreeViewColumnSizing.Fixed; 50 treeViewColumnTitle.Resizable = true; 51 treeView.AppendColumn (treeViewColumnTitle); 52 53 TreeViewColumn treeViewColumnVersion = new TreeViewColumn (Catalog.GetString ("Version"), cellRenderer, "text", 1); 54 treeView.AppendColumn (treeViewColumnVersion); 55 56 TreeViewColumn treeViewColumnPath = new TreeViewColumn (Catalog.GetString ("Path"), cellRenderer, "text", 2); 57 treeView.AppendColumn (treeViewColumnPath); 58 59 treeView.RulesHint = true; 60 61 data = new ListStore (typeof (string), typeof (string), typeof (string)); 62 treeView.Model = data; 63 64 ScrolledWindow scrolledWindow = new ScrolledWindow (); 65 scrolledWindow.Add (treeView); 66 scrolledWindow.ShadowType = ShadowType.In; 67 68 BorderWidth = 6; 69 70 71 var toplayout = new VBox(); 72 var copyButton = new Button (Catalog.GetString ("Copy Version Info")); 73 copyButton.Clicked += CopyButton_Clicked; 74 75 76 toplayout.Add (copyButton); 77 toplayout.Add (scrolledWindow); 78 toplayout.Homogeneous = false; 79 toplayout.SetChildPacking (copyButton, false, false, 0, PackType.Start); 80 toplayout.SetChildPacking (scrolledWindow, true, true, 0, PackType.End); 81 82 PackStart (toplayout, true, true, 0); 83 84 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ()) { 85 try { 86 AssemblyName assemblyName = assembly.GetName (); 87 data.AppendValues (assemblyName.Name, assemblyName.Version.ToString (), System.IO.Path.GetFullPath (assembly.Location)); 88 } catch { } 89 } 90 91 92 data.SetSortColumnId (0, SortType.Ascending); 93 } 94 95 OnDestroyed()96 protected override void OnDestroyed () 97 { 98 if (cellRenderer != null) { 99 cellRenderer.Destroy (); 100 cellRenderer = null; 101 } 102 103 if (data != null) { 104 data.Dispose (); 105 data = null; 106 } 107 108 base.OnDestroyed (); 109 } 110 CopyButton_Clicked(object sender, EventArgs e)111 void CopyButton_Clicked (object sender, EventArgs e) 112 { 113 String delimeter = ","; 114 String linesep = Environment.NewLine; 115 116 StringBuilder vinfo = new StringBuilder (); 117 //copy the version information is 'csv style' 118 TreeIter iter; 119 120 if (!treeView.Model.GetIterFirst (out iter)) { 121 return; 122 } 123 124 //do headers 125 for (int col = 0; col < treeView.Model.NColumns; col++) { 126 if (col != 0) { 127 vinfo.Append (delimeter); 128 } 129 130 vinfo.Append (treeView.GetColumn (col).Title); 131 } 132 133 vinfo.Append (linesep); 134 135 136 do { 137 for (int col = 0; col < treeView.Model.NColumns; col++) { 138 139 String val = (string) treeView.Model.GetValue (iter, col); 140 if (col != 0) { 141 vinfo.Append (delimeter); 142 } 143 144 vinfo.Append (val); 145 } 146 147 vinfo.Append (linesep); 148 } while (treeView.Model.IterNext (ref iter)); 149 150 151 152 if (vinfo.Length > 0) { 153 Gtk.Clipboard clipboard = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); 154 clipboard.Text = vinfo.ToString (); 155 } 156 157 158 } 159 160 } 161 } 162