PdfMod.Gui.Client.LoadPath C# (CSharp) Method

LoadPath() public method

public LoadPath ( string path, string suggestedFilename, System finishedCallback ) : void
path string
suggestedFilename string
finishedCallback System
return void
        public override void LoadPath (string path, string suggestedFilename, System.Action finishedCallback)
        {
            lock (this) {
                // One document per window
                if (loading || Document != null) {
                    new Client ().LoadPath (path, suggestedFilename);
                    return;
                }

                loading = true;
            }

            if (!path.StartsWith ("file://")) {
                path = System.IO.Path.GetFullPath (path);
            }

            Configuration.LastOpenFolder = System.IO.Path.GetDirectoryName (suggestedFilename ?? path);
            status_label.Text = Catalog.GetString ("Loading document...");

            ThreadAssist.SpawnFromMain (delegate {
                try {
                    Document = new Document ();
                    Document.Load (path, PasswordProvider, suggestedFilename != null);
                    if (suggestedFilename != null) {
                        Document.SuggestedSavePath = suggestedFilename;
                    }

                    ThreadAssist.BlockingProxyToMain (delegate {
                        IconView.SetDocument (Document);
                        BookmarkView.SetDocument (Document);
                        RecentManager.Default.AddItem (Document.Uri);

                        Document.Changed += UpdateForDocument;
                        UpdateForDocument ();
                        OnDocumentLoaded ();
                    });
                } catch (Exception e) {
                    Document = null;
                    ThreadAssist.BlockingProxyToMain (delegate {
                        status_label.Text = "";
                        if (e is System.IO.FileNotFoundException) {
                            try {
                                RecentManager.Default.RemoveItem (new Uri(path).AbsoluteUri);
                            } catch {}
                        }
                    });

                    Hyena.Log.Exception (e);
                    Hyena.Log.Error (
                        Catalog.GetString ("Error Loading Document"),
                        String.Format (Catalog.GetString ("There was an error loading {0}"), GLib.Markup.EscapeText (path ?? "")), true
                    );
                } finally {
                    lock (this) {
                        loading = false;
                    }

                    if (finishedCallback != null)
                        finishedCallback ();
                }
            });
        }

Usage Example

Beispiel #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);
                    }
                });
            }
        }
All Usage Examples Of PdfMod.Gui.Client::LoadPath