Пример #1
0
        public pluginner.IVEPlugin LoadFCVEPlugin(string name)
        {
            if (name.StartsWith("(internal)"))
            {            //плагин встроенный
                switch (name)
                {
                case "(internal)PlainText":
                    return(new base_plugins.ve.PlainText());

                    /* ==INTERNAL PLUGINS, THAT NEEDS TO BE CREATED==
                     * a simple raster image viewer/editor based on xwt drawing possibilities
                     * a markdown viewer based on Xwt.MarkdownView (readonly)
                     * a HEXadecimal editor (maybe integrated into PlainText as editor)
                     * a csv table viewer/editor
                     * a html viewer (based on modificated xwt's webview)
                     */
                }
            }
            else
            {            //плагин внешний
                string   file     = name;
                Assembly assembly = Assembly.LoadFile(file);

                foreach (Type type in assembly.GetTypes())
                {
                    Type iface = type.GetInterface("pluginner.IVEPlugin");

                    if (iface != null)
                    {
                        pluginner.IVEPlugin plugin = (pluginner.IVEPlugin)Activator.CreateInstance(type);
                        return(plugin);
                    }
                }
            }

            throw new PluginNotFoundException("Cannot load VE plugin " + name + " because it is somewhere else, but not in known places.");
        }
Пример #2
0
Файл: VEd.cs Проект: AVert/fcmd
        /// <summary>Load the file in the VE</summary>
        /// <param name="URL">The URL of the file</param>
        /// <param name="FS">The filesystem of the file</param>
        /// <param name="plugin">The VE plugin, which will be used to load this file</param>
        /// <param name="AllowEdit">Allow editing the file</param>
        public void LoadFile(string URL, pluginner.IFSPlugin FS, pluginner.IVEPlugin plugin, bool AllowEdit)
        {
            //check for external editor
            try{
                if (fcmd.Properties.Settings.Default.UseExternalEditor && AllowEdit || fcmd.Properties.Settings.Default.UseExternalViewer && !AllowEdit && URL.StartsWith("file:"))
                {
                    CanBeShowed = false;
                    if (AllowEdit)
                    {
                        ExecuteProgram(fcmd.Properties.Settings.Default.ExternalEditor.Replace("$", "\"" + URL));
                    }
                    else
                    {
                        ExecuteProgram(fcmd.Properties.Settings.Default.ExternalViewer.Replace("$", "\"" + URL));
                    }
                    return;
                }
            }
            catch (Exception ex) { Xwt.MessageDialog.ShowError(Locale.GetString("CantRunEXE"), ex.Message); CanBeShowed = false; return; }

            string FiNa4Title = URL.Substring(URL.LastIndexOf(FS.DirSeparator) + 1);

            IsEditor = AllowEdit;

            if (AllowEdit)
            {
                this.Title = string.Format(Locale.GetString("FCETitle"), FiNa4Title);
            }
            else
            {
                this.Title = string.Format(Locale.GetString("FCVTitle"), FiNa4Title);
            }

            FileProcessDialog ProgressDialog      = new FileProcessDialog();
            string            ProgressInitialText = String.Format(Locale.GetString("FCVELoadingMsg"), URL);

            ProgressDialog.lblStatus.Text = ProgressInitialText;
            FS.ProgressChanged           += (d) => { ProgressDialog.pbrProgress.Fraction = (d >= 0 && d <= 1) ? d : ProgressDialog.pbrProgress.Fraction; Xwt.Application.MainLoop.DispatchPendingEvents(); };
            FS.StatusChanged += (d) => { ProgressDialog.lblStatus.Text = ProgressInitialText + "\n" + d; Xwt.Application.MainLoop.DispatchPendingEvents(); };
            ProgressDialog.cmdCancel.Clicked += (o, ea) => { CanBeShowed = false; ProgressDialog.Hide(); return; };
            ProgressDialog.Show();
            Xwt.Application.MainLoop.DispatchPendingEvents();

            if (!CanBeShowed)
            {
                return;
            }

            Plugin          = plugin;
            Plugin.ReadOnly = !AllowEdit;
            Plugin.OpenFile(URL, FS);
            Plugin.ShowToolbar = fcmd.Properties.Settings.Default.VE_ShowToolbar;
            Plugin.Stylist     = s;
            mnuFormat.SubMenu  = Plugin.FormatMenu;

            bool Mode = AllowEdit;

            if (!Plugin.CanEdit && AllowEdit)
            {
                Xwt.MessageDialog.ShowWarning(String.Format(Locale.GetString("FCVEpluginro1"), Plugin.Name + " " + Plugin.Version), Locale.GetString("FCVEpluginro2"));
                Mode = false;
            }

            FSPlugin   = FS;
            PluginBody = Plugin.Body;
            SetVEMode(Mode);
            BuildLayout();
            ProgressDialog.Hide();

            PluginBody.KeyReleased += (sender, e) => {
                if (e.Key == Xwt.Key.Escape)
                {
                    CommandBox.SetFocus();
                }
                if (e.Key == Xwt.Key.q)
                {
                    this.OnCloseRequested();
                }
            };
        }
