Permalink
Browse files

* libstetic/ClassDescriptor.cs: Handle <contextmenu ref="..." />

	* libstetic/DND.cs (Cancel): fix a crash

	* libstetic/Registry.cs (LookupContextMenu): look up a context
	menu by class name.
	(NewInstance): Look up a class and invoke NewInstance on it

	* libstetic/wrapper/ButtonBox.cs: Wrapper for ButtonBox, that
	automatically fills in dummy buttons as needed.

	* libstetic/wrapper/objects.xml (Gtk.ButtonBox): use the new
	ButtonBox wrapper. Add a "Size" property and a context menu.

	* libstetic/wrapper/Container.cs (AllowPlaceholders): new virtual
	property saying whether or not to allow arbitrary placeholders in
	the container.
	(Wrap, GladeImport, Delete): Don't add placeholders if
	!AllowPlaceholders
	(DragEnd): Remove the dragSource placeholder after a successful
	drag if !AllowPlaceholders

	* libstetic/wrapper/Box.cs (AllowPlaceholders): false
	(InsertBefore, InsertAfter): If invoked on the box directly
	(rather than via the submenu from one of its children), insert
	before the first / after the last child.

	* libstetic/wrapper/Button.cs: Remove CreateInstance method;
	default to text-only buttons like Glade does.

	* libstetic/wrapper/Dialog.cs (AddButton): Use
	Registry.NewInstance.

	* libstetic/wrapper/Notebook.cs (InsertPage): Use
	Registry.NewInstance

	* stetic/ContextMenu.cs: Fix up for bxc 75689 again, since it was
	still broken before.

svn path=/trunk/stetic/; revision=50529
  • Loading branch information...
