Пример #1
0
 public bool Contains(ToolbarButton item)
 {
     if (item == null)
     {
         return(false);
     }
     return(_toolbarButtons.Contains(item));
 }
Пример #2
0
 public int IndexOf(ToolbarButton item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("Item cannot be null.");
     }
     return(_toolbarButtons.IndexOf(item));
 }
Пример #3
0
        public int Add(ToolbarButton item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Item cannot be null.");
            }

            _toolbarButtons.Add(item);
            item.ToolbarParent = ToolbarParent;

            if (_isTrackingViewState)
            {
                ((IStateManager)item).TrackViewState();
                item.SetDirty();
            }

            return(_toolbarButtons.Count - 1);
        }
Пример #4
0
        public void Remove(ToolbarButton item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Item cannot be null.");
            }

            int index = IndexOf(item);

            if (index >= 0)
            {
                RemoveAt(index);
            }

            if (item.Index == ToolbarParent.LastSelectedIndex)
            {
                ToolbarParent.LastSelectedIndex = -1;
            }
        }
Пример #5
0
        public void Insert(int index, ToolbarButton item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Item cannot be null.");
            }

            _toolbarButtons.Insert(index, item);

            if (index <= ToolbarParent.LastSelectedIndex)
            {
                ToolbarParent.LastSelectedIndex++;
            }

            item.ToolbarParent = ToolbarParent;

            if (_isTrackingViewState)
            {
                ((IStateManager)item).TrackViewState();
                _saveAll = true;
            }
        }
Пример #6
0
        protected virtual bool MergeClientChange(ToolbarButton button, string property, string value)
        {
            bool changed = false;

            switch (property.ToUpper())
            {
            case "TEXT":
                if (!value.Equals(button.Text, StringComparison.CurrentCulture))
                {
                    changed = true;
                }

                button.Text = value;
                break;

            case "VISIBLE":
                bool newVisible = Convert.ToBoolean(value);

                if (!value.Equals(newVisible))
                {
                    changed = true;
                }

                button.Visible = newVisible;
                break;

            case "ENABLED":
                bool newEnabled = Convert.ToBoolean(value);

                if (!value.Equals(newEnabled))
                {
                    changed = true;
                }

                button.Enabled = newEnabled;
                break;

            case "SELECTED":
                bool newSelected = Convert.ToBoolean(value);

                if (!value.Equals(newSelected))
                {
                    changed = true;
                }

                button.Selected = newSelected;
                break;

            case "CSS":
                if (!value.Equals(button.CssClass, StringComparison.CurrentCultureIgnoreCase))
                {
                    changed = true;
                }

                button.CssClass = value;
                break;


            case "CSSENABLED":
                if (!value.Equals(button.CssClassEnabled, StringComparison.CurrentCultureIgnoreCase))
                {
                    changed = true;
                }

                button.CssClassEnabled = value;
                break;

            case "CSSDISABLED":
                if (!value.Equals(button.CssClassDisabled, StringComparison.CurrentCultureIgnoreCase))
                {
                    changed = true;
                }

                button.CssClassDisabled = value;
                break;

            case "CSSSELECTED":
                if (!value.Equals(button.CssClassSelected, StringComparison.CurrentCultureIgnoreCase))
                {
                    changed = true;
                }

                button.CssClassSelected = value;
                break;
            }
            return(changed);
        }
