[pdfmod] Inserting another document using menu/toolbar



Hello,
When I first launched PdfMod, I searched for 2 minutes how to add pages from another file. I finally found out that you had to drag the file from nautilus, but I think this functionnality should be present in the menu/toolbar.

The attached patch adds this to the "Edit" menu and to the toolbar as well.

Regards,
Julien
diff --git a/src/PdfMod/PdfMod/Document.cs b/src/PdfMod/PdfMod/Document.cs
index af9b81c..a2db4f5 100644
--- a/src/PdfMod/PdfMod/Document.cs
+++ b/src/PdfMod/PdfMod/Document.cs
@@ -247,6 +247,24 @@ namespace PdfMod
                 }
             }
         }
+        
+        public void AddFromUri (Uri uri) 
+        {
+            AddFromUri(uri, 0);    
+        }
+        
+        public void AddFromUri (Uri uri, int to_index) 
+        {
+            Console.WriteLine ("Inserting pages from {0} to index {1}", uri, to_index);
+            using (var doc = PdfSharp.Pdf.IO.PdfReader.Open (uri.AbsolutePath, null, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)) {
+                var pages = new List<Page> ();
+                for (int i = 0; i < doc.PageCount; i++) {
+                    pages.Add (new Page (doc.Pages [i]));
+                }
+                this.Add (to_index, pages.ToArray ());
+                to_index += pages.Count;
+            }
+        }
 
         public void Add (int to_index, params Page [] add_pages)
         {
diff --git a/src/PdfMod/PdfMod/GlobalActions.cs b/src/PdfMod/PdfMod/GlobalActions.cs
index d808548..90a350d 100644
--- a/src/PdfMod/PdfMod/GlobalActions.cs
+++ b/src/PdfMod/PdfMod/GlobalActions.cs
@@ -44,6 +44,7 @@ namespace PdfMod
 
             AddImportant (
                 new ActionEntry ("OpenAction",   Gtk.Stock.Open,   null, "<control>O", Catalog.GetString ("Open a document"), OnOpen),
+                new ActionEntry ("InsertFromAction", Gtk.Stock.Add, Catalog.GetString("_Insert from..."), null, Catalog.GetString("Insert pages from another document"), OnInsertFrom),
                 new ActionEntry ("SaveAction",   Gtk.Stock.Save,   null, "<control>S", Catalog.GetString ("Save changes to this document, overwriting the existing file"), OnSave),
                 new ActionEntry ("SaveAsAction", Gtk.Stock.SaveAs, null, "<control><shift>S", Catalog.GetString ("Save this document to a new file"), OnSaveAs),
 
@@ -146,6 +147,7 @@ namespace PdfMod
             foreach (string action in require_page_actions)
                 UpdateAction (action, true, have_page);
 
+            UpdateAction("InsertFromAction", true, have_doc);
             UpdateAction ("UndoAction", true, have_doc && undo_manager.CanUndo);
             UpdateAction ("RedoAction", true, have_doc && undo_manager.CanRedo);
             UpdateActions (true, have_doc && app.Document.HasUnsavedChanged, "SaveAction", "SaveAsAction");
@@ -187,6 +189,26 @@ namespace PdfMod
                 PdfMod.RunIdle (delegate { app.LoadPath (filename); });
             }
         }
+        
+        private void OnInsertFrom (object o, EventArgs args)
+        {
+            var chooser = new Gtk.FileChooserDialog (Catalog.GetString ("Select PDF"), app.Window, FileChooserAction.Open);
+            chooser.AddFilter (GtkUtilities.GetFileFilter ("PDF Documents", new string [] {"pdf"}));
+            chooser.AddFilter (GtkUtilities.GetFileFilter (Catalog.GetString ("All Files"), new string [] {"*"}));
+            chooser.SelectMultiple = false;
+            chooser.AddButton (Stock.Cancel, ResponseType.Cancel);
+            chooser.AddButton (Stock.Open, ResponseType.Ok);
+            chooser.DefaultResponse = ResponseType.Ok;
+            
+            var response = chooser.Run ();
+            string filename = chooser.Filename;
+            chooser.Destroy();
+            
+            if (response == (int)ResponseType.Ok) {
+                app.Document.AddFromUri(new Uri(filename));
+            }
+                      
+        }
 
         private void OnSave (object o, EventArgs args)
         {
diff --git a/src/PdfMod/PdfMod/PdfIconView.cs b/src/PdfMod/PdfMod/PdfIconView.cs
index 61d45e6..bf986f9 100644
--- a/src/PdfMod/PdfMod/PdfIconView.cs
+++ b/src/PdfMod/PdfMod/PdfIconView.cs
@@ -282,15 +282,7 @@ namespace PdfMod
                     // TODO pwd handling - keyring#?
                     // TODO make action/undoable
                     foreach (var uri in uris) {
-                        Console.WriteLine ("Inserting pages from {0} to index {1}", uri, to_index);
-                        using (var doc = PdfSharp.Pdf.IO.PdfReader.Open (new Uri (uri).AbsolutePath, null, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)) {
-                            var pages = new List<Page> ();
-                            for (int i = 0; i < doc.PageCount; i++) {
-                                pages.Add (new Page (doc.Pages [i]));
-                            }
-                            this.document.Add (to_index, pages.ToArray ());
-                            to_index += pages.Count;
-                        }
+                        this.document.AddFromUri(new Uri(uri), to_index);
                     }
                     args.RetVal = true;
                 }
diff --git a/src/PdfMod/Resources/UIManager.xml b/src/PdfMod/Resources/UIManager.xml
index 82ca186..cc1aeb4 100644
--- a/src/PdfMod/Resources/UIManager.xml
+++ b/src/PdfMod/Resources/UIManager.xml
@@ -2,6 +2,7 @@
   <menubar name="MainMenu" action="MainMenuAction">
     <menu name="FileMenu" action="FileMenuAction">
       <menuitem action="OpenAction"/>
+      <menuitem action="InsertFromAction"/>
       <menuitem action="SaveAction"/>
       <menuitem action="SaveAsAction"/>
       <menuitem action="RecentMenuAction"/>
@@ -48,6 +49,7 @@
     <toolitem action="PropertiesAction"/>
     <separator/>
     <toolitem action="ExtractAction"/>
+    <toolitem action="InsertFromAction"/>
     <toolitem action="RemoveAction"/>
     <toolitem action="RotateLeftAction"/>
     <toolitem action="RotateRightAction"/>


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