Example #1
0
 //dynamically add an item to the favourites drop down menu given a Favourite
 public void addFavToMenu(Favourite f)
 {
     ContainerControl cc = new ContainerControl();
     cc.BackColor = Color.WhiteSmoke;
     ToolStripControlHost c = new ToolStripControlHost(cc);
     Button b = new Button();
     b.Parent = cc;
     initRemoveFavButton(b);
     b.Click += (s, e) => { favMenu.DropDownItems.Remove(c);favs.removeFavourite(f); };
     TextBox temp = new TextBox();
     temp.Text = f.name;
     temp.Click += (s, e) => { initNewTab(f.url); };
     temp.Parent = cc;
     temp.Left = b.Size.Width;
     temp.Left = (int)Math.Floor((float)temp.Left * 1.3f);
     initFavBox(temp);
     Button t = new Button();
     t.Text = f.url;
     t.Parent = cc;
     initMenuButton(t);
     t.Top = temp.Height>b.Height?temp.Height :b.Height;
     t.Top = (int)Math.Floor((float)t.Top * 1.1f);
     t.Left = temp.Left;
     t.Enabled = false;
     Button eb = new Button();
     eb.Parent = cc;
     eb.Left = temp.Left + temp.Size.Width;
     eb.Click += (s, e) => editButtonClick(temp, eb, f);
     initEditButton(eb);
     favMenu.DropDownItems.Add(c);
 }
Example #2
0
 //make favourite name editable and change the button to a confirm button
 private void editButtonClick(TextBox temp, Button eb, Favourite f)
 {
     temp.ReadOnly = false;
     eb.Text       = "S";
     eb.ForeColor  = Color.Green;
     eb.Click     += (s, e) => confirmEditClick(temp, eb, f);
 }
Example #3
0
 //save changes to favourite name and change the button back to the edit button
 private void confirmEditClick(TextBox temp, Button eb, Favourite f)
 {
     temp.ReadOnly = true;
     eb.Text       = "E";
     eb.ForeColor  = Color.Blue;
     favs.changeFavName(f, temp.Text);
     eb.Click += (s, e) => editButtonClick(temp, eb, f);
 }
Example #4
0
 //----------------------------------------//
 //----------Methods-----------------------//
 //----------------------------------------//
 //creates a new favourite given a url and a name and adds it to the dictionary and to file
 public void addFavourite(string url, string name)
 {
     //using a random int as the key because we are also using this as an id in the xml file
     Random rnd = new Random();
     int i;
     do {
         i = rnd.Next();
     } while (favs.ContainsKey(i));
     Favourite temp = new Favourite(url, name);
     favs.Add(i, temp);
     addFavToFile(i, temp);
 }
Example #5
0
 //remove a favourite from the lists and from file
 public void removeFavourite(Favourite f)
 {
     foreach(var fav in favs.Where(kvp => kvp.Value.Equals(f)).ToList())
     {
         favs.Remove(fav.Key);
         var favourites = from el in xmlElem.Elements("Favourite")
                         where (int)el.Element("Id") == fav.Key
                         select el;
         foreach(XElement xel in favourites)
         {
             xel.Remove();
         }
     }
     xmlElem.Save(fileName);
 }
Example #6
0
 //change a favourites name to a given name in the dictionary and in file
 public void changeFavName(Favourite f, string name)
 {
     foreach (var fav in favs.Where(kvp => kvp.Value.Equals(f)).ToList())
     {
         fav.Value.name = name;
         var favourites = from el in xmlElem.Elements("Favourite")
                          where (int)el.Element("Id") == fav.Key
                          select el;
         foreach (XElement xel in favourites)
         {
             xel.SetElementValue("Name", name);
         }
     }
     xmlElem.Save(fileName);
 }
Example #7
0
 //change a favourites name to a given name in the dictionary and in file
 public void changeFavName(Favourite f, string name)
 {
     foreach (var fav in favs.Where(kvp => kvp.Value.Equals(f)).ToList())
     {
         fav.Value.name = name;
         var favourites = from el in xmlElem.Elements("Favourite")
                          where (int)el.Element("Id") == fav.Key
                          select el;
         foreach (XElement xel in favourites)
         {
             xel.SetElementValue("Name", name);
         }
     }
     xmlElem.Save(fileName);
 }
