Пример #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); }
        }
Пример #2
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);
     }
 }
Пример #3
0
        /* ----------------------------------------------------------------- */
        ///
        /// MoveNext
        ///
        /// <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 MoveNext(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);
        }
Пример #4
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);
        }
Пример #5
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
                       ));
        }
Пример #6
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));
        }
Пример #7
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);
            }
        }
Пример #8
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
                       ));
        }
Пример #9
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();
        }
Пример #10
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();
        }
Пример #11
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 e)
     {
         var cancel = e is OperationCanceledException ||
                      e is TwiceException;
         if (!cancel)
         {
             src.Bindable.IO.TryDelete(link?.FullName);
         }
         throw;
     }
 }
Пример #12
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.GetFolderPath(Environment.SpecialFolder.Recent);
            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));
        }
Пример #13
0
 /* ----------------------------------------------------------------- */
 ///
 /// InsertOrMove
 ///
 /// <summary>
 /// Inserts or moves the specified pages accoding to the specified
 /// condition.
 /// </summary>
 ///
 /// <param name="src">Facade 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.Bindable.Count.Value);
         src.Insert(index, obj.Pages);
     }
     else if (obj.DragIndex < obj.DropIndex)
     {
         src.MoveNext(obj);
     }
     else
     {
         src.MovePrevious(obj);
     }
 }
Пример #14
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());
Пример #15
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);
Пример #16
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);
Пример #17
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);
Пример #18
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
 });