Ejemplo n.º 1
0
Archivo: VEd.cs Proyecto: AVert/fcmd
        /// <summary>Load the file in the VE (with plugin autodetection)</summary>
        /// <param name="URL">The file's URL</param>
        /// <param name="FS">The file's filesystem</param>
        /// <param name="AllowEdit">Mode of VE: true=editor, false=viewer</param>
        public void LoadFile(string URL, pluginner.IFSPlugin FS, bool AllowEdit)
        {
            byte[]       ContentBytes = FS.GetFileContent(URL);
            string       content      = (ContentBytes != null && ContentBytes.Length > 0) ? Encoding.UTF8.GetString(ContentBytes) : "";
            pluginfinder pf           = new pluginfinder();

            try
            {
                string GottenHeaders;
                if (content.Length >= 20)
                {
                    GottenHeaders = content.Substring(0, 20);
                }
                else
                {
                    GottenHeaders = content;
                }
                LoadFile(URL, FS, pf.GetFCVEplugin("NAME=" + URL + "HEADERS=" + GottenHeaders), AllowEdit);
            }
            catch (pluginfinder.PluginNotFoundException ex)
            {
                Console.WriteLine("ERROR: VE plugin is not loaded: " + ex.Message + "\n" + ex.StackTrace);
                Xwt.MessageDialog.ShowError(Locale.GetString("FCVE_PluginNotFound"));
                LoadFile(URL, FS, new base_plugins.ve.PlainText(), AllowEdit);
            }
            catch (Exception ex)
            {
                Xwt.MessageDialog.ShowError(string.Format(Locale.GetString("FCVE_LoadError"), ex.Message));
                Console.WriteLine("ERROR: VE can't load file: " + ex.Message + "\n" + ex.StackTrace);
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the file <paramref name="url"/> and returns it as string
        /// (for File Commander's CLI panel)
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string Cat(string url)
        {
            pluginner.IFSPlugin fs = ActivePanel.FS;
            if (!fs.FileExists(url))
            {
                return("Файл не найден\n");
            }

            return(Encoding.ASCII.GetString(fs.GetFileContent(url)));
        }
Ejemplo n.º 3
0
        /* ЗАМЕТКА РАЗРАБОТЧИКУ
         *
         * В данном файле размещаются подпрограммы для управления файлами, которые
         * вызываются из MainWindow.cs. Также планируется использование этих подпрограмм
         * после реализации текстовой коммандной строки FC (которая внизу окна).
         * Все комманды работают с активной и пассивой панелью - Active/PassivePanel.
         * FC всегда их определяет сам. Пассивая панель - всегда получатель файлов.
         * Названия комманд - UNIX в верблюжьем регистре (Ls, Rm, MkDir, Touch и т.п.).
         * Всем коммандам параметры передаются строкой, но допускаются исключения, напр.,
         * если базовая функция "перегружена" функцией для нужд графического интерфейса.
         * Sorry for my bad english.
         */

        /// <summary>
        /// Reads the file <paramref name="url"/> and shows in FC Viewer
        /// </summary>
        /// <param name="url"></param>
        public void FCView(string url)
        {
            VEd fcv = new VEd();

            pluginner.IFSPlugin fs = ActivePanel.FS;
            if (!fs.FileExists(url))
            {
                //MessageBox.Show(string.Format(locale.GetString("FileNotFound"), ActivePanel.list.SelectedItems[0].Text), "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Xwt.MessageDialog.ShowError(string.Format(Locale.GetString("FileNotFound"), ActivePanel.GetValue(ActivePanel.dfDisplayName)));
                return;
            }

            pluginner.File SelectedFile = fs.GetFile(url, new int());
            string         FileContent  = Encoding.ASCII.GetString(fs.GetFileContent(url));

            fcv.LoadFile(url, ActivePanel.FS, false);
            fcv.Show();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Searches for the good FS plugin to work with filesystem of the file/directory <paramref name="url"/>
        /// </summary>
        /// <param name="url">The uniform resource locator for the requested file</param>
        /// <returns>The good filesystem plugin (IFSPlugin-based class) or an exception if no plugins found</returns>
        public pluginner.IFSPlugin GetFSplugin(string url)
        {
            string[] UrlParts = url.Split("://".ToCharArray());
            foreach (string CurDescription in FSPlugins)
            {
                string[] Parts = CurDescription.Split(";".ToCharArray());
                if (System.Text.RegularExpressions.Regex.IsMatch(UrlParts[0], Parts[0]))
                {
                    //оно!
                    if (Parts[1].StartsWith("(internal)"))
                    {                    //плагин встроенный
                        switch (Parts[1])
                        {
                        case "(internal)LocalFS":
                            return(new fcmd.base_plugins.fs.localFileSystem());
                        }
                    }
                    else
                    {                    //плагин внешний
                        string   file     = Parts[1];
                        Assembly assembly = Assembly.LoadFile(file);

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

                            if (iface != null)
                            {
                                pluginner.IFSPlugin plugin = (pluginner.IFSPlugin)Activator.CreateInstance(type);
                                return(plugin);
                            }
                        }
                    }
                }
            }
            throw new PluginNotFoundException("Не найден плагин ФС для протокола " + UrlParts[0]);
        }
Ejemplo n.º 5
0
Archivo: VEd.cs Proyecto: 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();
                }
            };
        }
