Example #1
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // check
            var xfile = (SuperFile)args.File;

            if (!xfile.Explorer.CanGetContent)
            {
                args.Result = JobResult.Default;
                return;
            }

            // call
            var argsExport = new GetContentEventArgs(args.Mode, xfile.File, args.FileName);

            xfile.Explorer.GetContent(argsExport);

            // results
            args.Result           = argsExport.Result;
            args.UseText          = argsExport.UseText;
            args.CanSet           = argsExport.CanSet;
            args.UseFileName      = argsExport.UseFileName;
            args.UseFileExtension = argsExport.UseFileExtension;
        }
Example #2
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // info
            PSPropertyInfo pi = Cast <PSPropertyInfo> .From(args.File.Data);

            if (pi == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // text
            args.UseText = Converter.InfoToText(pi);
            if (args.UseText == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            args.CanSet = pi.IsSettable;
        }
Example #3
0
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }
            var value = (SettingsPropertyValue)args.File.Data;

            // no text
            if (value.Property.SerializeAs != SettingsSerializeAs.String && value.Property.SerializeAs != SettingsSerializeAs.Xml)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // text
            args.UseText = args.File.Description;

            // tweaks
            args.CanSet = !value.Property.IsReadOnly;
            if (value.Property.SerializeAs == SettingsSerializeAs.Xml)
            {
                args.UseFileExtension = ".xml";
            }
            else
            {
                args.UseFileExtension = ".txt";
            }
        }
Example #4
0
        public override void GetContent(GetContentEventArgs args)
        {
            var filedata = args.File.Data ?? GetFileData(args.File);
            var data     = InspectedFile.ReadEntry(filedata);

            File.WriteAllBytes(args.FileName, data ?? new byte[0]);
        }
Example #5
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            PSPropertyInfo pi = args.File.Data as PSPropertyInfo;

            if (pi == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            try
            {
                args.CanSet  = pi.IsSettable;
                args.UseText = Converter.InfoToLine(pi);
                if (args.UseText == null)
                {
                    args.UseText = A.InvokeCode("$args[0] | Out-String -Width $args[1] -ErrorAction Stop", pi.Value, int.MaxValue)[0].ToString();
                }
            }
            catch (RuntimeException ex)
            {
                Far.Api.ShowError("Edit", ex);
            }
        }
Example #6
0
 ///
 public override void DoGetContent(GetContentEventArgs args)
 {
     if (args == null)
     {
         return;
     }
     args.UseText = A.InvokeFormatList(args.File.Data, false);
 }
Example #7
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public sealed override void GetContent(GetContentEventArgs args)
 {
     if (AsGetContent == null)
     {
         DoGetContent(args);
     }
     else
     {
         A.InvokeScriptReturnAsIs(AsGetContent, this, args);
     }
 }
Example #8
0
        /// <inheritdoc/>
        public override void DoGetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            if (!My.ProviderInfoEx.HasContent(Provider))
            {
                args.Result = JobResult.Ignore;
                if (args.UI)
                {
                    A.Message(Res.NotSupportedByProvider);
                }
                return;
            }

            if (args.File.IsDirectory)
            {
                return;
            }

            args.CanSet = true;

            // actual file
            string filePath = My.PathEx.TryGetFilePath(args.File.Data);

            if (filePath != null)             //????base.UIEditFile(file); // to use RealNames?
            {
                args.UseFileName = filePath;
                return;
            }

            try
            {
                // item path
                string itemPath = My.PathEx.Combine(Location, args.File.Name);

                // get content
                const string code = "Get-Content -LiteralPath $args[0] -ReadCount 0";
                args.UseText = A.InvokeCode(code, itemPath);
            }
            catch (RuntimeException ex)
            {
                if (args.UI)
                {
                    Far.Api.ShowError("Edit", ex);
                }
            }
        }
