Example #1
0
        private static void OnAboutMmsf(ref InvokeCommandInfo invokeCommandInfo, IList <string> fileNames)
        {
            var fvi  = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
            var text = $"Build with MSF version {fvi.ProductVersion}";

            MessageBox.Show(text);
        }
Example #2
0
        private static void OnEditWithNotepadCommand(ref InvokeCommandInfo invokeCommandInfo, IList <string> fileNames)
        {
            Contract.Requires(fileNames != null);
            Contract.Requires(fileNames.Count == 1);

            // Use the command line param to pass the exe filename. This causes
            // Windows to use the path to find notepad.
            Process.Start("notepad.exe", "\"" + fileNames[0] + "\"");
        }
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="command">The command to be executed.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T>(this IObservable <T> item, ICommand command)
        {
            var canExecuteChanged = Observable
                                    .FromEventPattern(h => command.CanExecuteChanged += h, h => command.CanExecuteChanged -= h)
                                    .Select(_ => Unit.Default)
                                    .StartWith(Unit.Default);

            return(WithLatestFromFixed(item, canExecuteChanged, (value, _) => InvokeCommandInfo.From(command, command.CanExecute(value), value))
                   .Where(ii => ii.CanExecute)
                   .Do(ii => command.Execute(ii.Value))
                   .Subscribe());
        }
        void IContextMenu.InvokeCommand(IntPtr pici)
        {
            InvokeCommandInfo cmdInfo = (InvokeCommandInfo)Marshal.PtrToStructure(pici, typeof(Win32API.InvokeCommandInfo));
            StringBuilder     sb      = new StringBuilder(1024);
            StringBuilder     sbAll   = new StringBuilder();
            uint nselected            = Helpers.DragQueryFile((uint)_UnionMember, 0xffffffff, null, 0);

            for (uint i = 0; i < nselected; i++)
            {
                Helpers.DragQueryFile((uint)_UnionMember, i, sb, sb.Capacity + 1);
                sbAll.Append(sb.ToString());
            }

            switch (cmdInfo.Verb.ToInt32())
            {
            case 0:
                //删除 .svn
                DeleteMatchingFolder(sbAll.ToString(), ".svn");
                break;

            case 1:
                //删除 Thumbs.db
                DeleteMatchingFile(sbAll.ToString(), "Thumbs.db");
                break;

            case 2:
                //批量重命名
                BatchRenameForm renameForm = new BatchRenameForm(sbAll.ToString());
                renameForm.Show();
                break;

            case 3:
                //批量文本编码格式转换
                EncodingConvertForm encodingForm = new EncodingConvertForm(sbAll.ToString());
                encodingForm.Show();
                break;

            case 4:
                //发送反馈邮件
                Process proc = new Process();
                proc.StartInfo.FileName       = "IExplore.exe";
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.Arguments      = "mailto:[email protected]?subject=ContextMenuExtensionFactory Suggestion";
                proc.Start();
                proc.WaitForExit();
                proc.Close();
                break;

            default:
                break;
            }
        }
Example #5
0
        void IContextMenu.InvokeCommand(ref InvokeCommandInfo invokeCommandInfo)
        {
            Debug.WriteLine("[{0}] ContextMenuBase.IContextMenu.InvokeCommand (Size={1})", Id, invokeCommandInfo.Size);

            if (invokeCommandInfo.lpVerb.ToInt32() >> 16 != 0)
            {
                throw new ArgumentException("Verbs not supported");
            }

            var index = (ushort)invokeCommandInfo.lpVerb.ToInt32();
            var item  = menuItems[index];

            item.Command(ref invokeCommandInfo, FilesNames);
        }
Example #6
0
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <typeparam name="TTarget">The target type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="target">The root object which has the Command.</param>
        /// <param name="commandProperty">The expression to reference the Command.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T, TResult, TTarget>(this IObservable <T> item, TTarget target, Expression <Func <TTarget, ReactiveCommandBase <T, TResult> > > commandProperty)
            where TTarget : class
        {
            var command        = target.WhenAnyValue(commandProperty);
            var invocationInfo = command
                                 .Select(cmd => cmd == null ? Observable <InvokeCommandInfo <ReactiveCommandBase <T, TResult>, T> > .Empty : cmd
                                         .CanExecute
                                         .Select(canExecute => InvokeCommandInfo.From(cmd, canExecute, default(T))))
                                 .Switch();

            return(WithLatestFromFixed(item, invocationInfo, (value, ii) => ii.WithValue(value))
                   .Where(ii => ii.CanExecute)
                   .SelectMany(ii => ii.Command.Execute(ii.Value).Catch(Observable <TResult> .Empty))
                   .Subscribe());
        }
Example #7
0
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="command">The command to be executed.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T>(this IObservable <T> item, ICommand command)
        {
            var canExecuteChanged = Observable.FromEvent <EventHandler, Unit>(
                eventHandler =>
            {
                void Handler(object sender, EventArgs e) => eventHandler(Unit.Default);
                return(Handler);
            },
                h => command.CanExecuteChanged += h,
                h => command.CanExecuteChanged -= h)
                                    .StartWith(Unit.Default);

            return(WithLatestFromFixed(item, canExecuteChanged, (value, _) => InvokeCommandInfo.From(command, command.CanExecute(value), value))
                   .Where(ii => ii.CanExecute)
                   .Do(ii => command.Execute(ii.Value))
                   .Subscribe());
        }
