/// <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))); }
/* ЗАМЕТКА РАЗРАБОТЧИКУ * * В данном файле размещаются подпрограммы для управления файлами, которые * вызываются из 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(); }
/// <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 }