예제 #1
0
        protected void OnBtnDeleteClicked(object sender, EventArgs e)
        {
            WindowState = WindowStateBehavior.Delete;

            TreeIter treeitr;
            var model = (Gtk.ListStore)comboPortfolios.Model;

            // Remove from the model and the combobox will update accordingly...
            if (comboPortfolios.GetActiveIter(out treeitr))
            {
                //Remove portfolio name from combobox
                model.Remove(ref treeitr);

                // Now we remove from our book collection
                // which will take care of our main window's menu
                if (book.Contains(CurrentPortfolio))
                    book.Remove(CurrentPortfolio);

                // If we still have portfolios in the book / combobox
                // lets select the first one in the list.
                if (book.Any())
                    comboPortfolios.Active = 0;
                else
                    CurrentPortfolio = null;

                book.IsDirty = true;
            }
            else
            {
                var dlg = 
                    new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, 
                        string.Format("An error occurred while deleting the Portfolio [{0}].", CurrentPortfolio.Name));
                dlg.Run();
                dlg.Destroy();
            }

            WindowState = WindowStateBehavior.Default;
        }
예제 #2
0
        protected void OnBtnRenameClicked(object sender, EventArgs e)
        {
            TreeIter itr;
            if (WindowState == WindowStateBehavior.Rename && comboPortfolios.GetActiveIter(out itr))
            {            
                // Update the name on the portfolio object
                CurrentPortfolio.Name = txtPortfolioName.Text.Trim().ToUpperInvariant();

                // Update the name on the combobox item
                var model = (Gtk.ListStore)comboPortfolios.Model;
                model.SetValue(itr, 0, CurrentPortfolio.Name);

                // Optionally set the combobox item to renamed portfolio
                comboPortfolios.SetActiveIter(itr);

                book.IsDirty = true;

                // Return the dialog back to normal state
                WindowState = WindowStateBehavior.Default;
                return;
            }
            else if (WindowState == WindowStateBehavior.Rename)
            {
                var dlg = 
                    new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, 
                        string.Format("An error occurred while renaming the Portfolio [{0}].", CurrentPortfolio.Name));
                dlg.Run();
                dlg.Destroy();
            }

            WindowState = WindowStateBehavior.Rename;
        }
예제 #3
0
        void WindowStateChanged(WindowStateBehavior winstate)
        {
            switch (winstate)
            {
                case WindowStateBehavior.Add:
                    {
                        listSymbols.Sensitive = true;
                        buttonOk.Sensitive = false;
                        btnNew.Sensitive = false;
                        btnDelete.Sensitive = false;
                        btnRename.Sensitive = false;
                        comboPortfolios.Hide();
                        txtPortfolioName.ShowAll();                         
                        listSymbols.AddButtonClicked += this.AddNewPortfolioComplete;
                        txtPortfolioName.TooltipText = "Add one or more symbols to save";
                    }
                    break;

                case WindowStateBehavior.Rename:
                    {
                        listSymbols.Sensitive = true;
                        buttonOk.Sensitive = false;
                        btnNew.Sensitive = false;
                        btnDelete.Sensitive = false;
                        btnRename.Sensitive = true;

                        comboPortfolios.Hide();
                        txtPortfolioName.Text = CurrentPortfolio.Name;
                        txtPortfolioName.Visible = true;

                        btnRename.Image = txtPortfolioName.Visible ? lockedIcon : unlockedIcon;
                        btnRename.TooltipText = "Press again to to save name";
                        btnRename.Relief = ReliefStyle.Normal;
                        btnRename.Show();
                    }
                    break;

                case WindowStateBehavior.Delete:
                    {
                        this.btnNew.Sensitive = false;
                        this.btnDelete.Sensitive = false;
                        this.btnRename.Sensitive = false;                       
                    }
                    break;

                default:
                    {
                        listSymbols.Sensitive = book.Any();
                        this.buttonOk.Sensitive = true;
                        this.btnNew.Sensitive = book.Count < 20;
                        this.btnDelete.Sensitive = book.Any();
                        this.btnRename.Sensitive = book.Any();
                        this.comboPortfolios.ShowAll();
                        this.txtPortfolioName.Visible = false;
                        txtPortfolioName.TooltipText = string.Empty;
                        txtPortfolioName.Text = comboPortfolios.ActiveText;
                        btnRename.Image = txtPortfolioName.Visible ? lockedIcon : unlockedIcon;
                        btnRename.TooltipText = "Rename portfolio";
                        btnRename.Relief = ReliefStyle.None;
                        btnRename.Show();
                    }
                    break;
            }

        }