Example #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// Save
        ///
        /// <summary>
        /// Save the PDF document
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="dest">Saving file information.</param>
        /// <param name="close">Close action.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Save(this MainFacade src, Information dest, Action close)
        {
            var data = src.Bindable;
            var tmp  = data.IO.Combine(dest.DirectoryName, Guid.NewGuid().ToString("D"));

            try
            {
                var reader = data.Source.Value.GetItexReader(data.Query, data.IO);
                data.Set(reader.Metadata, reader.Encryption);

                using (var writer = new DocumentWriter())
                {
                    writer.Add(reader.Attachments);
                    writer.Add(data.Images.Select(e => e.RawObject), reader);
                    writer.Set(data.Metadata);
                    writer.Set(data.Encryption);
                    writer.Save(tmp);
                }

                close();
                src.Backup.Invoke(dest);
                data.IO.Copy(tmp, dest.FullName, true);
            }
            finally { data.IO.TryDelete(tmp); }
        }
Example #2
0
File: Save.cs Project: yas/Cube.Pdf
 /* ----------------------------------------------------------------- */
 ///
 /// Extract
 ///
 /// <summary>
 /// Extracts the selected PDF pages and saves to the specified
 /// file.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="dest">Path to save.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Extract(this MainFacade src, string dest) =>
 src.Extract(new SaveOption(src.Value.IO)
 {
     Target      = SaveTarget.Selected,
     Split       = false,
     Destination = dest,
 });
Example #3
0
 /* ----------------------------------------------------------------- */
 ///
 /// Overwrite
 ///
 /// <summary>
 /// Overwrites the PDF document.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Overwrite(this MainFacade src)
 {
     if (src.Bindable.History.Undoable)
     {
         src.Save(src.Bindable.Source.Value.FullName);
     }
 }
Example #4
0
File: Open.cs Project: yas/Cube.Pdf
 /* ----------------------------------------------------------------- */
 ///
 /// Close
 ///
 /// <summary>
 /// Closes the current PDF document.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="save">Save before closing.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Close(this MainFacade src, bool save)
 {
     if (save)
     {
         src.Save(src.Value.Source.FullName, false);
     }
     src.Close();
 }
Example #5
0
        /* ----------------------------------------------------------------- */
        ///
        /// MoveNext
        ///
        /// <summary>
        /// Moves selected items according to the specified condition.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private static void MoveNext(this MainFacade src, DragDropObject obj)
        {
            var delta = obj.DropIndex - obj.DragIndex;
            var n     = src.Value.Images.Selection.Indices
                        .Where(i => i > obj.DragIndex && i <= obj.DropIndex).Count();

            src.Move(delta - n);
        }
Example #6
0
        /* ----------------------------------------------------------------- */
        ///
        /// MovePrevious
        ///
        /// <summary>
        /// Moves selected items accoding to the specified condition.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="obj">Drag&amp;Drop result.</param>
        ///
        /* ----------------------------------------------------------------- */
        private static void MovePrevious(this MainFacade src, DragDropObject obj)
        {
            var delta = obj.DropIndex - obj.DragIndex;
            var n     = src.Bindable.Images.Selection.Indices
                        .Where(i => i < obj.DragIndex && i >= obj.DropIndex).Count();

            src.Move(delta + n);
        }
Example #7
0
        /* ----------------------------------------------------------------- */
        ///
        /// Zoom
        ///
        /// <summary>
        /// Executes the Zoom command by using the current settings.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Zoom(this MainFacade src)
        {
            var items = src.Bindable.Images.Preferences.ItemSizeOptions;
            var prev  = src.Bindable.Images.Preferences.ItemSizeIndex;
            var next  = items.LastIndexOf(x => x <= src.Settings.Value.ItemSize);

            src.Zoom(next - prev);
        }
Example #8
0
        /* ----------------------------------------------------------------- */
        ///
        /// IsInsertable
        ///
        /// <summary>
        /// Gets the value indicating whether the specified file is
        /// insertable.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="path">File path.</param>
        ///
        /// <remarks>
        /// TODO: 現在は拡張子で判断しているが、ファイル内容の Signature を
        /// 用いて判断するように修正する。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static bool IsInsertable(this MainFacade src, string path)
        {
            var ext = src.Bindable.IO.Get(path).Extension.ToLowerInvariant();
            var cmp = new List <string> {
                ".pdf", ".png", ".jpg", ".jpeg", ".bmp"
            };

            return(cmp.Contains(ext));
        }
