/// <summary>
        /// 每当搜索项中的词典的勾选状态发生改变,则写入到数据库中。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewSearchManage_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            string dictName = e.Item.Text;

            List <DictInfo> checkChangedList = DictsInfoList.Where(i => i.DictName == dictName).ToList();
            DictInfo        checkChangedDict = checkChangedList[0];
            int             index            = DictsInfoList.IndexOf(checkChangedDict);
            bool            checkStateInArr  = CheckedStateArr[index] == 1 ? true : false;

            if (e.Item.Checked == checkStateInArr)//没有变化,是又进入了TabControl或进行了TabPage切换
            {
                return;
            }

            DictOps dictOp = e.Item.Checked ? DictOps.DictChecked : DictOps.DictUnchecked;

            SetupDictsInfo(checkChangedList, dictOp, FormMain.sqliteInstance);
        }
        /// <summary>
        /// 设置_Dicts_Info的信息,每当有词典的导入、卸载、向上、向下时,都要设置
        /// </summary>
        /// <param name="tableNames"></param>
        /// <param name="dictOop"></param>
        public static int SetupDictsInfo(List <DictInfo> toOpDictInfos, DictOps dictOp, SqliteSingleton sqliteInstance)
        {
            if (toOpDictInfos.Count == 0)
            {
                return(0);
            }
            int resultCount = 1;

            switch (dictOp)
            {
            case DictOps.AddDict:
                DictInfo toAddDictInfo = toOpDictInfos[0];
                toAddDictInfo.Priority = dictinfoList.Count + 1;    //其他信息已经设置
                dictinfoList.Add(toAddDictInfo);
                break;

            case DictOps.RemoveDicts:
                foreach (DictInfo di in toOpDictInfos)     //其实只允许选中一个
                {
                    dictinfoList.Remove(di);
                }
                for (int i = 0; i < dictinfoList.Count; i++)
                {
                    DictInfo di = dictinfoList[i];
                    di.Priority = i + 1;
                }
                resultCount = toOpDictInfos.Count;
                break;

            case DictOps.DictToHigher:    //TODO:暂时只向上移动一个

                DictInfo toHigherDictInfo = toOpDictInfos[0];
                toHigherDictInfo.Priority -= 1;
                DictInfo adjecent2Higher = GetAdjecentDictInfo(dictinfoList, toHigherDictInfo, Direction.ToHigher);
                adjecent2Higher.Priority += 1;
                Swap(dictinfoList, toHigherDictInfo, adjecent2Higher);
                break;

            case DictOps.DictToLower:    //TODO:暂时只向下移动一个
                DictInfo toLowerrDictInfo = toOpDictInfos[0];
                DictInfo adjecent2Lower   = GetAdjecentDictInfo(dictinfoList, toLowerrDictInfo, Direction.ToLower);
                toLowerrDictInfo.Priority += 1;
                adjecent2Lower.Priority   -= 1;
                Swap(dictinfoList, toLowerrDictInfo, adjecent2Lower);
                break;

            case DictOps.DictChecked:
                DictInfo checkedDictInfo = toOpDictInfos[0];
                checkedDictInfo.IsChecked = 1;
                break;

            case DictOps.DictUnchecked:
                DictInfo uncheckedDictInfo = toOpDictInfos[0];
                uncheckedDictInfo.IsChecked = 0;
                break;
            }

            DataTable dt = ConvertDictInfoList(dictinfoList);

            sqliteInstance.WriteTable2Db(dt, _Dicts_Info_Table, Sql2CreatelDictsInfo);
            return(resultCount);
        }
