banshee r4668 - in trunk/banshee: . src/Core/Banshee.ThickClient src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor src/Libraries/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Widgets src/Libraries/Hyena/Hyena
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4668 - in trunk/banshee: . src/Core/Banshee.ThickClient src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor src/Libraries/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Widgets src/Libraries/Hyena/Hyena
- Date: Wed, 8 Oct 2008 21:11:47 +0000 (UTC)
Author: abock
Date: Wed Oct 8 21:11:47 2008
New Revision: 4668
URL: http://svn.gnome.org/viewvc/banshee?rev=4668&view=rev
Log:
* banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextEntry.cs:
* banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/GenreEntry.cs:
* banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEditableUndoAdapter.cs:
Updated to use the now generic EditableUndoAdapter
* banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextViewEntry.cs:
Use the new TextViewEditable, implement ICanUndo
* banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs:
* banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs:
* banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs:
Make generic, adapting widgets implementing Gtk.Editable instead of
only against Gtk.Entry
* banshee/src/Libraries/Hyena/Hyena/IUndoAction.cs: Whitespace
* banshee/src/Libraries/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs: A
Gtk.TextView that implements Gtk.Editable
Added:
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEditableUndoAdapter.cs (contents, props changed)
- copied, changed from r4665, /trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEntryUndoAdapter.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs (contents, props changed)
- copied, changed from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryEraseAction.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs (contents, props changed)
- copied, changed from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryInsertAction.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs (contents, props changed)
- copied, changed from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryUndoAdapter.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs
Removed:
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEntryUndoAdapter.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryEraseAction.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryInsertAction.cs
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryUndoAdapter.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/GenreEntry.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextEntry.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextViewEntry.cs
trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.csproj
trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am
trunk/banshee/src/Libraries/Hyena/Hyena/IUndoAction.cs
Copied: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEditableUndoAdapter.cs (from r4665, /trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEntryUndoAdapter.cs)
==============================================================================
--- /trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEntryUndoAdapter.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/EditorEditableUndoAdapter.cs Wed Oct 8 21:11:47 2008
@@ -1,5 +1,5 @@
//
-// EditorEntryUndoAdapter.cs
+// EditorEditableUndoAdapter.cs
//
// Author:
// Aaron Bockover <abockover novell com>
@@ -34,11 +34,11 @@
namespace Banshee.Gui.TrackEditor
{
- public class EditorEntryUndoAdapter
+ public class EditorEditableUndoAdapter<T> where T : Widget, Editable
{
- private Dictionary<EditorTrackInfo, EntryUndoAdapter> undo_adapters
- = new Dictionary<EditorTrackInfo, EntryUndoAdapter> ();
- private EntryUndoAdapter current_adapter;
+ private Dictionary<EditorTrackInfo, EditableUndoAdapter<T>> undo_adapters
+ = new Dictionary<EditorTrackInfo, EditableUndoAdapter<T>> ();
+ private EditableUndoAdapter<T> current_adapter;
public void DisconnectUndo ()
{
@@ -48,14 +48,14 @@
}
}
- public void ConnectUndo (Entry entry, EditorTrackInfo track)
+ public void ConnectUndo (T entry, EditorTrackInfo track)
{
DisconnectUndo ();
if (undo_adapters.ContainsKey (track)) {
current_adapter = undo_adapters[track];
} else {
- current_adapter = new EntryUndoAdapter (entry);
+ current_adapter = new EditableUndoAdapter<T> (entry);
undo_adapters.Add (track, current_adapter);
}
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/GenreEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/GenreEntry.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/GenreEntry.cs Wed Oct 8 21:11:47 2008
@@ -39,7 +39,7 @@
public class GenreEntry : ComboBoxEntry, ICanUndo, IEditorField
{
private ListStore genre_model;
- private EditorEntryUndoAdapter undo_adapter = new EditorEntryUndoAdapter ();
+ private EditorEditableUndoAdapter<Entry> undo_adapter = new EditorEditableUndoAdapter<Entry> ();
public GenreEntry ()
{
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextEntry.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextEntry.cs Wed Oct 8 21:11:47 2008
@@ -35,7 +35,7 @@
{
public class TextEntry : Entry, IEditorField, ICanUndo
{
- private EditorEntryUndoAdapter undo_adapter = new EditorEntryUndoAdapter ();
+ private EditorEditableUndoAdapter<Entry> undo_adapter = new EditorEditableUndoAdapter<Entry> ();
public TextEntry () : base ()
{
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextViewEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextViewEntry.cs (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TextViewEntry.cs Wed Oct 8 21:11:47 2008
@@ -29,13 +29,18 @@
using System;
using Gtk;
+using Hyena.Widgets;
+
namespace Banshee.Gui.TrackEditor
{
- public class TextViewEntry : ScrolledWindow, IEditorField
- {
+ public class TextViewEntry : Gtk.ScrolledWindow, IEditorField, ICanUndo
+ {
+ private EditorEditableUndoAdapter<TextViewEditable> undo_adapter
+ = new EditorEditableUndoAdapter<TextViewEditable> ();
+
public event EventHandler Changed;
- private TextView entry;
+ private TextViewEditable entry;
public TextView TextView {
get { return entry; }
}
@@ -51,7 +56,7 @@
HscrollbarPolicy = PolicyType.Never;
ShadowType = ShadowType.In;
- Add (entry = new TextView ());
+ Add (entry = new TextViewEditable ());
entry.AcceptsTab = false;
entry.Show ();
entry.Buffer.Changed += OnChanged;
@@ -66,6 +71,16 @@
metrics.Dispose ();
HeightRequest = (line_height + 2) * 2;
}
+
+ public void DisconnectUndo ()
+ {
+ undo_adapter.DisconnectUndo ();
+ }
+
+ public void ConnectUndo (EditorTrackInfo track)
+ {
+ undo_adapter.ConnectUndo (entry, track);
+ }
private void OnChanged (object o, EventArgs args)
{
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj Wed Oct 8 21:11:47 2008
@@ -211,7 +211,7 @@
<Compile Include="Banshee.Preferences.Gui\DescriptionLabel.cs" />
<Compile Include="Banshee.Gui.Dialogs\DefaultApplicationHelperDialog.cs" />
<Compile Include="Banshee.Gui.TrackEditor\ICanUndo.cs" />
- <Compile Include="Banshee.Gui.TrackEditor\EditorEntryUndoAdapter.cs" />
+ <Compile Include="Banshee.Gui.TrackEditor\EditorEditableUndoAdapter.cs" />
<Compile Include="Banshee.Collection.Gui\ColumnCellTrackNumber.cs" />
<Compile Include="Banshee.Collection.Gui\ColumnCellDiscAndCount.cs" />
<Compile Include="Banshee.Collection.Gui\ColumnCellLocation.cs" />
Modified: trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am (original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am Wed Oct 8 21:11:47 2008
@@ -53,7 +53,7 @@
Banshee.Gui.DragDrop/DragDropUtilities.cs \
Banshee.Gui.TrackEditor/AlbumArtistEntry.cs \
Banshee.Gui.TrackEditor/BasicTrackDetailsPage.cs \
- Banshee.Gui.TrackEditor/EditorEntryUndoAdapter.cs \
+ Banshee.Gui.TrackEditor/EditorEditableUndoAdapter.cs \
Banshee.Gui.TrackEditor/EditorMode.cs \
Banshee.Gui.TrackEditor/EditorTrackInfo.cs \
Banshee.Gui.TrackEditor/EditorUtilities.cs \
Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.csproj
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.csproj (original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.csproj Wed Oct 8 21:11:47 2008
@@ -48,9 +48,9 @@
<Compile Include="Hyena.Gui.Dialogs\VersionInformationDialog.cs" />
<Compile Include="Hyena.Gui\CairoExtensions.cs" />
<Compile Include="Hyena.Data.Gui\ObjectListView.cs" />
- <Compile Include="Hyena.Gui\EntryEraseAction.cs" />
- <Compile Include="Hyena.Gui\EntryInsertAction.cs" />
- <Compile Include="Hyena.Gui\EntryUndoAdapter.cs" />
+ <Compile Include="Hyena.Gui\EditableEraseAction.cs" />
+ <Compile Include="Hyena.Gui\EditableInsertAction.cs" />
+ <Compile Include="Hyena.Gui\EditableUndoAdapter.cs" />
<Compile Include="Hyena.Gui\GtkUtilities.cs" />
<Compile Include="Hyena.Data.Gui\CellContext.cs" />
<Compile Include="Hyena.Data.Gui\IHeaderCell.cs" />
@@ -120,6 +120,7 @@
<Compile Include="Hyena.Widgets\PulsingButton.cs" />
<Compile Include="Hyena.Gui.Theatrics\Pulsator.cs" />
<Compile Include="Hyena.Gui\PixbufImageSurface.cs" />
+ <Compile Include="Hyena.Widgets\TextViewEditable.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Copied: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs (from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryEraseAction.cs)
==============================================================================
--- /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryEraseAction.cs (original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableEraseAction.cs Wed Oct 8 21:11:47 2008
@@ -1,10 +1,10 @@
//
-// EntryEraseAction.cs
+// EditableEraseAction.cs
//
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -33,42 +33,42 @@
namespace Hyena.Gui
{
- internal class EntryEraseAction : IUndoAction
+ internal class EditableEraseAction : IUndoAction
{
- private Entry entry;
+ private Editable editable;
private string text;
private int start;
private int end;
private bool is_forward;
private bool is_cut;
- public EntryEraseAction(Entry entry, int start, int end)
+ public EditableEraseAction (Editable editable, int start, int end)
{
- this.entry = entry;
- this.text = entry.GetChars(start, end);
+ this.editable = editable;
+ this.text = editable.GetChars (start, end);
this.start = start;
this.end = end;
this.is_cut = end - start > 1;
- this.is_forward = entry.Position < start;
+ this.is_forward = editable.Position < start;
}
- public void Undo()
+ public void Undo ()
{
int start_r = start;
- entry.InsertText(text, ref start_r);
- entry.Position = is_forward ? start_r : end;
+ editable.InsertText (text, ref start_r);
+ editable.Position = is_forward ? start_r : end;
}
- public void Redo()
+ public void Redo ()
{
- entry.DeleteText(start, end);
- entry.Position = start;
+ editable.DeleteText (start, end);
+ editable.Position = start;
}
- public void Merge(IUndoAction action)
+ public void Merge (IUndoAction action)
{
- EntryEraseAction erase = (EntryEraseAction)action;
- if(start == erase.start) {
+ EditableEraseAction erase = (EditableEraseAction)action;
+ if (start == erase.start) {
text += erase.text;
end += erase.end - erase.start;
} else {
@@ -77,10 +77,10 @@
}
}
- public bool CanMerge(IUndoAction action)
+ public bool CanMerge (IUndoAction action)
{
- EntryEraseAction erase = action as EntryEraseAction;
- if(erase == null) {
+ EditableEraseAction erase = action as EditableEraseAction;
+ if (erase == null) {
return false;
}
@@ -93,9 +93,9 @@
);
}
- public override string ToString()
+ public override string ToString ()
{
- return String.Format("Erased: [{0}] ({1},{2})", text, start, end);
+ return String.Format ("Erased: [{0}] ({1},{2})", text, start, end);
}
}
}
Copied: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs (from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryInsertAction.cs)
==============================================================================
--- /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryInsertAction.cs (original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableInsertAction.cs Wed Oct 8 21:11:47 2008
@@ -1,10 +1,10 @@
//
-// EntryInsertAction.cs
+// EditableInsertAction.cs
//
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -33,44 +33,43 @@
namespace Hyena.Gui
{
- internal class EntryInsertAction : IUndoAction
+ internal class EditableInsertAction : IUndoAction
{
- private Entry entry;
+ private Editable editable;
private string text;
private int index;
private bool is_paste;
- public EntryInsertAction(Entry entry, int start, string text, int length)
+ public EditableInsertAction (Editable editable, int start, string text, int length)
{
- this.entry = entry;
+ this.editable = editable;
this.text = text;
this.index = start;
this.is_paste = length > 1;
}
- public void Undo()
+ public void Undo ()
{
- entry.DeleteText(index, index + text.Length);
- entry.Position = index;
+ editable.DeleteText (index, index + text.Length);
+ editable.Position = index;
}
- public void Redo()
+ public void Redo ()
{
int index_r = index;
- entry.InsertText(text, ref index_r);
- entry.Position = index_r;
+ editable.InsertText (text, ref index_r);
+ editable.Position = index_r;
}
- public void Merge(IUndoAction action)
+ public void Merge (IUndoAction action)
{
- EntryInsertAction insert = (EntryInsertAction)action;
- text += insert.text;
+ text += ((EditableInsertAction)action).text;
}
- public bool CanMerge(IUndoAction action)
+ public bool CanMerge (IUndoAction action)
{
- EntryInsertAction insert = action as EntryInsertAction;
- if(insert == null || String.IsNullOrEmpty(text)) {
+ EditableInsertAction insert = action as EditableInsertAction;
+ if (insert == null || String.IsNullOrEmpty (text)) {
return false;
}
@@ -82,9 +81,9 @@
);
}
- public override string ToString()
+ public override string ToString ()
{
- return String.Format("Inserted: [{0}] ({1})", text, index);
+ return String.Format ("Inserted: [{0}] ({1})", text, index);
}
}
}
Copied: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs (from r4665, /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryUndoAdapter.cs)
==============================================================================
--- /trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EntryUndoAdapter.cs (original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/EditableUndoAdapter.cs Wed Oct 8 21:11:47 2008
@@ -1,10 +1,10 @@
//
-// EntryUndoAdapter.cs
+// EditableUndoAdapter.cs
//
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -27,50 +27,69 @@
//
using System;
+using System.Reflection;
using Gtk;
using Hyena;
namespace Hyena.Gui
{
- public class EntryUndoAdapter
+ public class EditableUndoAdapter<T> where T : Widget, Editable
{
- private Entry entry;
- private UndoManager undo_manager = new UndoManager();
- private AccelGroup accel_group = new AccelGroup();
-
- public EntryUndoAdapter(Entry entry)
- {
- this.entry = entry;
+ private T editable;
+ private UndoManager undo_manager = new UndoManager ();
+ private AccelGroup accel_group = new AccelGroup ();
+ private EventInfo popup_event_info;
+ private Delegate populate_popup_handler;
+
+ public EditableUndoAdapter (T editable)
+ {
+ this.editable = editable;
+ popup_event_info = editable.GetType ().GetEvent ("PopulatePopup");
+ if (popup_event_info != null) {
+ populate_popup_handler = new PopulatePopupHandler (OnPopulatePopup);
+ }
}
public void Connect ()
{
- entry.KeyPressEvent += OnKeyPressEvent;
- entry.TextDeleted += OnTextDeleted;
- entry.TextInserted += OnTextInserted;
- entry.PopulatePopup += OnPopulatePopup;
+ editable.KeyPressEvent += OnKeyPressEvent;
+ editable.TextDeleted += OnTextDeleted;
+ editable.TextInserted += OnTextInserted;
+ TogglePopupConnection (true);
}
public void Disconnect ()
{
- entry.KeyPressEvent -= OnKeyPressEvent;
- entry.TextDeleted -= OnTextDeleted;
- entry.TextInserted -= OnTextInserted;
- entry.PopulatePopup -= OnPopulatePopup;
+ editable.KeyPressEvent -= OnKeyPressEvent;
+ editable.TextDeleted -= OnTextDeleted;
+ editable.TextInserted -= OnTextInserted;
+ TogglePopupConnection (false);
+ }
+
+ private void TogglePopupConnection (bool connect)
+ {
+ // Ugh, stupid Gtk+/Gtk# and lack of interfaces
+ if (popup_event_info != null && populate_popup_handler != null) {
+ if (connect) {
+ popup_event_info.AddEventHandler (editable, populate_popup_handler);
+ } else {
+ popup_event_info.RemoveEventHandler (editable, populate_popup_handler);
+ }
+ }
}
- private void OnKeyPressEvent(object o, KeyPressEventArgs args)
+ private void OnKeyPressEvent (object o, KeyPressEventArgs args)
{
- if((args.Event.State & Gdk.ModifierType.ControlMask) != 0) {
- switch(args.Event.Key) {
+ if ((args.Event.State & Gdk.ModifierType.ControlMask) != 0) {
+ switch (args.Event.Key) {
case Gdk.Key.z:
- undo_manager.Undo();
+ undo_manager.Undo ();
args.RetVal = true;
break;
case Gdk.Key.Z:
case Gdk.Key.y:
- undo_manager.Redo();
+ undo_manager.Redo ();
args.RetVal = true;
break;
}
@@ -80,46 +99,44 @@
}
[GLib.ConnectBefore]
- private void OnTextDeleted(object o, TextDeletedArgs args)
+ private void OnTextDeleted (object o, TextDeletedArgs args)
{
- if(args.StartPos != args.EndPos) {
- undo_manager.AddUndoAction(new EntryEraseAction(entry,
- args.StartPos, args.EndPos));
+ if (args.StartPos != args.EndPos) {
+ undo_manager.AddUndoAction (new EditableEraseAction (editable, args.StartPos, args.EndPos));
}
}
[GLib.ConnectBefore]
- private void OnTextInserted(object o, TextInsertedArgs args)
+ private void OnTextInserted (object o, TextInsertedArgs args)
{
- undo_manager.AddUndoAction(new EntryInsertAction(entry,
- args.Position, args.Text, args.Length));
+ undo_manager.AddUndoAction (new EditableInsertAction (editable, args.Position, args.Text, args.Length));
}
- private void OnPopulatePopup(object o, PopulatePopupArgs args)
+ private void OnPopulatePopup (object o, PopulatePopupArgs args)
{
Menu menu = args.Menu;
MenuItem item;
- item = new SeparatorMenuItem();
- item.Show();
- menu.Prepend(item);
+ item = new SeparatorMenuItem ();
+ item.Show ();
+ menu.Prepend (item);
- item = new ImageMenuItem(Stock.Redo, null);
+ item = new ImageMenuItem (Stock.Redo, null);
item.Sensitive = undo_manager.CanRedo;
- item.Activated += delegate { undo_manager.Redo(); };
- item.AddAccelerator("activate", accel_group, (uint)Gdk.Key.z,
+ item.Activated += delegate { undo_manager.Redo (); };
+ item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask,
AccelFlags.Visible);
- item.Show();
- menu.Prepend(item);
+ item.Show ();
+ menu.Prepend (item);
- item = new ImageMenuItem(Stock.Undo, null);
+ item = new ImageMenuItem (Stock.Undo, null);
item.Sensitive = undo_manager.CanUndo;
- item.Activated += delegate { undo_manager.Undo(); };
- item.AddAccelerator("activate", accel_group, (uint)Gdk.Key.z,
+ item.Activated += delegate { undo_manager.Undo (); };
+ item.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.z,
Gdk.ModifierType.ControlMask, AccelFlags.Visible);
- item.Show();
- menu.Prepend(item);
+ item.Show ();
+ menu.Prepend (item);
}
public UndoManager UndoManager {
Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Widgets/TextViewEditable.cs Wed Oct 8 21:11:47 2008
@@ -0,0 +1,159 @@
+//
+// TextViewEditable.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Gtk;
+
+namespace Hyena.Widgets
+{
+ public class TextViewEditable : TextView, Editable
+ {
+ public TextViewEditable ()
+ {
+ Buffer.Changed += OnBufferChanged;
+ Buffer.InsertText += OnBufferInsertText;
+ Buffer.DeleteRange += OnBufferDeleteRange;
+ }
+
+ public event EventHandler Changed;
+ public event TextDeletedHandler TextDeleted;
+ public event TextInsertedHandler TextInserted;
+
+ private void OnBufferChanged (object o, EventArgs args)
+ {
+ EventHandler handler = Changed;
+ if (handler != null) {
+ handler (this, EventArgs.Empty);
+ }
+ }
+
+ private void OnBufferInsertText (object o, InsertTextArgs args)
+ {
+ TextInsertedHandler handler = TextInserted;
+ if (handler != null) {
+ TextInsertedArgs raise_args = new TextInsertedArgs ();
+ raise_args.Args = new object [] {
+ args.Text,
+ args.Length,
+ args.Pos.Offset
+ };
+ handler (this, raise_args);
+ }
+ }
+
+ private void OnBufferDeleteRange (object o, DeleteRangeArgs args)
+ {
+ TextDeletedHandler handler = TextDeleted;
+ if (handler != null) {
+ TextDeletedArgs raise_args = new TextDeletedArgs ();
+ raise_args.Args = new object [] {
+ args.Start.Offset,
+ args.End.Offset
+ };
+ handler (this, raise_args);
+ }
+ }
+
+ void Editable.PasteClipboard ()
+ {
+ }
+
+ void Editable.CutClipboard ()
+ {
+ }
+
+ void Editable.CopyClipboard ()
+ {
+ }
+
+ public void DeleteText (int start_pos, int end_pos)
+ {
+ start_pos--;
+ end_pos--;
+
+ TextIter start_iter = Buffer.GetIterAtOffset (start_pos);
+ TextIter end_iter = Buffer.GetIterAtOffset (start_pos + (end_pos - start_pos));
+ Buffer.Delete (ref start_iter, ref end_iter);
+ }
+
+ public void InsertText (string new_text, ref int position)
+ {
+ TextIter iter = Buffer.GetIterAtOffset (position - 1);
+ Buffer.Insert (ref iter, new_text);
+ position = iter.Offset + 1;
+ }
+
+ public string GetChars (int start_pos, int end_pos)
+ {
+ start_pos--;
+ end_pos--;
+
+ TextIter start_iter = Buffer.GetIterAtOffset (start_pos);
+ TextIter end_iter = Buffer.GetIterAtOffset (start_pos + (end_pos - start_pos));
+ return Buffer.GetText (start_iter, end_iter, true);
+ }
+
+ public void SelectRegion (int start, int end)
+ {
+ Buffer.SelectRange (Buffer.GetIterAtOffset (start - 1), Buffer.GetIterAtOffset (end - 1));
+ }
+
+ public bool GetSelectionBounds (out int start, out int end)
+ {
+ TextIter start_iter, end_iter;
+ start = 0;
+ end = 0;
+
+ if (Buffer.GetSelectionBounds (out start_iter, out end_iter)) {
+ start = start_iter.Offset + 1;
+ end = end_iter.Offset + 1;
+ return true;
+ }
+
+ return true;
+ }
+
+ public void DeleteSelection ()
+ {
+ TextIter start, end;
+ if (Buffer.GetSelectionBounds (out start, out end)) {
+ Buffer.Delete (ref start, ref end);
+ }
+ }
+
+ public int Position {
+ get { return Buffer.CursorPosition; }
+ set { Buffer.PlaceCursor (Buffer.GetIterAtOffset (Position)); }
+ }
+
+ public bool IsEditable {
+ get { return Editable; }
+ set { Editable = value; }
+ }
+ }
+}
Modified: trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am (original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am Wed Oct 8 21:11:47 2008
@@ -44,9 +44,9 @@
Hyena.Gui/CleanRoomStartup.cs \
Hyena.Gui/CompositeUtils.cs \
Hyena.Gui/Contrast.cs \
- Hyena.Gui/EntryEraseAction.cs \
- Hyena.Gui/EntryInsertAction.cs \
- Hyena.Gui/EntryUndoAdapter.cs \
+ Hyena.Gui/EditableEraseAction.cs \
+ Hyena.Gui/EditableInsertAction.cs \
+ Hyena.Gui/EditableUndoAdapter.cs \
Hyena.Gui/GtkUtilities.cs \
Hyena.Gui/GtkWorkarounds.cs \
Hyena.Gui/PangoCairoHelper.cs \
@@ -85,6 +85,7 @@
Hyena.Widgets/ScrolledWindow.cs \
Hyena.Widgets/SegmentedBar.cs \
Hyena.Widgets/SmoothScrolledWindow.cs \
+ Hyena.Widgets/TextViewEditable.cs \
Hyena.Widgets/WrapLabel.cs
RESOURCES =
Modified: trunk/banshee/src/Libraries/Hyena/Hyena/IUndoAction.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena/IUndoAction.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena/IUndoAction.cs Wed Oct 8 21:11:47 2008
@@ -4,7 +4,7 @@
// Author:
// Aaron Bockover <abockover novell com>
//
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2007-2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -30,9 +30,9 @@
{
public interface IUndoAction
{
- void Undo();
- void Redo();
- void Merge(IUndoAction action);
- bool CanMerge(IUndoAction action);
+ void Undo ();
+ void Redo ();
+ void Merge (IUndoAction action);
+ bool CanMerge (IUndoAction action);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]