public SparkleDiffWindow(string file_path, string [] revisions)
            : base("")
        {
            string file_name = System.IO.Path.GetFileName (file_path);
            Revisions = revisions;

             		SetPosition (WindowPosition.Center);
            BorderWidth = 12;
            IconName = "image-x-generic";

            FaceCollection face_collection = new FaceCollection ();
            face_collection.UseGravatar = true;

            DeleteEvent += Quit;

            Title = file_name;

            VBox layout_vertical = new VBox (false, 12);

                HBox layout_horizontal = new HBox (true, 6);

                    Process process = new Process ();
                    process.EnableRaisingEvents = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.UseShellExecute = false;

                    process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path);
                    process.StartInfo.FileName = "git";
                    process.StartInfo.Arguments = "log --format=\"%ct\t%an\t%ae\" " + file_name;
                    process.Start ();

                    ViewLeft  = new LeftRevisionView  ();
                    ViewRight = new RightRevisionView ();

                    string output = process.StandardOutput.ReadToEnd ();
                    string [] revisions_info = Regex.Split (output.Trim (), "\n");

                    int i = 0;
                    foreach (string revision_info in revisions_info) {

                        string [] parts = Regex.Split (revision_info.Trim (), "\t");

                        int timestamp = int.Parse (parts [0]);
                        string author = parts [1];
                        string email  = parts [2];

                        string date;
                        // TRANSLATORS: This is a format specifier according to System.Globalization.DateTimeFormatInfo
                        if (i == 0)
                            date = "Latest Revision";
                        else
                            date = String.Format (_("{0} at {1}"),
                                   UnixTimestampToDateTime (timestamp).ToString (_("ddd MMM d, yyyy")),
                                   UnixTimestampToDateTime (timestamp).ToString (_("H:mm")));

                        face_collection.AddFace (email);

                        ViewLeft.AddRow  (face_collection.GetFace (email, 32), author, date);
                        ViewRight.AddRow (face_collection.GetFace (email, 32), author, date);

                        i++;

                    }

                    ViewLeft.SetImage  (new RevisionImage (file_path, Revisions [1]));
                    ViewRight.SetImage (new RevisionImage (file_path, Revisions [0]));

                    ViewLeft.IconView.SelectionChanged += delegate {

                        ViewLeft.SetImage  (new RevisionImage (file_path, Revisions [ViewLeft.GetSelected ()]));

                        ViewLeft.ScrolledWindow.Hadjustment = ViewRight.ScrolledWindow.Hadjustment;
                        ViewLeft.ScrolledWindow.Vadjustment = ViewRight.ScrolledWindow.Vadjustment;

                        HookUpViews ();

                    };

                    ViewRight.IconView.SelectionChanged += delegate {

                        ViewRight.SetImage  (new RevisionImage (file_path, Revisions [ViewRight.GetSelected ()]));

                        ViewRight.ScrolledWindow.Hadjustment = ViewLeft.ScrolledWindow.Hadjustment;
                        ViewRight.ScrolledWindow.Vadjustment = ViewLeft.ScrolledWindow.Vadjustment;

                        HookUpViews ();

                    };

                    ViewLeft.ToggleButton.Clicked += delegate {
                        if (ViewLeft.ToggleButton.Active)
                            DetachViews ();
                        else
                            HookUpViews ();
                    };

                    ViewRight.ToggleButton.Clicked += delegate {
                        if (ViewLeft.ToggleButton.Active)
                            DetachViews ();
                        else
                            HookUpViews ();
                    };

                layout_horizontal.PackStart (ViewLeft);
                layout_horizontal.PackStart (ViewRight);

                ResizeToViews ();

                // Order time view according to the user's reading direction
                if (Direction == Gtk.TextDirection.Rtl)
                    layout_horizontal.ReorderChild (ViewLeft, 1);

                HookUpViews ();

                HButtonBox dialog_buttons  = new HButtonBox ();
                dialog_buttons.Layout      = ButtonBoxStyle.End;
                dialog_buttons.BorderWidth = 0;

                    Button close_button = new Button (Stock.Close);
                    close_button.Clicked += delegate (object o, EventArgs args) {
                        Environment.Exit (0);
                    };

                dialog_buttons.Add (close_button);

            layout_vertical.PackStart (layout_horizontal, true, true, 0);
            layout_vertical.PackStart (dialog_buttons, false, false, 0);

            Add (layout_vertical);
        }