Exemple #3
0
        public ManagedObject(object obj)
        {
//			Console.WriteLine ("new ManagedObject created wrapping object of type {0}, handle == {1}", obj.GetType(), Handle);

            managed = obj;
            lock (cachedObjects)
                cachedObjects[obj] = new WeakReference(this);

            Type type = obj.GetType();

            bool isScriptable = type.IsDefined(typeof(ScriptableTypeAttribute), true);

            // add properties
            TypeOps typeOps = null;

            foreach (PropertyInfo pi in type.GetProperties())
            {
                if (!isScriptable && !pi.IsDefined(typeof(ScriptableMemberAttribute), true))
                {
                    continue;
                }
                RegisterScriptableProperty(pi);
                if (IsCreateable(pi.PropertyType))
                {
                    typeOps = typeOps ?? new TypeOps();
                    typeOps.RegisterCreateableType(pi.PropertyType);
                }
            }

            // add events
            foreach (EventInfo ei in type.GetEvents())
            {
                if (!isScriptable && !ei.IsDefined(typeof(ScriptableMemberAttribute), true))
                {
                    continue;
                }
                RegisterScriptableEvent(ei);
                HasEvents = true;

                // XXX toshok - do we need to RegisterCreateableTypes for parameters on the delegate?
            }

            // add functions
            foreach (MethodInfo mi in type.GetMethods())
            {
                if (!isScriptable && !mi.IsDefined(typeof(ScriptableMemberAttribute), true))
                {
                    continue;
                }
                RegisterScriptableMethod(mi);
                if (IsCreateable(mi))
                {
                    typeOps = typeOps ?? new TypeOps();
                    typeOps.RegisterCreateableTypes(mi);
                }
            }

            if (typeOps != null)
            {
                RegisterBuiltinScriptableMethod(typeof(TypeOps).GetMethod("CreateManagedObject"), "createManagedObject", typeOps);
            }

            if (HasEvents)
            {
                EventOps eventOps     = new EventOps(this);
                Type     eventOpsType = typeof(EventOps);
                RegisterBuiltinScriptableMethod(eventOpsType.GetMethod("AddEventListener"), "addEventListener", eventOps);
                RegisterBuiltinScriptableMethod(eventOpsType.GetMethod("RemoveEventListener"), "removeEventListener", eventOps);
            }

            RegisterScriptableMethod(type.GetMethod("ToString", Type.EmptyTypes), "toString");

            if (ManagedObject is IList)
            {
                if (type.GetProperty("Length") != null)
                {
                    RegisterScriptableProperty(type.GetProperty("Length"), "length");
                }
                else if (type.GetProperty("Count") != null)
                {
                    RegisterScriptableProperty(type.GetProperty("Count"), "length");
                }

                foreach (MethodInfo mi in type.GetMethods())
                {
                    switch (mi.Name)
                    {
                    case "IndexOf":
                        RegisterScriptableMethod(mi, "indexOf");
                        break;

                    case "LastIndexOf":
                        RegisterScriptableMethod(mi, "lastIndexOf");
                        break;

                    case "ToArray":
                        RegisterScriptableMethod(mi, "toArray");
                        break;
                    }
                }

                Type listType = typeof(object);
                if (type.IsArray)
                {
                    listType = type.GetElementType();
                }
                else
                {
                    foreach (Type t in type.GetInterfaces())
                    {
                        if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IList <>))
                        {
                            listType = t.GetGenericArguments()[0];
                            break;
                        }
                    }
                }

                var  listOps     = CreateListOpsInstance(listType);
                Type listOpsType = listOps.GetType();

                if (type.GetProperty("Item") != null)
                {
                    RegisterScriptableProperty(type.GetProperty("Item"), "item");
                }
                else
                {
                    RegisterScriptableProperty(listOpsType.GetProperty("Item"), "item", listOps);
                }

                RegisterScriptableMethod(listOpsType.GetMethod("Pop"), "pop", listOps);
                RegisterScriptableMethod(listOpsType.GetMethod("Push"), "push", listOps);
                RegisterScriptableMethod(listOpsType.GetMethod("Reverse"), "reverse", listOps);
                RegisterScriptableMethod(listOpsType.GetMethod("Shift"), "shift", listOps);
                RegisterScriptableMethod(listOpsType.GetMethod("Unshift"), "unshift", listOps);
                RegisterScriptableMethod(listOpsType.GetMethod("Splice"), "splice", listOps);
            }
            else if (ManagedObject is IDictionary)
            {
                DictOps dictOps     = new DictOps((IDictionary)ManagedObject);
                Type    dictOpsType = typeof(DictOps);

                RegisterScriptableProperty(dictOpsType.GetProperty("Item"), "item", dictOps);
            }
        }
