Beispiel #1
0
        ///
        public override void DoCreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            args.Result = JobResult.Ignore;
            Panel.DoCreateFile();
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override void DoCreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            args.Result = JobResult.Ignore;

            // prompt for a command
            string code = Far.Api.MacroState == MacroState.None ? A.Psf.InputCode() : Far.Api.Input(null);

            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            // invoke the command
            Collection <PSObject> values = A.InvokeCode(code);

            if (values.Count == 0)
            {
                return;
            }

            // add the objects
            AddObjects(values);

            // done, post the first object
            args.PostData = values[0];
            args.Result   = JobResult.Done;
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override void UICreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // skip data panel
            if (Parent is DataPanel)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // call
            Explorer.CreateFile(args);
            if (args.Result != JobResult.Done)
            {
                return;
            }

            // update that panel if the instance is the same
            MemberPanel that = TargetPanel as MemberPanel;

            if (that != null && that.Target == Target)
            {
                that.UpdateRedraw(true);
            }
        }
Beispiel #4
0
        public override void CreateFile(CreateFileEventArgs args)
        {
            OperationResult or = get(args).CreatePlayList(string.Empty);

            args.PostName = (string)or.ResultData ?? string.Empty;

            args.Result = processResult(or, args.Mode.HasFlag(ExplorerModes.Silent));
        }
Beispiel #5
0
        /// <summary>
        /// Calls <see cref="FarNet.Explorer.CreateFile"/> and <see cref="OnThisFileChanged"/>.
        /// </summary>
        /// <param name="args">.</param>
        public virtual void UICreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            Explorer.CreateFile(args);

            if (args.Result != JobResult.Ignore)
                OnThisFileChanged(args);
        }
Beispiel #6
0
        public override void UICreateFile(CreateFileEventArgs args)
        {
            var name = Far.Api.Input("File name", null, "MyPanel");

            if (!String.IsNullOrEmpty(name))
            {
                args.Data = name;
                base.UICreateFile(args);
            }
        }
Beispiel #7
0
        ///
        public override void DoCreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            args.Result = JobResult.Ignore;
            Panel.DoCreateFile();
        }
Beispiel #8
0
        public override void CreateFile(CreateFileEventArgs args)
        {
            var name = (string)args.Data;

            _files.Add(new SetFile()
            {
                Name = name, Description = "demo file"
            });
            args.PostName = name;
        }
Beispiel #9
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public sealed override void CreateFile(CreateFileEventArgs args)
 {
     if (AsCreateFile == null)
     {
         DoCreateFile(args);
     }
     else
     {
         A.InvokeScriptReturnAsIs(AsCreateFile, this, args);
     }
 }
Beispiel #10
0
        /// <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;
                }
            }
        }
Beispiel #11
0
        /// <inheritdoc/>
        public override void UICreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            // call
            Explorer.CreateFile(args);
            if (args.Result != JobResult.Done)
                return;

            // update that panel if the path is the same
            PropertyPanel that = TargetPanel as PropertyPanel;
            if (that != null && that.Explorer.ItemPath == Explorer.ItemPath)
                that.UpdateRedraw(true);
        }
Beispiel #12
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;
                }
            }
        }
Beispiel #13
0
        /// <inheritdoc/>
        public override void UICreateFile(CreateFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // call
            Explorer.CreateFile(args);
            if (args.Result != JobResult.Done)
            {
                return;
            }

            // update that panel if the path is the same
            if (TargetPanel is PropertyPanel that && that.Explorer.ItemPath == Explorer.ItemPath)
            {
                that.UpdateRedraw(true);
            }
        }
Beispiel #14
0
        public override void UICreateFile(CreateFileEventArgs args)
        {
            if (!ensurePathExist())
            {
                return;
            }

            base.UICreateFile(args);
        }
Beispiel #15
0
 /// <summary>
 /// Creates a new directory/file.
 /// </summary>
 /// <param name="args">.</param>
 /// <remarks>
 /// It is normally called by the core on [F7] if the explorer has its flag <see cref="CanCreateFile"/> set.
 /// If the explorer creates something then it may also want to set one of the <c>Post*</c>,
 /// so that the specified file, normally just created, is set current by the core.
 /// </remarks>
 public virtual void CreateFile(CreateFileEventArgs args)
 {
     if (args != null) args.Result = JobResult.Ignore;
 }
Beispiel #16
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
                {
                    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;
                }
            }
        }
Beispiel #17
0
        /// <inheritdoc/>
        public override void UICreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            // skip data panel
            if (Parent is DataPanel)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // call
            Explorer.CreateFile(args);
            if (args.Result != JobResult.Done)
                return;

            // update that panel if the instance is the same
            MemberPanel that = TargetPanel as MemberPanel;
            if (that != null && that.Target == Target)
                that.UpdateRedraw(true);
        }
Beispiel #18
0
 /// <summary>
 /// <see cref="Explorer.CreateFile"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoCreateFile(CreateFileEventArgs args)
 {
     base.CreateFile(args);
 }
Beispiel #19
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public override sealed void CreateFile(CreateFileEventArgs args)
 {
     if (AsCreateFile == null)
         DoCreateFile(args);
     else
         A.InvokeScriptReturnAsIs(AsCreateFile, this, args);
 }
Beispiel #20
0
        /// <summary>
        /// Creates a new file or directory.
        /// </summary>
        /// <remarks>
        /// It is normally called on [F7].
        /// It calls <see cref="UICreateFile"/> if the explorer supports it.
        /// <para>
        /// Current file after the operation is defined by <c>Post*</c> in the arguments.
        /// </para>
        /// </remarks>
        public void UICreate()
        {
            // can?
            if (!Explorer.CanCreateFile)
                return;

            // call
            var args = new CreateFileEventArgs(ExplorerModes.None);
            UICreateFile(args);
            if (args.Result != JobResult.Done)
                return;

            // post
            Post(args);

            // show
            Update(true);
            Redraw();
        }
Beispiel #21
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;
                }
            }
        }
Beispiel #22
0
 /// <summary>
 /// <see cref="Explorer.CreateFile"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoCreateFile(CreateFileEventArgs args)
 {
     base.CreateFile(args);
 }
Beispiel #23
0
        /// <inheritdoc/>
        public override void DoCreateFile(CreateFileEventArgs args)
        {
            if (args == null) return;

            args.Result = JobResult.Ignore;

            // prompt for a command
            string code = Far.Api.MacroState == MacroState.None ? A.Psf.InputCode() : Far.Api.Input(null);
            if (string.IsNullOrEmpty(code))
                return;

            // invoke the command
            Collection<PSObject> values = A.InvokeCode(code);
            if (values.Count == 0)
                return;

            // add the objects
            AddObjects(values);

            // done, post the first object
            args.PostData = values[0];
            args.Result = JobResult.Done;
        }