/// <summary> /// Move the selected file or directory /// </summary> void Mv() { if (ActivePanel.GetValue<string>(ActivePanel.dfDisplayName) == "..") { return; } pluginner.IFSPlugin SourceFS = ActivePanel.FS; pluginner.IFSPlugin DestinationFS = PassivePanel.FS; foreach (pluginner.ListView2Item selitem in ActivePanel.ListingView.ChoosedRows) { //Getting useful URL parts string SourceName = selitem.Data[ActivePanel.dfDisplayName].ToString(); //ActivePanel.GetValue<string>(ActivePanel.dfDisplayName); string SourcePath = selitem.Data[ActivePanel.dfURL].ToString(); //ActivePanel.GetValue<string>(ActivePanel.dfURL); string DestinationPath = DestinationFS.CurrentDirectory + DestinationFS.DirSeparator + SourceName; InputBox ibx = new InputBox ( string.Format(Locale.GetString("MoveTo"), SourceName), DestinationPath ); if (ibx.ShowDialog()) DestinationPath = ibx.Result; else return; // Comparing the filesystems; if they is diffrent, use copy&delete // instead of direct move (if anyone knows, how a file can be moved // from an FTP to an ext2fs on Windows or MacOS please tell me :-) ) if (SourceFS.GetType() != DestinationFS.GetType()) { Xwt.MessageDialog.ShowError("Cannot move between diffrent filesystems!\nНе сделана поддержка перемещения между разными ФС."); Cp(); return; //todo } //Now, assuming that the src & dest fs is same and supports //cross-disk file moving if (SourcePath == DestinationPath) { string itself = Locale.GetString("CantCopySelf"); string toshow = string.Format(Locale.GetString("CantMove"), SourcePath, itself); Xwt.Application.Invoke(new Action(delegate { Xwt.MessageDialog.ShowWarning(toshow); })); //calling the msgbox in non-main threads causes some UI bugs, thus pushing this call into main thread return; } if (SourceFS.DirectoryExists(SourcePath)) {//this is a directory SourceFS.MoveDirectory(SourcePath, DestinationPath); } if (SourceFS.FileExists(SourcePath)) {//this is a file SourceFS.MoveFile(SourcePath, DestinationPath); } ActivePanel.LoadDir(); PassivePanel.LoadDir(); } }
public void Cp() { if (ActivePanel.GetValue<string>(ActivePanel.dfDisplayName) == "..") { return; } foreach (pluginner.ListView2Item selitem in ActivePanel.ListingView.ChoosedRows) { int Progress = 0; string SourceURL = selitem.Data[ActivePanel.dfURL].ToString(); pluginner.IFSPlugin SourceFS = ActivePanel.FS; pluginner.File SourceFile = SourceFS.GetFile(SourceURL, Progress); //check for file existing if (SourceFS.FileExists(SourceURL)) { InputBox ibx = new InputBox(String.Format(Locale.GetString("CopyTo"), SourceFile.Name), PassivePanel.FS.CurrentDirectory + PassivePanel.FS.DirSeparator + SourceFile.Name); if (ibx.ShowDialog(this)) { String DestinationFilePath = ibx.Result; string StatusMask = Locale.GetString("DoingCopy"); ReplaceQuestionDialog.ClickedButton dummy = ReplaceQuestionDialog.ClickedButton.Cancel; AsyncCopy AC = new AsyncCopy(); Thread CpThread = new Thread(delegate() { DoCp(ActivePanel.FS, PassivePanel.FS, SourceFile, DestinationFilePath, ref dummy, AC); }); CpThread.TrySetApartmentState(ApartmentState.STA); FileProcessDialog fpd = new FileProcessDialog(); fpd.InitialLocation = Xwt.WindowLocation.CenterParent; fpd.lblStatus.Text = String.Format(StatusMask, ActivePanel.GetValue<string>(ActivePanel.dfURL), ibx.Result, null); fpd.cmdCancel.Clicked += (object s, EventArgs e) => { CpThread.Abort(); new MsgBox(Locale.GetString("Canceled"), ActivePanel.GetValue<string>(ActivePanel.dfURL), MsgBox.MsgBoxType.Warning); }; AC.ReportMessage = Locale.GetString("CopyStatus"); AC.OnProgress += (msg, proc) => { Xwt.Application.Invoke( delegate { try { fpd.pbrProgress.Fraction = (double)((double)proc / (double)100); fpd.lblStatus.Text = String.Format(StatusMask, ActivePanel.GetValue<string>(ActivePanel.dfURL), ibx.Result, msg); } catch { } } ); }; fpd.Show(); CpThread.Start(); do { Xwt.Application.MainLoop.DispatchPendingEvents(); } while (CpThread.ThreadState == ThreadState.Running); //todo: замер и показ скорости, пауза, запрос отмены, вывод в фоновый поток (кнопка "в фоне"). fpd.Hide(); } continue; } //not a file...maybe directory? if (SourceFS.DirectoryExists(SourceURL))//а вдруг есть такой каталог? { InputBox ibxd = new InputBox(String.Format(Locale.GetString("CopyTo"), SourceFile.Name), PassivePanel.FS.CurrentDirectory + "/" + SourceFile.Name); if (ibxd.ShowDialog()) { String DestinationDirPath = ibxd.Result; //копирование каталога Thread CpDirThread = new Thread(delegate() { DoCpDir(SourceURL, DestinationDirPath, ActivePanel.FS, PassivePanel.FS); }); CpDirThread.TrySetApartmentState(ApartmentState.STA); FileProcessDialog CpDirProgressDialog = new FileProcessDialog(); CpDirProgressDialog.InitialLocation = Xwt.WindowLocation.CenterParent; CpDirProgressDialog.lblStatus.Text = String.Format(Locale.GetString("DoingCopy"), "\n" + ActivePanel.GetValue<string>(ActivePanel.dfURL) + " [" + Locale.GetString("Directory") + "]\n", ibxd.Result, null); CpDirProgressDialog.cmdCancel.Clicked += (object s, EventArgs e) => { CpDirThread.Abort(); new MsgBox(Locale.GetString("Canceled"), ActivePanel.GetValue<string>(ActivePanel.dfURL), MsgBox.MsgBoxType.Warning); }; CpDirProgressDialog.Show(); CpDirThread.Start(); do { Xwt.Application.MainLoop.DispatchPendingEvents(); } while (CpDirThread.ThreadState == ThreadState.Running); //LoadDir(PassivePanel.FSProvider.CurrentDirectory, PassivePanel); //обновление пассивной панели PassivePanel.LoadDir(); CpDirProgressDialog.Hide(); } continue; } //and, if none of those IF blocks has been entered, say that this isn't a real file nor a directory Xwt.MessageDialog.ShowWarning( Locale.GetString("FileNotFound"), ActivePanel.GetValue<string>( ActivePanel.dfURL ) ); continue; } }
/// <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 }