示例#1
0
Keymap::Keymap(Type i_type,
	       const tstringi &i_name,
	       const tstringi &i_windowClass,
	       const tstringi &i_windowTitle,
	       KeySeq *i_defaultKeySeq,
	       Keymap *i_parentKeymap)
  : m_type(i_type),
    m_name(i_name),
    m_defaultKeySeq(i_defaultKeySeq),
    m_parentKeymap(i_parentKeymap),
    m_windowClass(_T(".*")),
    m_windowTitle(_T(".*"))
{
  if (i_type == Type_windowAnd || i_type == Type_windowOr)
    try
    {
      tregex::flag_type f = (tregex::normal
			     | tregex::icase
// 			     | tregex::use_except
							 );
      if (!i_windowClass.empty())
	m_windowClass.assign(i_windowClass, f);
      if (!i_windowTitle.empty())
	m_windowTitle.assign(i_windowTitle, f);
    }
    catch (boost::bad_expression &i_e)
    {
      throw ErrorMessage() << i_e.what();
    }
}
示例#2
0
文件: setting.cpp 项目: byplayer/yamy
// get filename
bool SettingLoader::getFilename(const tstringi &i_name, tstringi *o_path,
								int i_debugLevel) const
{
	// the default filename is ".mayu"
	const tstringi &name = i_name.empty() ? tstringi(_T(".mayu")) : i_name;

	bool isFirstTime = true;

	while (true) {
		// find file from registry
		if (i_name.empty()) {			// called not from 'include'
			Setting::Symbols symbols;
			if (getFilenameFromRegistry(NULL, o_path, &symbols)) {
				if (o_path->empty())
					// find file from home directory
				{
					HomeDirectories pathes;
					getHomeDirectories(&pathes);
					for (HomeDirectories::iterator
							i = pathes.begin(); i != pathes.end(); ++ i) {
						*o_path = *i + _T("\\") + name;
						if (isReadable(*o_path, i_debugLevel))
							goto add_symbols;
					}
					return false;
				} else {
					if (!isReadable(*o_path, i_debugLevel))
						return false;
				}
add_symbols:
				for (Setting::Symbols::iterator
						i = symbols.begin(); i != symbols.end(); ++ i)
					m_setting->m_symbols.insert(*i);
				return true;
			}
		}

		if (!isFirstTime)
			return false;

		// find file from home directory
		HomeDirectories pathes;
		getHomeDirectories(&pathes);
		for (HomeDirectories::iterator i = pathes.begin(); i != pathes.end(); ++ i) {
			*o_path = *i + _T("\\") + name;
			if (isReadable(*o_path, i_debugLevel))
				return true;
		}

		if (!i_name.empty())
			return false;				// called by 'include'

		if (!DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG_setting),
					   NULL, dlgSetting_dlgProc))
			return false;
	}
}
示例#3
0
文件: setting.cpp 项目: byplayer/yamy
/* load m_setting
   If called by "include", 'filename' describes filename.
   Otherwise the 'filename' is empty.
 */
bool SettingLoader::load(Setting *i_setting, const tstringi &i_filename)
{
	m_setting = i_setting;
	m_isThereAnyError = false;

	tstringi path;
	if (!getFilename(i_filename, &path)) {
		if (i_filename.empty()) {
			Acquire a(m_soLog);
			getFilename(i_filename, &path, 0);	// show filenames
			return false;
		} else
			throw ErrorMessage() << _T("`") << i_filename
			<< _T("': no such file or other error.");
	}

	// create global keymap's default keySeq
	ActionFunction af(createFunctionData(_T("OtherWindowClass")));
	KeySeq *globalDefault = m_setting->m_keySeqs.add(KeySeq(_T("")).add(af));

	// add default keymap
	m_currentKeymap = m_setting->m_keymaps.add(
						  Keymap(Keymap::Type_windowOr, _T("Global"), _T(""), _T(""),
								 globalDefault, NULL));

	/*
	// add keyboard layout name
	if (filename.empty())
	{
	  char keyboardLayoutName[KL_NAMELENGTH];
	  if (GetKeyboardLayoutName(keyboardLayoutName))
	  {
	    tstringi kl = tstringi(_T("KeyboardLayout/")) + keyboardLayoutName;
	    m_setting->symbols.insert(kl);
	    Acquire a(m_soLog);
	    *m_log << _T("KeyboardLayout: ") << kl << std::endl;
	  }
	}
	*/

	// load
	load(path);

	// finalize
	if (i_filename.empty())
		m_setting->m_keymaps.adjustModifier(m_setting->m_keyboard);

	return !m_isThereAnyError;
}
示例#4
0
文件: setting.cpp 项目: byplayer/yamy
// is the filename readable ?
bool SettingLoader::isReadable(const tstringi &i_filename,
							   int i_debugLevel) const
{
	if (i_filename.empty())
		return false;
#ifdef UNICODE
	tifstream ist(to_string(i_filename).c_str());
#else
	tifstream ist(i_filename.c_str());
#endif
	if (ist.good()) {
		if (m_log && m_soLog) {
			Acquire a(m_soLog, 0);
			*m_log << _T("  loading: ") << i_filename << std::endl;
		}
		return true;
	} else {
		if (m_log && m_soLog) {
			Acquire a(m_soLog, i_debugLevel);
			*m_log << _T("not found: ") << i_filename << std::endl;
		}
		return false;
	}
}