[pdfmod] Add Insert From to the menu/toolbar
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pdfmod] Add Insert From to the menu/toolbar
- Date: Sun, 2 Aug 2009 17:54:49 +0000 (UTC)
commit 994c355cb45fa3ec71f1c316141fa3016fc660ff
Author: Julien Rebetez <julien fhtagn net>
Date: Sun Aug 2 10:51:20 2009 -0700
Add Insert From to the menu/toolbar
Signed-off-by: Gabriel Burt <gabriel burt gmail com>
src/PdfMod/PdfMod/Document.cs | 18 ++++++++++++++++++
src/PdfMod/PdfMod/GlobalActions.cs | 22 +++++++++++++++++++++-
src/PdfMod/PdfMod/PdfIconView.cs | 10 +---------
src/PdfMod/Resources/UIManager.xml | 2 ++
4 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/src/PdfMod/PdfMod/Document.cs b/src/PdfMod/PdfMod/Document.cs
index af9b81c..4e32e9c 100644
--- a/src/PdfMod/PdfMod/Document.cs
+++ b/src/PdfMod/PdfMod/Document.cs
@@ -248,6 +248,24 @@ namespace PdfMod
}
}
+ public void AddFromUri (Uri uri)
+ {
+ AddFromUri (uri, 0);
+ }
+
+ public void AddFromUri (Uri uri, int to_index)
+ {
+ Log.DebugFormat ("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]));
+ }
+ Add (to_index, pages.ToArray ());
+ to_index += pages.Count;
+ }
+ }
+
public void Add (int to_index, params Page [] add_pages)
{
int i = to_index;
diff --git a/src/PdfMod/PdfMod/GlobalActions.cs b/src/PdfMod/PdfMod/GlobalActions.cs
index d808548..ca25913 100644
--- a/src/PdfMod/PdfMod/GlobalActions.cs
+++ b/src/PdfMod/PdfMod/GlobalActions.cs
@@ -25,7 +25,7 @@ namespace PdfMod
private static string [] require_doc_actions = new string[] {
"SaveAction", "SaveAsAction", "PropertiesAction", "UndoAction", "RedoAction", "ZoomFitAction",
- "SelectAllAction", "SelectEvensAction", "SelectOddsAction", "SelectMatchingAction"
+ "SelectAllAction", "SelectEvensAction", "SelectOddsAction", "SelectMatchingAction", "InsertFromAction"
};
private static string [] require_page_actions = new string[] {
@@ -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),
@@ -188,6 +189,25 @@ namespace PdfMod
}
}
+ 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)
{
app.Document.Save (app.Document.SuggestedSavePath);
diff --git a/src/PdfMod/PdfMod/PdfIconView.cs b/src/PdfMod/PdfMod/PdfIconView.cs
index 61d45e6..a2af705 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;
- }
+ 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..ebb8483 100644
--- a/src/PdfMod/Resources/UIManager.xml
+++ b/src/PdfMod/Resources/UIManager.xml
@@ -15,6 +15,7 @@
<menuitem action="RedoAction"/>
<separator/>
<menuitem action="ExtractAction"/>
+ <menuitem action="InsertFromAction"/>
<menuitem action="RemoveAction"/>
<menuitem action="ExportImagesAction"/>
<separator/>
@@ -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]