📄 handleusergesture.cs
字号:
namespace FTP.View
{
using System;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.Threading;
using FTP.View.DataStructures;
using FTP.Model.DataStructures;
using FTP.Controller;
internal class HandleUserGestures : System.Windows.Forms.ToolBar
{
// private PaulsFTPView parentForm;
private PaulsFTPController ftpController;
private ModelViewState ftpViewState;
private PaulsFTPView parentForm;
public HandleUserGestures(PaulsFTPView pParentForm, PaulsFTPController pFtpController ,ref ModelViewState pFtpViewState)
{
this.ftpController = pFtpController;
this.ftpViewState = pFtpViewState;
this.parentForm = pParentForm;
}
internal void handleUserGesture(string pGesture)
{
// Ensure the ViewState property matches any user changes
this.ftpViewState = parentForm.ftpModelViewState; // xyzzy - why is it
parentForm.PullStateFromPanels();
UserGesture userGesture = new UserGesture();
switch (pGesture)
{
case "CONNECT":
userGesture.command = "CONNECT";
ftpController.processUserGesture(userGesture);
break;
case "DICONNECT":
break;
case "EXIT":
Application.Exit();
break;
// View Menu
// File Menu
case "DOWNLOADTO":
// Check we have a selected file
if (this.ftpViewState.selectedServerFiles.Length==0)
break;
// Get the selected filename
string[] selectedFiles = ftpViewState.getFileNamesFromIntegerArray(ftpViewState.selectedServerFiles);
this.ftpViewState.serverFile = selectedFiles[0];
// Ask user where they wish to download to
SaveFileDialog getFilenameDialog = new SaveFileDialog();
getFilenameDialog.RestoreDirectory = true ;
getFilenameDialog.FileName = this.ftpViewState.serverFile;
if(getFilenameDialog.ShowDialog() == DialogResult.OK)
{
this.ftpViewState.clientFile = getFilenameDialog.FileName;
this.Text = getFilenameDialog.FileName;
userGesture.command = "DOWNLOAD";
ftpController.processUserGesture(userGesture);
}
break;
case "UPLOADFROM":
// Let the user select a file to upload
// Ask user where they wish to download to
OpenFileDialog openFilenameDialog = new OpenFileDialog();
openFilenameDialog.RestoreDirectory = true ;
if(openFilenameDialog.ShowDialog() == DialogResult.OK)
{
this.ftpViewState.clientFile = openFilenameDialog.FileName;
this.ftpViewState.serverFile = openFilenameDialog.FileName;
this.ftpViewState.serverFile = this.ftpViewState.serverFile.Substring(this.ftpViewState.serverFile.LastIndexOf("\\") + 1);
userGesture.command = "UPLOADFROM";
ftpController.processUserGesture(userGesture);
}
break;
case "CHANGEDIRECTORY":
userGesture.command = "CWD";
ftpController.processUserGesture(userGesture);
break;
case "CREATEDIRECTORY":
userGesture.command = "MKD";
this.ftpViewState.newServerDirectory = "New Folder";
ftpController.processUserGesture(userGesture);
break;
case "REMOVEDIRECTORY":
userGesture.command = "RMD";
this.ftpViewState.deleteServerDirectory = "NEW_DIR";
ftpController.processUserGesture(userGesture);
break;
case "DELETE":
userGesture.command = "DELE";
selectedFiles = ftpViewState.getFileNamesFromIntegerArray(ftpViewState.selectedServerFiles);
this.ftpViewState.deleteServerFile = selectedFiles[0];
ftpController.processUserGesture(userGesture);
break;
case "REFRESH":
userGesture.command = "REFRESH";
ftpController.processUserGesture(userGesture);
break;
} // end of switch
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -