LoadPath() public méthode

public LoadPath ( string path, string suggestedFilename, System finishedCallback ) : void
path string
suggestedFilename string
finishedCallback System
Résultat void
Exemple #1
0
        // File menu actions

        void OnOpen(object o, EventArgs args)
        {
            var chooser = app.CreateChooser(Catalog.GetString("Select PDF"), FileChooserAction.Open);

            chooser.SelectMultiple = true;
            chooser.AddButton(Stock.Open, ResponseType.Ok);

            if (app.Document != null)
            {
                chooser.SetCurrentFolder(System.IO.Path.GetDirectoryName(app.Document.SuggestedSavePath));
            }
            else
            {
                chooser.SetCurrentFolder(Client.Configuration.LastOpenFolder);
            }

            var response  = chooser.Run();
            var filenames = chooser.Filenames;

            chooser.Destroy();

            if (response == (int)ResponseType.Ok)
            {
                Client.RunIdle(delegate {
                    foreach (var file in filenames)
                    {
                        app.LoadPath(file);
                    }
                });
            }
        }
        void HandleDragDataReceived(object o, DragDataReceivedArgs args)
        {
            args.RetVal = false;
            string target = (string)args.SelectionData.Target;

            if (target == move_internal_target.Target)
            {
                // Move pages within the document
                int to_index = GetDropIndex(args.X, args.Y);
                if (to_index < 0)
                {
                    return;
                }

                Hyena.Gui.DragDropList <Page> pages = args.SelectionData;
                to_index -= pages.Count(p => p.Index < to_index);
                var action = new MoveAction(document, pages, to_index);
                action.Do();
                app.Actions.UndoManager.AddUndoAction(action);
                args.RetVal = true;
            }
            else if (target == move_external_target.Target)
            {
                int to_index = GetDropIndex(args.X, args.Y);
                if (to_index < 0)
                {
                    return;
                }

                string doc_and_pages = System.Text.Encoding.UTF8.GetString(args.SelectionData.Data);
                var    pieces        = doc_and_pages.Split(newline, StringSplitOptions.RemoveEmptyEntries);
                string uri           = pieces[0];
                int [] pages         = pieces[1].Split(',').Select(p => Int32.Parse(p)).ToArray();

                document.AddFromUri(new Uri(uri), to_index, pages);
                args.RetVal = true;
            }
            else if (target == uri_src_target.Target)
            {
                var uris = System.Text.Encoding.UTF8.GetString(args.SelectionData.Data).Split(newline, StringSplitOptions.RemoveEmptyEntries);
                if (uris.Length == 1 && app.Document == null)
                {
                    app.LoadPath(uris[0]);
                    args.RetVal = true;
                }
                else
                {
                    int to_index = GetDropIndex(args.X, args.Y);
                    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;
                }
            }

            Gtk.Drag.Finish(args.Context, (bool)args.RetVal, false, args.Time);
        }
