Author: danw
Date: 2005-03-18 14:53:55 -0500 (Fri, 18 Mar 2005)
New Revision: 42007
Added:
trunk/stetic/libstetic/editor/Image.cs
trunk/stetic/libstetic/editor/ImageFile.cs
Removed:
trunk/stetic/libstetic/editor/File.cs
trunk/stetic/libstetic/wrapper/pixmaps/missing.png
Modified:
trunk/stetic/ChangeLog
trunk/stetic/TODO
trunk/stetic/libstetic/Makefile.am
trunk/stetic/libstetic/editor/StockItem.cs
trunk/stetic/libstetic/wrapper/Image.cs
trunk/stetic/libstetic/wrapper/Window.cs
trunk/stetic/libstetic/wrapper/pixmaps/COPIED
Log:
* libstetic/editor/Image.cs: editor that allows selecting a stock
image or a file
* libstetic/editor/ImageFile.cs: subclass of Stetic.Editor.Image
that only allows picking a file
* libstetic/editor/StockItem.cs: now a subclass of Image
* libstetic/editor/File.cs: gone
* libstetic/wrapper/Image.cs: Use ImageFile editor and fix things
up a bit.
* libstetic/wrapper/Window.cs (Icon): wrap, using the ImageFile editor
Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog 2005-03-18 19:31:44 UTC (rev 42006)
+++ trunk/stetic/ChangeLog 2005-03-18 19:53:55 UTC (rev 42007)
@@ -1,3 +1,20 @@
+2005-03-18 Dan Winship <[EMAIL PROTECTED]>
+
+ * libstetic/editor/StockItem.cs: now a subclass of Image
+
+ * libstetic/editor/Image.cs: editor that allows selecting a stock
+ image or a file
+
+ * libstetic/editor/ImageFile.cs: subclass of Stetic.Editor.Image
+ that only allows picking a file
+
+ * libstetic/editor/File.cs: gone
+
+ * libstetic/wrapper/Image.cs: Use ImageFile editor and fix things
+ up a bit.
+
+ * libstetic/wrapper/Window.cs (Icon): wrap, using the ImageFile editor
+
2005-03-17 Dan Winship <[EMAIL PROTECTED]>
* libstetic/WidgetBox.cs (Internal): new property saying that the
Modified: trunk/stetic/TODO
===================================================================
--- trunk/stetic/TODO 2005-03-18 19:31:44 UTC (rev 42006)
+++ trunk/stetic/TODO 2005-03-18 19:53:55 UTC (rev 42007)
@@ -66,6 +66,7 @@
implementation should be generic, like how it works
in Visual Studio)
- EntryCompletion
+ - Stock items
- Make widgets more HIGalicious
Modified: trunk/stetic/libstetic/Makefile.am
===================================================================
--- trunk/stetic/libstetic/Makefile.am 2005-03-18 19:31:44 UTC (rev 42006)
+++ trunk/stetic/libstetic/Makefile.am 2005-03-18 19:53:55 UTC (rev 42007)
@@ -30,8 +30,9 @@
editor/Color.cs \
editor/Enumeration.cs \
editor/GroupPicker.cs \
- editor/File.cs \
editor/FloatRange.cs \
+ editor/Image.cs \
+ editor/ImageFile.cs \
editor/IntRange.cs \
editor/OptIntRange.cs \
editor/ResponseId.cs \
Deleted: trunk/stetic/libstetic/editor/File.cs
===================================================================
--- trunk/stetic/libstetic/editor/File.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/editor/File.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -1,10 +0,0 @@
-using System;
-
-namespace Stetic.Editor {
-
- [PropertyEditor ("Filename", "Changed")]
- public class File : Gnome.FileEntry {
-
- public File () : base ("fileselector", "Select a File") {}
- }
-}
Added: trunk/stetic/libstetic/editor/Image.cs
===================================================================
--- trunk/stetic/libstetic/editor/Image.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/editor/Image.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -0,0 +1,222 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Editor {
+
+ public class Image : Gtk.HBox {
+ Gtk.Image image;
+ Gtk.ComboBoxEntry combo;
+ Gtk.Entry entry;
+ Gtk.Button button;
+ Gtk.ListStore store;
+
+ const int IconColumn = 0;
+ const int LabelColumn = 1;
+
+ static string[] stockIds, stockLabels;
+ static int imgWidth, imgHeight;
+
+ static Image ()
+ {
+ ArrayList items = new ArrayList (), nonItems = new
ArrayList ();
+ foreach (string id in Gtk.Stock.ListIds ()) {
+ Gtk.StockItem item = Gtk.Stock.Lookup (id);
+ if (item.StockId == null)
+ nonItems.Add (id);
+ else {
+ item.Label = item.Label.Replace ("_",
"");
+ items.Add (item);
+ }
+ }
+ items.Sort (new StockItemSorter ());
+ nonItems.Sort ();
+
+ stockIds = new string[items.Count + nonItems.Count];
+ stockLabels = new string[items.Count + nonItems.Count];
+ for (int i = 0; i < items.Count; i++) {
+ stockIds[i] = ((Gtk.StockItem)items[i]).StockId;
+ stockLabels[i] =
((Gtk.StockItem)items[i]).Label;
+ }
+ for (int i = 0; i < nonItems.Count; i++) {
+ stockIds[i + items.Count] = nonItems[i] as
string;
+ stockLabels[i + items.Count] = nonItems[i] as
string;
+ }
+
+ Gtk.IconFactory.LookupIconSize (Gtk.IconSize.Button,
out imgWidth, out imgHeight);
+ }
+
+ class StockItemSorter : IComparer {
+ public int Compare (object itemx, object itemy)
+ {
+ Gtk.StockItem x = (Gtk.StockItem)itemx;
+ Gtk.StockItem y = (Gtk.StockItem)itemy;
+
+ return string.Compare (x.Label, y.Label);
+ }
+ }
+
+ public Image () : this (true, true) {}
+
+ public Image (bool allowStock, bool allowFile) : base (false, 6)
+ {
+ image = new Gtk.Image (Gnome.Stock.Blank,
Gtk.IconSize.Button);
+ PackStart (image, false, false, 0);
+
+ if (allowStock) {
+ store = new Gtk.ListStore (typeof (string),
typeof (string));
+ store.AppendValues (Gnome.Stock.Blank,
"(None)");
+ for (int i = 0; i < stockIds.Length; i++)
+ store.AppendValues (stockIds[i],
stockLabels[i]);
+
+ combo = new Gtk.ComboBoxEntry (store,
LabelColumn);
+ Gtk.CellRendererPixbuf iconRenderer = new
Gtk.CellRendererPixbuf ();
+ iconRenderer.StockSize =
(uint)Gtk.IconSize.Menu;
+ combo.PackStart (iconRenderer, false);
+ combo.Reorder (iconRenderer, 0);
+ combo.AddAttribute (iconRenderer, "stock-id",
IconColumn);
+ PackStart (combo, true, true, 0);
+ combo.Changed += combo_Changed;
+
+ entry = (Gtk.Entry)combo.Child;
+ entry.Changed += entry_Changed;
+
+ useStock = true;
+ }
+
+ if (allowFile) {
+ if (!allowStock) {
+ entry = new Gtk.Entry ();
+ PackStart (entry, true, true, 0);
+ entry.Changed += entry_Changed;
+ }
+
+ button = new Gtk.Button ();
+ Gtk.Image icon = new Gtk.Image (Gtk.Stock.Open,
Gtk.IconSize.Button);
+ button.Add (icon);
+ PackStart (button, false, false, 0);
+ button.Clicked += button_Clicked;
+ }
+ }
+
+ public event EventHandler Changed;
+
+ bool syncing;
+
+ void combo_Changed (object obj, EventArgs args)
+ {
+ if (syncing)
+ return;
+
+ useStock = true;
+ syncing = true;
+ if (combo.Active > 0)
+ StockId = stockIds[combo.Active - 1];
+ else
+ StockId = null;
+ if (Changed != null)
+ Changed (this, EventArgs.Empty);
+ syncing = false;
+ }
+
+ void entry_Changed (object obj, EventArgs args)
+ {
+ if (syncing)
+ return;
+
+ useStock = true;
+ syncing = true;
+ StockId = entry.Text;
+ if (Changed != null)
+ Changed (this, EventArgs.Empty);
+ syncing = false;
+ }
+
+ void button_Clicked (object obj, EventArgs args)
+ {
+ Gtk.FileChooserDialog dialog =
+ new Gtk.FileChooserDialog ("Image", null,
Gtk.FileChooserAction.Open,
+ Gtk.Stock.Cancel,
Gtk.ResponseType.Cancel,
+ Gtk.Stock.Open,
Gtk.ResponseType.Ok);
+ int response = dialog.Run ();
+ string file = dialog.Filename;
+ dialog.Destroy ();
+
+ if (response == (int)Gtk.ResponseType.Ok) {
+ syncing = true;
+ useStock = false;
+ entry.Text = file;
+ File = file;
+ if (Changed != null)
+ Changed (this, EventArgs.Empty);
+ syncing = false;
+ }
+ }
+
+ bool useStock;
+
+ string stockId;
+ public string StockId {
+ get {
+ return stockId;
+ }
+ set {
+ useStock = true;
+ stockId = value;
+ file = null;
+
+ image.SetFromStock (stockId,
Gtk.IconSize.Button);
+
+ if (!syncing) {
+ int id = Array.IndexOf (stockIds,
value);
+ if (id != -1) {
+ syncing = true;
+ combo.Active = id + 1;
+ syncing = false;
+ }
+ }
+ }
+ }
+
+ string file;
+ public string File {
+ get {
+ return file;
+ }
+ set {
+ useStock = false;
+ stockId = null;
+ file = value;
+
+ if (value == null)
+ value = "";
+
+ try {
+ image.Pixbuf = new Gdk.Pixbuf (value,
imgWidth, imgHeight);
+ } catch {
+ image.SetFromStock (Gnome.Stock.Blank,
Gtk.IconSize.Button);
+ }
+
+ if (!syncing) {
+ syncing = true;
+ entry.Text = value;
+ syncing = false;
+ }
+ }
+ }
+
+ public string Value {
+ get {
+ if (useStock)
+ return "stock:" + StockId;
+ else
+ return "file:" + File;
+ }
+ set {
+ if (value.StartsWith ("stock:"))
+ StockId = value.Substring (6);
+ else if (value.StartsWith ("file:"))
+ File = value.Substring (5);
+ }
+ }
+ }
+}
Added: trunk/stetic/libstetic/editor/ImageFile.cs
===================================================================
--- trunk/stetic/libstetic/editor/ImageFile.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/editor/ImageFile.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -0,0 +1,10 @@
+using System;
+
+namespace Stetic.Editor {
+
+ [PropertyEditor ("File", "Changed")]
+ public class ImageFile : Image {
+
+ public ImageFile () : base (false, true) { }
+ }
+}
Modified: trunk/stetic/libstetic/editor/StockItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/StockItem.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/editor/StockItem.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -1,73 +1,10 @@
using System;
-using System.Collections;
namespace Stetic.Editor {
[PropertyEditor ("StockId", "Changed")]
- public class StockItem : Gtk.ComboBox, IComparer {
+ public class StockItem : Image {
- const int IconColumn = 0;
- const int LabelColumn = 1;
-
- ArrayList stockIds;
-
- public StockItem ()
- {
- Gtk.ListStore store = new Gtk.ListStore (typeof
(string), typeof (string));
-
- ArrayList stockItems = new ArrayList ();
- foreach (string id in Gtk.Stock.ListIds ()) {
- Gtk.StockItem item = Gtk.Stock.Lookup (id);
- if (item.StockId == null)
- continue;
- stockItems.Add (item);
- }
- stockItems.Sort (this);
-
- stockIds = new ArrayList ();
- foreach (Gtk.StockItem item in stockItems) {
- string markup;
-
- stockIds.Add (item.StockId);
-
- int uline = item.Label.IndexOf ('_');
- if (uline != -1 && uline < item.Label.Length -
2)
- markup = item.Label.Substring (0,
uline) + "<u>" + item.Label.Substring (uline + 1, 1) + "</u>" +
item.Label.Substring (uline + 2);
- else
- markup = item.Label;
- store.AppendValues (item.StockId, markup);
- }
-
- Model = store;
-
- Gtk.CellRendererPixbuf iconRenderer = new
Gtk.CellRendererPixbuf ();
- iconRenderer.StockSize = (uint)Gtk.IconSize.Menu;
- PackStart (iconRenderer, false);
- AddAttribute (iconRenderer, "stock-id", IconColumn);
-
- Gtk.CellRendererText labelRenderer = new
Gtk.CellRendererText ();
- PackStart (labelRenderer, true);
- AddAttribute (labelRenderer, "markup", LabelColumn);
- }
-
- public int Compare (object itemx, object itemy)
- {
- Gtk.StockItem x = (Gtk.StockItem)itemx;
- Gtk.StockItem y = (Gtk.StockItem)itemy;
-
- return string.Compare (x.Label.Replace ("_", ""),
- y.Label.Replace ("_", ""));
- }
-
- public string StockId {
- get {
- return (string)stockIds[Active];
- }
- set {
- int id = stockIds.IndexOf (value);
- if (id != -1)
- Active = id;
- }
- }
+ public StockItem () : base (true, false) { }
}
}
Modified: trunk/stetic/libstetic/wrapper/Image.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Image.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/wrapper/Image.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -25,15 +25,13 @@
return new Gtk.Image (Gtk.Stock.Execute,
Gtk.IconSize.Dialog);
}
- static Gdk.Pixbuf missing = Gdk.Pixbuf.LoadFromResource
("missing.png");
-
public override void Wrap (object obj, bool initialized)
{
base.Wrap (obj, initialized);
useStock = (image.StorageType == Gtk.ImageType.Stock);
if (useStock) {
- stock = Stock;
- iconSize = IconSize;
+ stock = image.Stock;
+ iconSize = (Gtk.IconSize)image.IconSize;
} else
File = filename;
}
@@ -69,7 +67,7 @@
[Description ("Stock Icon", "The stock icon to display")]
public string Stock {
get {
- return image.Stock;
+ return stock;
}
set {
image.Stock = stock = value;
@@ -80,7 +78,7 @@
[GladeProperty (GladeProperty.UseUnderlying)]
public Gtk.IconSize IconSize {
get {
- return (Gtk.IconSize)image.IconSize;
+ return iconSize;
}
set {
image.IconSize = (int)(iconSize = value);
@@ -89,7 +87,7 @@
string filename = "";
- [Editor (typeof (Stetic.Editor.File))]
+ [Editor (typeof (Stetic.Editor.ImageFile))]
public string File {
get {
return filename;
@@ -97,7 +95,7 @@
set {
image.File = filename = value;
if (value == "")
- image.Pixbuf = missing;
+ image.Stock = Gtk.Stock.MissingImage;
}
}
}
Modified: trunk/stetic/libstetic/wrapper/Window.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Window.cs 2005-03-18 19:31:44 UTC (rev
42006)
+++ trunk/stetic/libstetic/wrapper/Window.cs 2005-03-18 19:53:55 UTC (rev
42007)
@@ -100,5 +100,22 @@
type = value;
}
}
+
+ string icon;
+ [Editor (typeof (Stetic.Editor.ImageFile))]
+ public string Icon {
+ get {
+ return icon;
+ }
+ set {
+ icon = value;
+ Gtk.Window window = (Gtk.Window)Wrapped;
+ try {
+ window.Icon = new Gdk.Pixbuf (icon);
+ } catch {
+ window.Icon = null;
+ }
+ }
+ }
}
}
Modified: trunk/stetic/libstetic/wrapper/pixmaps/COPIED
===================================================================
--- trunk/stetic/libstetic/wrapper/pixmaps/COPIED 2005-03-18 19:31:44 UTC
(rev 42006)
+++ trunk/stetic/libstetic/wrapper/pixmaps/COPIED 2005-03-18 19:53:55 UTC
(rev 42007)
@@ -1,2 +1 @@
-These were stolen from glade3 and are GPLed (except for missing.png
-which was stolen from gtk+ and is LGPLed.)
+These were stolen from glade3 and are GPLed.
\ No newline at end of file
Deleted: trunk/stetic/libstetic/wrapper/pixmaps/missing.png
===================================================================
(Binary files differ)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches