//used to update the name associated with the current favourited url
        private void modifyBtn_Click(object sender, EventArgs e)
        {
            List <string> readText = Favourites.getFaves().ToList();

            //a space character indicates the beginning of the user assigned name and the end of the url (seeing a url can't contain spaces)
            string[] result = null;
            try
            {
                result = readText[(readText.Count - 1) - favesDisplay.SelectedIndex].Split(' ');
            }
            catch (Exception noFaveToModify)
            {
                return;
            }

            string input = Microsoft.VisualBasic.Interaction.InputBox("Please enter a new name for the address " + result[0], "New name", result[1], -1, -1);

            if (input.Length < 1)
            {
                return;
            }

            string newLine = result[0] + " " + input;

            readText[(readText.Count - 1) - favesDisplay.SelectedIndex] = newLine;

            Favourites.setFavouritesFile(readText);

            favesDisplay.Items[favesDisplay.SelectedIndex] = newLine;

            //potentially delegate??? Seemed useless at time as I couldn't imagine ever adding more functionality to this event
            browse.populateFavourites();
        }
Exemplo n.º 2
0
        public void populateFavourites()
        {
            favesMenu.DropDownItems.Clear();

            // reads lines from fave file
            string[] faveText = Favourites.getFaves();


            int index = 0;

            //loops from last index as we want to display the last entered favourite first
            for (int i = faveText.Length - 1; i >= 0; i--)
            {
                //a space character indicates the beginning of the user assigned name and the end of the url (seeing a url can't contain spaces)
                string[] result = faveText[i].Split(' ');

                favesMenu.DropDownItems.Add(result[1]);
                //On tab strip item click, init tab with the url value assigned to that item
                ToolStripItem newFaveItem = favesMenu.DropDownItems[index];
                newFaveItem.Click += (a, e) => {
                    initNewTab(result[0]);
                };
                index++;
                //keeps favourites drop down list to a count of 10
                if (index > 9)
                {
                    return;
                }
            }
        }
        private void displayFaves()
        {
            // read lines from fave file
            string[] faveList = Favourites.getFaves();

            for (int i = faveList.Length - 1; i >= 0; i--)
            {
                favesDisplay.Items.Add(faveList[i]);
            }
        }
        //Potential for improvement, currently deletes by rewriting over entire favourite file
        private void deleteBtn_Click(object sender, EventArgs e)
        {
            List <string> readText = Favourites.getFaves().ToList();

            try
            {
                readText.RemoveAt((readText.Count - 1) - favesDisplay.SelectedIndex);
            }catch (Exception noFaveToDelete)
            {
                return;
            }

            Favourites.clearFavouritesFile();
            Favourites.setFavouritesFile(readText);

            favesDisplay.Items.RemoveAt(favesDisplay.SelectedIndex);

            //potentially delegate??? Seemed useless at time as I couldn't imagine ever adding more functionality to this event
            browse.populateFavourites();
        }