6 changed files with 360 additions and 9 deletions
@ -0,0 +1,68 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 20:05 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.Core.WinForms; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.Commands |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of DesignerVerbSubmenuBuilder.
|
||||||
|
/// </summary>
|
||||||
|
public class DesignerVerbSubmenuBuilder : IMenuItemBuilder |
||||||
|
{ |
||||||
|
#region IMenuItemBuilder implementation
|
||||||
|
|
||||||
|
public IEnumerable<object> BuildItems(Codon codon, object owner) |
||||||
|
{ |
||||||
|
var menuCommandService = (IMenuCommandService)owner; |
||||||
|
|
||||||
|
var items = new List<ToolStripItem>(); |
||||||
|
|
||||||
|
foreach (DesignerVerb verb in menuCommandService.Verbs) { |
||||||
|
Console.WriteLine("{0}",verb.Text); |
||||||
|
items.Add(new ContextMenuCommand(verb)); |
||||||
|
} |
||||||
|
|
||||||
|
// add separator at the end of custom designer verbs
|
||||||
|
if (items.Count > 0) { |
||||||
|
items.Add(new MenuSeparator()); |
||||||
|
} |
||||||
|
|
||||||
|
return items.ToArray(); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
|
||||||
|
sealed class ContextMenuCommand : ICSharpCode.Core.WinForms.MenuCommand |
||||||
|
{ |
||||||
|
DesignerVerb verb; |
||||||
|
|
||||||
|
public ContextMenuCommand(DesignerVerb verb) : base(verb.Text) |
||||||
|
{ |
||||||
|
this.Enabled = verb.Enabled; |
||||||
|
// this.Checked = verb.Checked;
|
||||||
|
this.verb = verb; |
||||||
|
Click += InvokeCommand; |
||||||
|
} |
||||||
|
|
||||||
|
void InvokeCommand(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
try { |
||||||
|
verb.Invoke(); |
||||||
|
} catch (Exception ex) { |
||||||
|
MessageService.ShowException(ex); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 20:35 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.Reporting.Addin.Views; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.Commands |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of FormsCommands.
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public abstract class AbstractFormsDesignerCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public abstract CommandID CommandID { |
||||||
|
get; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual bool CanExecuteCommand(IDesignerHost host) |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
protected static DesignerView ReportDesigner { |
||||||
|
get { |
||||||
|
var window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||||
|
if (window == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return window.ActiveViewContent as DesignerView; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
var formDesigner = ReportDesigner; |
||||||
|
if (formDesigner != null && CanExecuteCommand(formDesigner.Host)) { |
||||||
|
var menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService)); |
||||||
|
menuCommandService.GlobalInvoke(CommandID); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
internal virtual void CommandCallBack(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
Run(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class ViewCode : AbstractFormsDesignerCommand |
||||||
|
{ |
||||||
|
public override CommandID CommandID { |
||||||
|
get { |
||||||
|
return StandardCommands.ViewCode; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
var window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; |
||||||
|
if (window == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
var formDesigner = AbstractFormsDesignerCommand.ReportDesigner; |
||||||
|
if (formDesigner != null) { |
||||||
|
formDesigner.ShowSourceCode(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Peter Forstmeier |
||||||
|
* Date: 21.05.2014 |
||||||
|
* Time: 19:37 |
||||||
|
* |
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||||
|
*/ |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel.Design; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.SharpDevelop.WinForms; |
||||||
|
|
||||||
|
namespace ICSharpCode.Reporting.Addin.UndoRedo |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of ReportDesignerUndoEngine.
|
||||||
|
/// </summary>
|
||||||
|
public class ReportDesignerUndoEngine : UndoEngine, IUndoHandler |
||||||
|
{ |
||||||
|
Stack<UndoEngine.UndoUnit> undoStack = new Stack<UndoEngine.UndoUnit>(); |
||||||
|
Stack<UndoEngine.UndoUnit> redoStack = new Stack<UndoEngine.UndoUnit>(); |
||||||
|
|
||||||
|
public ReportDesignerUndoEngine(IServiceProvider provider) : base(provider) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
#region IUndoHandler
|
||||||
|
public bool EnableUndo { |
||||||
|
get { |
||||||
|
return undoStack.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public bool EnableRedo { |
||||||
|
get { |
||||||
|
return redoStack.Count > 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Undo() |
||||||
|
{ |
||||||
|
if (undoStack.Count > 0) { |
||||||
|
UndoEngine.UndoUnit unit = undoStack.Pop(); |
||||||
|
unit.Undo(); |
||||||
|
redoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Redo() |
||||||
|
{ |
||||||
|
if (redoStack.Count > 0) { |
||||||
|
UndoEngine.UndoUnit unit = redoStack.Pop(); |
||||||
|
unit.Undo(); |
||||||
|
undoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
protected override void AddUndoUnit(UndoEngine.UndoUnit unit) |
||||||
|
{ |
||||||
|
undoStack.Push(unit); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue