Exemplo n.º 1
0
        private void btnReorderDown_Click(object sender, RoutedEventArgs e)
        {
            if (lstbSelected.SelectedItem != null)
            {
                int    oldIdx     = lstbSelected.SelectedIndex;
                int    wantedIdx  = Math.Min(lstbSelected.SelectedIndex + 1, lstbSelected.Items.Count - 1);
                string oldSlotStr = lstSelectedStrsUI[wantedIdx];
                lstSelectedStrsUI[wantedIdx] = lstSelectedStrsUI[lstbSelected.SelectedIndex];
                lstSelectedStrsUI[oldIdx]    = oldSlotStr;

                //update lock saved indexes
                StudyLock movedLock   = LockController.Instance.GetLockAtIdx(GetSelectedCategory(), oldIdx);
                StudyLock swappedLock = LockController.Instance.GetLockAtIdx(GetSelectedCategory(), wantedIdx);
                if (movedLock != null)
                {
                    movedLock.DesiredIdx = wantedIdx;
                }
                if (swappedLock != null)
                {
                    swappedLock.DesiredIdx = oldIdx;
                }

                RefreshListBoxSelected();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Re-adds the selected strings to the final box
        /// </summary>
        void RefreshListBoxSelected()
        {
            List <string> selectedStrs = new List <string>();

            selectedStrs.AddRange(lstSelectedStrsUI);

            //add lock symbols to the locked strings
            List <StudyLock> newLockOrder = new List <StudyLock>();

            for (int i = 0; i < selectedStrs.Count; i++)
            {
                string    s  = selectedStrs[i];
                StudyLock lk = ContainsLockStr(LockController.Instance.GetLocks(GetSelectedCategory()), s);
                if (lk != null && lk.DesiredIdx == i)
                {
                    if (!selectedStrs[i].StartsWith("🔒"))
                    {
                        selectedStrs[i] = "🔒" + s;
                    }
                    newLockOrder.Add(new StudyLock(GetSelectedCategory(), s, i));
                }
            }

            lstbSelected.ItemsSource = selectedStrs;

            //apply new lock order
            LockController.Instance.OverwriteCategoryLocks(GetSelectedCategory(), newLockOrder);
        }
Exemplo n.º 3
0
        private void lstbSelected_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (lstbSelected.SelectedItem != null)
            {
                //dont delete locked strings
                if (ContainsLockStr(LockController.Instance.GetLocks(GetSelectedCategory()), lstSelectedStrsUI[lstbSelected.SelectedIndex]) != null)
                {
                    return;
                }
                int removedIdx = lstbSelected.SelectedIndex;
                lstSelectedStrsUI.RemoveAt(lstbSelected.SelectedIndex);

                //get all locks above the removed entry and -1 their desired indexes
                for (int i = removedIdx; i < lstSelectedStrsUI.Count; i++)
                {
                    string    s  = lstSelectedStrsUI[i];
                    StudyLock lk = ContainsLockStr(LockController.Instance.GetLocks(GetSelectedCategory()), s);
                    if (lk != null)
                    {
                        lk.DesiredIdx -= 1;
                    }
                }

                RefreshListBoxSelected();
            }
        }
Exemplo n.º 4
0
        public void RemoveLock(string category, int idx, bool save = true)
        {
            if (!categorizedLocks.ContainsKey(category))
            {
                categorizedLocks.Add(category, new List <StudyLock>());
            }
            StudyLock sl = null;

            foreach (StudyLock s in categorizedLocks[category])
            {
                if (s.DesiredIdx == idx)
                {
                    sl = s;
                    break;
                }
            }
            if (sl != null)
            {
                categorizedLocks[category].Remove(sl);
            }
            if (save)
            {
                SaveLocks();
            }
        }
Exemplo n.º 5
0
        private void selectedMenuRightClickLock_Click(object sender, RoutedEventArgs e)
        {
            string    category    = ((TabItem)tabs.SelectedItem).Header.ToString();
            string    selectedStr = lstbSelected.SelectedItem.ToString();
            StudyLock sl          = new StudyLock(category, selectedStr, lstbSelected.SelectedIndex);

            LockController.Instance.AddLock(sl);

            RefreshListBoxSelected();
        }
Exemplo n.º 6
0
 StudyLock ContainsLockStr(List <StudyLock> lks, string s)
 {
     for (int i = 0; i < lks.Count; i++)
     {
         StudyLock sl = lks[i];
         if (sl.LockStr == s)
         {
             return(sl);
         }
     }
     return(null);
 }
Exemplo n.º 7
0
 public void AddLock(StudyLock lok, bool save = true)
 {
     if (!categorizedLocks.ContainsKey(lok.Category))
     {
         categorizedLocks.Add(lok.Category, new List <StudyLock>());
     }
     categorizedLocks[lok.Category].Add(lok);
     if (save)
     {
         SaveLocks();
     }
 }
Exemplo n.º 8
0
 int LockStrIdx(List <StudyLock> lks, string s)
 {
     for (int i = 0; i < lks.Count; i++)
     {
         StudyLock sl = lks[i];
         if (sl.LockStr == s)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 9
0
 void UnpackSaved()
 {
     foreach (string s in Properties.Settings.Default.LockedStrings)
     {
         int sepPos1 = s.IndexOf(lockSep);
         if (sepPos1 > 0)
         {
             string[] lockstrs = s.Split(lockSep);
             if (lockstrs.Length >= 3)
             {
                 StudyLock sl = new StudyLock(lockstrs[0], lockstrs[1], int.Parse(lockstrs[2]));
                 AddLock(sl, false);
             }
         }
         else
         {
             //ignore the disgusting ill-formatted heathen
         }
     }
     SaveLocks();
 }