1 parent 3d95ef0 commit ff551ac8abdf3d67709f5ff1173af94863af9ebc Dan Winship committed Sep 22, 2005
View
41 ChangeLog
@@ -1,3 +1,44 @@
+2005-09-22 Dan Winship <danw@novell.com>
+
+ * libstetic/ClassDescriptor.cs: Handle <contextmenu ref="..." />
+
+ * libstetic/DND.cs (Cancel): fix a crash
+
+ * libstetic/Registry.cs (LookupContextMenu): look up a context
+ menu by class name.
+ (NewInstance): Look up a class and invoke NewInstance on it
+
+ * libstetic/wrapper/ButtonBox.cs: Wrapper for ButtonBox, that
+ automatically fills in dummy buttons as needed.
+
+ * libstetic/wrapper/objects.xml (Gtk.ButtonBox): use the new
+ ButtonBox wrapper. Add a "Size" property and a context menu.
+
+ * libstetic/wrapper/Container.cs (AllowPlaceholders): new virtual
+ property saying whether or not to allow arbitrary placeholders in
+ the container.
+ (Wrap, GladeImport, Delete): Don't add placeholders if
+ !AllowPlaceholders
+ (DragEnd): Remove the dragSource placeholder after a successful
+ drag if !AllowPlaceholders
+
+ * libstetic/wrapper/Box.cs (AllowPlaceholders): false
+ (InsertBefore, InsertAfter): If invoked on the box directly
+ (rather than via the submenu from one of its children), insert
+ before the first / after the last child.
+
+ * libstetic/wrapper/Button.cs: Remove CreateInstance method;
+ default to text-only buttons like Glade does.
+
+ * libstetic/wrapper/Dialog.cs (AddButton): Use
+ Registry.NewInstance.
+
+ * libstetic/wrapper/Notebook.cs (InsertPage): Use
+ Registry.NewInstance
+
+ * stetic/ContextMenu.cs: Fix up for bxc 75689 again, since it was
+ still broken before.
+
2005-09-20 Dan Winship <danw@novell.com>
* libstetic/EnumDescriptor.cs: New descriptor class for English
View
4 TODO
@@ -12,13 +12,9 @@ UI-Designing UI:
- Fix up not-fully-functional wrappers:
- - ButtonBox should fill itself in with buttons, like glade
- does, and needs to implement insert/remove commands
-
- Dialog
- "Buttons" should automatically switch to "Custom" if
you add/remove them.
- - "Buttons" menu labels need to be better
- action_area is currently broken on glade import
- Notebook has a few problems:
View
10 libstetic/ClassDescriptor.cs
@@ -95,9 +95,13 @@ public ClassDescriptor (Assembly assembly, XmlElement elem)
}
XmlElement contextElem = elem["contextmenu"];
- if (contextElem != null)
- contextMenu = new ItemGroup (contextElem, this);
- else
+ if (contextElem != null) {
+ if (contextElem.HasAttribute ("ref")) {
+ string refname = contextElem.GetAttribute ("ref");
+ contextMenu = Registry.LookupContextMenu (refname);
+ } else
+ contextMenu = new ItemGroup (contextElem, this);
+ } else
contextMenu = ItemGroup.Empty;
XmlElement ichildElem = elem["internal-children"];
View
3 libstetic/DND.cs
@@ -115,6 +115,9 @@ public static Stetic.Wrapper.Widget Drop (Gdk.DragContext ctx, Gtk.Widget target
// Call this from a DragEnd event to check if the widget wasn't dropped
public static Gtk.Widget Cancel ()
{
+ if (dragWidget == null)
+ return null;
+
Gtk.Widget w = dragWidget;
dragWidget = null;
View
1 libstetic/Makefile.am
@@ -42,6 +42,7 @@ libstetic_dll_sources = \
editor/Translatable.cs \
wrapper/Box.cs \
wrapper/Button.cs \
+ wrapper/ButtonBox.cs \
wrapper/CheckButton.cs \
wrapper/ColorButton.cs \
wrapper/ComboBox.cs \
View
13 libstetic/Registry.cs
@@ -129,5 +129,18 @@ public static ItemDescriptor LookupItem (string name)
throw new ArgumentException ("No class " + classname + " for property " + propname);
return klass[propname];
}
+
+ public static ItemGroup LookupContextMenu (string classname)
+ {
+ ClassDescriptor klass = (ClassDescriptor)classes_by_csname[classname];
+ if (klass == null)
+ throw new ArgumentException ("No class for contextmenu " + classname);
+ return klass.ContextMenu;
+ }
+
+ public static object NewInstance (Type type, IProject proj)
+ {
+ return LookupClass (type).NewInstance (proj);
+ }
}
}
View
44 libstetic/wrapper/Box.cs
@@ -21,6 +21,12 @@ public override void Wrap (object obj, bool initialized)
}
}
+ protected override bool AllowPlaceholders {
+ get {
+ return false;
+ }
+ }
+
// DoSync() does two things: first, it makes sure that all of the
// PackStart widgets have Position numbers less than all of the
// PackEnd widgets. Second, it creates faults anywhere two widgets
@@ -114,28 +120,50 @@ protected override void DoSync ()
internal void InsertBefore (Gtk.Widget context)
{
- Gtk.Box.BoxChild bc = box[context] as Gtk.Box.BoxChild;
+ int position;
+ Gtk.PackType type;
+
+ if (context == box) {
+ position = 0;
+ type = Gtk.PackType.Start;
+ } else {
+ Gtk.Box.BoxChild bc = box[context] as Gtk.Box.BoxChild;
+ position = bc.Position;
+ type = bc.PackType;
+ }
+
Placeholder ph = CreatePlaceholder ();
- if (bc.PackType == Gtk.PackType.Start) {
+ if (type == Gtk.PackType.Start) {
box.PackStart (ph);
- box.ReorderChild (ph, bc.Position);
+ box.ReorderChild (ph, position);
} else {
box.PackEnd (ph);
- box.ReorderChild (ph, bc.Position + 1);
+ box.ReorderChild (ph, position + 1);
}
EmitContentsChanged ();
}
internal void InsertAfter (Gtk.Widget context)
{
- Gtk.Box.BoxChild bc = box[context] as Gtk.Box.BoxChild;
+ int position;
+ Gtk.PackType type = Gtk.PackType.Start;
+
+ if (context == box) {
+ position = 0;
+ type = Gtk.PackType.End;
+ } else {
+ Gtk.Box.BoxChild bc = box[context] as Gtk.Box.BoxChild;
+ position = bc.Position;
+ type = bc.PackType;
+ }
+
Placeholder ph = CreatePlaceholder ();
- if (bc.PackType == Gtk.PackType.Start) {
+ if (type == Gtk.PackType.Start) {
box.PackStart (ph);
- box.ReorderChild (ph, bc.Position + 1);
+ box.ReorderChild (ph, position + 1);
} else {
box.PackEnd (ph);
- box.ReorderChild (ph, bc.Position);
+ box.ReorderChild (ph, position);
}
EmitContentsChanged ();
}
View
5 libstetic/wrapper/Button.cs
@@ -6,11 +6,6 @@ namespace Stetic.Wrapper {
public class Button : Container {
- public static new Gtk.Button CreateInstance ()
- {
- return new Gtk.Button (Gtk.Stock.Ok);
- }
-
public override void Wrap (object obj, bool initialized)
{
base.Wrap (obj, initialized);
View
57 libstetic/wrapper/ButtonBox.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ public class ButtonBox : Box {
+
+ public override void Wrap (object obj, bool initialized)
+ {
+ base.Wrap (obj, initialized);
+ FillButtons ();
+ }
+
+ void FillButtons ()
+ {
+ foreach (Gtk.Widget child in buttonbox.Children) {
+ if (child is Placeholder)
+ ReplaceChild (child, (Gtk.Button)Registry.NewInstance (typeof (Gtk.Button), proj));
+ }
+ }
+
+ protected Gtk.ButtonBox buttonbox {
+ get {
+ return (Gtk.ButtonBox)Wrapped;
+ }
+ }
+
+ internal new void InsertBefore (Gtk.Widget context)
+ {
+ base.InsertBefore (context);
+ FillButtons ();
+ }
+
+ internal new void InsertAfter (Gtk.Widget context)
+ {
+ base.InsertAfter (context);
+ FillButtons ();
+ }
+
+ public int Size {
+ get {
+ return buttonbox.Children.Length;
+ }
+ set {
+ Gtk.Widget[] children = buttonbox.Children;
+ int cursize = children.Length;
+
+ while (cursize > value)
+ buttonbox.Remove (children[--cursize]);
+ while (cursize < value) {
+ buttonbox.PackStart ((Gtk.Button)Registry.NewInstance (typeof (Gtk.Button), proj), false, false, 0);
+ cursize++;
+ }
+ }
+ }
+ }
+}
View
20 libstetic/wrapper/Container.cs
@@ -22,7 +22,7 @@ public override void Wrap (object obj, bool initialized)
child.Name = container.Name + "_" + prop.GladeName;
}
- if (!initialized && container.Children.Length == 0)
+ if (!initialized && container.Children.Length == 0 && AllowPlaceholders)
AddPlaceholder ();
container.Removed += ChildRemoved;
@@ -40,6 +40,12 @@ public override void Wrap (object obj, bool initialized)
}
}
+ protected virtual bool AllowPlaceholders {
+ get {
+ return true;
+ }
+ }
+
int freeze;
protected void Freeze ()
{
@@ -74,7 +80,7 @@ public override void GladeImport (XmlElement elem)
try {
if (child_elem.HasAttribute ("internal-child"))
GladeSetInternalChild (child_elem);
- else if (child_elem["widget"] == null)
+ else if (child_elem["widget"] == null && AllowPlaceholders)
AddPlaceholder ();
else
GladeImportChild (child_elem);
@@ -415,7 +421,10 @@ void DragEnd (object obj, Gtk.DragEndArgs args)
dragSource = null;
if (DND.DragWidget == null) {
- ph.SetSizeRequest (-1, -1);
+ if (AllowPlaceholders)
+ ph.SetSizeRequest (-1, -1);
+ else
+ container.Remove (ph);
Sync ();
} else
ReplaceChild (ph, DND.Cancel ());
@@ -429,7 +438,10 @@ void SizeAllocated (object obj, Gtk.SizeAllocatedArgs args)
public void Delete (Stetic.Wrapper.Widget wrapper)
{
- ReplaceChild (wrapper.Wrapped, CreatePlaceholder ());
+ if (AllowPlaceholders)
+ ReplaceChild (wrapper.Wrapped, CreatePlaceholder ());
+ else
+ container.Remove (wrapper.Wrapped);
wrapper.Wrapped.Destroy ();
}
View
7 libstetic/wrapper/Dialog.cs
@@ -93,17 +93,12 @@ public enum StandardButtons {
}
}
- static ClassDescriptor buttonClass;
-
Gtk.Button AddButton (string stockId, Gtk.ResponseType response, bool hasDefault)
{
Stetic.Wrapper.Button wrapper;
Gtk.Button button;
- if (buttonClass == null)
- buttonClass = Registry.LookupClass ("GtkButton");
-
- button = (Gtk.Button)buttonClass.NewInstance (proj);
+ button = (Gtk.Button)Registry.NewInstance (typeof (Gtk.Button), proj);
wrapper = (Stetic.Wrapper.Button) ObjectWrapper.Lookup (button);
if (stockId != null) {
wrapper.Type = Button.ButtonType.StockItem;
View
7 libstetic/wrapper/Notebook.cs
@@ -72,14 +72,9 @@ public override void ReplaceChild (Gtk.Widget oldChild, Gtk.Widget newChild)
}
}
- static ClassDescriptor labelClass;
-
int InsertPage (int position)
{
- if (labelClass == null)
- labelClass = Registry.LookupClass ("GtkLabel");
-
- Gtk.Label label = (Gtk.Label)labelClass.NewInstance (proj);
+ Gtk.Label label = (Gtk.Label)Registry.NewInstance (typeof (Gtk.Label), proj);
label.LabelProp = "page" + (notebook.NPages + 1).ToString ();
tabs.Insert (position, label);
View
16 libstetic/wrapper/objects.xml
@@ -241,14 +241,23 @@
</itemgroups>
</object>
- <object type="Gtk.ButtonBox,gtk-sharp">
+ <object type="Gtk.ButtonBox,gtk-sharp" wrapper="Stetic.Wrapper.ButtonBox">
<itemgroups>
<itemgroup label="Button Box Properties">
+ <property name="Size" label="Size"
+ description="The number of buttons"
+ min="0" />
<property name="LayoutStyle" />
<property name="Spacing" />
<property name="BorderWidth" />
</itemgroup>
</itemgroups>
+ <contextmenu>
+ <command name="InsertBefore" label="Insert Before"
+ description="Insert a new button before the selected one" />
+ <command name="InsertAfter" label="Insert After"
+ description="Insert a new button after the selected one" />
+ </contextmenu>
</object>
<object type="Gtk.ButtonBox+ButtonBoxChild,gtk-sharp">
<itemgroups>
@@ -590,8 +599,7 @@
<itemgroup ref="Gtk.ButtonBox" />
<itemgroup ref="Gtk.Widget" />
</itemgroups>
- <contextmenu ref="Gtk.Box" />
-
+ <contextmenu ref="Gtk.ButtonBox" />
<glade-transform>
<!-- If a child has a "response_id" of -11 (GTK_RESPONSE_HELP), it should be packed with the "secondary" property -->
<import>
@@ -1198,7 +1206,7 @@
<itemgroup ref="Gtk.ButtonBox" />
<itemgroup ref="Gtk.Widget" />
</itemgroups>
- <contextmenu ref="Gtk.Box" />
+ <contextmenu ref="Gtk.ButtonBox" />
</object>
<object type="Gtk.Viewport,gtk-sharp" wrapper="Stetic.Wrapper.Viewport"
View
3 stetic/ContextMenu.cs
@@ -46,7 +46,8 @@ public ContextMenu (Stetic.Wrapper.Widget wrapper, Gtk.Widget context)
ClassDescriptor klass = Registry.LookupClass (widget.GetType ());
if (klass != null) {
- foreach (CommandDescriptor cmd in klass.ContextMenu) {
+ foreach (ItemDescriptor id in klass.ContextMenu) {
+ CommandDescriptor cmd = (CommandDescriptor)id;
item = new MenuItem (cmd.Label);
if (cmd.Enabled (widget, context)) {
Gtk.Widget wdup = widget, cdup = context; // FIXME bxc 75689

0 comments on commit ff551ac

Please sign in to comment.