Exemple #4
0
		public ManagedObject (object obj)
		{
//			Console.WriteLine ("new ManagedObject created wrapping object of type {0}, handle == {1}", obj.GetType(), Handle);

			managed = obj;

			Type type = obj.GetType ();

			bool isScriptable = type.IsDefined (typeof(ScriptableTypeAttribute), true);

			// add properties

			foreach (PropertyInfo pi in type.GetProperties ()) {
				if (!isScriptable && !pi.IsDefined (typeof(ScriptableMemberAttribute), true))
					continue;
				RegisterScriptableProperty (pi);
				if (RegisterScriptableTypes (pi))
					HasTypes = true;
			}

			// add events
			foreach (EventInfo ei in type.GetEvents ()) {
				if (!isScriptable && !ei.IsDefined (typeof(ScriptableMemberAttribute), true))
					continue;
				RegisterScriptableEvent (ei);
				HasEvents = true;

				// XXX toshok - do we need to RegisterScriptableTypes for parameters on the delegate?
			}

			// add functions
			foreach (MethodInfo mi in type.GetMethods ()) {
				if (!isScriptable && !mi.IsDefined (typeof(ScriptableMemberAttribute), true))
					continue;
				RegisterScriptableMethod (mi);
				if (RegisterScriptableTypes (mi))
					HasTypes = true;
			}

			if (HasTypes) {
				TypeOps typeOps = new TypeOps ();
				Type typeOpsType = typeof (TypeOps);
				RegisterBuiltinScriptableMethod (typeOpsType.GetMethod ("CreateManagedObject"), "createManagedObject", typeOps);
			}

			if (HasEvents) {
				EventOps eventOps = new EventOps (this);
				Type eventOpsType = typeof (EventOps);
				RegisterBuiltinScriptableMethod (eventOpsType.GetMethod ("AddEventListener"), "addEventListener", eventOps);
				RegisterBuiltinScriptableMethod (eventOpsType.GetMethod ("RemoveEventListener"), "removeEventListener", eventOps);
			}

			RegisterScriptableMethod (type.GetMethod ("ToString"), "toString");

			if (ManagedObject is IList) {
				if (type.GetProperty ("Length") != null)
					RegisterScriptableProperty (type.GetProperty ("Length"), "length");
				else if (type.GetProperty ("Count") != null)
					RegisterScriptableProperty (type.GetProperty ("Count"), "length");

				foreach (MethodInfo mi in type.GetMethods ()) {
					switch (mi.Name) {
					case "IndexOf":
						RegisterScriptableMethod (mi, "indexOf");
						break;
					case "LastIndexOf":
						RegisterScriptableMethod (mi, "lastIndexOf");
						break;
					case "ToArray":
						RegisterScriptableMethod (mi, "toArray");
						break;
					}
				}

				ListOps listOps = new ListOps ((IList)ManagedObject);
				Type listOpsType = typeof (ListOps);

				if (type.GetProperty ("Item") != null)
					RegisterScriptableProperty (type.GetProperty ("Item"), "item");
				else
					RegisterScriptableProperty (listOpsType.GetProperty ("Item"), "item", listOps);

				RegisterScriptableMethod (listOpsType.GetMethod ("Pop"), "pop", listOps);
				RegisterScriptableMethod (listOpsType.GetMethod ("Push"), "push", listOps);
				RegisterScriptableMethod (listOpsType.GetMethod ("Reverse"), "reverse", listOps);
				RegisterScriptableMethod (listOpsType.GetMethod ("Shift"), "shift", listOps);
				RegisterScriptableMethod (listOpsType.GetMethod ("Unshift"), "unshift", listOps);
				RegisterScriptableMethod (listOpsType.GetMethod ("Splice"), "splice", listOps);
			} else if (ManagedObject is IDictionary) {
				DictOps dictOps = new DictOps ((IDictionary)ManagedObject);
				Type dictOpsType = typeof (DictOps);

				RegisterScriptableProperty (dictOpsType.GetProperty ("Item"), "item", dictOps);
			}
		}