Пример #3
0
        /// <summary>Load the file in the VE</summary>
        /// <param name="URL">The URL of the file</param>
        /// <param name="FS">The filesystem of the file</param>
        /// <param name="plugin">The VE plugin, which will be used to load this file</param>
        /// <param name="AllowEdit">Allow editing the file</param>
        public void LoadFile(string URL, pluginner.IFSPlugin FS, pluginner.IVEPlugin plugin, bool AllowEdit)
        {
            //check for external editor
            try{
                if (fcmd.Properties.Settings.Default.UseExternalEditor && AllowEdit || fcmd.Properties.Settings.Default.UseExternalViewer && !AllowEdit && URL.StartsWith("file:")){
                    CanBeShowed = false;
                    if (AllowEdit){
                        ExecuteProgram(fcmd.Properties.Settings.Default.ExternalEditor.Replace("$", "\"" + URL));
                    }
                    else{
                        ExecuteProgram(fcmd.Properties.Settings.Default.ExternalViewer.Replace("$", "\"" + URL));
                    }
                    return;
                }
            }
            catch (Exception ex) { Xwt.MessageDialog.ShowError(Locale.GetString("CantRunEXE"), ex.Message); CanBeShowed = false; return; }

            string FiNa4Title = URL.Substring(URL.LastIndexOf(FS.DirSeparator) + 1);
            IsEditor = AllowEdit;

            if(AllowEdit)
                this.Title = string.Format(Locale.GetString("FCETitle"), FiNa4Title);
            else
                this.Title = string.Format(Locale.GetString("FCVTitle"), FiNa4Title);

            FileProcessDialog ProgressDialog = new FileProcessDialog();
            string ProgressInitialText = String.Format(Locale.GetString("FCVELoadingMsg"),URL);
            ProgressDialog.lblStatus.Text = ProgressInitialText;
            FS.ProgressChanged += (d) => { ProgressDialog.pbrProgress.Fraction = (d >= 0 && d <= 1) ? d : ProgressDialog.pbrProgress.Fraction; Xwt.Application.MainLoop.DispatchPendingEvents();  };
            FS.StatusChanged += (d) => { ProgressDialog.lblStatus.Text = ProgressInitialText + "\n" + d; Xwt.Application.MainLoop.DispatchPendingEvents(); };
            ProgressDialog.cmdCancel.Clicked += (o, ea) => { CanBeShowed = false; ProgressDialog.Hide(); return; };
            ProgressDialog.Show();
            Xwt.Application.MainLoop.DispatchPendingEvents();

            if (!CanBeShowed) return;

            Plugin = plugin;
            Plugin.ReadOnly = !AllowEdit;
            Plugin.OpenFile(URL, FS);
            Plugin.ShowToolbar = fcmd.Properties.Settings.Default.VE_ShowToolbar;
            Plugin.Stylist = s;
            mnuFormat.SubMenu = Plugin.FormatMenu;

            bool Mode = AllowEdit;

            if (!Plugin.CanEdit && AllowEdit)
            {
                Xwt.MessageDialog.ShowWarning(String.Format(Locale.GetString("FCVEpluginro1"), Plugin.Name + " " + Plugin.Version), Locale.GetString("FCVEpluginro2"));
                Mode = false;
            }

            FSPlugin = FS;
            PluginBody = Plugin.Body;
            SetVEMode(Mode);
            BuildLayout();
            ProgressDialog.Hide();

            PluginBody.KeyReleased += (sender, e) => {
                if(e.Key == Xwt.Key.Escape) CommandBox.SetFocus();
                if(e.Key == Xwt.Key.q) this.OnCloseRequested();
            };
        }