Example #9
0
        ///
        public static GetContentEventArgs WorksExportExplorerFile(Explorer explorer, Panel panel, ExplorerModes mode, FarFile file, string fileName)
        {
            if (explorer == null) throw new ArgumentNullException("explorer");
            if (panel == null) throw new ArgumentNullException("panel");

            if (!explorer.CanGetContent)
                return null;

            // export file
            Log.Source.TraceInformation("ExportFile");
            var args = new GetContentEventArgs(mode, file, fileName);
            panel.UIGetContent(args);
            if (args.Result != JobResult.Done)
                return null;

            // no text or an actual file exists?
            if (args.UseText == null || !string.IsNullOrEmpty(args.UseFileName))
                return args;

            // export text
            string text = args.UseText as string;
            if (text == null)
            {
                IEnumerable collection = args.UseText as IEnumerable;
                if (collection == null)
                {
                    text = args.UseText.ToString();
                }
                else
                {
                    // write collection
                    using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.Unicode))
                        foreach (var it in collection)
                            writer.WriteLine(it);
                    return args;
                }
            }

            // write text
            File.WriteAllText(fileName, text, Encoding.Unicode);
            args.CodePage = 1200;
            return args;
        }
Example #10
0
        /// <inheritdoc/>
        public override void DoGetContent(GetContentEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // use existing file
            string filePath = My.PathEx.TryGetFilePath(args.File.Data);

            if (filePath != null)
            {
                args.UseFileName = filePath;
                args.CanSet      = true;
                return;
            }

            // text
            args.UseText = A.InvokeFormatList(args.File.Data, true);
        }
Example #11
0
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null) return;
            var value = (SettingsPropertyValue)args.File.Data;

            // no text
            if (value.Property.SerializeAs != SettingsSerializeAs.String && value.Property.SerializeAs != SettingsSerializeAs.Xml)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // text
            args.UseText = args.File.Description;

            // tweaks
            args.CanSet = !value.Property.IsReadOnly;
            if (value.Property.SerializeAs == SettingsSerializeAs.Xml)
                args.UseFileExtension = ".xml";
            else
                args.UseFileExtension = ".txt";
        }
Example #12
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null) return;

            PSPropertyInfo pi = args.File.Data as PSPropertyInfo;
            if (pi == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            try
            {
                args.CanSet = pi.IsSettable;
                args.UseText = Converter.InfoToLine(pi);
                if (args.UseText == null)
                    args.UseText = A.InvokeCode("$args[0] | Out-String -Width $args[1] -ErrorAction Stop", pi.Value, int.MaxValue)[0].ToString();
            }
            catch (RuntimeException ex)
            {
                Far.Api.ShowError("Edit", ex);
            }
        }
Example #13
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null) return;

            // info
            PSPropertyInfo pi = Cast<PSPropertyInfo>.From(args.File.Data);
            if (pi == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            // text
            args.UseText = Converter.InfoToText(pi);
            if (args.UseText == null)
            {
                args.Result = JobResult.Ignore;
                return;
            }

            args.CanSet = pi.IsSettable;
        }
Example #14
0
        /// <inheritdoc/>
        public override void GetContent(GetContentEventArgs args)
        {
            if (args == null) return;

            // check
            var xfile = (SuperFile)args.File;
            if (!xfile.Explorer.CanGetContent)
            {
                args.Result = JobResult.Default;
                return;
            }

            // call
            var argsExport = new GetContentEventArgs(args.Mode, xfile.File, args.FileName);
            xfile.Explorer.GetContent(argsExport);

            // results
            args.Result = argsExport.Result;
            args.UseText = argsExport.UseText;
            args.CanSet = argsExport.CanSet;
            args.UseFileName = argsExport.UseFileName;
            args.UseFileExtension = argsExport.UseFileExtension;
        }
Example #15
0
        /// <inheritdoc/>
        public override void DoGetContent(GetContentEventArgs args)
        {
            if (args == null) return;

            // use existing file
            string filePath = My.PathEx.TryGetFilePath(args.File.Data);
            if (filePath != null)
            {
                args.UseFileName = filePath;
                args.CanSet = true;
                return;
            }

            // text
            args.UseText = A.InvokeFormatList(args.File.Data, true);
        }