Example #2
0
        public void Attach(Gtk.Orientation orientation_new)
        {
            Gtk.Box.BoxChild child = null;
            Box box;

            switch (Orientation)
            {
            case Gtk.Orientation.Vertical:
                box = main_hbox;
                break;

            case Gtk.Orientation.Horizontal:
            {
                box = framework_vbox;
                break;
            }

            default:
                throw new InvalidOperationException();
            }

            bool contained = false;

            foreach (var ch in box.AllChildren)
            {
                if (ch == this)
                {
                    contained = true;
                    break;
                }
            }
            if (contained == true)
            {
                box.Remove(this);
            }

            Orientation = (Gtk.Orientation)orientation_new;

            switch (Orientation)
            {
            case Gtk.Orientation.Vertical:
                main_hbox.Add(this);
                main_hbox.ReorderChild(this, 0);
                child = ((Gtk.Box.BoxChild)(main_hbox[this]));
                break;

            case Gtk.Orientation.Horizontal:
                framework_vbox.Add(this);
                framework_vbox.ReorderChild(this, 1);
                child = ((Gtk.Box.BoxChild)(framework_vbox[this]));
                break;

            default:
                throw new InvalidOperationException();
            }

            child.Expand = false;
            child.Fill   = false;
            ShowAll();
            InitCompleted = true;
        }