Пример #7
0
        /// <summary>
        /// Setups the client API.
        /// </summary>
        protected virtual void SetupClientApi()
        {
            if (EnableClientApi && Items.Count > 0)
            {
                if (!Util.IsAjaxInstalled)
                {
                    throw new ApplicationException(@"The Ajax assembly System.Web.Extensions 
                        is required by the client API but was not found.");
                }

                ScriptManager manager = Util.GetScriptManager(this.Page);

                ScriptReference sr = new ScriptReference();

                if (HttpContext.Current.IsDebuggingEnabled)
                {
                    manager.Scripts.Add(new ScriptReference("SCS.Web.UI.WebControls.Toolbar.debug.js", "SCS.Web.UI.WebControls.Toolbar"));
                }
                else
                {
                    manager.Scripts.Add(new ScriptReference("SCS.Web.UI.WebControls.Toolbar.js", "SCS.Web.UI.WebControls.Toolbar"));
                }

                StringBuilder buttonData = new StringBuilder(256);

                for (int i = 0; i < _items.Count; i++)
                {
                    ToolbarButton button = _items[i];

                    buttonData.Append("{");

                    if (!string.IsNullOrEmpty(button.ConfirmationMessage))
                    {
                        buttonData.AppendFormat(@"""confirmMessage"": ""{0}"", ", button.ConfirmationMessage);
                    }

                    if (!string.IsNullOrEmpty(button.CssClassEnabled))
                    {
                        buttonData.AppendFormat(@"""enabledCssClass"": ""{0}"", ", button.CssClassEnabled);
                    }

                    if (!string.IsNullOrEmpty(button.CssClassDisabled))
                    {
                        buttonData.AppendFormat(@"""disabledCssClass"": ""{0}"", ", button.CssClassDisabled);
                    }

                    if (!string.IsNullOrEmpty(button.CssClassSelected))
                    {
                        buttonData.AppendFormat(@"""selectedCssClass"": ""{0}"", ", button.CssClassSelected);
                    }

                    if (button.Enabled && !string.IsNullOrEmpty(button.DisabledImageUrl))
                    {
                        buttonData.AppendFormat(@"""disabledImageUrl"": ""{0}"", ", Page.ResolveClientUrl(button.DisabledImageUrl));
                    }
                    else
                    {
                        buttonData.AppendFormat(@"""imageUrl"": ""{0}"", ", Page.ResolveClientUrl(button.ImageUrl));
                    }

                    buttonData.AppendFormat(@"""enabled"": {0}", button.Enabled.ToString().ToLower());
                    buttonData.Append("}, ");
                }

                if (buttonData.Length > 0)
                {
                    buttonData.Remove(buttonData.Length - 2, 2); // remove last comma and space
                }
                string props = string.Format(_createParamsJson,
                                             BehaviorId,
                                             Enum.GetName(typeof(SelectionModeType), SelectionMode),
                                             ButtonCssClasses.CssClass,
                                             ButtonCssClasses.CssClassEnabled,
                                             ButtonCssClasses.CssClassDisabled,
                                             ButtonCssClasses.CssClassSelected,
                                             buttonData.ToString());

                string events = (string.IsNullOrEmpty(OnClientButtonClick)) ? "null" : string.Format(_eventsJson, OnClientButtonClick);

                string js =
                    @"Sys.Application.add_load({0}_Loader);

                function {0}_Loader() {{                    
                    $create(SCS.Toolbar, {1}, {3}, null, $get(""{2}""));   
                }};";

                js = string.Format(js, this.ClientID, props, this.ClientID, events);
                if (!Page.ClientScript.IsStartupScriptRegistered(this.UniqueID + "_ClientCode"))
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Toolbar), this.UniqueID + "_ClientCode", js, true);
                }
            }
        }
Пример #8
0
        object IStateManager.SaveViewState()
        {
            if (_saveAll == true)
            {
                // Save all items.
                ArrayList types  = new ArrayList(Count);
                ArrayList states = new ArrayList(Count);
                for (int i = 0; i < Count; i++)
                {
                    ToolbarButton tabItem = (ToolbarButton)_toolbarButtons[i];
                    tabItem.SetDirty();

                    //if (tabItem is ToolbarButton)
                    //{
                    types.Add('c');
                    //}
                    //else
                    //{
                    //	types.Add('r');
                    //}
                    states.Add(((IStateManager)tabItem).SaveViewState());
                }
                if (types.Count > 0)
                {
                    return(new Pair(types, states));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                // Save only the dirty items.
                ArrayList indices = new ArrayList();
                ArrayList types   = new ArrayList();
                ArrayList states  = new ArrayList();

                for (int i = 0; i < Count; i++)
                {
                    ToolbarButton tabItem = (ToolbarButton)_toolbarButtons[i];
                    object        state   = ((IStateManager)tabItem).SaveViewState();
                    if (state != null)
                    {
                        states.Add(state);
                        indices.Add(i);

                        //if (tabItem is ToolbarButton)
                        //{
                        types.Add('c');
                        //}
                        //else
                        //{
                        //	types.Add('r');
                        //}
                    }
                }

                if (indices.Count > 0)
                {
                    return(new Triplet(indices, types, states));
                }

                return(null);
            }
        }
Пример #9
0
        void IStateManager.LoadViewState(object savedState)
        {
            if (savedState == null)
            {
                return;
            }

            if (savedState is Pair)
            {
                // All items were saved.
                // Create new ToolbarButton collection using view state.
                _saveAll = true;
                Pair      p      = (Pair)savedState;
                ArrayList types  = (ArrayList)p.First;
                ArrayList states = (ArrayList)p.Second;
                int       count  = types.Count;

                _toolbarButtons = new ArrayList(count);
                for (int i = 0; i < count; i++)
                {
                    ToolbarButton tabItem = null;
                    if (((char)types[i]).Equals('c'))
                    {
                        //{
                        tabItem = new ToolbarButton();
                    }
                    //}
                    //else
                    //{

                    //}
                    Add(tabItem);
                    ((IStateManager)tabItem).LoadViewState(states[i]);
                }
            }
            else
            {
                // Load modified items.
                Triplet   t       = (Triplet)savedState;
                ArrayList indices = (ArrayList)t.First;
                ArrayList types   = (ArrayList)t.Second;
                ArrayList states  = (ArrayList)t.Third;

                for (int i = 0; i < indices.Count; i++)
                {
                    int index = (int)indices[i];
                    if (index < this.Count)
                    {
                        ((IStateManager)_toolbarButtons[index]).LoadViewState(states[i]);
                    }
                    else
                    {
                        ToolbarButton tabItem = null;
                        //if (((char)types[i]).Equals('c'))
                        //{
                        tabItem = new ToolbarButton();
                        //}
                        //else
                        //{

                        //}
                        Add(tabItem);
                        ((IStateManager)tabItem).LoadViewState(states[i]);
                    }
                }
            }
        }
Пример #10
0
 public ButtonEventArgs(CommandEventArgs e, ToolbarButton sourceButton)
     : base(e)
 {
     _sourceButton = sourceButton;
 }
Пример #11
0
 public ButtonEventArgs(string commandName, object commandArgument, ToolbarButton sourceButton)
     : base(commandName, commandArgument)
 {
     _sourceButton = sourceButton;
 }