Exemple #3
0
        public Actions (Client app, ActionManager action_manager) : base (action_manager, "Global")
        {
            this.app = app;
            undo_manager = new UndoManager ();

            AddImportant (
                new ActionEntry ("FileMenu", null, Catalog.GetString ("_File"), null, null, null),
                new ActionEntry ("Open",   Gtk.Stock.Open,   null, "<control>O", Catalog.GetString ("Open a document"), OnOpen),
                new ActionEntry ("Save",   Gtk.Stock.Save,   null, "<control>S", Catalog.GetString ("Save changes to this document, overwriting the existing file"), OnSave),
                new ActionEntry ("SaveAs", Gtk.Stock.SaveAs, null, "<control><shift>S", Catalog.GetString ("Save this document to a new file"), OnSaveAs),
                new ActionEntry ("RecentMenu", null, Catalog.GetString ("Recent _Files"), null, null, null),
                new ActionEntry ("InsertFrom", Gtk.Stock.Add, Catalog.GetString("_Insert From..."), null, Catalog.GetString("Insert pages from another document"), OnInsertFrom),
                new ActionEntry ("Close", Gtk.Stock.Close, null, "<control>W", null, OnClose),

                new ActionEntry ("EditMenu", null, Catalog.GetString ("_Edit"), null, null, null),
                new ActionEntry ("Undo", Stock.Undo, null, "<control>z", null, OnUndo),
                new ActionEntry ("Redo", Stock.Redo, null, "<control>y", null, OnRedo),
                new ActionEntry ("Extract", Gtk.Stock.New, null, null, null, OnExtractPages),
                new ActionEntry ("Remove", Gtk.Stock.Remove, null, "Delete", null, OnRemove),
                new ActionEntry ("RotateLeft", null, Catalog.GetString ("Rotate Left"), "bracketleft", Catalog.GetString ("Rotate left"), OnRotateLeft),
                new ActionEntry ("RotateRight", null, Catalog.GetString ("Rotate Right"), "bracketright", Catalog.GetString ("Rotate right"), OnRotateRight),
                new ActionEntry ("ExportImages", null, null, null, null, OnExportImages),
                new ActionEntry ("SelectAll", Stock.SelectAll, null, "<control>A", null, OnSelectAll),
                new ActionEntry ("SelectOdds", null, Catalog.GetString ("Select Odd Pages"), null, null, OnSelectOdds),
                new ActionEntry ("SelectEvens", null, Catalog.GetString ("Select Even Pages"), null, null, OnSelectEvens),
                new ActionEntry ("SelectMatching", null, Catalog.GetString ("Select Matching..."), "<control>F", null, OnSelectMatching),
                new ActionEntry ("SelectInverse", null, Catalog.GetString ("_Invert Selection"), "<shift><control>I", null, OnSelectInverse),

                new ActionEntry ("ViewMenu", null, Catalog.GetString ("_View"), null, null, null),
                new ActionEntry ("ZoomIn", Stock.ZoomIn, null, "<control>plus", null, OnZoomIn),
                new ActionEntry ("ZoomOut", Stock.ZoomOut, null, "<control>minus", null, OnZoomOut),
                new ActionEntry ("OpenInViewer", null, Catalog.GetString ("Open in Viewer"), "F5", Catalog.GetString ("Open in viewer"), OnOpenInViewer),

                new ActionEntry ("BookmarksMenu", null, Catalog.GetString ("_Bookmarks"), null, null, null),
                new ActionEntry ("AddBookmark", null, Catalog.GetString ("_Add Bookmark"), "<control>d", null, null),
                new ActionEntry ("RenameBookmark", null, Catalog.GetString ("Re_name Bookmark"), "F2", null, null),
                new ActionEntry ("ChangeBookmarkDest", null, Catalog.GetString ("_Change Bookmark Destination"), null, null, null),
                new ActionEntry ("RemoveBookmarks", Stock.Remove, Catalog.GetString ("_Remove Bookmark"), null, null, null),
                new ActionEntry ("EditBookmarks", null, Catalog.GetString ("_Edit Bookmarks"), "<control>B", null, OnEditBookmarks),

                new ActionEntry ("HelpMenu", null, Catalog.GetString ("_Help"), null, null, null),
                new ActionEntry ("Help", Stock.Help, Catalog.GetString ("_Contents"), "F1", null, OnHelp),
                new ActionEntry ("About", Stock.About, null, null, null, OnAbout),

                new ActionEntry ("PageContextMenu", null, "", null, null, OnPageContextMenu),
                new ActionEntry ("BookmarkContextMenu", null, "", null, null, OnBookmarkContextMenu)
            );

            this["AddBookmark"].ShortLabel = Catalog.GetString ("_Add");
            this["RemoveBookmarks"].ShortLabel = Catalog.GetString ("_Remove");

            AddImportant (
                new ToggleActionEntry ("Properties", Stock.Properties, null, "<alt>Return", Catalog.GetString ("View and edit the title, keywords, and more for this document"), OnProperties, false),
                new ToggleActionEntry ("ZoomFit", Stock.ZoomFit, null, "<control>0", null, OnZoomFit, true),
                new ToggleActionEntry ("ViewToolbar", null, Catalog.GetString ("Toolbar"), null, null, OnViewToolbar, Client.Configuration.ShowToolbar),
                new ToggleActionEntry ("ViewBookmarks", null, Catalog.GetString ("Bookmarks"), "F9", null, OnViewBookmarks, Client.Configuration.ShowBookmarks),
                new ToggleActionEntry ("FullScreenView", null, Catalog.GetString ("Fullscreen"), "F11", null, OnFullScreenView, false)
            );

            this["RotateRight"].IconName = "object-rotate-right";
            this["RotateLeft"].IconName = "object-rotate-left";
            this["ExportImages"].IconName = "image-x-generic";
            this["ViewBookmarks"].IconName = "user-bookmarks";
            this["AddBookmark"].IconName = "bookmark-new";

            UpdateAction ("Help", true);

            Update ();
            app.IconView.SelectionChanged += OnChanged;
            app.IconView.ZoomChanged += delegate { Update (); };
            app.DocumentLoaded += (o, a) => {
                app.Document.Changed += () => Update ();
                Update ();
            };
            undo_manager.UndoChanged += OnChanged;

            AddUiFromFile ("UIManager.xml");
            Register ();

            // Add additional menu item keybindings
            AddAccel ("/MainMenu/ViewMenu/ZoomIn",  Gdk.ModifierType.ControlMask, Gdk.Key.KP_Add, Gdk.Key.equal);
            AddAccel ("/MainMenu/ViewMenu/ZoomOut", Gdk.ModifierType.ControlMask, Gdk.Key.KP_Subtract, Gdk.Key.underscore);
            AddAccel ("/MainMenu/FileMenu/Close",   Gdk.ModifierType.ControlMask, Gdk.Key.q);
            AddAccel ("/MainMenu/EditMenu/Redo",    Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask, Gdk.Key.z);

            // Set up recent documents menu
            MenuItem recent_item = ActionManager.UIManager.GetWidget ("/MainMenu/FileMenu/RecentMenu") as MenuItem;
            var recent_chooser_item = new RecentChooserMenu (RecentManager.Default) {
                Filter = new RecentFilter (),
                SortType = RecentSortType.Mru
            };
            recent_chooser_item.Filter.AddPattern ("*.pdf");
            recent_chooser_item.ItemActivated += delegate {
                Client.RunIdle (delegate { app.LoadPath (recent_chooser_item.CurrentUri); });
            };
            recent_item.Submenu = recent_chooser_item;
        }
