public static RequestReply Request(RequestType type, string title, string message, List<string> choices, string default_choice) { RequestReply request = new RequestReply(); if(type== RequestType.Choice&&choices==null) throw new MException("NeedInfo Error","A choice was requested, but no options provided",true); RequestEventArgs e = new RequestEventArgs(type,title,message,choices,default_choice,request); ICommunicationReceiver receiver = getReceiver(); if(receiver==null) { request.cancelled =true; return request; } if(receiver.context!=null) { receiver.context.Post(new SendOrPostCallback(delegate(object state) { RequestEventHandler handler = receiver.requestInformation; if(handler!=null) { handler(e); } }),null); } else { receiver.requestInformation(e); } waitForResponse(e); if(e.response== ResponseType.Cancel||e.response== ResponseType.No) e.result.cancelled = true; return e.result; }
public void requestInformation(RequestEventArgs e) { }
public void requestInformation(RequestEventArgs e) { switch(e.info_type) { case RequestType.Question: if(askQuestion(e.title,e.message)) { e.result.selected_option = "Yes"; e.result.selected_index = 1; e.response = ResponseType.OK; } else { e.response = ResponseType.Cancel; } return; case RequestType.Choice: ChoiceWindow choice = new ChoiceWindow(e.title,e.message,e.options,e.default_option, this); if((bool)choice.ShowDialog()) { choice.Close(); e.result.selected_index = choice.selected_index; e.result.selected_option = choice.selected_item; e.response = ResponseType.OK; } else { e.response = ResponseType.Cancel; } return; case RequestType.BackupFolder: if(changeBackupPath()) { e.result.cancelled = false; e.response = ResponseType.OK; } else { e.result.cancelled = true; e.response = ResponseType.Cancel; } return; case RequestType.SyncFolder: if(changeSyncPath()) { e.result.cancelled = false; e.response = ResponseType.OK; } else { e.result.cancelled = true; e.response = ResponseType.Cancel; } return; default: throw new NotImplementedException("The specified request type " + e.info_type.ToString() + " is not supported in this GUI toolkit."); } }