Example #1
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public sealed override void SetFile(SetFileEventArgs args)
 {
     if (AsSetFile == null)
     {
         DoSetFile(args);
     }
     else
     {
         A.InvokeScriptReturnAsIs(AsSetFile, this, args);
     }
 }
Example #2
0
        /// <inheritdoc/>
        public override void SetFile(SetFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

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

            if (!xfile.Explorer.CanSetFile)
            {
                args.Result = JobResult.Default;
                return;
            }
            var argsImport = new SetFileEventArgs(args.Mode, xfile.File, args.FileName);

            xfile.Explorer.SetFile(argsImport);

            // result
            args.Result = argsImport.Result;
        }
Example #3
0
        /// <inheritdoc/>
        public override void SetFile(SetFileEventArgs args)
        {
            if (args == null) return;

            // call
            var xfile = (SuperFile)args.File;
            if (!xfile.Explorer.CanSetFile)
            {
                args.Result = JobResult.Default;
                return;
            }
            var argsImport = new SetFileEventArgs(args.Mode, xfile.File, args.FileName);
            xfile.Explorer.SetFile(argsImport);

            // result
            args.Result = argsImport.Result;
        }
Example #4
0
 /// <summary>
 /// <see cref="Explorer.SetFile"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoSetFile(SetFileEventArgs args)
 {
     base.SetFile(args);
 }
Example #5
0
 /// <include file='doc.xml' path='doc/ScriptFork/*'/>
 /// <param name="args">.</param>
 public override sealed void SetFile(SetFileEventArgs args)
 {
     if (AsSetFile == null)
         DoSetFile(args);
     else
         A.InvokeScriptReturnAsIs(AsSetFile, this, args);
 }
Example #6
0
 /// <summary>
 /// <see cref="Explorer.SetFile"/> worker.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void DoSetFile(SetFileEventArgs args)
 {
     base.SetFile(args);
 }
Example #7
0
 /// <summary>
 /// Sets the file content given the system file.
 /// </summary>
 /// <param name="args">.</param>
 /// <remarks>
 /// If this method is used then <see cref="Functions"/> should contain the <see cref="ExplorerFunctions.SetFile"/> flag.
 /// </remarks>
 public virtual void SetFile(SetFileEventArgs args)
 {
     if (args != null) args.Result = JobResult.Default;
 }
Example #8
0
        /// <summary>
        /// Opens the file in the editor.
        /// </summary>
        /// <param name="file">The file to edit.</param>
        /// <remarks>
        /// The default method calls <see cref="FarNet.Explorer.GetContent"/>  to get a temporary file to edit
        /// and <see cref="FarNet.Explorer.SetFile"/> to save changes when the editor closes.
        /// The explorer should have at least export implemented.
        /// </remarks>
        public virtual void UIEditFile(FarFile file)
        {
            if (file == null)
                return;

            // target
            var temp = Far.Api.TempName();

            // export
            var xExportArgs = WorksExportExplorerFile(Explorer, this, ExplorerModes.Edit, file, temp);
            if (xExportArgs == null)
                return;

            // case: actual file exists
            var asExportFileEventArgs = xExportArgs as GetContentEventArgs;
            if (asExportFileEventArgs != null && !string.IsNullOrEmpty(asExportFileEventArgs.UseFileName))
            {
                var editorActual = Far.Api.CreateEditor();
                editorActual.FileName = asExportFileEventArgs.UseFileName;
                editorActual.Title = file.Name;
                if (!asExportFileEventArgs.CanSet)
                    editorActual.IsLocked = true;
                editorActual.Open();
                return;
            }

            // rename
            if (!string.IsNullOrEmpty(xExportArgs.UseFileExtension))
            {
                string temp2 = temp + xExportArgs.UseFileExtension;
                File.Move(temp, temp2);
                temp = temp2;
            }

            // editor
            var editorTemp = Far.Api.CreateEditor();
            editorTemp.DeleteSource = DeleteSource.File;
            editorTemp.DisableHistory = true;
            editorTemp.FileName = temp;
            editorTemp.Title = file.Name;
            if (asExportFileEventArgs.CodePage != 0)
                editorTemp.CodePage = asExportFileEventArgs.CodePage;

            // future
            if (xExportArgs.CanSet)
            {
                if (Explorer.CanSetText)
                {
                    editorTemp.Saving += delegate
                    {
                        var xImportTextArgs = new SetTextEventArgs(ExplorerModes.Edit, file, editorTemp.GetText());
                        Log.Source.TraceInformation("ImportText");
                        UISetText(xImportTextArgs);
                    };
                }
                else
                {
                    editorTemp.Closed += delegate //???? to use Saved (Far 3), update docs.
                    {
                        if (editorTemp.TimeOfSave == DateTime.MinValue)
                            return;

                        var xImportFileArgs = new SetFileEventArgs(ExplorerModes.Edit, file, temp);
                        Log.Source.TraceInformation("ImportFile");
                        UISetFile(xImportFileArgs);
                    };
                }
            }
            else
            {
                // to lock
                editorTemp.IsLocked = true;
            }

            // go
            editorTemp.Open();
        }
Example #9
0
        /// <summary>
        /// Calls <see cref="FarNet.Explorer.SetFile"/> and <see cref="OnThisFileChanged"/>.
        /// </summary>
        /// <param name="args">.</param>
        public virtual void UISetFile(SetFileEventArgs args)
        {
            if (args == null) return;

            Explorer.SetFile(args);

            if (args.Result != JobResult.Ignore)
                OnThisFileChanged(args);
        }