private void AddRecentFile(string filename)
        {
            // Search for an existing entry for that filename
            KryptonRibbonRecentDoc recentDoc = null;

            foreach (KryptonRibbonRecentDoc entry in kryptonRibbon.RibbonAppButton.AppButtonRecentDocs)
            {
                if (entry.Text.Equals(filename))
                {
                    recentDoc = entry;
                    break;
                }
            }

            // If no existing entry then create a new one
            if (recentDoc == null)
            {
                recentDoc        = new KryptonRibbonRecentDoc();
                recentDoc.Click += new EventHandler(buttonRecentFile_Clicked);
                recentDoc.Text   = filename;
            }

            // Remove entry from current list and insert at the top
            kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Remove(recentDoc);
            kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Insert(0, recentDoc);

            // Restrict list to just 9 entries
            if (kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Count > _maxRecentDocs)
            {
                for (int i = kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Count; i > _maxRecentDocs; i--)
                {
                    kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.RemoveAt(kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Count - 1);
                }
            }
        }
        private void AsyncCallback(ESGI.Entity.Interfaces.IContainer container)
        {
            KryptonRibbonRecentDoc rDoc = new KryptonRibbonRecentDoc()
            {
                Text = container.Property("c_id").Get <String>(),
                Tag  = container
            };

            rDoc.Click += new EventHandler(ClickWork);

            kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Add(rDoc);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawRibbonAppMenuRecentDec class.
        /// </summary>
        /// <param name="ribbon">Reference to owning ribbon instance.</param>
        /// <param name="provider">Provider of context menu information.</param>
        /// <param name="recentDoc">Source recent document instance.</param>
        /// <param name="maxWidth">Maximum width allowed for the item.</param>
        /// <param name="needPaintDelegate">Delegate for requesting paint updates.</param>
        /// <param name="index">Recent document index.</param>
        public ViewDrawRibbonAppMenuRecentDec(KryptonRibbon ribbon,
                                              IContextMenuProvider provider,
                                              KryptonRibbonRecentDoc recentDoc,
                                              int maxWidth,
                                              NeedPaintHandler needPaintDelegate,
                                              int index)
            : base(provider.ProviderStateNormal.ItemHighlight.Back,
                   provider.ProviderStateNormal.ItemHighlight.Border,
                   provider.ProviderStateNormal.ItemHighlight,
                   PaletteMetricPadding.ContextMenuItemHighlight,
                   VisualOrientation.Top)
        {
            _maxWidth    = maxWidth;
            Provider     = provider;
            RecentDoc    = recentDoc;
            ShortcutText = index < 10 ? @"&" + index.ToString() : @"A";

            // Use docker to organize horizontal items
            ViewLayoutDocker docker = new()
            {
                // End of line gap
                { new ViewLayoutSeparator(5), ViewDockStyle.Right }
            };

            // Add the text/extraText/Image entry
            FixedContentValue entryContent = new(recentDoc.Text, recentDoc.ExtraText, recentDoc.Image, recentDoc.ImageTransparentColor);
            RibbonRecentDocsEntryToContent entryPalette = new(ribbon.StateCommon.RibbonGeneral, ribbon.StateCommon.RibbonAppMenuDocsEntry);
            ViewDrawContent entryDraw = new(entryPalette, entryContent, VisualOrientation.Top);

            docker.Add(entryDraw, ViewDockStyle.Fill);

            // Shortcut to Content gap
            docker.Add(new ViewLayoutSeparator(5), ViewDockStyle.Left);

            // Add the shortcut column
            FixedContentValue shortcutContent = new(ShortcutText, null, null, Color.Empty);
            RibbonRecentDocsShortcutToContent shortcutPalette = new(ribbon.StateCommon.RibbonGeneral, ribbon.StateCommon.RibbonAppMenuDocsEntry);
            ViewDrawRibbonRecentShortcut      shortcutDraw    = new(shortcutPalette, shortcutContent);

            docker.Add(shortcutDraw, ViewDockStyle.Left);

            // Start of line gap
            docker.Add(new ViewLayoutSeparator(3), ViewDockStyle.Left);

            // Attach a controller so menu item can be tracked and pressed
            RecentDocController controller = new(Provider.ProviderViewManager, this, needPaintDelegate);

            MouseController  = controller;
            KeyController    = controller;
            SourceController = controller;

            Add(docker);
        }
        private void buttonRecentFile_Clicked(object sender, EventArgs e)
        {
            // Always remove the selected entry, we only put it back if we find it is valid
            KryptonRibbonRecentDoc recentDoc = (KryptonRibbonRecentDoc)sender;

            kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Remove(recentDoc);

            // Get the existing page that contains the selected filename
            KryptonPage page = GetPageForFilename(recentDoc.Text);

            if (page != null)
            {
                // Make this the top most 'recent doc' entry
                kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Insert(0, recentDoc);

                // Select the page and we are done
                KryptonWorkspaceCell cell = kryptonWorkspace.CellForPage(page);
                cell.SelectedPage           = page;
                kryptonWorkspace.ActiveCell = cell;
                return;
            }

            // If we get here then we need to try and load the document
            FileInfo fileInfo = new FileInfo(recentDoc.Text);

            if (fileInfo.Exists)
            {
                using (StreamReader reader = new StreamReader(fileInfo.FullName))
                {
                    // Make this the top most 'recent doc' entry
                    kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Insert(0, recentDoc);

                    // Add contents of the file as a new page associated with the file
                    AddNewMemo(fileInfo.Name, fileInfo.FullName, reader.ReadToEnd());
                }
            }
        }
        private void MemoEditorForm1_Load(object sender, EventArgs e)
        {
            // Try and open the saved settings for memo editor
            RegistryKey memoEditorSettings = Registry.CurrentUser.OpenSubKey(_memoEditorPath);

            if (memoEditorSettings != null)
            {
                try
                {
                    // Look for each of the maximum number of entries
                    for (int i = 1; i <= _maxRecentDocs; i++)
                    {
                        // If we managed to get an entry
                        string filename = memoEditorSettings.GetValue(i.ToString()) as string;
                        if (!string.IsNullOrEmpty(filename))
                        {
                            KryptonRibbonRecentDoc recentDoc = new KryptonRibbonRecentDoc();
                            recentDoc.Click += new EventHandler(buttonRecentFile_Clicked);
                            recentDoc.Text   = filename;

                            // Add to end of the recent docs collection
                            kryptonRibbon.RibbonAppButton.AppButtonRecentDocs.Add(recentDoc);
                        }
                    }
                }
                catch { };

                try
                {
                    // Restore the global palette selected previously
                    string globalPalette = memoEditorSettings.GetValue("GlobalPalette") as string;
                    if (!string.IsNullOrEmpty(globalPalette))
                    {
                        kryptonManager.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), globalPalette);
                    }

                    // Restore the cell mode selected previously
                    string cellMode = memoEditorSettings.GetValue("CellMode") as string;
                    if (!string.IsNullOrEmpty(cellMode))
                    {
                        _cellMode = (NavigatorMode)Enum.Parse(typeof(NavigatorMode), cellMode);
                    }
                }
                catch { };

                memoEditorSettings.Close();
            }

            // Add the three predefined memos as content
            buttonReadMe_Click(null, EventArgs.Empty);
            buttonShortcuts_Click(null, EventArgs.Empty);
            buttonPersistence_Click(null, EventArgs.Empty);

            // Organize them
            buttonGridArrange_Click(null, EventArgs.Empty);

            // Make the first cell the selected one
            kryptonWorkspace.ActiveCell = kryptonWorkspace.FirstCell();

            UpdateCellsFromGrouping();
            UpdateButtonsFromGrouping();
            UpdateButtonsFromPalette();
            UpdateApplicationTitle();
            UpdateOptions();
        }