Пример #1
0
        private FileStream GetPatternFile(FileMode mode, FileAccess access)
        {
            string patternDir = FileResourcePath.GetUserPath();

            FileStream fs = new FileStream(System.IO.Path.Combine(patternDir, "export_patterns"), mode, access);

            return(fs);
        }
Пример #2
0
        private PluginManager(Type pluginType, object[] args)
        {
            plugins         = new Dictionary <string, Plugin>();
            this.pluginType = pluginType;

            ctorArgTypes = new Type[args.Length];
            ctorArgs     = args;

            for (int i = 0; i < ctorArgs.Length; i++)
            {
                ctorArgTypes[i] = ctorArgs[i].GetType();
            }

            // find system-wide plugins
            string systemPluginDir = FileResourcePath.GetBinPath();

            string[]    systemPluginFiles = Directory.GetFiles(systemPluginDir);
            CompareInfo compare           = CultureInfo.InvariantCulture.CompareInfo;

            foreach (string file in systemPluginFiles)
            {
                if (compare.IndexOf(file, "plugin", CompareOptions.IgnoreCase) >= 0 &&
                    file.EndsWith(".dll"))
                {
                    //Console.WriteLine("Searching File {0}", file);
                    AddPluginFile(file);
                }
            }

            try {
                // find local user plugins
                string   userPluginDir   = FileResourcePath.GetUserPath("plugins");
                string[] userPluginFiles = Directory.GetFiles(userPluginDir);

                foreach (string file in userPluginFiles)
                {
                    if (compare.IndexOf(file, "plugin", CompareOptions.IgnoreCase) >= 0 &&
                        file.EndsWith(".dll"))
                    {
                        //Console.WriteLine("Searching File {0}", file);
                        AddPluginFile(file);
                    }
                }
            }
            catch (IOException e) {
                System.Console.WriteLine("Failed to open plugins directory: " + e.Message);
            }
        }
Пример #3
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();
    }