Example #9
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetMetadata
        ///
        /// <summary>
        /// Sets the Metadata object.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="value">Metadata object.</param>
        ///
        /// <returns>
        /// History item to execute undo and redo actions.
        /// </returns>
        ///
        /* ----------------------------------------------------------------- */
        public static HistoryItem SetMetadata(this MainFacade src, Metadata value)
        {
            var prev = src.Bindable.Metadata;

            return(HistoryItem.CreateInvoke(
                       () => src.Bindable.Metadata = value,
                       () => src.Bindable.Metadata = prev
                       ));
        }
Example #10
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetEncryption
        ///
        /// <summary>
        /// Sets the Encryption object.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="value">Encryption object.</param>
        ///
        /// <returns>
        /// History item to execute undo and redo actions.
        /// </returns>
        ///
        /* ----------------------------------------------------------------- */
        public static HistoryItem SetEncryption(this MainFacade src, Encryption value)
        {
            var prev = src.Bindable.Encryption;

            return(HistoryItem.CreateInvoke(
                       () => src.Bindable.Encryption = value,
                       () => src.Bindable.Encryption = prev
                       ));
        }
Example #11
0
        /* ----------------------------------------------------------------- */
        ///
        /// Open
        ///
        /// <summary>
        /// Opens the first item of the specified collection.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="files">File collection.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Open(this MainFacade src, IEnumerable <string> files)
        {
            var path = src.GetFirst(files);

            if (path.HasValue())
            {
                src.Open(path);
            }
        }
Example #12
0
File: Save.cs Project: yas/Cube.Pdf
 /* ----------------------------------------------------------------- */
 ///
 /// Save
 ///
 /// <summary>
 /// Saves the PDF document to the specified file path.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="dest">Path to save.</param>
 /// <param name="reopen">
 /// Value indicating whether to reopen the document.
 /// </param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Save(this MainFacade src, string dest, bool reopen) => src.Save(
     dest,
     e => { src.Backup.Invoke(e); src.Cache?.Clear(); },
     e => {
     if (reopen)
     {
         src.Reload(e.FullName);
     }
     src.Value.Set(Properties.Resources.MessageSaved, e.FullName);
 }
     );
Example #13
0
        /* ----------------------------------------------------------------- */
        ///
        /// Restruct
        ///
        /// <summary>
        /// Restructs some properties with the specified new PDF document.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="doc">New PDF document.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Restruct(this MainFacade src, IDocumentReader doc)
        {
            var items = doc.Pages.Select((v, i) => new { Value = v, Index = i });

            foreach (var e in items)
            {
                src.Bindable.Images[e.Index].RawObject = e.Value;
            }
            src.Bindable.Source.Value = doc.File;
            src.Bindable.History.Clear();
        }
Example #14
0
File: Open.cs Project: yas/Cube.Pdf
        /* ----------------------------------------------------------------- */
        ///
        /// Reload
        ///
        /// <summary>
        /// Reload the specified file information.
        /// </summary>
        ///
        /// <param name="src">Source object.</param>
        /// <param name="path">File path to load.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Reload(this MainFacade src, string path)
        {
            var doc   = src.Cache.GetOrAdd(path, src.Value.Encryption.OwnerPassword);
            var items = doc.Pages.Select((v, i) => new { Value = v, Index = i });

            foreach (var e in items)
            {
                src.Value.Images[e.Index].RawObject = e.Value;
            }
            src.Value.Source = doc.File;
            src.Value.History.Clear();
        }
Example #15
0
File: Open.cs Project: yas/Cube.Pdf
        /* ----------------------------------------------------------------- */
        ///
        /// Load
        ///
        /// <summary>
        /// Loads properties of the specified file.
        /// </summary>
        ///
        /// <param name="src">Source object.</param>
        /// <param name="path">File path to load.</param>
        ///
        /// <remarks>
        /// PDFium は Metadata や Encryption の情報取得が不完全なため、
        /// これらの情報は、必要になったタイミングで iTextSharp を用いて
        /// 取得します。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        public static void Load(this MainFacade src, string path)
        {
            src.Value.Set(Properties.Resources.MessageLoading, path);
            var doc = src.Cache.GetOrAdd(path);

            src.Value.Source = doc.File;
            if (!doc.Encryption.Enabled)
            {
                src.Value.Encryption = doc.Encryption;
            }
            src.Value.Images.Add(doc.Pages);
            src.Value.Set(string.Empty);
        }
