private void AddNewFileType(ListBox control) {
     ICollection<FileTypeEntry> source = (ICollection<FileTypeEntry>)control.ItemsSource;
     FileTypeEntry item = new FileTypeEntry(this, "");
     source.Add(item);
     control.SelectedItem = item;
     control.ScrollIntoView(item);
     control.Focus();
     item.IsEditing = true;
 }
 private static void RemoveSelectedFileType(ListBox control) {
     var list = (ObservableCollection<FileTypeEntry>)control.ItemsSource;
     int idx = control.SelectedIndex;
     if(idx == -1) return;
     foreach(FileTypeEntry item in new ArrayList(control.SelectedItems)) {
         list.Remove(item);
     }
     control.Focus();
     control.SelectedIndex = Math.Min(idx, list.Count - 1);
 }
        private void ShowChanges(ListBoxItem lvItem, string hash, string author)
        {
            var sp = lvItem.Content as StackPanel;

              var dir = ProjectMonitor.GetProjectDirectory(project);
              ProcessReturn ret;
              List<string> files;
              curAuthor = author;
              if (hash == "") {
            ret = GitWrapper.Status(dir, "-uall");
            if (ret.ReturnValue != 0) throw new Exception(ret.Output);
            files = new List<string>(ret.Stdout.Split(new[] {'\0'}, StringSplitOptions.RemoveEmptyEntries));
            for (int i = 0; i < files.Count; i++) {
              files[i] = files[i].Substring(3);
            }
              } else {
            ret = GitWrapper.ListChangedFiles(dir, hash);
            if (ret.ReturnValue != 0) throw new Exception(ret.Output);
            files = new List<string>(ret.Stdout.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries));
              }

              // See what happened in each of these files.
              if (files.Count == 0) {
            diffViewer.DisplayEmpty();
            fileHistory.IsEnabled = save.IsEnabled = false;
            changesHeader.Text = "Changes";
            sp.Children.Add(new TextBlock { Text = "No files changed.", FontSize = 10, Margin = new Thickness(5, 5, 0, 0) });
              } else {
            fileHistory.IsEnabled = save.IsEnabled = true;
            sp.Children.Add(new TextBlock { Text = "Files changed:", FontSize = 10, Margin = new Thickness(5, 5, 0, 0) });
            var lb = new ListBox { HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(5, 2, 5, 0), BorderThickness = new Thickness(0) };
            lb.Style = new Style() {
              Resources = new ResourceDictionary {
            {SystemColors.HighlightBrushKey, new SolidColorBrush(Color.FromRgb(100, 100, 100))}
              }
            };
            sp.Children.Add(lb);

            updated = new List<string>();
            created = new List<string>();
            deleted = new List<string>();
            files.Sort();

            fileData = new Dictionary<string, Tuple<string, string>>();
            fullpath = new Dictionary<string, string>();
            foreach (var file in files) {
              string data1, data2;
              string winFile = Path.Combine(dir, file.Replace('/', Path.PathSeparator));
              fullpath[file] = winFile;
              if (hash == "") {
            ret = GitWrapper.ShowObject(dir, String.Format("{0}:\"{1}\"", "HEAD", file));
            data1 = ret.ReturnValue == 0 ? ret.Stdout : null;
            data2 = File.Exists(winFile) ? Util.ReadFile(winFile) : null;
              } else {
            ret = GitWrapper.ShowObject(dir, String.Format("{0}:\"{1}\"", hash + "^", file));
            data1 = ret.ReturnValue == 0 ? ret.Stdout : null;
            ret = GitWrapper.ShowObject(dir, String.Format("{0}:\"{1}\"", hash, file));
            data2 = ret.ReturnValue == 0 ? ret.Stdout : null;
              }

              fileData[file] = new Tuple<string, string>(data1, data2);
              if (data1 == null) {
            created.Add(file);
              } else if (data2 == null) {
            deleted.Add(file);
              } else {
            updated.Add(file);
              }
            }

            foreach (var file in updated) {
              var localFile = file;
              var item = new ListBoxItem {Content = file};
              item.Selected += (s, e) => DisplayDiff(localFile);
              lb.Items.Add(item);
            }

            foreach (var file in created) {
              var localFile = file;
              var item = new ListBoxItem {Content = file + " (added)"};
              item.Selected += (s, e) => DisplayDiff(localFile);
              lb.Items.Add(item);
            }

            foreach (var file in deleted) {
              var localFile = file;
              var item = new ListBoxItem {Content = file + " (deleted)"};
              item.Selected += (s, e) => DisplayDiff(localFile);
              lb.Items.Add(item);
            }

            lb.SelectedIndex = 0;
            lb.Focus();
              }
        }
Example #4
0
        private void SelectItem(ListBox listBox)
        {
            foreach (var item in listBox.Items)
            {
                if ((((KeyValuePair<string, string>)item).Key) == _textBox.Text)
                {
                    listBox.SelectedItem = item;
                    listBox.ScrollIntoView(listBox.SelectedItem);
                    listBox.Focus();

                    break;
                }
            }
        }
        //Shiftproblems to be solved
        public void showMethodsPopUP(Rect rect, TextBox txtbox, Popup popup, ListBox list,KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.LeftShift:
                case Key.RightShift:
                    isBig = true;
                    break;
                case Key.Right:
                case Key.Tab:
                case Key.Up:
                case Key.Left:
                break;
                case Key.Space:
                case Key.Enter:
                    popup.IsOpen = false;
                    know = string.Empty;
                    break;
                case Key.Down:
                    if (popup.IsOpen) list.Focus();
                    break;
                case Key.Back:
                    if(know.Length > 0)
                    know = know.Substring(0, know.Length - 1);
                    know = know.ToLower();

                    if (RearrangeList())
                        ShowPopUpInRightPlace(rect, txtbox, popup);

                    break;
                default:
                    if (isBig)
                    {
                        know += e.Key.ToString();
                        isBig = false;
                    }
                    else know += e.Key.ToString().ToLower();

                    if(RearrangeList())
                        ShowPopUpInRightPlace(rect, txtbox, popup);
                    else popup.IsOpen = false;
                    break;
            }

            if (know == string.Empty) popup.IsOpen = false;
        }