Example #3
0
        public GtkAlertDialog(MessageDescription message)
        {
            Init();
            this.buttons = message.Buttons.ToArray();
            this.message = message;

            Modal = true;

            string primaryText;
            string secondaryText;

            if (string.IsNullOrEmpty(message.SecondaryText))
            {
                secondaryText = message.Text;
                primaryText   = null;
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            if (!message.UseMarkup)
            {
                primaryText   = GLib.Markup.EscapeText(primaryText);
                secondaryText = GLib.Markup.EscapeText(secondaryText);
            }

            if (!string.IsNullOrEmpty(message.Icon))
            {
                image        = new ImageView();
                image.Yalign = 0.00f;
                image.Image  = ImageService.GetIcon(message.Icon, IconSize.Dialog);
                hbox.PackStart(image, false, false, 0);
                hbox.ReorderChild(image, 0);
            }

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(primaryText);
            markup.Append("</span>");
            if (!String.IsNullOrEmpty(secondaryText))
            {
                if (!String.IsNullOrEmpty(primaryText))
                {
                    markup.AppendLine();
                    markup.AppendLine();
                }
                markup.Append(secondaryText);
            }
            label.Markup     = markup.ToString();
            label.Selectable = true;
            label.CanFocus   = false;

            foreach (AlertButton button in message.Buttons)
            {
                Button newButton = new Button();
                newButton.Label        = button.Label;
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (!String.IsNullOrEmpty(button.Icon))
                {
                    newButton.Image = new ImageView(button.Icon, IconSize.Button);
                }
                newButton.Clicked += ButtonClicked;
                ActionArea.Add(newButton);
            }

            foreach (var op in message.Options)
            {
                CheckButton check = new CheckButton(op.Text);
                check.Active = op.Value;
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                CheckButton check = new CheckButton(GettextCatalog.GetString("Apply to all"));
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
Example #4
0
    public BlessMain(string[] args)
    {
        Application.Init();

        //
        Catalog.Init(ConfigureDefines.GETTEXT_PACKAGE, ConfigureDefines.LOCALE_DIR);

        // load main window from glade XML
        Glade.XML gxml = new Glade.XML(FileResourcePath.GetDataPath("bless.glade"), "MainWindow", "bless");
        gxml.Autoconnect(this);

        // set the application icon
        MainWindow.Icon = new Gdk.Pixbuf(FileResourcePath.GetDataPath("bless-48x48.png"));

        string blessConfDir = FileResourcePath.GetUserPath();

        // make sure local configuration directory exists
        try {
            if (!Directory.Exists(blessConfDir))
            {
                Directory.CreateDirectory(blessConfDir);
            }
        }
        catch (Exception ex) {
            ErrorAlert ea = new ErrorAlert(Catalog.GetString("Cannot create user configuration directory"), ex.Message + Catalog.GetString("\n\nSome features of Bless may not work properly."), MainWindow);
            ea.Run();
            ea.Destroy();
        }

        Preferences.Proxy.Enable = false;
        // load default preferences
        Preferences.Default.Load(FileResourcePath.GetDataPath("default-preferences.xml"));
        Preferences.Default["Default.Layout.File"] = FileResourcePath.GetDataPath("bless-default.layout");

        // load user preferences
        LoadPreferences(Path.Combine(blessConfDir, "preferences.xml"));
        Preferences.Instance.AutoSavePath = Path.Combine(blessConfDir, "preferences.xml");

        // add the (empty) Menubar and toolbar
        uiManager = new UIManager();
        MainWindow.AddAccelGroup(uiManager.AccelGroup);
        uiManager.AddUiFromString(uiXml);

        actionEntries = new ActionEntry[] {
            new ActionEntry("File", null, Catalog.GetString("_File"), null, null, null),
            new ActionEntry("Edit", null, Catalog.GetString("_Edit"), null, null, null),
            new ActionEntry("View", null, Catalog.GetString("_View"), null, null, null),
            new ActionEntry("Search", null, Catalog.GetString("_Search"), null, null, null),
            new ActionEntry("Tools", null, Catalog.GetString("_Tools"), null, null, null),
            new ActionEntry("Help", null, Catalog.GetString("_Help"), null, null, null)
        };

        ActionGroup group = new ActionGroup("MainMenuActions");

        group.Add(actionEntries);
        group.Add(new ToggleActionEntry[] {
            new ToggleActionEntry("ToolbarAction", null, Catalog.GetString("Toolbar"), null, null,
                                  new EventHandler(OnViewToolbarToggled), false)
        });

        uiManager.InsertActionGroup(group, 0);

        Widget mb = uiManager.GetWidget("/menubar");

        MainVBox.PackStart(mb, false, false, 0);
        MainVBox.ReorderChild(mb, 0);
        Widget tb = uiManager.GetWidget("/toolbar");

        tb.Visible = false;
        MainVBox.PackStart(tb, false, false, 0);
        MainVBox.ReorderChild(tb, 1);

        // create the DataBook
        dataBook             = new DataBook();
        dataBook.PageAdded  += new DataView.DataViewEventHandler(OnDataViewAdded);
        dataBook.Removed    += new RemovedHandler(OnDataViewRemoved);
        dataBook.SwitchPage += new SwitchPageHandler(OnSwitchPage);

        DataViewBox.PackStart(dataBook);


        // create the widget groups that hold utility widgets
        WidgetGroup widgetGroup0     = new WidgetGroup();
        WidgetGroup widgetGroup1     = new WidgetGroup();
        WidgetGroup sideWidgetGroup0 = new WidgetGroup();
        WidgetGroup sideWidgetGroup1 = new WidgetGroup();

        widgetGroup0.Show();
        widgetGroup1.Show();
        sideWidgetGroup0.Show();
        sideWidgetGroup1.Show();

        MainVBox.PackStart(widgetGroup0, false, false, 0);
        MainVBox.ReorderChild(widgetGroup0, 3);
        MainVBox.PackStart(widgetGroup1, false, false, 0);
        MainVBox.ReorderChild(widgetGroup1, 4);

        DataViewBox.PackStart(sideWidgetGroup0, false, false, 0);
        DataViewBox.ReorderChild(sideWidgetGroup0, 0);
        DataViewBox.PackEnd(sideWidgetGroup1, false, false, 0);
        //MainVBox.ReorderChild(widgetGroup1, 4);


        Services.File    = new FileService(dataBook, MainWindow);
        Services.Session = new SessionService(dataBook, MainWindow);
        Services.UI      = new UIService(uiManager);
        //Services.Info=new InfoService(infobar);

        // Add area plugins
        PluginManager.AddForType(typeof(AreaPlugin), new object[0]);
        PluginManager areaPlugins = PluginManager.GetForType(typeof(AreaPlugin));

        Area.InitiatePluginTable();
        foreach (AreaPlugin p in areaPlugins.Plugins)
        {
            Area.AddFactoryItem(p.Name, p.CreateArea);
        }

        // Load GUI plugins
        PluginManager.AddForType(typeof(GuiPlugin), new object[] { MainWindow, uiManager });
        PluginManager guiPlugins = PluginManager.GetForType(typeof(GuiPlugin));

        foreach (Plugin p in guiPlugins.Plugins)
        {
            guiPlugins.LoadPlugin(p);
        }

        // load recent file history
        try {
            History.Instance.Load(Path.Combine(blessConfDir, "history.xml"));
        }
        catch (Exception e) {
            System.Console.WriteLine(e.Message);
        }

        // if user specified files on the command line
        // try to load them
        if (args.Length > 0)
        {
            Services.File.LoadFiles(args);
        }
        else if (Preferences.Instance["Session.LoadPrevious"] == "True")
        {
            bool   loadIt          = true;
            string prevSessionFile = Path.Combine(blessConfDir, "last.session");

            if (Preferences.Instance["Session.AskBeforeLoading"] == "True" &&
                File.Exists(prevSessionFile))
            {
                MessageDialog md = new MessageDialog(MainWindow,
                                                     DialogFlags.DestroyWithParent,
                                                     MessageType.Question,
                                                     ButtonsType.YesNo, Catalog.GetString("Do you want to load your previous session?"));

                ResponseType result = (ResponseType)md.Run();
                md.Destroy();

                if (result == ResponseType.Yes)
                {
                    loadIt = true;
                }
                else
                {
                    loadIt = false;
                }
            }
            // try to load previous session
            if (loadIt)
            {
                Services.Session.Load(prevSessionFile);
            }
        }

        // if nothing has been loaded, create a new file
        if (dataBook.NPages == 0)
        {
            ByteBuffer bb = Services.File.NewFile();

            // create and setup a  DataView
            DataView dv = Services.File.CreateDataView(bb);

            // append the DataView to the DataBook
            dataBook.AppendView(dv, new CloseViewDelegate(Services.File.CloseFile), Path.GetFileName(bb.Filename));
        }

        PreferencesChangedHandler handler = new PreferencesChangedHandler(OnPreferencesChanged);

        Preferences.Proxy.Subscribe("View.Toolbar.Show", "mainwin", handler);


        // register drag and drop of files
        MainWindow.DragDataReceived += OnDragDataReceived;
        Gtk.Drag.DestSet(MainWindow, DestDefaults.Motion | DestDefaults.Drop, dropTargets, Gdk.DragAction.Copy | Gdk.DragAction.Move);

        DataViewBox.ShowAll();

        Preferences.Proxy.Enable = true;
        // fire the preferences changed event
        // so things are setup according to the preferences
        Preferences.Proxy.NotifyAll();

        Application.Run();
    }
Example #5
0
            private void Reparent (Widget widget, HBox box, int index)
            {
                if (widget.Parent == box) {
                    return;
                }

                if (widget.Parent == null) {
                    box.PackStart (widget, false, false, 0);
                } else {
                    widget.Reparent (box);
                    box.SetChildPacking (widget, false, false, 0, PackType.Start);
                }

                box.ReorderChild (widget, index);
                widget.Show ();
            }