示例#1
0
std::list<const char*> C4AulScriptEngine::GetFunctionNames(C4PropList * p)
{
	std::list<const char*> functions;
	std::list<const char*> global_functions;
	auto sort_alpha = [](const char * const &a, const char * const &b) -> bool { return strcmp(a, b) < 0; };
	if (!p) p = GetPropList();
	const C4ValueArray * a = p->GetProperties();
	for (int i = 0; i < a->GetSize(); ++i)
	{
		C4String * key = (*a)[i].getStr();
		if (!key) continue;
		C4AulFunc * f = p->GetFunc(key);
		if (!f) continue;
		if (!f->GetPublic()) continue;
		if (!::ScriptEngine.GetPropList()->HasProperty(key))
			functions.push_back(key->GetCStr());
		else
			global_functions.push_back(key->GetCStr());
	}
	delete a;
	functions.sort(sort_alpha);
	if (!functions.empty() && !global_functions.empty()) functions.push_back(0); // separator
	global_functions.sort(sort_alpha);
	functions.splice(functions.end(), global_functions);
	return functions;
}
示例#2
0
void C4PropertyDlg::UpdateInputCtrl(C4Object *pObj) {
  int cnt;
#ifdef WITH_DEVELOPER_MODE

  GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(entry));
  GtkListStore *store;

  // Uncouple list store from completion so that the completion is not
  // notified for every row we are going to insert. This enhances
  // performance significantly.
  if (!completion) {
    completion = gtk_entry_completion_new();
    store = gtk_list_store_new(1, G_TYPE_STRING);

    gtk_entry_completion_set_text_column(completion, 0);
    gtk_entry_set_completion(GTK_ENTRY(entry), completion);
    g_object_unref(G_OBJECT(completion));
  } else {
    store = GTK_LIST_STORE(gtk_entry_completion_get_model(completion));
    g_object_ref(G_OBJECT(store));
    gtk_entry_completion_set_model(completion, NULL);
  }

  GtkTreeIter iter;
  gtk_list_store_clear(store);
#endif  // WITH_DEVELOPER_MODE

  // add global and standard functions
  for (C4AulFunc *pFn = Game.ScriptEngine.GetFirstFunc(); pFn;
       pFn = Game.ScriptEngine.GetNextFunc(pFn))
    if (pFn->GetPublic()) {
      SCopy(pFn->Name, OSTR);
#ifdef WITH_DEVELOPER_MODE
      gtk_list_store_append(store, &iter);
      gtk_list_store_set(store, &iter, 0, OSTR, -1);
#endif
    }
// Add object script functions
  C4AulScriptFunc *pRef;
  // Object script available
  if (pObj && pObj->Def)
    // Scan all functions
    for (cnt = 0; pRef = pObj->Def->Script.GetSFunc(cnt); cnt++)
      // Public functions only
      if (pRef->Access = AA_PUBLIC) {
        // Add function
        SCopy(pRef->Name, OSTR);
#ifdef WITH_DEVELOPER_MODE
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, 0, OSTR, -1);
#endif
      }

#if WITH_DEVELOPER_MODE
  // Reassociate list store with completion
  gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
#endif
}