//+------------------------------------------------------------------+ //| FeaturesEditor.mqh | //| Copyright 2025, Niquel Mendoza. | //| https://www.mql5.com/es/users/nique_372 | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Niquel Mendoza." #property link "https://www.mql5.com/es/users/nique_372" #property strict #ifndef AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH #define AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include #include #include "..\\Defines.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string g_arr_feautres_editor_templates[2] = { "ict_features.fgblc", "complex_features.fgblc" }; /* [CFeaturesCodeEditor] // Aqui iria lo de BasicEditor m_buttom_compile="Compile" m_buttom_compile_tooltip="Click aqui para compilar" //--- Mensaes de error al compilar OnCompile_err_select_file="Fallo al selecionar archivos" OnCompile_err_compile="Fallo al compilar el FGBLC, revise los logs" OnCompile_err_save_file="Fallo al guardar los archivos" */ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CFeaturesCodeEditor : public CBasicCodeEditor { private: CButton m_buttom_compile; void OnCompile(); //--- int m_common_flag; // bandera common en caso el base path este en common //--- CAiLeoMulyiFeatureGen m_compiler; public: CFeaturesCodeEditor(void) : CBasicCodeEditor("CFeaturesCodeEditor") {} ~CFeaturesCodeEditor(void) {} //--- bool OnClickButtom(const long lparam); //--- bool CreateExtra(CWindow& main_window, const bool comon_flag, const CodeEditorColors& clrs); //--- void OnLenguajeChange() override final; }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CFeaturesCodeEditor::OnClickButtom(const long lparam) { if(lparam == m_buttom_compile.Id()) { OnCompile(); return true; } return CBasicCodeEditor::OnClickButtom(lparam); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CFeaturesCodeEditor::CreateExtra(CWindow& main_window, const bool comon_flag, const CodeEditorColors& clrs) { //--- m_common_flag = comon_flag ? FILE_COMMON : 0; //--- int x = m_combox_load_code.XGap() + m_combox_load_code.XSize() + 20; int y = m_buttom_save_code.YGap(); //--- const string txt = GUIBASE_COMPONENT_NAME(m_buttom_compile); //--- m_buttom_compile.YSize(clrs.btn_ysize); m_buttom_compile.Tooltip(m_language.Tooltip(txt)); ApplyButtonStyle(m_buttom_compile, clrs); if(!m_padre.CreateButton(m_buttom_compile, m_language[txt], main_window, 0, m_base_tab, m_base_tab_idx, x, y, 100)) { GUIBASE_ERROR_CREATION(m_buttom_compile); return false; } //--- return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CFeaturesCodeEditor::OnCompile(void) { //--- string file_name_out = ""; if(m_current_file_name.Length() > 4) // minimo .txt { file_name_out = m_current_file_name; } else { string arr[]; if(FileSelectDialog(m_file_select_dialog_cap, AIDATATASKRUNER_PATH_FEATURES_EDITOR, "TXT files (*.txt)|*.txt|FGBLC files (*.fgblc)|*.fgblc", ((m_common_flag & FILE_COMMON) != 0 ? FSD_COMMON_FOLDER : 0) | FSD_FILE_MUST_EXIST, arr, NULL) < 1) // el archivo debera de exisitr { MessageBox(GUIBASE_MSG("err_select_file"), GUIBASE_COMMON("error"), MB_ICONERROR | MB_OK); return; } file_name_out = arr[0]; } //--- Check const bool comon_folder = (m_common_flag & FILE_COMMON) != 0; if(!m_compiler.InitByFile(file_name_out, comon_folder)) { MessageBox(GUIBASE_MSG("err_compile"), GUIBASE_COMMON("error"), MB_ICONERROR | MB_OK); } else { //--- Deternminamos que archivo final se usa uno custom o el mismo pero con extension ?¿ const int res = MessageBox(GUIBASE_MSG("msg_desea_usar_file_curr"), GUIBASE_COMMON("info"), MB_ICONQUESTION | MB_YESNO); if(res == IDNO) // No se desea usar el archivo file curr le damos posibdad de seleccionar { string arr[]; if(FileSelectDialog(m_file_select_dialog_cap, AIDATATASKRUNER_PATH_FEATURES_EDITOR, "CSV files (*.csv)|*.csv", (comon_folder ? FSD_COMMON_FOLDER : 0), arr, NULL) < 1) // no es boliatirio que exista { MessageBox(GUIBASE_MSG("err_select_file"), GUIBASE_COMMON("error"), MB_ICONERROR | MB_OK); return; } file_name_out = arr[0]; } else { file_name_out = FileRemoveExtension(file_name_out) + ".csv"; // solo quitamos la extension y lo ponemos csv } //--- const int fh = FileOpen(file_name_out, FILE_WRITE | FILE_CSV | m_common_flag, 0); if(fh == INVALID_HANDLE) { MessageBox(GUIBASE_MSG("err_save_file"), GUIBASE_COMMON("error"), MB_ICONERROR | MB_OK); return; } FileWriteString(fh, m_compiler.Header()); FileClose(fh); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CFeaturesCodeEditor::OnLenguajeChange() { CBasicCodeEditor::OnLenguajeChange(); m_buttom_compile.LabelText(m_language[GUIBASE_COMPONENT_NAME(m_buttom_compile)]); m_buttom_compile.Tooltip(m_language.Tooltip(GUIBASE_COMPONENT_NAME(m_buttom_compile))); m_buttom_compile.Update(true); } //+------------------------------------------------------------------+ #endif // AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH