Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Calls <see cref="FarNet.Explorer.GetContent"/>.
 /// </summary>
 /// <param name="args">.</param>
 public virtual void UIGetContent(GetContentEventArgs args)
 {
     Explorer.GetContent(args);
 }