Exemplo n.º 1
0
        public static string GetUntitledPath(string format, int limit = 0)
        {
            if (!UntitledNumbers.TryGetValue(format, out var number))
            {
                number = 0;
            }

            string path;

            do
            {
                number++;
                path = SR.GetString(format, limit);
            }while (File.Exists(path) && (limit > 0 || number <= limit));

            UntitledNumbers[format] = number;
            return(path);
        }
Exemplo n.º 2
0
        private void UpdateRecentFiles()
        {
            tsmOpenRecent.Enabled     =
                tsbOpenRecent.Enabled = RecentFiles.Count > 0;

            Clear(tsmOpenRecent.DropDownItems);
            AddItems(
                tsmOpenRecent.DropDownItems,
                tsmOpenRecent.Tag as string);

            Clear(tsbOpenRecent.DropDownItems);
            AddItems(
                tsbOpenRecent.DropDownItems,
                tsbOpenRecent.Tag as string);

            void AddItems(
                ToolStripItemCollection collection,
                string format)
            {
                for (var i = 0; i < RecentFiles.Count; i++)
                {
                    var path = RecentFiles[i];
                    var text = SR.GetString(
                        format,
                        i + 1,
                        path);

                    var tsi = new RecentFileToolStripItem
                    {
                        Text = text,
                    };

                    tsi.Click += (sender, e) =>
                    {
                        tsbOpenRecent.DropDown.Hide();
                        OnOpenRecentClick(new PathEventArgs(path));
                    };

                    tsi.Open += (sender, e) =>
                    {
                        tsbOpenRecent.DropDown.Hide();
                        OnOpenRecentClick(new PathEventArgs(path));
                    };

                    tsi.OpenAs += (sender, e) =>
                    {
                        tsbOpenRecent.DropDown.Hide();
                        OnOpenRecentAsClick(new PathEventArgs(path));
                    };

                    tsi.Remove += (sender, e) =>
                    {
                        tsbOpenRecent.DropDown.Hide();
                        OnRemoveRecentFileClick(new PathEventArgs(path));
                    };

                    collection.Insert(i, tsi);
                }
            }

            void Clear(ToolStripItemCollection collection)
            {
                for (var i = collection.Count - 2; --i >= 0;)
                {
                    collection.RemoveAt(i);
                }
            }
        }