Example #16
0
 /// <summary>
 /// Exports the file content to a file or returns it as text.
 /// </summary>
 /// <param name="args">.</param>
 /// <remarks>
 /// <para>
 /// It is normally called by the core on [F3], [F4], [CtrlQ], if the
 /// explorer sets the flag <see cref="CanGetContent"/>. It is also
 /// called in order to copy files to native destinations if the
 /// advanced method <see cref="ExportFiles"/> is not implemented. A
 /// user corrects invalid file system names interactively, if this is
 /// allowed. Otherwise such files are ignored.
 /// </para>
 /// <para>
 /// For export operations, especially batch, consider to use <see
 /// cref="ExportFiles"/>, it gets more overall control and it is more
 /// flexible in case of failures. Besides, content for view and edit
 /// operations does not have to be the same as content for export and
 /// import operations.
 /// </para>
 /// <para>
 /// If the content is settable then this method should set the <see
 /// cref="GetContentEventArgs.CanSet"/>. It is used on editing ([F4]).
 /// If the flag is not set then an editor is opened locked, changes are
 /// not allowed by default.
 /// </para>
 /// <para>
 /// There are three ways of getting file content:
 /// <ol>
 /// <li>Assign a string or a line collection to the <see cref="GetContentEventArgs.UseText"/>.</li>
 /// <li>Copy data to a temporary file with the provided <see cref="GetContentEventArgs.FileName"/>.</li>
 /// <li>If a file represents a system file then assign its path to the <see cref="GetContentEventArgs.UseFileName"/>.</li>
 /// </ol>
 /// </para>
 /// </remarks>
 public virtual void GetContent(GetContentEventArgs args)
 {
     if (args != null) args.Result = JobResult.Default;
 }
Example #17
0
 /// <summary>
 /// <see cref="Explorer.GetContent"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoGetContent(GetContentEventArgs args)
 {
     base.GetContent(args);
 }
Example #18
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public override sealed void GetContent(GetContentEventArgs args)
 {
     if (AsGetContent == null)
         DoGetContent(args);
     else
         A.InvokeScriptReturnAsIs(AsGetContent, this, args);
 }
Example #19
0
 ///
 public override void DoGetContent(GetContentEventArgs args)
 {
     if (args == null) return;
     args.UseText = A.InvokeFormatList(args.File.Data, false);
 }
Example #20
0
 /// <summary>
 /// Calls <see cref="FarNet.Explorer.GetContent"/>.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void UIGetContent(GetContentEventArgs args)
 {
     Explorer.GetContent(args);
 }
Example #21
0
 /// <summary>
 /// <see cref="Explorer.GetContent"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoGetContent(GetContentEventArgs args)
 {
     base.GetContent(args);
 }
Example #22
0
 public override void GetContent(GetContentEventArgs args)
 {
     File.WriteAllBytes(args.FileName, InspectedBank.ReadTrack(args.File.Data as BankFile.BankTrack));
 }
Example #23
0
        /// <inheritdoc/>
        public override void DoGetContent(GetContentEventArgs args)
        {
            if (args == null) return;

            if (!My.ProviderInfoEx.HasContent(Provider))
            {
                args.Result = JobResult.Ignore;
                if (args.UI)
                    A.Message(Res.NotSupportedByProvider);
                return;
            }

            if (args.File.IsDirectory)
                return;

            args.CanSet = true;

            // actual file
            string filePath = My.PathEx.TryGetFilePath(args.File.Data);
            if (filePath != null) //????base.UIEditFile(file); // to use RealNames?
            {
                args.UseFileName = filePath;
                return;
            }

            try
            {
                // item path
                string itemPath = My.PathEx.Combine(Location, args.File.Name);

                // get content
                const string code = "Get-Content -LiteralPath $args[0] -ReadCount 0";
                args.UseText = A.InvokeCode(code, itemPath);
            }
            catch (RuntimeException ex)
            {
                if (args.UI)
                    Far.Api.ShowError("Edit", ex);
            }
        }