[pdfmod] Better handling of files dropped from nautilus



commit 01e9e17fbe8d1a5f2e5b20bea528ebcdcdc15a07
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Aug 17 14:00:49 2010 -0700

    Better handling of files dropped from nautilus
    
    If there is no document already open, the first will be opened and the
    others appended to it.  Additionally, multiple documents dropped will
    get added at the dropped index, with each document appended after the
    prior (where before they'd end up in reverse order).

 src/PdfMod/Core/Client.cs          |    7 ++++++-
 src/PdfMod/Gui/Client.cs           |    9 ++++++---
 src/PdfMod/Gui/DocumentIconView.cs |   31 ++++++++++++++++++++++++-------
 src/PdfMod/Pdf/Document.cs         |    5 +++++
 4 files changed, 41 insertions(+), 11 deletions(-)
---
diff --git a/src/PdfMod/Core/Client.cs b/src/PdfMod/Core/Client.cs
index fd2199a..591009d 100644
--- a/src/PdfMod/Core/Client.cs
+++ b/src/PdfMod/Core/Client.cs
@@ -68,7 +68,12 @@ namespace PdfMod.Core
             LoadPath (path, null);
         }
 
-        public abstract void LoadPath (string path, string suggestedFilename);
+        public void LoadPath (string path, string suggestedFilename)
+        {
+            LoadPath (path, suggestedFilename, null);
+        }
+
+        public abstract void LoadPath (string path, string suggestedFilename, System.Action finishedCallback);
 
         static void InitCache ()
         {
diff --git a/src/PdfMod/Gui/Client.cs b/src/PdfMod/Gui/Client.cs
index 81e45f3..c7f8af0 100644
--- a/src/PdfMod/Gui/Client.cs
+++ b/src/PdfMod/Gui/Client.cs
@@ -239,7 +239,7 @@ namespace PdfMod.Gui
             }
         }
 
-        public override void LoadPath (string path, string suggestedFilename)
+        public override void LoadPath (string path, string suggestedFilename, System.Action finishedCallback)
         {
             lock (this) {
                 // One document per window
@@ -266,7 +266,7 @@ namespace PdfMod.Gui
                         Document.SuggestedSavePath = suggestedFilename;
                     }
 
-                    ThreadAssist.ProxyToMain (delegate {
+                    ThreadAssist.BlockingProxyToMain (delegate {
                         IconView.SetDocument (Document);
                         RecentManager.Default.AddItem (Document.Uri);
                         Document.Changed += UpdateForDocument;
@@ -275,7 +275,7 @@ namespace PdfMod.Gui
                     });
                 } catch (Exception e) {
                     Document = null;
-                    ThreadAssist.ProxyToMain (delegate {
+                    ThreadAssist.BlockingProxyToMain (delegate {
                         status_label.Text = "";
                         if (e is System.IO.FileNotFoundException) {
                             try {
@@ -293,6 +293,9 @@ namespace PdfMod.Gui
                     lock (this) {
                         loading = false;
                     }
+
+                    if (finishedCallback != null)
+                        finishedCallback ();
                 }
             });
         }
diff --git a/src/PdfMod/Gui/DocumentIconView.cs b/src/PdfMod/Gui/DocumentIconView.cs
index 18b1b95..c9e8041 100644
--- a/src/PdfMod/Gui/DocumentIconView.cs
+++ b/src/PdfMod/Gui/DocumentIconView.cs
@@ -339,14 +339,31 @@ namespace PdfMod.Gui
                     args.RetVal = true;
                 } else {
                     int to_index = GetDropIndex (args.X, args.Y);
-                    if (to_index < 0)
-                        return;
-                    // TODO somehow ask user for which pages of the docs to insert?
-                    // TODO pwd handling - keyring#?
-                    // TODO make action/undoable
-                    foreach (var uri in uris) {
-                        document.AddFromUri (new Uri (uri), to_index);
+                    int uri_i = 0;
+
+                    var add_pages = new System.Action (delegate {
+                        // TODO somehow ask user for which pages of the docs to insert?
+                        // TODO pwd handling - keyring#?
+                        // TODO make action/undoable
+                        for (; uri_i < uris.Length; uri_i++) {
+                            var before_count = document.Count;
+                            document.AddFromUri (new Uri (uris[uri_i]), to_index);
+                            to_index += document.Count - before_count;
+                        }
+                    });
+
+                    if (document == null || to_index < 0) {
+                        // Load the first page, then add the other pages to it
+                        app.LoadPath (uris[uri_i++], null, delegate {
+                            if (document != null) {
+                                to_index = document.Count;
+                                add_pages ();
+                            }
+                        });
+                    } else {
+                        add_pages ();
                     }
+
                     args.RetVal = true;
                 }
             }
diff --git a/src/PdfMod/Pdf/Document.cs b/src/PdfMod/Pdf/Document.cs
index 85313fd..be45113 100644
--- a/src/PdfMod/Pdf/Document.cs
+++ b/src/PdfMod/Pdf/Document.cs
@@ -274,6 +274,11 @@ namespace PdfMod.Pdf
             OnChanged ();
         }
 
+        public void AppendFromUri (Uri uri)
+        {
+            AddFromUri (uri, Count);
+        }
+
         public void AddFromUri (Uri uri)
         {
             AddFromUri (uri, 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]