コード例 #1
0
ファイル: ItemExplorer.cs プロジェクト: zertyuiop/FarNet
        /// <inheritdoc/>
        public override void DoCreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            args.Result = JobResult.Ignore;

            UI.NewValueDialog ui = new UI.NewValueDialog("New " + Provider.Name + " item");
            while (ui.Dialog.Show())
            {
                try
                {
                    using (var ps = A.Psf.NewPowerShell())
                    {
                        //! Don't use Value if it is empty (e.g. to avoid (default) property at new key in Registry).
                        //! Don't use -Force or you silently kill existing item\property (with all children, properties, etc.)
                        ps.AddCommand("New-Item")
                        .AddParameter("Path", My.PathEx.Combine(Location, ui.Name.Text))                                 // it is literal
                        .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                        if (ui.Type.Text.Length > 0)
                        {
                            ps.AddParameter("ItemType", ui.Type.Text);
                        }

                        if (ui.Value.Text.Length > 0)
                        {
                            ps.AddParameter("Value", ui.Value.Text);
                        }

                        ps.Invoke();

                        if (A.ShowError(ps))
                        {
                            continue;
                        }
                    }

                    // done
                    args.Result   = JobResult.Done;
                    args.PostName = ui.Name.Text;
                    return;
                }
                catch (RuntimeException ex)
                {
                    A.Message(ex.Message);
                    continue;
                }
            }
        }
コード例 #2
0
        /// <inheritdoc/>
        public override void CreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            args.Result = JobResult.Ignore;

            UI.NewValueDialog ui = new UI.NewValueDialog("New property");
            while (ui.Dialog.Show())
            {
                try
                {
                    // call value
                    object value;
                    if (ui.Type.Text.Length == 0)
                    {
                        value = ui.Value.Text;
                    }
                    else
                    {
                        value = A.InvokeCode("[" + ui.Type.Text + "]$args[0]", ui.Value.Text)[0].BaseObject;
                    }

                    // call Add-Member
                    A.InvokeCode(
                        "$args[0] | Add-Member -MemberType NoteProperty -Name $args[1] -Value $args[2] -Force -ErrorAction Stop",
                        Value, ui.Name.Text, value);

                    // done, post name
                    args.Result   = JobResult.Done;
                    args.PostName = ui.Name.Text;
                    return;
                }
                catch (RuntimeException ex)
                {
                    A.Message(ex.Message);
                    continue;
                }
            }
        }
コード例 #3
0
ファイル: PropertyExplorer.cs プロジェクト: pezipink/FarNet
        /// <inheritdoc/>
        public override void CreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;
            args.Result = JobResult.Ignore;

            UI.NewValueDialog ui = new UI.NewValueDialog("New property");
            while (ui.Dialog.Show())
            {
                try
                {
                    using (var ps = A.Psf.NewPowerShell())
                    {
                        //! Don't use Value if it is empty (e.g. to avoid (default) property at new key in Registry).
                        //! Don't use -Force or you silently kill existing item\property (with all children, properties, etc.)
                        ps.AddCommand("New-ItemProperty")
                            .AddParameter("LiteralPath", ItemPath)
                            .AddParameter(Word.Name, ui.Name.Text)
                            .AddParameter("PropertyType", ui.Type.Text)
                            .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                        if (ui.Value.Text.Length > 0)
                            ps.AddParameter("Value", ui.Value.Text);

                        ps.Invoke();

                        if (A.ShowError(ps))
                            continue;
                    }

                    // done
                    args.Result = JobResult.Done;
                    args.PostName = ui.Name.Text;
                    return;
                }
                catch (RuntimeException exception)
                {
                    A.Message(exception.Message);
                    continue;
                }
            }
        }
コード例 #4
0
ファイル: MemberExplorer.cs プロジェクト: pezipink/FarNet
        /// <inheritdoc/>
        public override void CreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            args.Result = JobResult.Ignore;

            UI.NewValueDialog ui = new UI.NewValueDialog("New property");
            while (ui.Dialog.Show())
            {
                try
                {
                    // call value
                    object value;
                    if (ui.Type.Text.Length == 0)
                        value = ui.Value.Text;
                    else
                        value = A.InvokeCode("[" + ui.Type.Text + "]$args[0]", ui.Value.Text)[0].BaseObject;

                    // call Add-Member
                    A.InvokeCode(
                        "$args[0] | Add-Member -MemberType NoteProperty -Name $args[1] -Value $args[2] -Force -ErrorAction Stop",
                        Value, ui.Name.Text, value);

                    // done, post name
                    args.Result = JobResult.Done;
                    args.PostName = ui.Name.Text;
                    return;
                }
                catch (RuntimeException ex)
                {
                    A.Message(ex.Message);
                    continue;
                }
            }
        }