Example #8
0
        void IContextMenu.InvokeCommand(IntPtr pici)
        {
            InvokeCommandInfo cmdInfo = (InvokeCommandInfo)Marshal.PtrToStructure(pici, typeof(Win32API.InvokeCommandInfo));
            StringBuilder     sb      = new StringBuilder(1024);
            StringBuilder     sbAll   = new StringBuilder();
            uint nselected            = Win32.DragQueryFile((uint)_UnionMember, 0xffffffff, null, 0);

            for (uint i = 0; i < nselected; i++)
            {
                Win32.DragQueryFile((uint)_UnionMember, i, sb, sb.Capacity + 1);
                sbAll.Append(sb.ToString());
            }

            IContextMenuCommand temp;

            if (commandDictionary.TryGetValue(cmdInfo.Verb.ToInt32(), out temp))
            {
                temp.InvokeCommand(sbAll.ToString());
            }
        }
Example #9
0
 private static void OnEditWithNotepadCommand(ref InvokeCommandInfo invokeCommandInfo, IList <string> fileNames)
 {
     // Use the command line parameters to pass the exe filename. This causes
     // Windows to use the path to find notepad.
     Process.Start("notepad.exe", "\"" + fileNames[0] + "\"");
 }
Example #10
0
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <typeparam name="TTarget">The target type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="target">The root object which has the Command.</param>
        /// <param name="commandProperty">The expression to reference the Command.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T, TTarget>(this IObservable <T> item, TTarget target, Expression <Func <TTarget, ICommand> > commandProperty)
            where TTarget : class
        {
            var commandObs = target.WhenAnyValue(commandProperty);
            var commandCanExecuteChanged = commandObs
                                           .Select(command => command == null ? Observable <ICommand> .Empty : Observable
                                                   .FromEvent <EventHandler, ICommand>(
                                                       eventHandler =>
            {
                void Handler(object sender, EventArgs e) => eventHandler(command);
                return(Handler);
            },
                                                       h => command.CanExecuteChanged += h,
                                                       h => command.CanExecuteChanged -= h)
                                                   .StartWith(command))
                                           .Switch();

            return(WithLatestFromFixed(item, commandCanExecuteChanged, (value, cmd) => InvokeCommandInfo.From(cmd, cmd.CanExecute(value), value))
                   .Where(ii => ii.CanExecute)
                   .Do(ii => ii.Command.Execute(ii.Value))
                   .Subscribe());
        }
Example #11
0
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="command">The command to be executed.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> item, ReactiveCommandBase <T, TResult> command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            return(WithLatestFromFixed(item, command.CanExecute, (value, canExecute) => InvokeCommandInfo.From(command, canExecute, value))
                   .Where(ii => ii.CanExecute)
                   .SelectMany(ii => command.Execute(ii.Value).Catch(Observable <TResult> .Empty))
                   .Subscribe());
        }
Example #12
0
 void IContextMenu2.InvokeCommand(ref InvokeCommandInfo invokeCommandInfo)
 {
     ((IContextMenu)this).InvokeCommand(ref invokeCommandInfo);
 }
        /// <summary>
        /// A utility method that will pipe an Observable to an ICommand (i.e.
        /// it will first call its CanExecute with the provided value, then if
        /// the command can be executed, Execute() will be called).
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <typeparam name="TTarget">The target type.</typeparam>
        /// <param name="item">The source observable to pipe into the command.</param>
        /// <param name="target">The root object which has the Command.</param>
        /// <param name="commandProperty">The expression to reference the Command.</param>
        /// <returns>An object that when disposes, disconnects the Observable
        /// from the command.</returns>
        public static IDisposable InvokeCommand <T, TTarget>(this IObservable <T> item, TTarget target, Expression <Func <TTarget, ICommand> > commandProperty)
            where TTarget : class
        {
            var command = target.WhenAnyValue(commandProperty);
            var commandCanExecuteChanged = command
                                           .Select(c => c == null ? Observable <ICommand> .Empty : Observable
                                                   .FromEventPattern(h => c.CanExecuteChanged += h, h => c.CanExecuteChanged -= h)
                                                   .Select(_ => c)
                                                   .StartWith(c))
                                           .Switch();

            return(WithLatestFromFixed(item, commandCanExecuteChanged, (value, cmd) => InvokeCommandInfo.From(cmd, cmd.CanExecute(value), value))
                   .Where(ii => ii.CanExecute)
                   .Do(ii => ii.Command.Execute(ii.Value))
                   .Subscribe());
        }
 /// <summary>
 /// A utility method that will pipe an Observable to an ICommand (i.e.
 /// it will first call its CanExecute with the provided value, then if
 /// the command can be executed, Execute() will be called).
 /// </summary>
 /// <typeparam name="T">The type.</typeparam>
 /// <typeparam name="TResult">The result type.</typeparam>
 /// <param name="this">The source observable to pipe into the command.</param>
 /// <param name="command">The command to be executed.</param>
 /// <returns>An object that when disposes, disconnects the Observable
 /// from the command.</returns>
 public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> @this, ReactiveCommandBase <T, TResult> command)
 {
     return(WithLatestFromFixed(@this, command.CanExecute, (value, canExecute) => InvokeCommandInfo.From(command, canExecute, value))
            .Where(ii => ii.CanExecute)
            .SelectMany(ii => command.Execute(ii.Value).Catch(Observable <TResult> .Empty))
            .Subscribe());
 }