Author: lluis
Date: 2007-10-16 07:59:17 -0400 (Tue, 16 Oct 2007)
New Revision: 87578
Added:
trunk/stetic/libstetic/Clipboard.cs
trunk/stetic/libstetic/IEditableObject.cs
trunk/stetic/libstetic/editor/ActionItem.cs
Removed:
trunk/stetic/libsteticui/Clipboard.cs
Modified:
trunk/stetic/ChangeLog
trunk/stetic/libstetic/Makefile.am
trunk/stetic/libstetic/Placeholder.cs
trunk/stetic/libstetic/editor/ActionGroupEditor.cs
trunk/stetic/libstetic/editor/ActionMenu.cs
trunk/stetic/libstetic/editor/ActionMenuBar.cs
trunk/stetic/libstetic/editor/ActionMenuItem.cs
trunk/stetic/libstetic/editor/ActionToolItem.cs
trunk/stetic/libstetic/editor/ActionToolbar.cs
trunk/stetic/libstetic/libstetic.mdp
trunk/stetic/libstetic/wrapper/Widget.cs
trunk/stetic/libsteticui/ContextMenu.cs
trunk/stetic/libsteticui/Makefile.am
trunk/stetic/libsteticui/ProjectBackend.cs
trunk/stetic/libsteticui/WidgetDesigner.cs
trunk/stetic/libsteticui/WidgetEditSession.cs
trunk/stetic/libsteticui/libsteticui.mdp
Log:
* libstetic/Clipboard.cs, libsteticui/Clipboard.cs: Moved to libstetic.
* libstetic/editor/ActionGroupEditor.cs,
libstetic/editor/ActionItem.cs, libstetic/editor/ActionMenuItem.cs,
libstetic/editor/ActionToolItem.cs: Factorized common code in
ActionMenuItem and ActionToolItem into ActionItem. Implemented
IEditableObject.
* libstetic/editor/ActionMenu.cs: Improved support for keyboard. Return
now edits the selected item, and ctrl+right/left adds/removes
submenus.
* libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionToolbar.cs:
Keep the selection when a node is deleted. Track other api changes.
* libstetic/IEditableObject.cs: New interface to be implemented by
objects which can handle clipboard operations.
* libstetic/libstetic.mdp, libstetic/Makefile.am,
libsteticui/libsteticui.mdp, libsteticui/Makefile.am: Updated.
* libstetic/Placeholder.cs, libstetic/wrapper/Widget.cs: Implemented
IEditableObject.
* libsteticui/ContextMenu.cs: Use the new IEditableObject interface to
implement the clipboard operations.
* libsteticui/ProjectBackend.cs, libsteticui/WidgetDesigner.cs,
libsteticui/WidgetEditSession.cs: Use IEditableObject to handle
clipboard operations.
Modified: trunk/stetic/ChangeLog
===================================================================
--- trunk/stetic/ChangeLog 2007-10-16 11:55:06 UTC (rev 87577)
+++ trunk/stetic/ChangeLog 2007-10-16 11:59:17 UTC (rev 87578)
@@ -1,5 +1,28 @@
2007-10-16 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+ * libstetic/Clipboard.cs, libsteticui/Clipboard.cs: Moved to libstetic.
+ * libstetic/editor/ActionGroupEditor.cs, libstetic/editor/ActionItem.cs,
+ libstetic/editor/ActionMenuItem.cs,
libstetic/editor/ActionToolItem.cs:
+ Factorized common code in ActionMenuItem and ActionToolItem into
+ ActionItem. Implemented IEditableObject.
+ * libstetic/editor/ActionMenu.cs: Improved support for keyboard. Return
now
+ edits the selected item, and ctrl+right/left adds/removes submenus.
+ * libstetic/editor/ActionMenuBar.cs, libstetic/editor/ActionToolbar.cs:
Keep
+ the selection when a node is deleted. Track other api changes.
+ * libstetic/IEditableObject.cs: New interface to be implemented by
objects
+ which can handle clipboard operations.
+ * libstetic/libstetic.mdp, libstetic/Makefile.am,
+ libsteticui/libsteticui.mdp, libsteticui/Makefile.am: Updated.
+ * libstetic/Placeholder.cs, libstetic/wrapper/Widget.cs: Implemented
+ IEditableObject.
+ * libsteticui/ContextMenu.cs: Use the new IEditableObject interface to
+ implement the clipboard operations.
+ * libsteticui/ProjectBackend.cs, libsteticui/WidgetDesigner.cs,
+ libsteticui/WidgetEditSession.cs: Use IEditableObject to handle
+ clipboard operations.
+
+2007-10-16 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
* libsteticui/WidgetEditSession.cs: Removed unneeded dispose and destroy
calls. The toolbar will be destroyed together with the parent.
* libsteticui/ActionGroupEditSession.cs: If the designer has not been
Copied: trunk/stetic/libstetic/Clipboard.cs (from rev 83669,
trunk/stetic/libsteticui/Clipboard.cs)
Added: trunk/stetic/libstetic/IEditableObject.cs
===================================================================
--- trunk/stetic/libstetic/IEditableObject.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/IEditableObject.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -0,0 +1,18 @@
+
+using System;
+
+namespace Stetic
+{
+ public interface IEditableObject
+ {
+ bool CanCopy { get; }
+ bool CanCut { get; }
+ bool CanPaste { get; }
+ bool CanDelete { get; }
+
+ void Copy ();
+ void Cut ();
+ void Paste ();
+ void Delete ();
+ }
+}
Modified: trunk/stetic/libstetic/Makefile.am
===================================================================
--- trunk/stetic/libstetic/Makefile.am 2007-10-16 11:55:06 UTC (rev 87577)
+++ trunk/stetic/libstetic/Makefile.am 2007-10-16 11:59:17 UTC (rev 87578)
@@ -10,11 +10,13 @@
pkglib_DATA = $(ASSEMBLY_FILES)
libstetic_dll_sources = \
ClassDescriptor.cs \
+ Clipboard.cs \
CommandDescriptor.cs \
CustomWidget.cs \
DND.cs \
editor/Accelerator.cs \
editor/ActionGroupEditor.cs \
+ editor/ActionItem.cs \
editor/ActionMenu.cs \
editor/ActionMenuBar.cs \
editor/ActionMenuItem.cs \
@@ -69,6 +71,7 @@
GladeException.cs \
GladeUtils.cs \
IDesignArea.cs \
+ IEditableObject.cs \
ImageInfo.cs \
IProject.cs \
IPropertyEditor.cs \
Modified: trunk/stetic/libstetic/Placeholder.cs
===================================================================
--- trunk/stetic/libstetic/Placeholder.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/Placeholder.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -3,7 +3,7 @@
namespace Stetic {
- public class Placeholder : Gtk.DrawingArea
+ public class Placeholder : Gtk.DrawingArea, IEditableObject
{
// This id is used by the undo methods to identify a child of a
container.
string undoId;
@@ -81,5 +81,41 @@
return base.OnExposeEvent (evt);
}
+
+ bool IEditableObject.CanDelete {
+ get { return true; }
+ }
+
+ bool IEditableObject.CanPaste {
+ get { return true; }
+ }
+
+ bool IEditableObject.CanCut {
+ get { return false; }
+ }
+
+ bool IEditableObject.CanCopy {
+ get { return false; }
+ }
+
+ void IEditableObject.Delete ()
+ {
+ Stetic.Wrapper.Container wc =
Stetic.Wrapper.Container.LookupParent (this);
+ if (wc != null)
+ wc.Delete (this);
+ }
+
+ void IEditableObject.Paste ()
+ {
+ Clipboard.Paste (this);
+ }
+
+ void IEditableObject.Cut ()
+ {
+ }
+
+ void IEditableObject.Copy ()
+ {
+ }
}
}
Modified: trunk/stetic/libstetic/editor/ActionGroupEditor.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionGroupEditor.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libstetic/editor/ActionGroupEditor.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -392,8 +392,10 @@
md.Destroy ();
}
- public void ShowContextMenu (ActionMenuItem menuItem)
+ void IMenuItemContainer.ShowContextMenu (ActionItem aitem)
{
+ ActionMenuItem menuItem = aitem as ActionMenuItem;
+
Gtk.Menu m = new Gtk.Menu ();
Gtk.MenuItem item = new Gtk.ImageMenuItem
(Gtk.Stock.Cut, null);
m.Add (item);
Added: trunk/stetic/libstetic/editor/ActionItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionItem.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/editor/ActionItem.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -0,0 +1,201 @@
+
+using System;
+using Stetic.Wrapper;
+
+namespace Stetic.Editor
+{
+ abstract class ActionItem: Gtk.EventBox, IEditableObject
+ {
+ protected IMenuItemContainer parentMenu;
+ protected ActionTreeNode node;
+ protected Widget wrapper;
+ protected bool localUpdate;
+ protected bool editOnRelease;
+ protected bool editing;
+ protected uint itemSpacing;
+ protected int minWidth;
+
+ // To use in the action editor
+ protected IDesignArea designArea;
+ protected IProject project;
+
+ public ActionItem (ActionTreeNode node, IMenuItemContainer
parent, uint itemSpacing)
+ {
+ DND.SourceSet (this);
+ this.parentMenu = parent;
+ this.node = node;
+ this.VisibleWindow = false;
+ this.CanFocus = true;
+ this.Events |= Gdk.EventMask.KeyPressMask;
+ this.itemSpacing = itemSpacing;
+ if (node.Action != null)
+ node.Action.ObjectChanged += OnActionChanged;
+ }
+
+ public ActionTreeNode Node {
+ get { return node; }
+ }
+
+ public uint ItemSpacing {
+ get { return itemSpacing; }
+ set { itemSpacing = value; }
+ }
+
+ public int MinWidth {
+ get { return minWidth; }
+ set { minWidth = value; }
+ }
+
+ public bool IsSelected {
+ get {
+ IDesignArea area = GetDesignArea ();
+ return area.IsSelected (this);
+ }
+ }
+
+ protected void UpdateSelectionStatus ()
+ {
+ IDesignArea area = GetDesignArea ();
+ IObjectSelection sel = area.GetSelection ();
+ sel.Disposed -= OnSelectionDisposed;
+ sel.Drag -= HandleItemDrag;
+
+ area.ResetSelection (this);
+
+ sel = area.SetSelection (this, this);
+ sel.Drag += HandleItemDrag;
+ sel.Disposed += OnSelectionDisposed;
+ }
+
+ public virtual void Select ()
+ {
+ IDesignArea area = GetDesignArea ();
+ if (area.IsSelected (this))
+ return;
+ IObjectSelection sel = area.SetSelection (this, this);
+ sel.Drag += HandleItemDrag;
+ sel.Disposed += OnSelectionDisposed;
+ GrabFocus ();
+ }
+
+ void OnSelectionDisposed (object ob, EventArgs a)
+ {
+ EndEditing (Gdk.Key.Return);
+ }
+
+ protected virtual void EndEditing (Gdk.Key exitKey)
+ {
+ }
+
+ void HandleItemDrag (Gdk.EventMotion evt, int dx, int dy)
+ {
+ ActionPaletteItem item = new ActionPaletteItem (node);
+ DND.Drag (parentMenu.Widget, evt, item);
+ }
+
+ protected IDesignArea GetDesignArea ()
+ {
+ if (wrapper != null)
+ return wrapper.GetDesignArea ();
+ else
+ return designArea;
+ }
+
+ protected IProject GetProject ()
+ {
+ if (wrapper != null)
+ return wrapper.Project;
+ else
+ return project;
+ }
+
+ void OnActionChanged (object ob, ObjectWrapperEventArgs a)
+ {
+ if (!localUpdate)
+ Refresh ();
+ }
+
+ public abstract void Refresh ();
+
+ protected override bool OnButtonPressEvent (Gdk.EventButton ev)
+ {
+ return ProcessButtonPress (ev);
+ }
+
+ public bool ProcessButtonPress (Gdk.EventButton ev)
+ {
+ if (ev.Button == 1) {
+ IDesignArea area = GetDesignArea ();
+ if (area == null)
+ return true;
+
+ // Clicking a selected item starts the edit mode
+ if (area.IsSelected (this)) {
+ editOnRelease = true;
+ return true;
+ }
+ } else if (ev.Button == 3) {
+ parentMenu.ShowContextMenu (this);
+ }
+
+ Select ();
+ return true;
+ }
+
+ protected override void OnDragBegin (Gdk.DragContext ctx)
+ {
+ ProcessDragBegin (ctx, null);
+ }
+
+ public virtual void ProcessDragBegin (Gdk.DragContext ctx,
Gdk.EventMotion evt)
+ {
+ editOnRelease = false;
+ ActionPaletteItem item = new ActionPaletteItem (node);
+ if (ctx != null)
+ DND.Drag (parentMenu.Widget, ctx, item);
+ else
+ DND.Drag (parentMenu.Widget, evt, item);
+ }
+
+ public bool CanCopy {
+ get { return !editing; }
+ }
+
+ public bool CanCut {
+ get { return false; }
+ }
+
+ public bool CanPaste {
+ get { return false; }
+ }
+
+ public bool CanDelete {
+ get { return !editing; }
+ }
+
+ public void Copy ()
+ {
+ }
+
+ public void Cut ()
+ {
+ }
+
+ public void Paste ()
+ {
+ }
+
+ public void Delete ()
+ {
+ if (node.ParentNode != null)
+ node.ParentNode.Children.Remove (node);
+ Destroy ();
+ }
+
+ void IEditableObject.Delete ()
+ {
+ if (!editing)
+ Delete ();
+ }
+ }
+}
Modified: trunk/stetic/libstetic/editor/ActionMenu.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenu.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/editor/ActionMenu.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -65,6 +65,8 @@
} else {
if (menuItems.Count > 0)
((ActionMenuItem)menuItems [0]).Select
();
+ else
+ InsertAction (0);
}
}
@@ -195,7 +197,7 @@
}
}
- void InsertAction (int pos)
+ ActionTreeNode InsertAction (int pos)
{
using (wrapper.UndoManager.AtomicChange) {
Action ac = (Action) ObjectWrapper.Create
(wrapper.Project, new Gtk.Action ("", "", null, null));
@@ -210,11 +212,22 @@
if (wrapper.LocalActionGroups.Count == 0)
wrapper.LocalActionGroups.Add (new
ActionGroup ("Default"));
wrapper.LocalActionGroups [0].Actions.Add (ac);
+ return newNode;
}
}
- void OnEditingDone (object ob, EventArgs args)
+ void DeleteAction (ActionMenuItem item)
{
+ int pos = menuItems.IndexOf (item);
+ item.Delete ();
+ if (pos >= menuItems.Count)
+ SelectLastItem ();
+ else
+ ((ActionMenuItem)menuItems [pos]).Select ();
+ }
+
+ void OnEditingDone (object ob, MenuItemEditEventArgs args)
+ {
ActionMenuItem item = (ActionMenuItem) ob;
item.EditingDone -= OnEditingDone;
if (item.Node.Action.GtkAction.Label.Length == 0 &&
item.Node.Action.GtkAction.StockId == null) {
@@ -224,9 +237,28 @@
nodes.Remove (item.Node);
wrapper.LocalActionGroups
[0].Actions.Remove (item.Node.Action);
}
+ SelectLastItem ();
}
+ else {
+ if (args.ExitKey == Gdk.Key.Up || args.ExitKey
== Gdk.Key.Down)
+ ProcessKey (item, args.ExitKey,
Gdk.ModifierType.None);
+ }
}
+ void SelectLastItem ()
+ {
+ if (menuItems.Count > 0)
+ ((ActionMenuItem)menuItems [menuItems.Count -
1]).Select ();
+ else if (parentMenu.Widget is ActionMenuBar) {
+ ActionMenuBar bar = (ActionMenuBar)
parentMenu.Widget;
+ bar.Select (parentNode);
+ }
+ else if (parentMenu.Widget is ActionMenu) {
+ ActionMenu parentAM = (ActionMenu)
parentMenu.Widget;
+ parentAM.Select (parentNode);
+ }
+ }
+
void OnChildAdded (object ob, ActionTreeNodeArgs args)
{
Refresh ();
@@ -234,6 +266,11 @@
void OnChildRemoved (object ob, ActionTreeNodeArgs args)
{
+ IDesignArea area = wrapper.GetDesignArea ();
+ IObjectSelection asel = area.GetSelection ();
+ ActionMenuItem curSel = asel != null ? asel.DataObject
as ActionMenuItem : null;
+ int pos = menuItems.IndexOf (curSel);
+
ActionMenuItem mi = FindMenuItem (args.Node);
if (mi != null) {
// Remove the table row that contains the menu
item
@@ -248,6 +285,10 @@
if (tc.BottomAttach > row)
tc.BottomAttach--;
}
+ if (pos != -1 && pos < menuItems.Count)
+ ((ActionMenuItem)menuItems[pos]).Select
();
+ else
+ SelectLastItem ();
GLib.Timeout.Add (50, new GLib.TimeoutHandler
(RepositionSubmenu));
}
}
@@ -376,12 +417,19 @@
return base.OnDragDrop (context, x, y, time);
}
+ [GLib.ConnectBefore]
void OnItemKeyPress (object s, Gtk.KeyPressEventArgs args)
{
- int pos = menuItems.IndexOf (s);
ActionMenuItem item = (ActionMenuItem) s;
+ ProcessKey (item, args.Event.Key, args.Event.State);
+ args.RetVal = true;
+ }
+
+ void ProcessKey (ActionMenuItem item, Gdk.Key key,
Gdk.ModifierType modifier)
+ {
+ int pos = menuItems.IndexOf (item);
- switch (args.Event.Key) {
+ switch (key) {
case Gdk.Key.Up:
if (pos > 0)
((ActionMenuItem)menuItems[pos
- 1]).Select ();
@@ -398,6 +446,13 @@
}
break;
case Gdk.Key.Right:
+ if ((modifier &
Gdk.ModifierType.ControlMask) != 0 && item.Node.Type ==
Gtk.UIManagerItemType.Menuitem) {
+ // Create a submenu
+ using
(item.Node.Action.UndoManager.AtomicChange) {
+ item.Node.Type =
Gtk.UIManagerItemType.Menu;
+ }
+ item.Node.Action.NotifyChanged
();
+ }
if (item.HasSubmenu) {
item.ShowSubmenu ();
if (openSubmenu != null)
@@ -412,6 +467,16 @@
}
break;
case Gdk.Key.Left:
+ if ((modifier &
Gdk.ModifierType.ControlMask) != 0 && item.Node.Type ==
Gtk.UIManagerItemType.Menu) {
+ // Remove the submenu
+ OpenSubmenu = null;
+ using
(item.Node.Action.UndoManager.AtomicChange) {
+ item.Node.Type =
Gtk.UIManagerItemType.Menuitem;
+
item.Node.Children.Clear ();
+ }
+ item.Node.Action.NotifyChanged
();
+ break;
+ }
if (parentNode != null) {
ActionMenu parentAM =
parentMenu.Widget as ActionMenu;
if (parentAM != null) {
@@ -425,8 +490,20 @@
}
}
break;
+ case Gdk.Key.Return:
+ item.EditingDone += OnEditingDone;
+ item.StartEditing ();
+ break;
+ case Gdk.Key.Insert:
+ if ((modifier &
Gdk.ModifierType.ControlMask) != 0)
+ InsertActionAt (item, true,
true);
+ else
+ InsertActionAt (item, false,
false);
+ break;
+ case Gdk.Key.Delete:
+ DeleteAction (item);
+ break;
}
- args.RetVal = true;
}
void InsertActionAt (ActionMenuItem item, bool after, bool
separator)
@@ -441,6 +518,7 @@
if (separator) {
ActionTreeNode newNode = new ActionTreeNode
(Gtk.UIManagerItemType.Separator, null, null);
nodes.Insert (pos, newNode);
+ Select (newNode);
} else
InsertAction (pos);
}
@@ -449,8 +527,9 @@
{
}
- public void ShowContextMenu (ActionMenuItem menuItem)
+ void IMenuItemContainer.ShowContextMenu (ActionItem aitem)
{
+ ActionMenuItem menuItem = aitem as ActionMenuItem;
Gtk.Menu m = new Gtk.Menu ();
Gtk.MenuItem item = new Gtk.MenuItem (Catalog.GetString
("Insert Before"));
m.Add (item);
@@ -497,7 +576,7 @@
item = new Gtk.ImageMenuItem (Gtk.Stock.Delete, null);
m.Add (item);
item.Activated += delegate (object s, EventArgs a) {
- menuItem.Delete ();
+ DeleteAction (menuItem);
};
m.ShowAll ();
m.Popup ();
@@ -568,6 +647,6 @@
ActionMenu OpenSubmenu { get; set; }
bool IsTopMenu { get; }
Gtk.Widget Widget { get; }
- void ShowContextMenu (ActionMenuItem item);
+ void ShowContextMenu (ActionItem item);
}
}
Modified: trunk/stetic/libstetic/editor/ActionMenuBar.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenuBar.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libstetic/editor/ActionMenuBar.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -198,6 +198,14 @@
void OnChildRemoved (object ob, ActionTreeNodeArgs args)
{
+ OpenSubmenu = null;
+
+ Widget wrapper = Widget.Lookup (this);
+ IDesignArea area = wrapper.GetDesignArea ();
+ IObjectSelection asel = area.GetSelection ();
+ ActionMenuItem curSel = asel != null ? asel.DataObject
as ActionMenuItem : null;
+ int pos = menuItems.IndexOf (curSel);
+
foreach (Gtk.Widget w in Children) {
if (w is CustomMenuBarItem &&
((CustomMenuBarItem)w).ActionMenuItem.Node == args.Node) {
Remove (w);
@@ -207,6 +215,10 @@
break;
}
}
+ if (pos != -1 && pos < menuItems.Count)
+ ((ActionMenuItem)menuItems[pos]).Select ();
+ else if (menuItems.Count > 0)
+
((ActionMenuItem)menuItems[menuItems.Count-1]).Select ();
}
void Refresh ()
@@ -476,8 +488,10 @@
{
}
- public void ShowContextMenu (ActionMenuItem menuItem)
+ public void ShowContextMenu (ActionItem aitem)
{
+ ActionMenuItem menuItem = (ActionMenuItem) aitem;
+
Gtk.Menu m = new Gtk.Menu ();
Gtk.MenuItem item = new Gtk.MenuItem (Catalog.GetString
("Insert Before"));
m.Add (item);
Modified: trunk/stetic/libstetic/editor/ActionMenuItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionMenuItem.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libstetic/editor/ActionMenuItem.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -5,32 +5,19 @@
namespace Stetic.Editor
{
- public class ActionMenuItem: Gtk.EventBox
+ class ActionMenuItem: ActionItem
{
- ActionTreeNode node;
- Widget wrapper;
- IMenuItemContainer parentMenu;
-
Gtk.Widget icon;
Gtk.Widget label;
Gtk.Widget accel;
- bool editing;
- bool localUpdate;
- bool editOnRelease;
bool motionDrag;
CustomMenuBarItem menuBarItem;
- uint itemSpacing;
- int minWidth;
static Gdk.Pixbuf addMenuImage;
static Gdk.Pixbuf removeMenuImage;
- // To use in the action editor
- IDesignArea designArea;
- IProject project;
+ public event MenuItemEditEventHandler EditingDone;
- public event EventHandler EditingDone;
-
static ActionMenuItem ()
{
addMenuImage = Gdk.Pixbuf.LoadFromResource
("add-menu.png");
@@ -49,18 +36,9 @@
this.designArea = designArea;
}
- internal ActionMenuItem (Widget wrapper, IMenuItemContainer
parent, ActionTreeNode node, uint itemSpacing)
+ internal ActionMenuItem (Widget wrapper, IMenuItemContainer
parent, ActionTreeNode node, uint itemSpacing): base (node, parent, itemSpacing)
{
- DND.SourceSet (this);
- this.parentMenu = parent;
this.wrapper = wrapper;
- this.node = node;
- if (node.Action != null)
- node.Action.ObjectChanged += OnActionChanged;
- this.VisibleWindow = false;
- this.CanFocus = true;
- this.Events |= Gdk.EventMask.KeyPressMask;
- this.itemSpacing = itemSpacing;
CreateControls ();
}
@@ -76,39 +54,29 @@
base.Dispose ();
}
- public ActionTreeNode Node {
- get { return node; }
- }
-
public bool HasSubmenu {
get { return node.Type == Gtk.UIManagerItemType.Menu; }
}
- public uint ItemSpacing {
- get { return itemSpacing; }
- set { itemSpacing = value; }
- }
-
- public int MinWidth {
- get { return minWidth; }
- set { minWidth = value; }
- }
-
public void StartEditing ()
{
if (!editing) {
editing = true;
+
Refresh ();
if (node.Type == Gtk.UIManagerItemType.Menu)
HideSubmenu ();
+
+ UpdateSelectionStatus ();
}
}
- public void EndEditing ()
+
+ protected override void EndEditing (Gdk.Key exitKey)
{
if (editing) {
Gtk.Entry entry = label as Gtk.Entry;
- if (entry != null) {
+ if (entry != null && exitKey != Gdk.Key.Escape)
{
localUpdate = true;
if (entry.Text.Length > 0 ||
node.Action.GtkAction.StockId != null) {
using
(node.Action.UndoManager.AtomicChange) {
@@ -131,49 +99,27 @@
}
}
GrabFocus ();
- if (EditingDone != null)
- EditingDone (this, EventArgs.Empty);
+ UpdateSelectionStatus ();
+
+ if (EditingDone != null) {
+ MenuItemEditEventArgs args = new
MenuItemEditEventArgs ();
+ args.ExitKey = exitKey;
+ EditingDone (this, args);
+ }
}
}
- public void Select ()
+ public override void Select ()
{
- IDesignArea area = GetDesignArea ();
- if (area.IsSelected (this))
- return;
- IObjectSelection sel = area.SetSelection (this,
node.Action != null ? node.Action.GtkAction : null);
- sel.Drag += HandleItemDrag;
- sel.Disposed += OnSelectionDisposed;
+ base.Select ();
parentMenu.OpenSubmenu = null;
if (HasSubmenu)
- ShowSubmenu (area, this);
+ ShowSubmenu (GetDesignArea (), this);
GrabFocus ();
}
- public bool IsSelected {
- get {
- IDesignArea area = GetDesignArea ();
- return area.IsSelected (this);
- }
- }
-
- public void Copy ()
- {
- }
-
- public void Cut ()
- {
- }
-
- public void Delete ()
- {
- if (node.ParentNode != null)
- node.ParentNode.Children.Remove (node);
- Destroy ();
- }
-
public void Attach (Gtk.Table table, uint row, uint col)
{
table.Attach (this, col, col + 3, row, row + 1);
@@ -292,6 +238,7 @@
Gtk.Entry entry = new Gtk.Entry ();
entry.Text = text;
entry.Activated += OnLabelActivated;
+ entry.KeyPressEvent += OnEntryKeyPress;
entry.HasFrame = false;
this.label = entry;
tooltips.SetTip (entry, Catalog.GetString
("Action label"), "");
@@ -307,10 +254,10 @@
string tip;
if (node.Type != Gtk.UIManagerItemType.Menu) {
img = addMenuImage;
- tip = Catalog.GetString ("Add submenu");
+ tip = Catalog.GetString ("Add submenu
(Ctrl+Right)");
} else {
img = removeMenuImage;
- tip = Catalog.GetString ("Remove
submenu");
+ tip = Catalog.GetString ("Remove
submenu (Ctrl+Left)");
}
Gtk.Button sb = new Gtk.Button (new Gtk.Image
(img));
@@ -364,16 +311,30 @@
node.Type = Gtk.UIManagerItemType.Menu;
}
- EndEditing ();
+ EndEditing (Gdk.Key.Return);
node.Action.NotifyChanged ();
}
}
void OnLabelActivated (object ob, EventArgs args)
{
- EndEditing ();
+ EndEditing (Gdk.Key.Return);
}
+ [GLib.ConnectBefore]
+ void OnEntryKeyPress (object ob, Gtk.KeyPressEventArgs args)
+ {
+ switch (args.Event.Key) {
+ case Gdk.Key.Down:
+ case Gdk.Key.Escape:
+ case Gdk.Key.Up:
+ EndEditing (args.Event.Key);
+ args.RetVal = true;
+ break;
+ }
+ args.RetVal = false;
+ }
+
[GLib.ConnectBeforeAttribute]
void OnSelectIcon (object sender, Gtk.ButtonPressEventArgs e)
{
@@ -463,7 +424,7 @@
}
}
- public void Refresh ()
+ public override void Refresh ()
{
Gtk.Table table = (Gtk.Table)Parent;
if (table == null)
@@ -525,31 +486,6 @@
}
}
- protected override bool OnButtonPressEvent (Gdk.EventButton ev)
- {
- return ProcessButtonPress (ev);
- }
-
- public bool ProcessButtonPress (Gdk.EventButton ev)
- {
- if (ev.Button == 1) {
- IDesignArea area = GetDesignArea ();
- if (area == null)
- return true;
-
- // Clicking a selected item starts the edit mode
- if (area.IsSelected (this)) {
- editOnRelease = true;
- return true;
- }
- } else if (ev.Button == 3) {
- parentMenu.ShowContextMenu (this);
- }
-
- Select ();
- return true;
- }
-
protected override bool OnButtonReleaseEvent (Gdk.EventButton
ev)
{
return ProcessButtonRelease (ev);
@@ -565,21 +501,11 @@
return true;
}
- protected override void OnDragBegin (Gdk.DragContext ctx)
+ public override void ProcessDragBegin (Gdk.DragContext ctx,
Gdk.EventMotion evt)
{
- ProcessDragBegin (ctx, null);
- }
-
- public void ProcessDragBegin (Gdk.DragContext ctx,
Gdk.EventMotion evt)
- {
if (HasSubmenu)
HideSubmenu ();
- editOnRelease = false;
- ActionPaletteItem item = new ActionPaletteItem (node);
- if (ctx != null)
- DND.Drag (parentMenu.Widget, ctx, item);
- else
- DND.Drag (parentMenu.Widget, evt, item);
+ base.ProcessDragBegin (ctx, evt);
}
void OnActionChanged (object ob, ObjectWrapperEventArgs a)
@@ -588,18 +514,13 @@
Refresh ();
}
- void OnSelectionDisposed (object ob, EventArgs a)
- {
- EndEditing ();
- }
-
public bool IsSubmenuVisible {
get {
ActionMenu menu = parentMenu.OpenSubmenu;
return (menu != null && menu.ParentNode ==
node);
}
}
-
+
public void ShowSubmenu ()
{
ShowSubmenu (wrapper.GetDesignArea (), this);
@@ -621,28 +542,6 @@
{
parentMenu.OpenSubmenu = null;
}
-
- void HandleItemDrag (Gdk.EventMotion evt, int dx, int dy)
- {
- ActionPaletteItem item = new ActionPaletteItem (node);
- DND.Drag (parentMenu.Widget, evt, item);
- }
-
- IDesignArea GetDesignArea ()
- {
- if (wrapper != null)
- return wrapper.GetDesignArea ();
- else
- return designArea;
- }
-
- IProject GetProject ()
- {
- if (wrapper != null)
- return wrapper.Project;
- else
- return project;
- }
}
class CheckActionIcon: Gtk.EventBox
@@ -670,4 +569,11 @@
return true;
}
}
+
+ delegate void MenuItemEditEventHandler (object s, MenuItemEditEventArgs
args);
+
+ class MenuItemEditEventArgs: EventArgs
+ {
+ public Gdk.Key ExitKey;
+ }
}
Modified: trunk/stetic/libstetic/editor/ActionToolItem.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionToolItem.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libstetic/editor/ActionToolItem.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -5,19 +5,12 @@
namespace Stetic.Editor
{
- public class ActionToolItem: Gtk.EventBox
+ class ActionToolItem: ActionItem
{
- ActionTreeNode node;
- Widget wrapper;
- ActionToolbar parentMenu;
+ ActionToolbar parentToolbar;
- bool editing;
- bool localUpdate;
- bool editOnRelease;
bool motionDrag;
- uint itemSpacing;
bool showingText;
- int minWidth;
Gtk.Widget dropButton;
public event EventHandler EditingDone;
@@ -27,35 +20,13 @@
{
}
- internal ActionToolItem (Widget wrapper, ActionToolbar parent,
ActionTreeNode node, uint itemSpacing)
+ internal ActionToolItem (Widget wrapper, ActionToolbar parent,
ActionTreeNode node, uint itemSpacing): base (node, parent, itemSpacing)
{
- DND.SourceSet (this);
- this.parentMenu = parent;
+ this.parentToolbar = parent;
this.wrapper = wrapper;
- this.node = node;
- if (node.Action != null)
- node.Action.ObjectChanged += OnActionChanged;
- this.VisibleWindow = false;
- this.CanFocus = true;
- this.Events |= Gdk.EventMask.KeyPressMask;
- this.itemSpacing = itemSpacing;
CreateControls ();
}
- public ActionTreeNode Node {
- get { return node; }
- }
-
- public uint ItemSpacing {
- get { return itemSpacing; }
- set { itemSpacing = value; }
- }
-
- public int MinWidth {
- get { return minWidth; }
- set { minWidth = value; }
- }
-
public void StartEditing (bool doClick)
{
if (!editing && node.Action != null) {
@@ -74,7 +45,7 @@
}
}
- public void EndEditing ()
+ protected override void EndEditing (Gdk.Key exitKey)
{
if (editing) {
editing = false;
@@ -86,40 +57,7 @@
EditingDone (this, EventArgs.Empty);
}
}
-
- public void Select ()
- {
- IDesignArea area = GetDesignArea ();
- if (area.IsSelected (this))
- return;
- IObjectSelection sel = area.SetSelection (this,
node.Action != null ? node.Action.GtkAction : null);
- sel.Drag += HandleItemDrag;
- sel.Disposed += OnSelectionDisposed;
- GrabFocus ();
- }
-
- public bool IsSelected {
- get {
- IDesignArea area = GetDesignArea ();
- return area.IsSelected (this);
- }
- }
-
- public void Copy ()
- {
- }
-
- public void Cut ()
- {
- }
-
- public void Delete ()
- {
- if (node.ParentNode != null)
- node.ParentNode.Children.Remove (node);
- Destroy ();
- }
-
+
void CreateControls ()
{
Gtk.Widget icon = null;
@@ -134,7 +72,7 @@
if (node.Type == Gtk.UIManagerItemType.Separator) {
Gtk.Widget sep;
- if (parentMenu.Orientation ==
Gtk.Orientation.Horizontal) {
+ if (parentToolbar.Orientation ==
Gtk.Orientation.Horizontal) {
sep = new Gtk.VSeparator ();
} else {
sep = new Gtk.HSeparator ();
@@ -151,13 +89,13 @@
Gtk.Action gaction = node.Action.GtkAction;
- bool showText = parentMenu.ToolbarStyle ==
Gtk.ToolbarStyle.Text;
- bool showIcon = parentMenu.ToolbarStyle ==
Gtk.ToolbarStyle.Icons;
- if (parentMenu.ToolbarStyle == Gtk.ToolbarStyle.Both) {
+ bool showText = parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.Text;
+ bool showIcon = parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.Icons;
+ if (parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.Both) {
showText = showIcon = true;
}
- else if (parentMenu.ToolbarStyle ==
Gtk.ToolbarStyle.BothHoriz) {
- showText = parentMenu.Orientation ==
Gtk.Orientation.Vertical || gaction.IsImportant;
+ else if (parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.BothHoriz) {
+ showText = parentToolbar.Orientation ==
Gtk.Orientation.Vertical || gaction.IsImportant;
showIcon = true;
}
@@ -167,7 +105,7 @@
if (showIcon)
{
if (gaction.StockId != null) {
- icon = node.Action.CreateIcon
(parentMenu.IconSize);
+ icon = node.Action.CreateIcon
(parentToolbar.IconSize);
} else if (!gaction.IsImportant) {
icon = CreateFakeItem ();
}
@@ -206,12 +144,12 @@
}
if (icon != null && label != null) {
- if (parentMenu.ToolbarStyle ==
Gtk.ToolbarStyle.BothHoriz) {
+ if (parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.BothHoriz) {
Gtk.HBox box = new Gtk.HBox ();
box.PackStart (icon, false, false, 0);
box.PackStart (label, true, true, 0);
icon = box;
- } else if (parentMenu.ToolbarStyle ==
Gtk.ToolbarStyle.Both) {
+ } else if (parentToolbar.ToolbarStyle ==
Gtk.ToolbarStyle.Both) {
Gtk.VBox box = new Gtk.VBox ();
Gtk.Alignment al = new Gtk.Alignment
(0.5f, 0f, 0f, 0f);
al.Add (icon);
@@ -249,7 +187,7 @@
Gtk.Frame frm = new Gtk.Frame ();
frm.ShadowType = Gtk.ShadowType.Out;
int w, h;
- Gtk.Icon.SizeLookup (parentMenu.IconSize, out w, out h);
+ Gtk.Icon.SizeLookup (parentToolbar.IconSize, out w, out
h);
frm.WidthRequest = w;
frm.HeightRequest = h;
return frm;
@@ -271,7 +209,7 @@
void OnLabelActivated (object ob, EventArgs args)
{
- EndEditing ();
+ EndEditing (Gdk.Key.Return);
}
[GLib.ConnectBeforeAttribute]
@@ -373,7 +311,7 @@
}
}
- public void Refresh ()
+ public override void Refresh ()
{
CreateControls ();
}
@@ -409,31 +347,6 @@
}
}
- protected override bool OnButtonPressEvent (Gdk.EventButton ev)
- {
- return ProcessButtonPress (ev);
- }
-
- public bool ProcessButtonPress (Gdk.EventButton ev)
- {
- if (ev.Button == 1) {
- IDesignArea area = GetDesignArea ();
- if (area == null)
- return true;
-
- // Clicking a selected item starts the edit mode
- if (area.IsSelected (this)) {
- editOnRelease = true;
- return true;
- }
- } else if (ev.Button == 3) {
- parentMenu.ShowContextMenu (this);
- }
-
- Select ();
- return true;
- }
-
protected override bool OnButtonReleaseEvent (Gdk.EventButton
ev)
{
return ProcessButtonRelease (ev);
@@ -453,50 +366,10 @@
protected override bool OnKeyPressEvent (Gdk.EventKey e)
{
if (e.Key == Gdk.Key.Return)
- EndEditing ();
+ EndEditing (Gdk.Key.Return);
+ else if (e.Key == Gdk.Key.Escape)
+ EndEditing (Gdk.Key.Escape);
return base.OnKeyPressEvent (e);
}
-
- protected override void OnDragBegin (Gdk.DragContext ctx)
- {
- ProcessDragBegin (ctx, null);
- }
-
- public void ProcessDragBegin (Gdk.DragContext ctx,
Gdk.EventMotion evt)
- {
- editOnRelease = false;
- ActionPaletteItem item = new ActionPaletteItem (node);
- if (ctx != null)
- DND.Drag (parentMenu, ctx, item);
- else
- DND.Drag (parentMenu, evt, item);
- }
-
- void OnActionChanged (object ob, ObjectWrapperEventArgs a)
- {
- if (!localUpdate)
- Refresh ();
- }
-
- void OnSelectionDisposed (object ob, EventArgs a)
- {
- EndEditing ();
- }
-
- void HandleItemDrag (Gdk.EventMotion evt, int dx, int dy)
- {
- ActionPaletteItem item = new ActionPaletteItem (node);
- DND.Drag (parentMenu, evt, item);
- }
-
- IDesignArea GetDesignArea ()
- {
- return wrapper.GetDesignArea ();
- }
-
- IProject GetProject ()
- {
- return wrapper.Project;
- }
}
}
Modified: trunk/stetic/libstetic/editor/ActionToolbar.cs
===================================================================
--- trunk/stetic/libstetic/editor/ActionToolbar.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libstetic/editor/ActionToolbar.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -7,7 +7,7 @@
namespace Stetic.Editor
{
- class ActionToolbar: Gtk.Toolbar
+ class ActionToolbar: Gtk.Toolbar, IMenuItemContainer
{
ActionTree actionTree;
int dropPosition = -1;
@@ -43,7 +43,7 @@
HideSpacerItem ();
toolItems.Clear ();
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
foreach (Gtk.Widget w in Children) {
Remove (w);
@@ -140,11 +140,24 @@
}
}
}
+
+ public Stetic.Editor.ActionMenu OpenSubmenu {
+ get { return null; }
+ set { }
+ }
+
+ public bool IsTopMenu {
+ get { return true; }
+ }
+
+ public Gtk.Widget Widget {
+ get { return this; }
+ }
public void Unselect ()
{
// Unselects any selected item
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
IDesignArea area = wrapper.GetDesignArea ();
if (area != null) {
foreach (Gtk.Widget w in Children) {
@@ -162,6 +175,12 @@
void OnChildRemoved (object ob, ActionTreeNodeArgs args)
{
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
+ IDesignArea area = wrapper.GetDesignArea ();
+ IObjectSelection asel = area.GetSelection ();
+ ActionToolItem curSel = asel != null ? asel.DataObject
as ActionToolItem : null;
+ int pos = toolItems.IndexOf (curSel);
+
foreach (Gtk.Widget w in Children) {
if (w is CustomToolbarItem &&
((CustomToolbarItem)w).ActionToolItem.Node == args.Node) {
Remove (w);
@@ -172,11 +191,16 @@
break;
}
}
+
+ if (pos != -1 && pos < toolItems.Count)
+ ((ActionToolItem)toolItems[pos]).Select ();
+ else if (toolItems.Count > 0)
+
((ActionToolItem)toolItems[toolItems.Count-1]).Select ();
}
void Refresh ()
{
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
IDesignArea area = wrapper.GetDesignArea ();
if (area == null)
return;
@@ -211,7 +235,7 @@
void InsertAction (int pos)
{
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
using (wrapper.UndoManager.AtomicChange) {
Action ac = (Action) ObjectWrapper.Create
(wrapper.Project, new Gtk.Action ("", "", null, null));
ActionTreeNode node = new ActionTreeNode
(Gtk.UIManagerItemType.Toolitem, "", ac);
@@ -231,7 +255,7 @@
void OnEditingDone (object ob, EventArgs args)
{
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
if (wrapper == null)
return;
@@ -334,7 +358,7 @@
newNode.Type = Gtk.UIManagerItemType.Toolitem;
}
- Widget wrapper = Widget.Lookup (this);
+ Widget wrapper = Stetic.Wrapper.Widget.Lookup (this);
using (wrapper.UndoManager.AtomicChange) {
if (dropIndex < actionTree.Children.Count) {
// Do nothing if trying to drop the
node over the same node
@@ -415,8 +439,10 @@
{
}
- public void ShowContextMenu (ActionToolItem menuItem)
+ public void ShowContextMenu (ActionItem aitem)
{
+ ActionToolItem menuItem = aitem as ActionToolItem;
+
Gtk.Menu m = new Gtk.Menu ();
Gtk.MenuItem item = new Gtk.MenuItem (Catalog.GetString
("Insert Before"));
m.Add (item);
Modified: trunk/stetic/libstetic/libstetic.mdp
===================================================================
--- trunk/stetic/libstetic/libstetic.mdp 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/libstetic.mdp 2007-10-16 11:59:17 UTC (rev
87578)
@@ -247,6 +247,9 @@
<File name="./wrapper/pixmaps/comboentry.png" subtype="Code"
buildaction="EmbedAsResource" />
<File name="./wrapper/pixmaps/iconview.png" subtype="Code"
buildaction="EmbedAsResource" />
<File name="./wrapper/IconView.cs" subtype="Code" buildaction="Compile" />
+ <File name="./IEditableObject.cs" subtype="Code" buildaction="Compile" />
+ <File name="./Clipboard.cs" subtype="Code" buildaction="Compile" />
+ <File name="./editor/ActionItem.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="gnome-sharp,
Version=2.4.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Modified: trunk/stetic/libstetic/wrapper/Widget.cs
===================================================================
--- trunk/stetic/libstetic/wrapper/Widget.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libstetic/wrapper/Widget.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -6,7 +6,7 @@
namespace Stetic.Wrapper {
- public class Widget : Object
+ public class Widget : Object, IEditableObject
{
static DiffGenerator propDiffGenerator;
@@ -859,6 +859,72 @@
if (MemberNameChanged != null)
MemberNameChanged (this, args);
}
+
+ bool IEditableObject.CanCopy {
+ get { return ClipboardCanCopy; }
+ }
+
+ bool IEditableObject.CanCut {
+ get { return ClipboardCanCut; }
+ }
+
+ bool IEditableObject.CanPaste {
+ get { return ClipboardCanPaste; }
+ }
+
+ bool IEditableObject.CanDelete {
+ get { return CanDelete; }
+ }
+
+ void IEditableObject.Copy ()
+ {
+ ClipboardCopy ();
+ }
+
+ void IEditableObject.Cut ()
+ {
+ ClipboardCut ();
+ }
+
+ void IEditableObject.Paste ()
+ {
+ ClipboardPaste ();
+ }
+
+ void IEditableObject.Delete ()
+ {
+ Delete ();
+ }
+
+ protected virtual bool ClipboardCanCopy {
+ get { return !IsTopLevel; }
+ }
+
+ protected virtual bool ClipboardCanCut {
+ get { return InternalChildProperty == null &&
!IsTopLevel; }
+ }
+
+ protected virtual bool ClipboardCanPaste {
+ get { return false; }
+ }
+
+ protected virtual bool CanDelete {
+ get { return ClipboardCanCut; }
+ }
+
+ protected virtual void ClipboardCopy ()
+ {
+ Clipboard.Copy (Wrapped);
+ }
+
+ protected virtual void ClipboardCut ()
+ {
+ Clipboard.Cut (Wrapped);
+ }
+
+ protected virtual void ClipboardPaste ()
+ {
+ }
}
internal static class InsensitiveManager {
Deleted: trunk/stetic/libsteticui/Clipboard.cs
===================================================================
--- trunk/stetic/libsteticui/Clipboard.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/Clipboard.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -1,91 +0,0 @@
-using Gtk;
-using System;
-using System.Xml;
-
-namespace Stetic {
-
- internal static class Clipboard {
-
- const int SteticType = 0;
- const int TextType = 1;
-
- static Gtk.TargetEntry[] targets;
- static Gtk.TargetEntry[] Targets {
- get {
- if (targets == null) {
-#if GTK_SHARP_2_6
- Gtk.TargetList list = new
Gtk.TargetList ();
- list.Add
((string)WidgetUtils.ApplicationXSteticAtom, 0, SteticType);
- list.AddTextTargets (TextType);
- targets = (Gtk.TargetEntry[])list;
-#else
- targets = new Gtk.TargetEntry[] {
- new Gtk.TargetEntry
((string)WidgetUtils.ApplicationXSteticAtom, 0, SteticType)
- };
-#endif
- }
- return targets;
- }
- }
-
- static Gtk.Clipboard MainClipboard {
- get {
- return Gtk.Clipboard.Get
(Gdk.Selection.Clipboard);
- }
- }
-
- static XmlElement selection;
-
- static void ClipboardGet (Gtk.Clipboard clipboard,
Gtk.SelectionData seldata, uint info)
- {
- if (selection == null)
- return;
-
- if (info == TextType)
- seldata.Text = selection.OuterXml;
- else
- seldata.Set
(WidgetUtils.ApplicationXSteticAtom, 8, System.Text.Encoding.UTF8.GetBytes
(selection.OuterXml));
- }
-
- static void ClipboardClear (Gtk.Clipboard clipboard)
- {
- selection = null;
- }
-
- public static void Copy (Gtk.Widget widget)
- {
- MainClipboard.SetWithData (Targets, ClipboardGet,
ClipboardClear);
- selection = widget != null ? WidgetUtils.ExportWidget
(widget) : null;
- }
-
- public static void Cut (Gtk.Widget widget)
- {
- Copy (widget);
- Stetic.Wrapper.Widget wrapper =
Stetic.Wrapper.Widget.Lookup (widget);
- if (wrapper != null)
- wrapper.Delete ();
- }
-
- static Placeholder target;
-
- static void ClipboardPaste (Gtk.Clipboard clipboard,
Gtk.SelectionData seldata)
- {
- Stetic.Wrapper.Container parent =
Stetic.Wrapper.Container.LookupParent (target);
- if (parent == null)
- return;
-
- Stetic.Wrapper.Widget wrapper = WidgetUtils.Paste
(parent.Project, seldata);
- if (wrapper == null)
- return;
-
- parent.PasteChild (target, wrapper.Wrapped);
- target = null;
- }
-
- public static void Paste (Placeholder target)
- {
- Clipboard.target = target;
- MainClipboard.RequestContents
(WidgetUtils.ApplicationXSteticAtom, ClipboardPaste);
- }
- }
-}
Modified: trunk/stetic/libsteticui/ContextMenu.cs
===================================================================
--- trunk/stetic/libsteticui/ContextMenu.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/ContextMenu.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -9,11 +9,13 @@
class ContextMenu : Gtk.Menu {
Gtk.Widget widget;
+ IEditableObject editable;
public ContextMenu (Placeholder ph)
{
MenuItem item;
+ editable = ph;
this.widget = ph;
item = LabelItem (ph);
@@ -24,7 +26,7 @@
item.Sensitive = false;
Add (item);
- BuildContextMenu (Stetic.Wrapper.Container.LookupParent
(ph), false, false, true, ph);
+ BuildContextMenu (Stetic.Wrapper.Container.LookupParent
(ph), true, ph);
}
public ContextMenu (Stetic.Wrapper.Widget wrapper) : this
(wrapper, wrapper.Wrapped) {}
@@ -33,6 +35,7 @@
{
MenuItem item;
+ editable = wrapper;
widget = wrapper.Wrapped;
if (widget == context) {
@@ -61,35 +64,35 @@
}
}
- BuildContextMenu (wrapper.ParentWrapper, true,
wrapper.InternalChildProperty != null, widget == context, context);
+ BuildContextMenu (wrapper.ParentWrapper, widget ==
context, context);
}
- void BuildContextMenu (Stetic.Wrapper.Widget parentWrapper,
bool occupied, bool isInternal, bool top, Widget context)
+ void BuildContextMenu (Stetic.Wrapper.Widget parentWrapper,
bool top, Widget context)
{
MenuItem item;
item = new ImageMenuItem (Gtk.Stock.Cut, null);
- if (occupied && !isInternal && parentWrapper != null)
+ if (editable.CanCut)
item.Activated += DoCut;
else
item.Sensitive = false;
Add (item);
item = new ImageMenuItem (Gtk.Stock.Copy, null);
- if (occupied)
+ if (editable.CanCopy)
item.Activated += DoCopy;
else
item.Sensitive = false;
Add (item);
item = new ImageMenuItem (Gtk.Stock.Paste, null);
- if (!occupied)
+ if (editable.CanPaste)
item.Activated += DoPaste;
else
item.Sensitive = false;
Add (item);
- if (!isInternal && parentWrapper != null) {
+ if (editable.CanDelete) {
item = new ImageMenuItem (Gtk.Stock.Delete,
null);
item.Activated += DoDelete;
Add (item);
@@ -122,32 +125,22 @@
void DoCut (object obj, EventArgs args)
{
- Clipboard.Cut (widget);
+ editable.Cut ();
}
void DoCopy (object obj, EventArgs args)
{
- Clipboard.Copy (widget);
+ editable.Copy ();
}
void DoPaste (object obj, EventArgs args)
{
- Clipboard.Paste (widget as Placeholder);
+ editable.Paste ();
}
void DoDelete (object obj, EventArgs args)
{
- Stetic.Wrapper.Widget wrapper =
Stetic.Wrapper.Widget.Lookup (widget);
- if (wrapper != null) {
- wrapper.Delete ();
- } else {
- Placeholder ph = widget as Placeholder;
- if (ph != null) {
- Stetic.Wrapper.Container wc =
Stetic.Wrapper.Container.LookupParent (ph);
- if (wc != null)
- wc.Delete (ph);
- }
- }
+ editable.Delete ();
}
static MenuItem LabelItem (Gtk.Widget widget)
Modified: trunk/stetic/libsteticui/Makefile.am
===================================================================
--- trunk/stetic/libsteticui/Makefile.am 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/Makefile.am 2007-10-16 11:59:17 UTC (rev
87578)
@@ -25,7 +25,6 @@
CecilPropertyDescriptor.cs \
CecilSignalDescriptor.cs \
CecilWidgetLibrary.cs \
- Clipboard.cs \
CodeGenerationResult.cs \
CodeGenerator.cs \
CodeGeneratorInternalClass.cs \
Modified: trunk/stetic/libsteticui/ProjectBackend.cs
===================================================================
--- trunk/stetic/libsteticui/ProjectBackend.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/ProjectBackend.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -505,21 +505,6 @@
GladeFiles.Export (this, fileName);
}
- internal void ClipboardCopySelection ()
- {
- Clipboard.Copy (Selection);
- }
-
- public void ClipboardCutSelection ()
- {
- Clipboard.Cut (Selection);
- }
-
- public void ClipboardPaste ()
- {
- Clipboard.Paste (Selection as Placeholder);
- }
-
public void EditIcons ()
{
using (Stetic.Editor.EditIconFactoryDialog dlg = new
Stetic.Editor.EditIconFactoryDialog (null, this, this.IconFactory)) {
@@ -527,21 +512,6 @@
}
}
- public void DeleteSelection ()
- {
- Stetic.Wrapper.Widget wrapper =
Stetic.Wrapper.Widget.Lookup (Selection);
- if (wrapper != null)
- wrapper.Delete ();
- else {
- Placeholder ph = Selection as Placeholder;
- if (ph != null) {
- Stetic.Wrapper.Container wc =
Stetic.Wrapper.Container.LookupParent (ph);
- if (wc != null)
- wc.Delete (ph);
- }
- }
- }
-
internal WidgetEditSession CreateWidgetDesignerSession
(WidgetDesignerFrontend frontend, string windowName, Stetic.ProjectBackend
editingBackend, bool autoCommitChanges)
{
return new WidgetEditSession (this, frontend,
windowName, editingBackend, autoCommitChanges);
Modified: trunk/stetic/libsteticui/WidgetDesigner.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetDesigner.cs 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/WidgetDesigner.cs 2007-10-16 11:59:17 UTC (rev
87578)
@@ -170,25 +170,25 @@
public void CopySelection ()
{
if (session != null)
- session.EditingBackend.ClipboardCopySelection
();
+ session.ClipboardCopySelection ();
}
public void CutSelection ()
{
if (session != null)
- session.EditingBackend.ClipboardCutSelection ();
+ session.ClipboardCutSelection ();
}
public void PasteToSelection ()
{
if (session != null)
- session.EditingBackend.ClipboardPaste ();
+ session.ClipboardPaste ();
}
public void DeleteSelection ()
{
if (session != null)
- session.EditingBackend.DeleteSelection ();
+ session.DeleteSelection ();
}
public bool CanDeleteSelection {
Modified: trunk/stetic/libsteticui/WidgetEditSession.cs
===================================================================
--- trunk/stetic/libsteticui/WidgetEditSession.cs 2007-10-16 11:55:06 UTC
(rev 87577)
+++ trunk/stetic/libsteticui/WidgetEditSession.cs 2007-10-16 11:59:17 UTC
(rev 87578)
@@ -353,16 +353,15 @@
bool canCut, canCopy, canPaste, canDelete;
ObjectWrapper obj = ObjectWrapper.Lookup
(widget.Selection);
Stetic.Wrapper.Widget wrapper = obj as
Stetic.Wrapper.Widget;
- if (wrapper != null) {
- canCut = wrapper.InternalChildProperty
== null && !wrapper.IsTopLevel;
- canCopy = !wrapper.IsTopLevel;
- canPaste = false;
- canDelete = canCut;
+ IEditableObject editable = widget.Selection as
IEditableObject;
+ if (editable == null)
+ editable = obj as IEditableObject;
+ if (editable != null) {
+ canCut = editable.CanCut;
+ canCopy = editable.CanCopy;
+ canPaste = editable.CanPaste;
+ canDelete = editable.CanDelete;
}
- else if (widget.Selection is Placeholder) {
- canCut = canCopy = false;
- canPaste = canDelete = true;
- }
else {
canCut = canCopy = canPaste = canDelete
= false;
}
@@ -381,5 +380,41 @@
public void RestoreState (object sessionData)
{
}
+
+ internal void ClipboardCopySelection ()
+ {
+ IEditableObject editable = widget.Selection as
IEditableObject;
+ if (editable == null)
+ editable = ObjectWrapper.Lookup
(widget.Selection) as IEditableObject;
+ if (editable != null)
+ editable.Copy ();
+ }
+
+ public void ClipboardCutSelection ()
+ {
+ IEditableObject editable = widget.Selection as
IEditableObject;
+ if (editable == null)
+ editable = ObjectWrapper.Lookup
(widget.Selection) as IEditableObject;
+ if (editable != null)
+ editable.Cut ();
+ }
+
+ public void ClipboardPaste ()
+ {
+ IEditableObject editable = widget.Selection as
IEditableObject;
+ if (editable == null)
+ editable = ObjectWrapper.Lookup
(widget.Selection) as IEditableObject;
+ if (editable != null)
+ editable.Paste ();
+ }
+
+ public void DeleteSelection ()
+ {
+ IEditableObject editable = widget.Selection as
IEditableObject;
+ if (editable == null)
+ editable = ObjectWrapper.Lookup
(widget.Selection) as IEditableObject;
+ if (editable != null)
+ editable.Delete ();
+ }
}
}
Modified: trunk/stetic/libsteticui/libsteticui.mdp
===================================================================
--- trunk/stetic/libsteticui/libsteticui.mdp 2007-10-16 11:55:06 UTC (rev
87577)
+++ trunk/stetic/libsteticui/libsteticui.mdp 2007-10-16 11:59:17 UTC (rev
87578)
@@ -14,7 +14,6 @@
</Configuration>
</Configurations>
<Contents>
- <File name="./Clipboard.cs" subtype="Code" buildaction="Compile" />
<File name="./ContextMenu.cs" subtype="Code" buildaction="Compile" />
<File name="./Grid.cs" subtype="Code" buildaction="Compile" />
<File name="./PaletteBackend.cs" subtype="Code" buildaction="Compile" />
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches