Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <lluis@novell.com>2010-06-01 15:49:58 +0400
committerLluis Sanchez <lluis@novell.com>2010-06-01 15:49:58 +0400
commitc58c94789c4a986b450e524ef484faa63df68382 (patch)
treeb3a358ddbf12398a4ae0dd0c5409941b691f0430 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands
parentbd2e44805cd30947bb9eebccc853ed748987835b (diff)
* MonoDevelop.Components.AutoTest/AutoTestSession.cs: The current
object is now always the active widget unless some other specific object is set. * MonoDevelop.Components.AutoTest/AutoTestService.cs: Added basic support for recording a test session. * MonoDevelop.Components.Commands/CommandInfo.cs: * MonoDevelop.Components.Commands/CommandManager.cs: * MonoDevelop.Components.Commands/CommandArrayInfo.cs: Notofy key presses through the new KeyPressed event. Include the selected data item in the CommandActivated event args. Properly notify CommandActivated event when running the default handler of a command. * MonoDevelop.Components.Commands/ActionCommand.cs: Removed DispatchCommand and UpdateCommandInfo virtuals. They are not used and makes things more complex in the command manager. * MonoDevelop.Ide.Desktop/RecentItem.cs: Implemented Equals. svn path=/trunk/monodevelop/; revision=158270
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/ActionCommand.cs13
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandArrayInfo.cs6
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandInfo.cs5
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs104
4 files changed, 90 insertions, 38 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/ActionCommand.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/ActionCommand.cs
index 0f06f0cd38..fd92edcc49 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/ActionCommand.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/ActionCommand.cs
@@ -100,18 +100,7 @@ namespace MonoDevelop.Components.Commands
set { defaultHandler = value; }
}
- public virtual bool DispatchCommand (object dataItem)
- {
- if (defaultHandler == null) {
- if (DefaultHandlerType == null)
- return false;
- defaultHandler = (CommandHandler) Activator.CreateInstance (DefaultHandlerType);
- }
- defaultHandler.InternalRun (dataItem);
- return true;
- }
-
- public virtual void UpdateCommandInfo (CommandInfo info)
+ internal void UpdateCommandInfo (CommandInfo info)
{
if (defaultHandler == null) {
if (DefaultHandlerType == null) {
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandArrayInfo.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandArrayInfo.cs
index d81d07e729..846597139b 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandArrayInfo.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandArrayInfo.cs
@@ -29,6 +29,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
namespace MonoDevelop.Components.Commands
{
@@ -49,6 +50,11 @@ namespace MonoDevelop.Components.Commands
list.Clear ();
}
+ public CommandInfo FindCommandInfo (object dataItem)
+ {
+ return list.FirstOrDefault (ci => ci.HandlesItem (dataItem));
+ }
+
public void Insert (int index, CommandInfoSet infoSet)
{
Insert (index, infoSet, null);
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandInfo.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandInfo.cs
index a62b8bc5e5..1f2a1c2da2 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandInfo.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandInfo.cs
@@ -132,5 +132,10 @@ namespace MonoDevelop.Components.Commands
public bool IsArraySeparator {
get; internal set;
}
+
+ public bool HandlesItem (object item)
+ {
+ return item == DataItem || Object.Equals (item, DataItem);
+ }
}
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs
index 89d28e2cc4..fbacd2d9da 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs
@@ -207,6 +207,7 @@ namespace MonoDevelop.Components.Commands
} else {
e.RetVal = false;
mode = null;
+ NotifyKeyPressed (e);
return;
}
@@ -224,10 +225,21 @@ namespace MonoDevelop.Components.Commands
// The command has not been handled.
// If there is at least a handler that sets the bypass flag, allow gtk to execute the default action
- e.RetVal = commands.Count > 0 && !bypass;
+ if (commands.Count > 0 && !bypass)
+ e.RetVal = true;
+ else {
+ e.RetVal = false;
+ NotifyKeyPressed (e);
+ }
mode = null;
}
+ void NotifyKeyPressed (Gtk.KeyPressEventArgs e)
+ {
+ if (KeyPressed != null)
+ KeyPressed (this, new KeyPressArgs () { Key = e.Event.Key, Modifiers = e.Event.State });
+ }
+
public void SetRootWindow (Gtk.Window root)
{
if (rootWidget != null)
@@ -533,18 +545,10 @@ namespace MonoDevelop.Components.Commands
if (cui != null) {
if (cmd.CommandArray) {
// Make sure that the option is still active
- CommandArrayInfo ainfo = new CommandArrayInfo (info);
- cui.Run (cmdTarget, ainfo);
- if (!ainfo.Bypass) {
- bool found = false;
- foreach (CommandInfo ci in ainfo) {
- if (dataItem == ci.DataItem || Object.Equals (dataItem, ci.DataItem)) {
- found = true;
- break;
- }
- }
-
- if (!found)
+ info.ArrayInfo = new CommandArrayInfo (info);
+ cui.Run (cmdTarget, info.ArrayInfo);
+ if (!info.ArrayInfo.Bypass) {
+ if (info.ArrayInfo.FindCommandInfo (dataItem) == null)
return false;
} else
bypass = true;
@@ -564,16 +568,16 @@ namespace MonoDevelop.Components.Commands
object localTarget = cmdTarget;
if (cmd.CommandArray) {
handlers.Add (delegate {
- OnCommandActivating (commandId, info, localTarget, source);
+ OnCommandActivating (commandId, info, dataItem, localTarget, source);
chi.Run (localTarget, cmd, dataItem);
- OnCommandActivated (commandId, info, localTarget, source);
+ OnCommandActivated (commandId, info, dataItem, localTarget, source);
});
}
else {
handlers.Add (delegate {
- OnCommandActivating (commandId, info, localTarget, source);
+ OnCommandActivating (commandId, info, dataItem, localTarget, source);
chi.Run (localTarget, cmd);
- OnCommandActivated (commandId, info, localTarget, source);
+ OnCommandActivated (commandId, info, dataItem, localTarget, source);
});
}
handlerFoundInMulticast = true;
@@ -594,10 +598,8 @@ namespace MonoDevelop.Components.Commands
return true;
}
- if (cmd.DispatchCommand (dataItem)) {
- OnCommandActivating (commandId, info, cmdTarget, source);
+ if (DefaultDispatchCommand (cmd, info, dataItem, cmdTarget, source)) {
UpdateToolbars ();
- OnCommandActivated (commandId, info, cmdTarget, source);
return true;
}
}
@@ -609,16 +611,38 @@ namespace MonoDevelop.Components.Commands
return false;
}
- void OnCommandActivating (object commandId, CommandInfo commandInfo, object target, CommandSource source)
+ bool DefaultDispatchCommand (ActionCommand cmd, CommandInfo info, object dataItem, object target, CommandSource source)
+ {
+ DefaultUpdateCommandInfo (cmd, info);
+
+ if (cmd.CommandArray) {
+ if (info.ArrayInfo.FindCommandInfo (dataItem) == null)
+ return false;
+ }
+ else if (!info.Enabled || !info.Visible)
+ return false;
+
+ if (cmd.DefaultHandler == null) {
+ if (cmd.DefaultHandlerType == null)
+ return false;
+ cmd.DefaultHandler = (CommandHandler) Activator.CreateInstance (cmd.DefaultHandlerType);
+ }
+ OnCommandActivating (cmd.Id, info, dataItem, target, source);
+ cmd.DefaultHandler.InternalRun (dataItem);
+ OnCommandActivated (cmd.Id, info, dataItem, target, source);
+ return true;
+ }
+
+ void OnCommandActivating (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source)
{
if (CommandActivating != null)
- CommandActivating (this, new CommandActivationEventArgs (commandId, commandInfo, target, source));
+ CommandActivating (this, new CommandActivationEventArgs (commandId, commandInfo, dataItem, target, source));
}
- void OnCommandActivated (object commandId, CommandInfo commandInfo, object target, CommandSource source)
+ void OnCommandActivated (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source)
{
if (CommandActivated != null)
- CommandActivated (this, new CommandActivationEventArgs (commandId, commandInfo, target, source));
+ CommandActivated (this, new CommandActivationEventArgs (commandId, commandInfo, dataItem, target, source));
}
public event EventHandler<CommandActivationEventArgs> CommandActivating;
@@ -702,7 +726,7 @@ namespace MonoDevelop.Components.Commands
}
info.Bypass = false;
- cmd.UpdateCommandInfo (info);
+ DefaultUpdateCommandInfo (cmd, info);
}
catch (Exception ex) {
if (!commandUpdateErrors.Contains (commandId)) {
@@ -720,6 +744,25 @@ namespace MonoDevelop.Components.Commands
return info;
}
+ void DefaultUpdateCommandInfo (ActionCommand cmd, CommandInfo info)
+ {
+ if (cmd.DefaultHandler == null) {
+ if (cmd.DefaultHandlerType == null) {
+ info.Enabled = false;
+ if (!cmd.DisabledVisible)
+ info.Visible = false;
+ return;
+ }
+ cmd.DefaultHandler = (CommandHandler) Activator.CreateInstance (cmd.DefaultHandlerType);
+ }
+ if (cmd.CommandArray) {
+ info.ArrayInfo = new CommandArrayInfo (info);
+ cmd.DefaultHandler.InternalUpdate (info.ArrayInfo);
+ }
+ else
+ cmd.DefaultHandler.InternalUpdate (info);
+ }
+
public object VisitCommandTargets (ICommandTargetVisitor visitor, object initialTarget)
{
CommandTargetRoute targetRoute = new CommandTargetRoute (initialTarget);
@@ -1155,6 +1198,7 @@ namespace MonoDevelop.Components.Commands
public event EventHandler ApplicationFocusOut; // Fired when the application loses the focus
public event EventHandler CommandTargetScanStarted;
public event EventHandler CommandTargetScanFinished;
+ public event EventHandler<KeyPressArgs> KeyPressed;
}
internal class HandlerTypeInfo
@@ -1513,18 +1557,20 @@ namespace MonoDevelop.Components.Commands
public class CommandActivationEventArgs : EventArgs
{
- public CommandActivationEventArgs (object commandId, CommandInfo commandInfo, object target, CommandSource source)
+ public CommandActivationEventArgs (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source)
{
this.CommandId = commandId;
this.CommandInfo = commandInfo;
this.Target = target;
this.Source = source;
+ this.DataItem = dataItem;
}
public object CommandId { get; private set; }
public CommandInfo CommandInfo { get; private set; }
public object Target { get; private set; }
public CommandSource Source { get; private set; }
+ public object DataItem { get; private set; }
}
public enum CommandSource
@@ -1563,5 +1609,11 @@ namespace MonoDevelop.Components.Commands
get { return targets; }
}
}
+
+ public class KeyPressArgs: EventArgs
+ {
+ public Gdk.Key Key { get; internal set; }
+ public Gdk.ModifierType Modifiers { get; internal set; }
+ }
}