void ConsoleTools::listTypes(bool load, bool useNames){ Writer *writer = null; try{ writer = new StreamWriter(stdout, outputEncodingIndex, bomOutput); ParserFactory pf(catalogPath); HRCParser *hrcParser = pf.getHRCParser(); fprintf(stderr, "\nloading file types...\n"); for(int idx = 0;; idx++){ FileType *type = hrcParser->enumerateFileTypes(idx); if (type == null) break; if (useNames){ writer->write(StringBuffer(type->getName())+"\n"); }else{ if (type->getGroup() != null){ writer->write(StringBuffer(type->getGroup()) + ": "); } writer->write(type->getDescription()); writer->write(DString("\n")); } if (load) type->getBaseScheme(); } delete writer; }catch(Exception &e){ delete writer; fprintf(stderr, "%s\n", e.getMessage()->getChars()); } }
void FarHrcSettings::writeProfileToRegistry() { HRCParser* hrcParser = parserFactory->getHRCParser(); FileTypeImpl* type = nullptr; SettingsControl ColorerSettings; ColorerSettings.rDeleteSubKey(0, HrcSettings); size_t hrc_subkey; hrc_subkey = ColorerSettings.rGetSubKey(0, HrcSettings); // enum all FileTypes for (int idx = 0; ; idx++) { type = static_cast<FileTypeImpl*>(hrcParser->enumerateFileTypes(idx)); if (!type) { break; } if (type->getParamCount() && type->getParamUserValueCount()) { // params>0 and user values >0 size_t type_subkey = ColorerSettings.rGetSubKey(hrc_subkey, type->getName()->getWChars()); // enum all params std::vector<SString> type_params = type->enumParams(); for (auto paramname = type_params.begin(); paramname != type_params.end(); ++paramname) { const String* v = type->getParamUserValue(*paramname); if (v != nullptr) { ColorerSettings.Set(type_subkey, paramname->getWChars(), v->getWChars()); } } } } }
void FarHrcSettings::UpdatePrototype(xercesc::DOMElement* elem, bool userValue) { const XMLCh* tagProtoAttrParamName = L"name"; const XMLCh* tagParam = L"param"; const XMLCh* tagParamAttrParamName = L"name"; const XMLCh* tagParamAttrParamValue = L"value"; const XMLCh* tagParamAttrParamDescription = L"description"; const XMLCh* typeName = elem->getAttribute(tagProtoAttrParamName); if (typeName == nullptr) { return; } HRCParser* hrcParser = parserFactory->getHRCParser(); DString typenamed = DString(typeName); FileTypeImpl* type = static_cast<FileTypeImpl*>(hrcParser->getFileType(&typenamed)); if (type == nullptr) { return; } for (xercesc::DOMNode* node = elem->getFirstChild(); node != nullptr; node = node->getNextSibling()) { if (node->getNodeType() == xercesc::DOMNode::ELEMENT_NODE) { xercesc::DOMElement* subelem = static_cast<xercesc::DOMElement*>(node); if (xercesc::XMLString::equals(subelem->getNodeName(), tagParam)) { const XMLCh* name = subelem->getAttribute(tagParamAttrParamName); const XMLCh* value = subelem->getAttribute(tagParamAttrParamValue); const XMLCh* descr = subelem->getAttribute(tagParamAttrParamDescription); if (*name == '\0' || *value == '\0') { continue; } if (type->getParamValue(DString(name)) == nullptr) { type->addParam(new SString(DString(name))); } if (descr != nullptr) { type->setParamDescription(DString(name), new SString(DString(descr))); } if (userValue) { type->setParamValue(DString(name), new SString(DString(value))); } else { delete type->getParamDefaultValue(DString(name)); type->setParamDefaultValue(DString(name), new SString(DString(value))); } } } } }
void FarHrcSettings::readProfileFromRegistry() { HRCParser* hrcParser = parserFactory->getHRCParser(); SettingsControl ColorerSettings; size_t hrc_subkey; hrc_subkey = ColorerSettings.rGetSubKey(0, HrcSettings); FarSettingsEnum fse; fse.StructSize = sizeof(FarSettingsEnum); // enum all the sections in HrcSettings if (ColorerSettings.rEnum(hrc_subkey, &fse)) { for (size_t i = 0; i < fse.Count; i++) { if (fse.Items[i].Type == FST_SUBKEY) { //check whether we have such a scheme DString named = DString(fse.Items[i].Name); FileTypeImpl* type = static_cast<FileTypeImpl*>(hrcParser->getFileType(&named)); if (type) { // enum all params in the section size_t type_subkey; type_subkey = ColorerSettings.rGetSubKey(hrc_subkey, fse.Items[i].Name); FarSettingsEnum type_fse; type_fse.StructSize = sizeof(FarSettingsEnum); if (ColorerSettings.rEnum(type_subkey, &type_fse)) { for (size_t j = 0; j < type_fse.Count; j++) { if (type_fse.Items[j].Type == FST_STRING) { DString name_fse= DString(type_fse.Items[j].Name); if (type->getParamValue(name_fse) == nullptr) { type->addParam(&name_fse); } const wchar_t* p = ColorerSettings.Get(type_subkey, type_fse.Items[j].Name, static_cast<wchar_t*>(nullptr)); if (p) { type->setParamValue(DString(type_fse.Items[j].Name), &DString(p)); } } } } } } } } }
void FarHrcSettings::UpdatePrototype(Element *elem, bool userValue) { const String *typeName = elem->getAttribute(DString("name")); if (typeName == null){ return; } HRCParser *hrcParser = parserFactory->getHRCParser(); FileTypeImpl *type = (FileTypeImpl *)hrcParser->getFileType(typeName); if (type== null){ return; }; for(Node *content = elem->getFirstChild(); content != null; content = content->getNextSibling()){ if (*content->getNodeName() == "param"){ const String *name = ((Element*)content)->getAttribute(DString("name")); const String *value = ((Element*)content)->getAttribute(DString("value")); const String *descr = ((Element*)content)->getAttribute(DString("description")); if (name == null || value == null){ continue; }; if (type->getParamValue(SString(name))==null){ type->addParam(name); } if (descr != null){ type->setParamDescription(SString(name), descr); } if (userValue){ delete type->getParamNotDefaultValue(DString(name)); type->setParamValue(SString(name), value); } else{ delete type->getParamDefaultValue(DString(name)); type->setParamDefaultValue(SString(name), value); } }; }; }
void FarHrcSettings::writeProfileToRegistry() { HRCParser *hrcParser = parserFactory->getHRCParser(); FileTypeImpl *type = NULL; SettingsControl ColorerSettings; ColorerSettings.rDeleteSubKey(0,HrcSettings); size_t hrc_subkey; hrc_subkey = ColorerSettings.rGetSubKey(0,HrcSettings); // enum all FileTypes for (int idx = 0; ; idx++){ type =(FileTypeImpl *) hrcParser->enumerateFileTypes(idx); if (!type){ break; } const String *p, *v; if (type->getParamCount() && type->getParamNotDefaultValueCount()){// params>0 and user values >0 size_t type_subkey = ColorerSettings.rGetSubKey(hrc_subkey,type->getName()->getWChars()); // enum all params for (int i=0;;i++){ p=type->enumerateParameters(i); if (!p){ break; } v=type->getParamNotDefaultValue(*p); if (v!=NULL){ ColorerSettings.Set(type_subkey,p->getWChars(),v->getWChars()); } } } } }
void FarEditor::reloadTypeSettings() { FileType *ftype = baseEditor->getFileType(); HRCParser *hrcParser = parserFactory->getHRCParser(); DString ds("default") ; FileType *def = hrcParser->getFileType(&ds); if (def == nullptr){ throw Exception(DString("No 'default' file type found")); } int backparse = def->getParamValueInt(DBackparse, 2000); maxLineLength = def->getParamValueInt(DMaxLen, 0); newfore = def->getParamValueInt(DDefFore, -1); newback = def->getParamValueInt(DDefBack, -1); const String *value; value = def->getParamValue(DFullback); if (value != nullptr && value->equals(&DNo)){ fullBackground = false; } value = def->getParamValue(DShowCross); if (drawCross==2 && value != nullptr){ if (value->equals(&DNone)){ showHorizontalCross = false; showVerticalCross = false; }; if (value->equals(&DVertical)){ showHorizontalCross = false; showVerticalCross = true; }; if (value->equals(&DHorizontal)){ showHorizontalCross = true; showVerticalCross = false; }; if (value->equals(&DBoth)){ showHorizontalCross = true; showVerticalCross = true; }; } value = def->getParamValue(DCrossZorder); if (value != nullptr && value->equals(&DTop)){ crossZOrder = 1; } // installs custom file properties backparse = ftype->getParamValueInt(DBackparse, backparse); maxLineLength = ftype->getParamValueInt(DMaxLen, maxLineLength); newfore = ftype->getParamValueInt(DDefFore, newfore); newback = ftype->getParamValueInt(DDefBack, newback); value = ftype->getParamValue(DFullback); if (value != nullptr && value->equals(&DNo)){ fullBackground = false; } value = ftype->getParamValue(DShowCross); if (drawCross==2 && value != nullptr){ if (value->equals(&DNone)){ showHorizontalCross = false; showVerticalCross = false; }; if (value->equals(&DVertical)){ showHorizontalCross = false; showVerticalCross = true; }; if (value->equals(&DHorizontal)){ showHorizontalCross = true; showVerticalCross = false; }; if (value->equals(&DBoth)){ showHorizontalCross = true; showVerticalCross = true; }; } value = ftype->getParamValue(DCrossZorder); if (value != nullptr && value->equals(&DTop)){ crossZOrder = 1; } baseEditor->setBackParse(backparse); }
void FarEditor::reloadTypeSettings() { FileType *ftype = baseEditor->getFileType(); HRCParser *hrcParser = parserFactory->getHRCParser(); FileType *def = hrcParser->getFileType(&DString("default")); if (def == null){ throw Exception(DString("No 'default' file type found")); } int backparse = 2000; UnicodeTools::getNumber(def->getParamValue(DString("backparse")), &backparse); UnicodeTools::getNumber(def->getParamValue(DString("maxlinelength")), &maxLineLength); UnicodeTools::getNumber(def->getParamValue(DString("default-fore")), &newfore); UnicodeTools::getNumber(def->getParamValue(DString("default-back")), &newback); const String *value; value = def->getParamValue(DString("fullback")); if (value != null && value->equals("no")) fullBackground = false; value = def->getParamValue(DString("show-cross")); if (value != null && value->equals("none")){ showHorizontalCross = false; showVerticalCross = false; }; if (value != null && value->equals("vertical")){ showHorizontalCross = false; showVerticalCross = true; }; if (value != null && value->equals("horizontal")){ showHorizontalCross = true; showVerticalCross = false; }; if (value != null && value->equals("both")){ showHorizontalCross = true; showVerticalCross = true; }; value = def->getParamValue(DString("cross-zorder")); if (value != null && value->equals("top")) crossZOrder = 1; // installs custom file properties UnicodeTools::getNumber(ftype->getParamValue(DString("backparse")), &backparse); UnicodeTools::getNumber(ftype->getParamValue(DString("maxlinelength")), &maxLineLength); UnicodeTools::getNumber(ftype->getParamValue(DString("default-fore")), &newfore); UnicodeTools::getNumber(ftype->getParamValue(DString("default-back")), &newback); value = ftype->getParamValue(DString("fullback")); if (value != null && value->equals("no")) fullBackground = false; value = ftype->getParamValue(DString("show-cross")); if (value != null && value->equals("none")){ showHorizontalCross = false; showVerticalCross = false; }; if (value != null && value->equals("vertical")){ showHorizontalCross = false; showVerticalCross = true; }; if (value != null && value->equals("horizontal")){ showHorizontalCross = true; showVerticalCross = false; }; if (value != null && value->equals("both")){ showHorizontalCross = true; showVerticalCross = true; }; value = ftype->getParamValue(DString("cross-zorder")); if (value != null && value->equals("top")) crossZOrder = 1; baseEditor->setBackParse(backparse); }