Example #16
0
        /* ----------------------------------------------------------------- */
        ///
        /// MainViewModel
        ///
        /// <summary>
        /// Initializes a new instance of the MainViewModel class
        /// with the specified settings.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public MainViewModel(SettingFolder src, SynchronizationContext context) :
            base(new Aggregator(), context)
        {
            var recent   = Environment.SpecialFolder.Recent.GetName();
            var mon      = new DirectoryMonitor(recent, "*.pdf.lnk", src.IO, GetDispatcher(false));
            var password = new Query <string>(e => Send(new PasswordViewModel(e, src.IO, context)));

            Model  = new MainFacade(src, password, context);
            Ribbon = new RibbonViewModel(Model.Bindable, Aggregator, context);
            Recent = new RecentViewModel(mon, Aggregator, context);

            SetCommands();
            Track(() => Model.Setup(App.Arguments));
        }
Example #17
0
        /* ----------------------------------------------------------------- */
        ///
        /// Setup
        ///
        /// <summary>
        /// Invokes some actions through the specified arguments.
        /// </summary>
        ///
        /// <param name="src">Facade object.</param>
        /// <param name="args">User arguments.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Setup(this MainFacade src, IEnumerable <string> args)
        {
            foreach (var ps in src.Settings.GetSplashProcesses())
            {
                ps.Kill();
            }
            var path = src.GetFirst(args);

            if (path.HasValue())
            {
                src.Open(path);
            }
            src.Backup.Cleanup();
        }
Example #18
0
 /* ----------------------------------------------------------------- */
 ///
 /// OpenLink
 ///
 /// <summary>
 /// Opens a PDF document with the specified link.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="link">Information for the link.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void OpenLink(this MainFacade src, Information link)
 {
     try { src.Open(Shortcut.Resolve(link?.FullName)?.Target); }
     catch (Exception err)
     {
         var cancel = err is OperationCanceledException ||
                      err is TwiceException;
         if (!cancel)
         {
             src.Bindable.IO.TryDelete(link?.FullName);
         }
         throw;
     }
 }
Example #19
0
 /* ----------------------------------------------------------------- */
 ///
 /// InsertOrMove
 ///
 /// <summary>
 /// Inserts or moves the specified pages according to the specified
 /// condition.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="obj">Drag&amp;Drop result.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void InsertOrMove(this MainFacade src, DragDropObject obj)
 {
     if (!obj.IsCurrentProcess)
     {
         var index = Math.Min(obj.DropIndex + 1, src.Value.Count);
         src.Insert(index, obj.Pages);
     }
     else if (obj.DragIndex < obj.DropIndex)
     {
         src.MoveNext(obj);
     }
     else
     {
         src.MovePrevious(obj);
     }
 }
Example #20
0
        /* ----------------------------------------------------------------- */
        ///
        /// MainViewModel
        ///
        /// <summary>
        /// Initializes a new instance of the MainViewModel class
        /// with the specified settings.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public MainViewModel(SettingsFolder src) : base(new Messenger())
        {
            var recent   = Environment.SpecialFolder.Recent.GetName();
            var mon      = new DirectoryMonitor(recent, "*.pdf.lnk", src.IO);
            var password = new Query <string>(e => Send(new PasswordViewModel(e, src.IO, Context)));

            Model  = new MainFacade(src, password, Context);
            Ribbon = new RibbonViewModel(Model.Bindable, MessengerInstance);
            Recent = new RecentViewModel(mon, MessengerInstance);

            Data.Source.PropertyChanged += (s, e) => Ribbon.Raise();
            Data.Busy.PropertyChanged   += (s, e) => Ribbon.Raise();

            SetCommands();
            Post(() => Model.Setup(App.Arguments));
        }
Example #21
0
File: Save.cs Project: yas/Cube.Pdf
        /* ----------------------------------------------------------------- */
        ///
        /// Save
        ///
        /// <summary>
        /// Save the PDF document
        /// </summary>
        ///
        /// <param name="src">Source object.</param>
        /// <param name="dest">Saving file information.</param>
        /// <param name="prev">Action to be invoked before saving.</param>
        /// <param name="next">Action to be invoked after saving.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Save(this MainFacade src, string dest, Action <Entity> prev, Action <Entity> next)
        {
            var obj   = src.Value;
            var itext = obj.Source.GetItext(obj.Query, obj.IO, false);

            obj.Set(itext.Metadata, itext.Encryption);

            src.Save(itext, new SaveOption(obj.IO)
            {
                Target      = SaveTarget.All,
                Split       = false,
                Destination = dest,
                Metadata    = obj.Metadata,
                Encryption  = obj.Encryption,
                Attachments = itext.Attachments,
            }, prev, next);
        }
Example #22
0
 /* ----------------------------------------------------------------- */
 ///
 /// RibbonViewModel
 ///
 /// <summary>
 /// Initializes a new instance of the RibbonViewModel
 /// class with the specified arguments.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="aggregator">Message aggregator.</param>
 /// <param name="context">Synchronization context.</param>
 ///
 /* ----------------------------------------------------------------- */
 public RibbonViewModel(MainFacade src,
                        Aggregator aggregator,
                        SynchronizationContext context
                        ) : base(src, aggregator, context)
 {
 }
Example #23
0
File: Save.cs Project: yas/Cube.Pdf
 /* ----------------------------------------------------------------- */
 ///
 /// Extract
 ///
 /// <summary>
 /// Extracts PDF pages saves to a file with the specified options.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 /// <param name="options">Save options.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Extract(this MainFacade src, SaveOption options) => src.Save(
     null,
     options,
     e => src.Backup.Invoke(e),
     e => src.Value.Set(Properties.Resources.MessageSaved, e.FullName)
     );
Example #24
0
 /* ----------------------------------------------------------------- */
 ///
 /// Select
 ///
 /// <summary>
 /// Sets or resets the IsSelected property of all items according
 /// to the current condition.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Select(this MainFacade src) =>
 src.Select(src.Bindable.Images.Selection.Count < src.Bindable.Images.Count);
Example #25
0
 /* ----------------------------------------------------------------- */
 ///
 /// StartProcess
 ///
 /// <summary>
 /// Starts a new process with the specified arguments.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="args">User arguments.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void StartProcess(this MainFacade src, string args) =>
 Process.Start(new ProcessStartInfo
 {
     FileName  = Assembly.GetExecutingAssembly().Location,
     Arguments = args
 });
Example #26
0
 /* ----------------------------------------------------------------- */
 ///
 /// Insert
 ///
 /// <summary>
 /// Inserts the specified file behind the selected index.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="files">Collection of inserting files.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Insert(this MainFacade src, IEnumerable <string> files) =>
 src.Insert(src.Bindable.Images.Selection.Last + 1, files);
Example #27
0
 /* ----------------------------------------------------------------- */
 ///
 /// GetFirst
 ///
 /// <summary>
 /// Gets the first item of the specified collection
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="files">File collection.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static string GetFirst(this MainFacade src, IEnumerable <string> files) =>
 files.FirstOrDefault(e => e.IsPdf());
Example #28
0
File: Save.cs Project: yas/Cube.Pdf
 /* ----------------------------------------------------------------- */
 ///
 /// Overwrite
 ///
 /// <summary>
 /// Overwrites the PDF document.
 /// </summary>
 ///
 /// <param name="src">Source object.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Overwrite(this MainFacade src) =>
 src.Value.History.Undoable.Then(() => src.Save(src.Value.Source.FullName));
Example #29
0
 /* ----------------------------------------------------------------- */
 ///
 /// Save
 ///
 /// <summary>
 /// Saves the PDF document to the specified file path.
 /// </summary>
 ///
 /// <param name="src">Facade object.</param>
 /// <param name="dest">File path.</param>
 ///
 /* ----------------------------------------------------------------- */
 public static void Save(this MainFacade src, string dest) => src.Save(dest, true);