Пример #1
0
        Widget createDiffWidget(AspectFrame af, AspectFrame af2, PixbufDiff diff)
        {
            VBox sumbox = new VBox ();

            sumbox.Add (createAspectFrame( diff.Diff ));

            Label infotext = new Label (diff.diffstring);
            infotext.LineWrap = true;
            sumbox.Add (infotext);
            Box.BoxChild infotextbc = ((Box.BoxChild)(sumbox [infotext]));
            infotextbc.Expand = false;
            sumbox.Add (new VBox ());

            int mywidth = 24;

            Image arrow = new Image ();
            arrow.Pixbuf = Stetic.IconLoader.LoadIcon (this, "gtk-go-forward", IconSize.LargeToolbar);
            Button button = new Button ();
            button.SetSizeRequest (mywidth, 15);
            button.Add (arrow);
            button.Clicked += (object sender, EventArgs e) => validateImage (diff.Path, af2);
            sumbox.Add (button);
            sumbox.Add (new VBox ());
            Gdk.Pixbuf pixbuf;
            if (af2.Child.Data ["pixbuf"] != null)
                pixbuf = af2.Child.Data ["pixbuf"] as Gdk.Pixbuf;
            else
                pixbuf = af.Child.Data ["pixbuf"] as Gdk.Pixbuf;
            int height = pixbuf.Height;
            int width = pixbuf.Width;
            this.SizeAllocated += (o, args) => {
                int scrollbarwidth = 20;
                sumbox.SetSizeRequest (mywidth, (this.Allocation.Width - mywidth - scrollbarwidth) / 2 * height / width);
            };
            return sumbox;
        }
Пример #2
0
        void recomputeDiffKernel()
        {
            Stopwatch watch = new Stopwatch ();
            watch.Start ();

            string folder = Path;
            IEnumerable<FileInfo> files = null;
            if (Directory.Exists (folder)) {
                DirectoryInfo di = new DirectoryInfo (folder);
                if (di.Exists)
                {
                    try {
                        di = new DirectoryInfo (GetFileSystemCasing(folder));
                        files = di.EnumerateFiles ();
                    } catch (System.Exception) {}
                }
            }
            if (files == null)
                files = new FileInfo[0];

            PixbufCache_.flagToPrune ();
            ReferenceCache_.flagToPrune ();
            List<PixbufDiff> diffs = new List<PixbufDiff> ();
            foreach (FileInfo fi in files) { // for (int i=0; i<files.Length; ++i) {
                string path = fi.FullName;
                PixbufDiff diff;
                if (ReferenceStore.equalfiles (path)) {
                    diff = new PixbufDiff (null, null, path);
                } else {
                    Pixbuf A = PixbufCache_.fromCache (path);
                    if (A == null) {
                        try {
                            using (FileStream fs = fi.OpenRead()) {
                                A = new Pixbuf (fs);
                                PixbufCache_.updateCache (path, A);
                            }
                        } catch (GLib.GException x) {
                            if (x.Message == "Unrecognized image file format") {
                                // Not an image file
                            } else if (x.Message == "Image has zero width") {
                                // ignore
                            } else {
                                System.Console.WriteLine (path + " " + x.Message);
                            }
                            continue;
                        } catch (Exception x) {
                            System.Console.WriteLine (path + " " + x.Message);
                            continue;
                        }
                    }

                    Pixbuf B = null;
                    if (ReferenceStore.hasReferenceImage (path))
                        B = ReferenceCache_.fromCache (path);

                    if (B == null) {
                        try {
                            B = ReferenceStore.getReferenceImage (path);
                            if (B != null)
                                ReferenceCache_.updateCache (path, B);
                        } catch (Exception x) {
                            B = Gtk.StatusIcon.NewFromStock(Gtk.Stock.DialogError).Pixbuf;
                            B.Data ["tooltip"] = x.Message;
                        }
                    }

                    // Compute a diff
                    diff = new PixbufDiff (A, B, path);
                }

                diffs.Add (diff);
            }

            PixbufCache_.prune ();
            ReferenceCache_.prune ();

            watch.Stop ();

            System.Console.WriteLine (string.Format ("Computed diff of '{2}' with {1} files in {0} s", watch.ElapsedMilliseconds * 1e-3, diffs.Count, folder));

            this.Diff = new DiffResult (diffs, folder, "");

            if (DiffListChanged != null)
                DiffListChanged (this);
        }