Example #8
0
 //remove a favourite from the lists and from file
 public void removeFavourite(Favourite f)
 {
     foreach (var fav in favs.Where(kvp => kvp.Value.Equals(f)).ToList())
     {
         favs.Remove(fav.Key);
         var favourites = from el in xmlElem.Elements("Favourite")
                          where (int)el.Element("Id") == fav.Key
                          select el;
         foreach (XElement xel in favourites)
         {
             xel.Remove();
         }
     }
     xmlElem.Save(fileName);
 }
Example #9
0
        //----------------------------------------//
        //----------Methods-----------------------//
        //----------------------------------------//

        //creates a new favourite given a url and a name and adds it to the dictionary and to file
        public void addFavourite(string url, string name)
        {
            //using a random int as the key because we are also using this as an id in the xml file
            Random rnd = new Random();
            int    i;

            do
            {
                i = rnd.Next();
            } while (favs.ContainsKey(i));
            Favourite temp = new Favourite(url, name);

            favs.Add(i, temp);
            addFavToFile(i, temp);
        }
Example #10
0
        //dynamically add an item to the favourites drop down menu given a Favourite
        public void addFavToMenu(Favourite f)
        {
            ContainerControl cc = new ContainerControl();

            cc.BackColor = Color.WhiteSmoke;
            ToolStripControlHost c = new ToolStripControlHost(cc);
            Button b = new Button();

            b.Parent = cc;
            initRemoveFavButton(b);
            b.Click += (s, e) => { favMenu.DropDownItems.Remove(c); favs.removeFavourite(f); };
            TextBox temp = new TextBox();

            temp.Text   = f.name;
            temp.Click += (s, e) => { initNewTab(f.url); };
            temp.Parent = cc;
            temp.Left   = b.Size.Width;
            temp.Left   = (int)Math.Floor((float)temp.Left * 1.3f);
            initFavBox(temp);
            Button t = new Button();

            t.Text   = f.url;
            t.Parent = cc;
            initMenuButton(t);
            t.Top     = temp.Height > b.Height?temp.Height :b.Height;
            t.Top     = (int)Math.Floor((float)t.Top * 1.1f);
            t.Left    = temp.Left;
            t.Enabled = false;
            Button eb = new Button();

            eb.Parent = cc;
            eb.Left   = temp.Left + temp.Size.Width;
            eb.Click += (s, e) => editButtonClick(temp, eb, f);
            initEditButton(eb);
            favMenu.DropDownItems.Add(c);
        }
Example #11
0
 //add a favourite page to the favourites menu
 private void addFavToMenu(Favourite f)
 {
     ((GUI)this.ParentForm).addFavToMenu(f);
 }
Example #12
0
 //add a new favourite to file with a given id
 private void addFavToFile(int id, Favourite f)
 {
     xmlElem.Add(new XElement("Favourite", new XElement("Id", id), new XElement("Url", f.url), new XElement("Name", f.name)));
     xmlElem.Save(fileName);
 }
Example #13
0
 //add a new favourite to file with a given id
 private void addFavToFile(int id, Favourite f)
 {
     xmlElem.Add(new XElement("Favourite", new XElement("Id", id), new XElement("Url", f.url), new XElement("Name", f.name)));
     xmlElem.Save(fileName);
 }
Example #14
0
 //add a favourite page to the favourites menu
 private void addFavToMenu(Favourite f)
 {
     ((GUI)this.ParentForm).addFavToMenu(f);
 }
Example #15
0
 //make favourite name editable and change the button to a confirm button
 private void editButtonClick(TextBox temp, Button eb, Favourite f)
 {
     temp.ReadOnly = false;
     eb.Text = "S";
     eb.ForeColor = Color.Green;
     eb.Click += (s, e) => confirmEditClick(temp, eb, f);
 }
Example #16
0
 //save changes to favourite name and change the button back to the edit button
 private void confirmEditClick(TextBox temp, Button eb, Favourite f)
 {
     temp.ReadOnly = true;
     eb.Text = "E";
     eb.ForeColor = Color.Blue;
     favs.changeFavName(f, temp.Text);
     eb.Click += (s, e) => editButtonClick(temp, eb, f);
 }