Esempio n. 1
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();
    }
Esempio n. 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;
        }
Esempio n. 3
0
        private Gtk.HBox create_element(Item item, string search_text, string snippet_text, VoidFunction update)
        {
            Gtk.HBox element = new Gtk.HBox();
            Gtk.VBox lines = new Gtk.VBox();
            Gtk.HBox title_date = new Gtk.HBox();

            Gtk.EventBox title_wrapper = new Gtk.EventBox();
            Gtk.Label title = new Gtk.Label();

            string str_title = item.name(40);

            string capitalized = search_text.Substring(0, 1).ToUpper() + search_text.Substring(1);

            if (str_title.Contains(search_text)) {
                int index = str_title.IndexOf(search_text);
                str_title = str_title.Substring(0, index) + "<b>" + search_text + "</b>" + str_title.Substring(index+search_text.Length);
            } else if (str_title.Contains(capitalized)) {
                int index = str_title.IndexOf(capitalized);
                str_title = str_title.Substring(0, index) + "<b>" + capitalized + "</b>" + str_title.Substring(index+capitalized.Length);
            }

            title.Markup = "<big>" + str_title + "</big>";
            title.UseUnderline = false;
            title.SetAlignment(0, 0); // left aligned
            title_wrapper.ButtonPressEvent += delegate(object sender, Gtk.ButtonPressEventArgs args) {
                if (args.Event.Button == 1)
                    item.open();
            };
            title_wrapper.Add(title);
            GtkCommon.set_background_color(title_wrapper, "white");

            GtkCommon.show_hand_and_tooltip(title_wrapper, String.Format(Mono.Unix.Catalog.GetString("Open: {0}"), item.long_name));

            GtkCommon.create_preview(item, lines, title_wrapper);

            title_date.PackStart(title_wrapper, true, true, 0);

            Gtk.Alignment date_alignment = new Gtk.Alignment(1, 0, 0, 0);
            Gtk.Label date = new Gtk.Label();
            date.Markup = "<big>" + String.Format("{0:dd/MM/yy}", item.last_modify) + "</big>";
            date_alignment.Add(date);
            date_alignment.LeftPadding = 10;
            title_date.PackStart(date_alignment, true, true, 0);

            lines.PackStart(title_date, true, true, 0);

            try {
                DocumentItem doc_item = item as DocumentItem;

                if (doc_item != null) {
                    doc_item.on_snippet_callback = delegate (string snippet) {
                        if (!String.IsNullOrEmpty(snippet)) {

                            System.Console.WriteLine("got snippet: {0}", snippet);

                            Gtk.Label snippet_label = new Gtk.Label();
                            snippet_label.SetAlignment(0, 0); // left aligned
                            snippet_label.Markup = snippet;
                            lines.PackStart(snippet_label, true, true, 2);
                            lines.ReorderChild(snippet_label, 1);

                            update();
                        }
                    };
                    if (!String.IsNullOrEmpty(doc_item.snippet))
                        doc_item.on_snippet_callback(doc_item.snippet);
                }
            } catch (Exception) { // not document item
            }

            Gtk.HBox label_links = new Gtk.HBox();

            Gtk.HBox bubbles = new Gtk.HBox();

            foreach (UserLabel label in item.labels)
                bubbles.Add(label.dot());

            label_links.PackStart(bubbles, false, false, 0);

            item.on_labels_callback = delegate() {
                foreach (Widget w in bubbles)
                    w.Destroy();

                foreach (UserLabel label in item.labels)
                    bubbles.Add(label.dot());

                element.ShowAll();
            };

            Gtk.Alignment links_alignment = new Gtk.Alignment(1,1,0,0);
            Gtk.HBox links = new Gtk.HBox();

            add_link(Mono.Unix.Catalog.GetString("Go to week"), CalendarDriver.View.Week, item.last_modify, links);
            add_link(Mono.Unix.Catalog.GetString("Go to month"), CalendarDriver.View.Month, item.last_modify, links);
            add_link(Mono.Unix.Catalog.GetString("Go to year"), CalendarDriver.View.Year, item.last_modify, links);

            links_alignment.Add(links);

            label_links.PackStart(links_alignment, true, true, 0);

            lines.PackStart(label_links, true, true, 2);

            string image = String.Empty;

            if (item.file != null)
                image = Singleton<Types>.Instance.get_type((int)item.file.type.category).icon;

            Gtk.Alignment img_alignment = new Gtk.Alignment(0, (float)0.05, 0,0);

            if (!String.IsNullOrEmpty(image))
            {
                Gtk.Image img;

                if (item.file.starred)
                    img = CairoDrawing.create_small_starred_image(image);
                else
                    img = new Gtk.Image(null, image);

                item.register_small_starred_change(delegate(bool starred) {
                    foreach (Widget w in img_alignment)
                        w.Destroy();
                    if (starred)
                        img = CairoDrawing.create_small_starred_image(image);
                    else
                        img = new Gtk.Image(null, image);
                    img_alignment.Add(img);
                    img_alignment.ShowAll();
                });

                img_alignment.Add(img);
                img_alignment.ShowAll();
            }

            element.PackStart(img_alignment, false, false, 5);

            element.PackStart(lines, true, true, 0);

            return element;
        }