Ejemplo n.º 1
0
        public void Get(string selection, string language, bool editable, List<TextContextItem> items)
        {
            if (selection == null && m_timeMachineDir != null)
            {
                ITextEditor editor = DoGetMainEditor();
                if (editor != null && editor.Path != null)
                {
                    if (DoCanOpen(editor.Path))
                    {
                        items.Add(new TextContextItem(0.1f));
                        items.Add(new TextContextItem("Find in Time Machine", s => {DoOpen(); return s;}, 0.11f));
                    }
                    else
                    {
                        string tmPath = editor.Path;
                        var entries = new List<Backup>();
                        bool isNew;

                        lock (m_mutex)
                        {
                            var tmIndex = m_backups.Indexer<UniqueIndexer<string, Backup>>("tm path");
                            if (tmIndex.ContainsItem(tmPath))
                            {
                                string realPath = tmIndex.GetItem(tmPath).RealPath;

                                var realIndex = m_backups.Indexer<Indexer<string, Backup>>("real path");
                                foreach (Backup backup in realIndex.GetItems(realPath))
                                {
                                    entries.Add(backup);
                                }
                            }

                            isNew = m_newFiles.Contains(editor.Path);	// if this is true we need to, or are in the middle of, finding time machine paths for this file
                        }

                        if (entries.Count > 0)
                        {
                            items.Add(new TextContextItem(0.9f));

                            entries.Sort((lhs, rhs) => rhs.WriteTime.CompareTo(lhs.WriteTime));
                            int j = entries.FindIndex(i => i.TimeMachinePath == tmPath);
                            int min = Math.Max(j - 10, 0);
                            int max = Math.Min(min + 21, entries.Count);

                            float sortOrder = 0.9f;
                            if (min > 0)
                            {
                                items.Add(new TextContextItem(Constants.Ellipsis, sortOrder));
                                sortOrder += 0.0001f;
                            }

                            for (int i = min; i < max; ++i)
                            {
                                Backup entry = entries[i];

                                TimeSpan age = DateTime.Now - entry.WriteTime;
                                string title = "Open from " + TimeMachineWindowTitle.AgeToString(age);
                                string tmP = entry.TimeMachinePath;		// need a temp or the delegate will use a value mutated by foreach

                                var item = new TextContextItem(title, s => {DoOpen(tmP); return s;}, sortOrder);
                                item.State = tmP == tmPath ? 1 : 0;
                                items.Add(item);
                                sortOrder += 0.0001f;
                            }

                            if (max < entries.Count)
                                items.Add(new TextContextItem(Constants.Ellipsis, sortOrder));
                        }
                        else if (isNew)
                        {
                            items.Add(new TextContextItem(0.9f));
                            items.Add(new TextContextItem("Finding old Files", null, 0.9f));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public Entry(TextContextItem command, int group)
     : this()
 {
     Command = command;
     Group = group;
 }