示例#1
0
        private bool LoadFilterProfiles(bool skipSelection)
        {
            // Get profiles
            string[] profiles = TradeListViewFilterList.GetProfiles();
            // Error? (i.e. failed to create directory)
            if (profiles == null)
            {
                Close();
                return(false);
            }
            // Nothign found?
            if (profiles.Length == 0)
            {
                // Create default
                string filepath = Path.Combine(TradeListViewFilterList.ProfileFolder, "Default." + TradeListViewFilterList.Extension);
                new TradeListViewFilterList(filepath).Save();
                // Load profiles again
                profiles = TradeListViewFilterList.GetProfiles();
                // Still nothing?
                if (profiles.Length == 0)
                {
                    MessageBox.Show("Failed to load profiles!\nPlease start again with admin rights.\n\nIf the Problem still exists, please report it to GodLesZ\nThank you", "Profile loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return(false);
                }
            }

            // Add all to combo box (without extension)
            foreach (string filepath in profiles)
            {
                cmbFilterProfile.Items.Add(Path.GetFileNameWithoutExtension(filepath));
            }

            if (skipSelection == false)
            {
                // Selected a profile?
                if (string.IsNullOrEmpty(Properties.Settings.Default.SelectedProfile) == false)
                {
                    int selectedIndex = cmbFilterProfile.Items.IndexOf(Properties.Settings.Default.SelectedProfile);
                    if (selectedIndex != -1)
                    {
                        cmbFilterProfile.SelectedIndex = selectedIndex;
                    }
                    else
                    {
                        // Old selection does not exist, so delete the reference
                        Properties.Settings.Default.SelectedProfile = null;
                    }
                }

                // Select default/first profile
                if (cmbFilterProfile.SelectedIndex == -1)
                {
                    int selectedIndex = cmbFilterProfile.Items.IndexOf("Default");
                    cmbFilterProfile.SelectedIndex = (selectedIndex != -1 ? selectedIndex : 0);
                }
            }

            return(true);
        }
示例#2
0
        private void cmbFilterProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFilterProfile.SelectedIndex == -1)
            {
                btnDeleteFilterProfile.Enabled = false;
                return;
            }

            string profile  = cmbFilterProfile.Items[cmbFilterProfile.SelectedIndex].ToString();
            string filename = profile + "." + TradeListViewFilterList.Extension;
            string filepath = Path.Combine(TradeListViewFilterList.ProfileFolder, filename);

            if (File.Exists(filepath) == false)
            {
                MessageBox.Show("Failed to open profile \"" + profile + "\".\n" + filepath, "Profile load error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Remove form list
                cmbFilterProfile.Items.RemoveAt(cmbFilterProfile.SelectedIndex);
                // Nothing left?
                if (cmbFilterProfile.Items.Count == 0)
                {
                    MessageBox.Show("All profiles seems to be lost!\nThe application will try to restore default profile..", "Profile load error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Update selection & reload profiles
                    cmbFilterProfile.SelectedIndex = -1;
                    LoadFilterProfiles();
                    return;
                }

                // Selected not found but still somthing in the list => select/load it
                cmbFilterProfile.SelectedIndex = 0;
                btnDeleteFilterProfile.Enabled = false;
                return;
            }

            // Profile found, load it
            listTrades.TradeFilterList = TradeListViewFilterList.Read(filepath);
            // Apply as new filter list & trigger filter
            listFilter.SetObjects(listTrades.TradeFilterList);
            listTrades.FilterObjects();

            // Remember last selection
            Properties.Settings.Default.SelectedProfile = cmbFilterProfile.Items[cmbFilterProfile.SelectedIndex].ToString();
            btnDeleteFilterProfile.Enabled = (Path.GetFileNameWithoutExtension(Properties.Settings.Default.SelectedProfile) != "Default");
        }