5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2009 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
20 using System
.Diagnostics
;
22 using System
.Resources
;
33 TreeView xap_file_view
;
34 ListStore xap_file_store
;
35 ScrolledWindow xap_file_scrollable
;
38 public bool Help { get; private set; }
39 public string File { get; private set; }
41 static void ShowHelp (OptionSet o
)
43 Console
.WriteLine ("Usage is: munxap [args] file.xap\n" +
45 o
.WriteOptionDescriptions (Console
.Out
);
48 static int Main (string [] args
)
51 Munxap unxap
= new Munxap ();
53 var p
= new OptionSet () {
54 { "h|?|help", v => unxap.Help = v != null }
,
57 List
<string> rest
= new List
<string> ();
59 rest
= p
.Parse (args
);
60 } catch (OptionException
){
61 Console
.Error
.WriteLine ("Try `munxap --help' for more information.");
70 if (rest
.Count
!= 1) {
75 unxap
.File
= rest
[0];
80 } catch (Exception ex
) {
81 Console
.WriteLine (ex
);
93 window
= new Window ("munxap: " + File
);
94 window
.Resize (600, 600);
95 window
.DeleteEvent
+= delegate (object obj
, DeleteEventArgs args
)
101 main
= new VBox (false, 10);
104 // label with the filename of the xap file on top
105 file_label
= new Label (File
);
106 main
.PackStart (file_label
, false, true, 0);
108 // the middle consists of a hbox, leftmost column a list of files in the zip file
109 xap
= new HBox (false, 10);
110 main
.PackStart (xap
, true, true, 0);
112 left
= new VBox (false, 10);
113 xap
.PackStart (left
, true, true, 0);
115 // a list of files in the zip file
116 xap_file_store
= new ListStore (typeof (String
), typeof (String
), typeof (ZipContent
));
117 xap_file_view
= new TreeView ();
118 xap_file_view
.Model
= xap_file_store
;
119 xap_file_view
.HeadersVisible
= true;
120 xap_file_view
.AppendColumn ("Name", new CellRendererText (), "text", 0);
121 xap_file_view
.AppendColumn ("Type", new CellRendererText (), "text", 1);
122 xap_file_view
.CursorChanged
+= HandleCursorChanged
;
123 xap_file_scrollable
= new ScrolledWindow ();
124 xap_file_scrollable
.Add (xap_file_view
);
125 left
.PackStart (xap_file_scrollable
, true, true, 0);
127 // close button at the bottom
128 close_button
= new Button ("Close");
129 close_button
.Clicked
+= delegate (object obj
, EventArgs args
)
133 main
.PackEnd (close_button
, false, true, 0);
136 foreach (ZipContent f
in zip
.Files
) {
137 xap_file_store
.AppendValues (f
.Filename
, f
.Type
, f
);
152 void HandleCursorChanged (object sender
, EventArgs e
)
154 TreeSelection selection
= xap_file_view
.Selection
;
161 // Find the selected column, and create a view for it
163 if (!selection
.GetSelected (out model
, out iter
))
167 xap_file_store
.GetValue (iter
, 2, ref v
);
168 content
= v
.Val
as ZipContent
;
170 if (content
== null) {
171 Console
.WriteLine ("No content here.");
175 switch (content
.Type
) {
178 view
= new ViewXaml (content
);
181 view
= new ViewAssembly (content
);
187 Console
.WriteLine ("Unknown type: {0}");
191 // Remove any previous views
192 while (left
.Children
.Length
> 1)
193 left
.Remove (left
.Children
[1]);
195 // Add the current one, if any
197 left
.PackStart (view
.GetView (), true, true, 0);