Exemple #4
0
        public Actions(Client app, ActionManager action_manager) : base(action_manager, "Global")
        {
            this.app     = app;
            undo_manager = new UndoManager();

            AddImportant(
                new ActionEntry("FileMenu", null, Catalog.GetString("_File"), null, null, null),
                new ActionEntry("Open", Gtk.Stock.Open, null, "<control>O", Catalog.GetString("Open a document"), OnOpen),
                new ActionEntry("Save", Gtk.Stock.Save, null, "<control>S", Catalog.GetString("Save changes to this document, overwriting the existing file"), OnSave),
                new ActionEntry("SaveAs", Gtk.Stock.SaveAs, null, "<control><shift>S", Catalog.GetString("Save this document to a new file"), OnSaveAs),
                new ActionEntry("RecentMenu", null, Catalog.GetString("Recent _Files"), null, null, null),
                new ActionEntry("InsertFrom", Gtk.Stock.Add, Catalog.GetString("_Insert From..."), null, Catalog.GetString("Insert pages from another document"), OnInsertFrom),
                new ActionEntry("Close", Gtk.Stock.Close, null, "<control>W", null, OnClose),

                new ActionEntry("EditMenu", null, Catalog.GetString("_Edit"), null, null, null),
                new ActionEntry("Undo", Stock.Undo, null, "<control>z", null, OnUndo),
                new ActionEntry("Redo", Stock.Redo, null, "<control>y", null, OnRedo),
                new ActionEntry("Extract", Gtk.Stock.New, null, null, null, OnExtractPages),
                new ActionEntry("Remove", Gtk.Stock.Remove, null, "Delete", null, OnRemove),
                new ActionEntry("RotateLeft", null, Catalog.GetString("Rotate Left"), "bracketleft", Catalog.GetString("Rotate left"), OnRotateLeft),
                new ActionEntry("RotateRight", null, Catalog.GetString("Rotate Right"), "bracketright", Catalog.GetString("Rotate right"), OnRotateRight),
                new ActionEntry("ExportImages", null, null, null, null, OnExportImages),
                new ActionEntry("SelectAll", Stock.SelectAll, null, "<control>A", null, OnSelectAll),
                new ActionEntry("SelectOdds", null, Catalog.GetString("Select Odd Pages"), null, null, OnSelectOdds),
                new ActionEntry("SelectEvens", null, Catalog.GetString("Select Even Pages"), null, null, OnSelectEvens),
                new ActionEntry("SelectMatching", null, Catalog.GetString("Select Matching..."), "<control>F", null, OnSelectMatching),
                new ActionEntry("SelectInverse", null, Catalog.GetString("_Invert Selection"), "<shift><control>I", null, OnSelectInverse),

                new ActionEntry("ViewMenu", null, Catalog.GetString("_View"), null, null, null),
                new ActionEntry("ZoomIn", Stock.ZoomIn, null, "<control>plus", null, OnZoomIn),
                new ActionEntry("ZoomOut", Stock.ZoomOut, null, "<control>minus", null, OnZoomOut),
                new ActionEntry("OpenInViewer", null, Catalog.GetString("Open in Viewer"), "F5", Catalog.GetString("Open in viewer"), OnOpenInViewer),

                new ActionEntry("BookmarksMenu", null, Catalog.GetString("_Bookmarks"), null, null, null),
                new ActionEntry("AddBookmark", null, Catalog.GetString("_Add Bookmark"), "<control>d", null, null),
                new ActionEntry("RenameBookmark", null, Catalog.GetString("Re_name Bookmark"), "F2", null, null),
                new ActionEntry("ChangeBookmarkDest", null, Catalog.GetString("_Change Bookmark Destination"), null, null, null),
                new ActionEntry("RemoveBookmarks", Stock.Remove, Catalog.GetString("_Remove Bookmark"), null, null, null),
                new ActionEntry("EditBookmarks", null, Catalog.GetString("_Edit Bookmarks"), "<control>B", null, OnEditBookmarks),

                new ActionEntry("HelpMenu", null, Catalog.GetString("_Help"), null, null, null),
                new ActionEntry("Help", Stock.Help, Catalog.GetString("_Contents"), "F1", null, OnHelp),
                new ActionEntry("About", Stock.About, null, null, null, OnAbout),

                new ActionEntry("PageContextMenu", null, "", null, null, OnPageContextMenu),
                new ActionEntry("BookmarkContextMenu", null, "", null, null, OnBookmarkContextMenu)
                );

            this["AddBookmark"].ShortLabel     = Catalog.GetString("_Add");
            this["RemoveBookmarks"].ShortLabel = Catalog.GetString("_Remove");

            AddImportant(
                new ToggleActionEntry("Properties", Stock.Properties, null, "<alt>Return", Catalog.GetString("View and edit the title, keywords, and more for this document"), OnProperties, false),
                new ToggleActionEntry("ZoomFit", Stock.ZoomFit, null, "<control>0", null, OnZoomFit, true),
                new ToggleActionEntry("ViewToolbar", null, Catalog.GetString("Toolbar"), null, null, OnViewToolbar, Client.Configuration.ShowToolbar),
                new ToggleActionEntry("ViewBookmarks", null, Catalog.GetString("Bookmarks"), "F9", null, OnViewBookmarks, Client.Configuration.ShowBookmarks),
                new ToggleActionEntry("FullScreenView", null, Catalog.GetString("Fullscreen"), "F11", null, OnFullScreenView, false)
                );

            this["RotateRight"].IconName   = "object-rotate-right";
            this["RotateLeft"].IconName    = "object-rotate-left";
            this["ExportImages"].IconName  = "image-x-generic";
            this["ViewBookmarks"].IconName = "user-bookmarks";
            this["AddBookmark"].IconName   = "bookmark-new";

            UpdateAction("Help", true);

            Update();
            app.IconView.SelectionChanged += OnChanged;
            app.IconView.ZoomChanged      += delegate { Update(); };
            app.DocumentLoaded            += (o, a) => {
                app.Document.Changed += () => Update();
                Update();
            };
            undo_manager.UndoChanged += OnChanged;

            AddUiFromFile("UIManager.xml");
            Register();

            // Add additional menu item keybindings
            AddAccel("/MainMenu/ViewMenu/ZoomIn", Gdk.ModifierType.ControlMask, Gdk.Key.KP_Add, Gdk.Key.equal);
            AddAccel("/MainMenu/ViewMenu/ZoomOut", Gdk.ModifierType.ControlMask, Gdk.Key.KP_Subtract, Gdk.Key.underscore);
            AddAccel("/MainMenu/FileMenu/Close", Gdk.ModifierType.ControlMask, Gdk.Key.q);
            AddAccel("/MainMenu/EditMenu/Redo", Gdk.ModifierType.ControlMask | Gdk.ModifierType.ShiftMask, Gdk.Key.z);

            // Set up recent documents menu
            MenuItem recent_item         = ActionManager.UIManager.GetWidget("/MainMenu/FileMenu/RecentMenu") as MenuItem;
            var      recent_chooser_item = new RecentChooserMenu(RecentManager.Default)
            {
                Filter   = new RecentFilter(),
                SortType = RecentSortType.Mru
            };

            recent_chooser_item.Filter.AddPattern("*.pdf");
            recent_chooser_item.ItemActivated += delegate {
                Client.RunIdle(delegate { app.LoadPath(recent_chooser_item.CurrentUri); });
            };
            recent_item.Submenu = recent_chooser_item;
        }