Example #1
0
        // --------------------------------------------------------------------------------------------------
        #region Class functions

        /// <summary>
        /// Bind Commands to an UIElement (handle CommandBindings and InputBindings)
        /// </summary>
        /// <param name="wxobj">UIElement to bind</param>
        /// <param name="cmds">Array of LimeCommand to bind</param>
        public static void Bind(UIElement wxobj, LimePropertyCollection cmds)
        {
            foreach (var prop in cmds)
            {
                if (prop != null && prop.Content is LimeCommand cmd && cmd.CommandBinding != null)
                {
                    wxobj.CommandBindings.Add(cmd.CommandBinding);
                }
            }
        }
Example #2
0
        // --------------------------------------------------------------------------------------------------
        #region Class functions

        /// <summary>
        /// Factory: load the settings to populate the Global structure
        /// </summary>
        public static void Load()
        {
            // Debug only: retrieve the Project-directory
                        #if DEBUG
            if (File.Exists("debug.cfg"))
            {
                DebugProjectDir = File.ReadAllText("debug.cfg").Trim();
            }
                        #endif


            if (Root != null)
            {
                throw new InvalidOperationException("Global.Load() can be called only once !");
            }

            // Initialize LimeLauncher data-root
            Root = LimeItem.Load(ConfigLocal.DataPath);
            if (Root == null)
            {
                Environment.Exit(10);
            }

            // Get Icon templates
            Root.Tree.DefaultDir = new LimeItem(ConfigLocal.TemplateDirPath)
            {
                Tree = Root.Tree
            };
            Root.Tree.DefaultFile = new LimeItem(ConfigLocal.TemplateFilePath)
            {
                Tree = Root.Tree
            };

            // Initialize MetaSearch
            Search = new LimeMetaSearch();

            // Initialize Persons Local Database
            LimePerson.LocalDbPath = ConfigLocal.PersonsPath;

            // Initialize the Lime Commands
            Properties           = new LimePropertyCollection(StringComparer.OrdinalIgnoreCase, typeof(Commands));
            LimeCommand.Commands = typeof(Commands);

            // Initialize LimeLauncher Settings (assume that the root is initialized properly)
            User = ConfigUser.Load();
            Properties.AddContent(User, null, false);

            Local = ConfigLocal.Load();
            Properties.AddContent(Local, null, false);

            // Initialize the Lime Config Tree
            ConfigTree = new ConfigTree();
            Properties.PropertyChanged += GlobalPropertyCollectionChanged;
        }
Example #3
0
        // -------------------------------------------
        #endregion


        // --------------------------------------------------------------------------------------------------
        #region Class functions

        private static LimePropertyCollection Factory(params string[] names)
        {
            var ret = new LimePropertyCollection(null);

            foreach (var name in names)
            {
                ret.Add(name != null ? Global.Properties[name] : null);
            }

            return(ret);
        }
Example #4
0
        protected override void OnPropertyChanged(LimeProperty prop, PropertyChangedEventArgs e)
        {
            if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Content")
            {
                LimeMsg.Debug("LimeListView OnPropertyChanged: {0} : {1} : {2}", prop, prop?.Ident, e?.PropertyName);

                int idx = 0;

                // Bellow we try to re-use the existing controls to avoid rendering overhead

                if (prop != null)
                {
                    LimePropertyCollection collec;

                    if (typeof(LimePropertyCollection).IsAssignableFrom(prop.Type))
                    {
                        collec = (LimePropertyCollection)prop.Content;
                    }
                    else
                    {
                        collec = new LimePropertyCollection(null, prop);
                    }

                    for (int i = 0; i < collec.Count; i++)
                    {
                        var         sprop  = collec[i];
                        LimeControl wxctrl = null;
                        var         type   = LimeControlSelector(sprop);
                        if (type == null)
                        {
                            continue;
                        }

                        if (idx < wxMain.Items.Count)
                        {
                            var wxitem   = (LimeControl)wxMain.Items[idx];
                            var propitem = (LimeProperty)wxitem.DataContext;
                            if (type == wxitem.GetType())
                            {
                                LimeMsg.Debug("LimeListView OnPropertyChanged: recycle {0} : {1} --> {2}", idx, propitem, sprop);
                                wxitem.DataContext = sprop;
                                wxitem.Visibility  = sprop?.Visible == true ? Visibility.Visible : Visibility.Collapsed;
                            }
                            else
                            {
                                LimeMsg.Debug("LimeListView OnPropertyChanged: replaced {0} : {1} --> {2}", idx, propitem, sprop);
                                wxMain.Items[idx] = wxctrl = (LimeControl)Activator.CreateInstance(type);
                            }
                        }
                        else
                        {
                            LimeMsg.Debug("LimeListView OnPropertyChanged: new {0} : {1}", idx, sprop);
                            wxMain.Items.Add(wxctrl = (LimeControl)Activator.CreateInstance(type));
                        }

                        if (wxctrl != null)
                        {
                            wxctrl.IsTabStop        = false;
                            wxctrl.Level            = Level > 0.11 ? Level - 0.1 : Level;
                            wxctrl.ReadOnly         = ReadOnly;
                            wxctrl.HeaderEnabled    = HeaderEnabled;
                            wxctrl.ValidateOnChange = ValidateOnChange;
                            wxctrl.DataContext      = sprop;
                        }

                        idx++;
                    }
                }

                // Hide remaining items from previous bindings
                for (; idx < wxMain.Items.Count; idx++)
                {
                    var wxitem = (LimeControl)wxMain.Items[idx];
                    wxitem.DataContext = null;
                    wxitem.Visibility  = Visibility.Collapsed;
                }
            }
        }
Example #5
0
        protected override void OnPropertyChanged(LimeProperty prop, PropertyChangedEventArgs e)
        {
            //LimeMsg.Debug("LimeListView OnPropertyChanged: {0} : {1} : {2}", prop, prop.Ident, e?.PropertyName);

            if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Content")
            {
                LimePropertyCollection collec = null;

                if (typeof(LimePropertyCollection).IsAssignableFrom(prop.Type))
                {
                    collec = (LimePropertyCollection)prop.Content;
                }
                else
                {
                    collec = new LimePropertyCollection(null, prop);
                }


                wxGridView.Columns.Clear();

                // Create column definitons from a template first row
                if (collec.Count != 0)
                {
                    var item = collec[0];

                    LimePropertyCollection items;
                    if (item.Content is LimePropertyCollection col)
                    {
                        items = col;
                    }
                    else
                    {
                        items = new LimePropertyCollection(null, item.Content, prop);
                    }

                    GridViewColumn last = null;
                    int            idx  = 0;
                    foreach (var iprop in items)
                    {
                        var path = "Content" +
                                   (iprop.Ident != null ?
                                    string.Format(".{0}", iprop.Ident) :
                                    string.Format("[{0}]", idx)
                                   );

                        // Not a recommended way to make DataTemplate in code-behind, but this word
                        // for this more-or-less static case.
                        var datatemplate = new FrameworkElementFactory(typeof(LimeControl));
                        datatemplate.SetBinding(DataContextProperty, new Binding(path));
                        datatemplate.SetValue(OptionsEnabledProperty, false);
                        datatemplate.SetValue(HeaderEnabledProperty, false);

                        // Create the colum definition
                        var gvcol = new GridViewColumn()
                        {
                            Header       = iprop.Name,
                            CellTemplate = new DataTemplate()
                            {
                                VisualTree = datatemplate
                            }
                        };

                        last = gvcol;
                        wxGridView.Columns.Add(gvcol);

                        idx++;
                    }
                }


                wxList.DataContext = collec;
            }
        }