Ejemplo n.º 6
0
 public void LoadFile(string url, pluginner.IFSPlugin fsplugin)
 {
     URL = url; FS = fsplugin;
     Content = Encoding.UTF8.GetString(fsplugin.GetFile (url, new int()).Content);
 }
Ejemplo n.º 7
0
 public void OpenFile(string url, pluginner.IFSPlugin fsplugin)
 {
     lblFileName.Text = url;
     fileContent      = fsplugin.GetFileContent(url);
     ChangeCodepage(Codepage);
 }
Ejemplo n.º 8
0
Archivo: VEd.cs Proyecto: kekekeks/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();
            };
        }
Ejemplo n.º 9
0
        /// <summary>The entry form's keyboard keypress handler (except commandbar keypresses)</summary>
        void PanelLayout_KeyReleased(object sender, Xwt.KeyEventArgs e)
        {
#if DEBUG
            pluginner.FileListPanel p1 = (PanelLayout.Panel1.Content as pluginner.FileListPanel);
            pluginner.FileListPanel p2 = (PanelLayout.Panel2.Content as pluginner.FileListPanel);
            Console.WriteLine("KEYBOARD DEBUG: " + e.Modifiers.ToString() + "+" + e.Key.ToString() + " was pressed. Panels focuses: " + (ActivePanel == p1) + " | " + (ActivePanel == p2));
#endif
            if (e.Key == Xwt.Key.Return)
            {
                return;                                     //ENTER presses are handled by other event
            }
            string URL1;
            if (ActivePanel.ListingView.SelectedRow > -1)
            {
                URL1 = ActivePanel.GetValue(ActivePanel.dfURL);
            }
            else
            {
                URL1 = null;
            }
            pluginner.IFSPlugin FS1 = ActivePanel.FS;

            string URL2;
            if (PassivePanel.ListingView.SelectedRow > -1)
            {
                URL2 = PassivePanel.GetValue(PassivePanel.dfURL);
            }
            else
            {
                URL2 = null;
            }
            pluginner.IFSPlugin FS2 = PassivePanel.FS;

            switch (e.Key)
            {
            case Xwt.Key.NumPadAdd:                     //[+] gray - add selection
                string Filter = @"*.*";

                InputBox     ibx_qs    = new InputBox(Locale.GetString("QuickSelect"), Filter);
                Xwt.CheckBox chkRegExp = new Xwt.CheckBox(Locale.GetString("NameFilterUseRegExp"));
                ibx_qs.OtherWidgets.Add(chkRegExp, 0, 0);
                if (!ibx_qs.ShowDialog())
                {
                    return;
                }
                Filter = ibx_qs.Result;
                if (chkRegExp.State == Xwt.CheckBoxState.Off)
                {
                    Filter = Filter.Replace(".", @"\.");
                    Filter = Filter.Replace("*", ".*");
                    Filter = Filter.Replace("?", ".");
                }
                try
                {
                    System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(Filter);

                    int Count = 0;
                    foreach (pluginner.ListView2Item lvi in ActivePanel.ListingView.Items)
                    {
                        if (re.IsMatch(lvi.Data[1].ToString()))
                        {
                            ActivePanel.ListingView.Select(lvi);
                            Count++;
                        }
                    }

                    ActivePanel.StatusBar.Text = string.Format(Locale.GetString("NameFilterFound"), Filter, Count);
                }
                catch (Exception ex)
                {
                    Xwt.MessageDialog.ShowError(Locale.GetString("NameFilterError"), ex.Message);
                }
                return;

            case Xwt.Key.NumPadSubtract:                     //[-] gray - add selection
                string Filter_qus = @"*.*";

                InputBox     ibx_qus       = new InputBox(Locale.GetString("QuickUnselect"), Filter_qus);
                Xwt.CheckBox chkRegExp_qus = new Xwt.CheckBox(Locale.GetString("NameFilterUseRegExp"));
                ibx_qus.OtherWidgets.Add(chkRegExp_qus, 0, 0);
                if (!ibx_qus.ShowDialog())
                {
                    return;
                }
                Filter_qus = ibx_qus.Result;
                if (chkRegExp_qus.State == Xwt.CheckBoxState.Off)
                {
                    Filter_qus = Filter_qus.Replace(".", @"\.");
                    Filter_qus = Filter_qus.Replace("*", ".*");
                    Filter_qus = Filter_qus.Replace("?", ".");
                }
                try
                {
                    System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(Filter_qus);

                    int Count_qus = 0;
                    foreach (pluginner.ListView2Item lvi in ActivePanel.ListingView.Items)
                    {
                        if (re.IsMatch(lvi.Data[1].ToString()))
                        {
                            ActivePanel.ListingView.Unselect(lvi);
                            Count_qus++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Xwt.MessageDialog.ShowError(Locale.GetString("NameFilterError"), ex.Message);
                }
                return;

            //F KEYS
            case Xwt.Key.F3:                     //F3: View. Shift+F3: View as text.
                if (URL1 == null)
                {
                    return;
                }

                if (!FS1.FileExists(URL1))
                {
                    Xwt.MessageDialog.ShowWarning(string.Format(Locale.GetString("FileNotFound"), ActivePanel.GetValue(ActivePanel.dfDisplayName)));
                    return;
                }

                VEd V = new VEd();
                if (e.Modifiers == Xwt.ModifierKeys.None)
                {
                    V.LoadFile(URL1, FS1, false); V.Show();
                }
                else if (e.Modifiers == Xwt.ModifierKeys.Shift)
                {
                    V.LoadFile(URL1, FS1, new base_plugins.ve.PlainText(), false); V.Show();
                }
                //todo: handle Ctrl+F3 (Sort by name).
                return;

            case Xwt.Key.F4:                     //F4: Edit. Shift+F4: Edit as txt.
                if (URL1 == null)
                {
                    return;
                }

                if (!FS1.FileExists(URL1))
                {
                    Xwt.MessageDialog.ShowWarning(string.Format(Locale.GetString("FileNotFound"), ActivePanel.GetValue(ActivePanel.dfDisplayName)));
                    return;
                }

                VEd E = new VEd();
                if (e.Modifiers == Xwt.ModifierKeys.None)
                {
                    E.LoadFile(URL1, FS1, true); E.Show();
                }
                else if (e.Modifiers == Xwt.ModifierKeys.Shift)
                {
                    E.LoadFile(URL1, FS1, new base_plugins.ve.PlainText(), true); E.Show();
                }
                //todo: handle Ctrl+F4 (Sort by extension).
                return;

            case Xwt.Key.F5:                     //F5: Copy.
                if (URL1 == null)
                {
                    return;
                }
                Cp();
                //todo: handle Ctrl+F5 (Sort by timestamp).
                return;

            case Xwt.Key.F6:                     //F6: Move/Rename.
                if (URL1 == null)
                {
                    return;
                }
                Mv();
                //todo: handle Ctrl+F6 (Sort by size).
                return;

            case Xwt.Key.F7:                     //F7: New directory.
                InputBox ibx = new InputBox(Locale.GetString("NewDirURL"), ActivePanel.FS.CurrentDirectory + Locale.GetString("NewDirTemplate"));
                if (ibx.ShowDialog())
                {
                    MkDir(ibx.Result);
                }
                return;

            case Xwt.Key.F8:                     //F8: delete
                if (URL1 == null)
                {
                    return;
                }
                Rm();
                //todo: move to trash can/recycle bin & handle Shit+F8 (remove completely)
                return;

            case Xwt.Key.F10:                     //F10: Exit
                //todo: ask user, are it really want to close FC?
                Xwt.Application.Exit();
                //todo: handle Alt+F10 (directory tree)
                return;
            }
#if DEBUG
            Console.WriteLine("KEYBOARD DEBUG: the key isn't handled");
#endif
        }
Ejemplo n.º 10
0
 public void LoadFile(string url, pluginner.IFSPlugin fsplugin)
 {
     URL     = url; FS = fsplugin;
     Content = Encoding.UTF8.GetString(fsplugin.GetFile(url, new int()).Content);
 }