From 7da840ac9d19e67e113b044c05fb67358aaa4e36 Mon Sep 17 00:00:00 2001 From: Julien Caillon Date: Wed, 15 Feb 2017 19:59:15 +0100 Subject: [PATCH] fixes #73 --- 3PA/MainFeatures/AppliMenu.cs | 20 ++++++---- 3PA/MainFeatures/Config.cs | 9 ++--- 3PA/MainFeatures/FileExplorer/FileExplorer.cs | 14 ++++--- .../FileExplorer/FileExplorerForm.cs | 20 ++++------ 3PA/MainFeatures/FileExplorer/FileListItem.cs | 4 ++ YamuiFramework/Controls/YamuiList/ListItem.cs | 17 +------- .../Controls/YamuiList/YamuiFilteredList.cs | 8 ++-- .../YamuiList/YamuiFilteredTypeList.cs | 8 ++-- .../YamuiList/YamuiFilteredTypeTreeList.cs | 6 ++- .../Controls/YamuiList/YamuiScrollList.cs | 25 +++++++----- YamuiFramework/Controls/YamuiPictureBox.cs | 18 +++++---- YamuiFramework/Forms/YamuiMenu.cs | 40 +++++++++++++------ 12 files changed, 106 insertions(+), 83 deletions(-) diff --git a/3PA/MainFeatures/AppliMenu.cs b/3PA/MainFeatures/AppliMenu.cs index 4a67b025..5f657dc7 100644 --- a/3PA/MainFeatures/AppliMenu.cs +++ b/3PA/MainFeatures/AppliMenu.cs @@ -140,7 +140,13 @@ public static void ShowEditCodeMenuAtCursor() { /// private static List DisableItemIfNeeded(List list) { var isCurrentFileProgressFile = Abl.IsCurrentProgressFile; - list.ForEach(item => item.IsDisabled = !isCurrentFileProgressFile && (!item.Generic)); + foreach (var menu in list) { + menu.IsDisabled = !isCurrentFileProgressFile && !menu.Generic; + if (menu.Children != null) + foreach (var subMenu in menu.Children.Cast()) { + subMenu.IsDisabled = !isCurrentFileProgressFile && (!menu.Generic || !subMenu.Generic); + } + } return list; } @@ -227,7 +233,7 @@ private AppliMenu() { _databaseTools = new List { new MenuItem(this, "Open data administration", ImageResources.DataAdmin, item => ProMisc.OpenDbAdmin(), "Data_admin", "") { Generic = true }, new MenuItem(this, "Open progress dictionary", ImageResources.Dictionary, item => ProMisc.OpenDictionary(), "Data_dictionary", "") { Generic = true }, - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Explore and modify your data", ImageResources.DataDigger, item => ProMisc.OpenDataDigger(), "Data_digger", "") { Generic = true }, new MenuItem(this, "Explore (read-only) your data", ImageResources.DataReader, item => ProMisc.OpenDataReader(), "Data_reader", "") { Generic = true }, @@ -248,24 +254,24 @@ private AppliMenu() { MainMenuList = new List { new MenuItem(this, "Show main window", ImageResources.MainWindow, item => Appli.Appli.ToggleView(), "Open_main_window", "Alt+Space") { Generic = true }, new MenuItem(this, "Show auto-completion at caret", ImageResources.Autocompletion, item => AutoCompletion.OnShowCompleteSuggestionList(), "Show_Suggestion_List", "Ctrl+Space"), - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Open 4GL help", ImageResources.ProgressHelp, item => ProMisc.Open4GlHelp(), "Open_4GL_help", "F1") { Generic = true }, new MenuItem(this, "Check syntax", ImageResources.CheckCode, item => ProMisc.StartProgressExec(ExecutionType.CheckSyntax), "Check_syntax", "Shift+F1"), new MenuItem(this, "Compile", ImageResources.CompileCode, item => ProMisc.StartProgressExec(ExecutionType.Compile), "Compile", "Alt+F1"), new MenuItem(this, "Run program", ImageResources.RunCode, item => ProMisc.StartProgressExec(ExecutionType.Run), "Run_program", "Ctrl+F1"), new MenuItem(this, "Prolint code", ImageResources.ProlintCode, item => ProMisc.StartProgressExec(ExecutionType.Prolint), "Prolint", "F12"), new MenuItem(this, "Deploy current file", ImageResources.Deploy, item => ProMisc.DeployCurrentFile(), "Deploy", "Ctrl+Alt+Prior") { Generic = true }, - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Progress desktop", ImageResources.ProDesktop, item => ProMisc.OpenProDesktop(), "Pro_desktop", "") { Generic = true }, new MenuItem(this, "Open in the AppBuilder", ImageResources.SendToAppbuilder, item => ProMisc.OpenCurrentInAppbuilder(), "Send_appbuilder", "Alt+O"), - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Start searching files", ImageResources.Search, item => FileExplorer.FileExplorer.Instance.StartSearch(), "Search_file", "Alt+Q") { Generic = true }, goToDefItem, goToPreviousJump, //new MenuItem(this, "New 4GL file", ImageResources.GenerateCode, ShowNewFileAtCursor, "New_file", "Ctrl+Shift+N") { // Children = GenerateCodeMenuList.Select(item => (YamuiMenuItem)item).ToList(), //}, - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Switch environment", ImageResources.Env, item => ShowEnvMenuAtCursor(), "Switch_env", "Ctrl+E") { Generic = true }, @@ -282,7 +288,7 @@ private AppliMenu() { new MenuItem(this, "Miscellaneous", ImageResources.Miscellaneous, item => ShowMiscMenuAtCursor(), "Miscellaneous", "Alt+M") { Children = _miscMenuList.Cast().ToList() }, - new MenuItem(true), // -------------------------- + new MenuItem(true) { Generic = true }, // -------------------------- new MenuItem(this, "Options", ImageResources.ShowOptions, item => Appli.Appli.GoToPage(PageNames.OptionsGeneral), "Go_to_options", null) {Generic = true} }; diff --git a/3PA/MainFeatures/Config.cs b/3PA/MainFeatures/Config.cs index 79949a1b..c0b01319 100644 --- a/3PA/MainFeatures/Config.cs +++ b/3PA/MainFeatures/Config.cs @@ -319,6 +319,9 @@ internal class ConfigObject { [Range(1000, 30000)] public int FileExplorerListFilesTimeOutInMs = 3000; + // Current folder mode for the file explorer : local/compilation/propath/everywhere + public int FileExplorerDirectoriesToExplore = 0; + #endregion #region CODE EXPLORER @@ -376,11 +379,7 @@ internal class ConfigObject { public NppEncodingFormat AutoSwitchEncodingTo = NppEncodingFormat._Automatic_default; #endregion - - - // Current folder mode for the file explorer : local/compilation/propath/everywhere - public int FileExplorerViewMode = 3; - + // Shared configuration last folder selected public string SharedConfFolder = ""; // a list of Label corresponding to confLine(s) that are auto-updated diff --git a/3PA/MainFeatures/FileExplorer/FileExplorer.cs b/3PA/MainFeatures/FileExplorer/FileExplorer.cs index 143308ef..cd340942 100644 --- a/3PA/MainFeatures/FileExplorer/FileExplorer.cs +++ b/3PA/MainFeatures/FileExplorer/FileExplorer.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using YamuiFramework.Controls.YamuiList; using YamuiFramework.Helper; @@ -159,18 +160,19 @@ public List ListFileOjectsInDirectory(string dirPath, bool recursi try { foreach (var directoryInfo in dirInfo.GetDirectories()) { if (!Config.Instance.FileExplorerIgnoreUnixHiddenFolders || !regex.IsMatch(directoryInfo.FullName)) { - // recursive - if (recursive && DateTime.Now.Subtract(_startTime).TotalMilliseconds <= Config.Instance.FileExplorerListFilesTimeOutInMs) { - output.AddRange(ListFileOjectsInDirectory(directoryInfo.FullName, true, true, false)); - } - output.Add(new FileListItem { + var folderItem = new FileListItem { DisplayText = directoryInfo.Name, BasePath = Path.GetDirectoryName(directoryInfo.FullName), FullPath = directoryInfo.FullName, CreateDateTime = directoryInfo.CreationTime, ModifieDateTime = directoryInfo.LastWriteTime, Type = FileType.Folder - }); + }; + output.Add(folderItem); + // recursive + if (recursive && DateTime.Now.Subtract(_startTime).TotalMilliseconds <= Config.Instance.FileExplorerListFilesTimeOutInMs) { + folderItem.Children = ListFileOjectsInDirectory(directoryInfo.FullName, true, true, false).Cast().ToList(); + } } } } catch (Exception e) { diff --git a/3PA/MainFeatures/FileExplorer/FileExplorerForm.cs b/3PA/MainFeatures/FileExplorer/FileExplorerForm.cs index 0138cd3d..779e2def 100644 --- a/3PA/MainFeatures/FileExplorer/FileExplorerForm.cs +++ b/3PA/MainFeatures/FileExplorer/FileExplorerForm.cs @@ -197,8 +197,6 @@ protected override void OnVisibleChanged(EventArgs e) { #endregion - #region File list - #region Refresh file list and selector mechanic /// @@ -228,7 +226,7 @@ private void RefreshFileListAction() { // get the list of FileObjects _initialObjectsList = new List(); - switch (Config.Instance.FileExplorerViewMode) { + switch (Config.Instance.FileExplorerDirectoriesToExplore) { case 0: _initialObjectsList = FileExplorer.Instance.ListFileOjectsInDirectory(ProEnvironment.Current.BaseLocalPath); break; @@ -284,8 +282,6 @@ private void RefreshFileListAction() { #endregion - #endregion - #region File list events private void YamuiListOnEnterPressed(YamuiScrollList yamuiScrollList, KeyEventArgs keyEventArgs) { @@ -322,25 +318,25 @@ private void RefreshGotoDirButton() { // refresh a button depending on the mode... if (IsHandleCreated) { BeginInvoke((Action) delegate { - btGotoDir.Visible = Config.Instance.FileExplorerViewMode <= 1; - Image tryImg = (Image)ImageResources.ResourceManager.GetObject("ExplorerDir" + Config.Instance.FileExplorerViewMode); + btGotoDir.Visible = Config.Instance.FileExplorerDirectoriesToExplore <= 1; + Image tryImg = (Image)ImageResources.ResourceManager.GetObject("ExplorerDir" + Config.Instance.FileExplorerDirectoriesToExplore); btDirectory.BackGrndImage = tryImg ?? ImageResources.Error; btDirectory.Invalidate(); - lbDirectory.Text = _explorerDirStr[Config.Instance.FileExplorerViewMode]; + lbDirectory.Text = _explorerDirStr[Config.Instance.FileExplorerDirectoriesToExplore]; }); } } private void BtGotoDirOnButtonPressed(object sender, EventArgs buttonPressedEventArgs) { - if (Config.Instance.FileExplorerViewMode == 0) + if (Config.Instance.FileExplorerDirectoriesToExplore == 0) Utils.OpenFolder(ProEnvironment.Current.BaseLocalPath); - else if (Config.Instance.FileExplorerViewMode == 1) + else if (Config.Instance.FileExplorerDirectoriesToExplore == 1) Utils.OpenFolder(ProEnvironment.Current.BaseCompilationPath); } private void BtDirectoryOnButtonPressed(object sender, EventArgs buttonPressedEventArgs) { - Config.Instance.FileExplorerViewMode++; - if (Config.Instance.FileExplorerViewMode > 3) Config.Instance.FileExplorerViewMode = 0; + Config.Instance.FileExplorerDirectoriesToExplore++; + if (Config.Instance.FileExplorerDirectoriesToExplore > 3) Config.Instance.FileExplorerDirectoriesToExplore = 0; RefreshGotoDirButton(); RefreshFileList(); diff --git a/3PA/MainFeatures/FileExplorer/FileListItem.cs b/3PA/MainFeatures/FileExplorer/FileListItem.cs index 956ca1ca..45816f2e 100644 --- a/3PA/MainFeatures/FileExplorer/FileListItem.cs +++ b/3PA/MainFeatures/FileExplorer/FileListItem.cs @@ -94,6 +94,10 @@ public override List TagImages { /// public override List Children { get; set; } + // make all items expanded by default + public FileListItem() { + IsExpanded = true; + } } /// diff --git a/YamuiFramework/Controls/YamuiList/ListItem.cs b/YamuiFramework/Controls/YamuiList/ListItem.cs index b48b91d2..cc42a81e 100644 --- a/YamuiFramework/Controls/YamuiList/ListItem.cs +++ b/YamuiFramework/Controls/YamuiList/ListItem.cs @@ -31,9 +31,6 @@ public class ListItem { #region private - private bool _isSeparator; - private bool _isDisabled; - #endregion #region Virtual properties @@ -46,22 +43,12 @@ public class ListItem { /// /// The item is disabled or not (a separator is necesseraly disabled) /// - public virtual bool IsDisabled { - get { return _isDisabled; } - set { _isDisabled = _isSeparator || value; } - } + public virtual bool IsDisabled { get; set; } /// /// true if the item is a separator /// - public virtual bool IsSeparator { - get { return _isSeparator; } - set { - _isSeparator = value; - if (_isSeparator) - IsDisabled = true; - } - } + public virtual bool IsSeparator { get; set; } #endregion diff --git a/YamuiFramework/Controls/YamuiList/YamuiFilteredList.cs b/YamuiFramework/Controls/YamuiList/YamuiFilteredList.cs index c46a25dc..cd45c024 100644 --- a/YamuiFramework/Controls/YamuiList/YamuiFilteredList.cs +++ b/YamuiFramework/Controls/YamuiList/YamuiFilteredList.cs @@ -225,7 +225,9 @@ protected virtual List GetFilteredAndSortedList(List /// Called by default to paint the row if no OnRowPaint is defined /// protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { - var backColor = YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); + var backColor = item.IsSeparator ? + YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : + YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !item.IsDisabled); // background @@ -241,7 +243,7 @@ protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs // foreground // left line - if (row.IsSelected && !item.IsDisabled) { + if (row.IsSelected) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.AccentColor)) { e.Graphics.FillRectangle(b, new Rectangle(0, 0, 3, row.ClientRectangle.Height)); } @@ -250,7 +252,7 @@ protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs var textRectangle = new Rectangle(5, 0, row.ClientRectangle.Width - 5, RowHeight); // letter highlight - if (!item.IsDisabled) + if (!(item.IsDisabled || item.IsSeparator)) DrawTextHighlighting(e.Graphics, ((FilteredListItem) item).InternalFilterMatchedRanges, textRectangle, item.DisplayText, TextFlags); // text diff --git a/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeList.cs b/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeList.cs index 8d0fc692..8c6efe7a 100644 --- a/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeList.cs +++ b/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeList.cs @@ -357,9 +357,11 @@ protected override void DrawButtons() { /// Called by default to paint the row if no OnRowPaint is defined /// protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { - + // background - var backColor = YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); + var backColor = item.IsSeparator ? + YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : + YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); e.Graphics.Clear(backColor); var curItem = item as FilteredTypeListItem; @@ -436,7 +438,7 @@ protected virtual void DrawFilteredTypeRow(Graphics g, FilteredTypeListItem item var textRectangle = new Rectangle(drawRect.X + 3 + (img != null ? img.Width : 0), 0, drawRect.Width - 3 - (img != null ? img.Width : 0), drawRect.Height); // letter highlight - if (!item.IsDisabled) + if (!(item.IsDisabled || item.IsSeparator)) DrawTextHighlighting(g, item.InternalFilterMatchedRanges, textRectangle, item.DisplayText, TextFlags); // text diff --git a/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeTreeList.cs b/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeTreeList.cs index a50d7c7b..f342fe29 100644 --- a/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeTreeList.cs +++ b/YamuiFramework/Controls/YamuiList/YamuiFilteredTypeTreeList.cs @@ -300,7 +300,9 @@ private bool ExpandCollapse(int itemIndex, ForceExpansion forceExpansion) { protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { // background - var backColor = YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); + var backColor = item.IsSeparator ? + YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : + YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); e.Graphics.Clear(backColor); var curItem = item as FilteredTypeTreeListItem; @@ -328,7 +330,7 @@ protected virtual Rectangle RowPaintTree(Graphics g, FilteredTypeTreeListItem cu // draw the branches of the tree if (ShowTreeBranches) { - using (var linePen = new Pen(!curItem.IsDisabled || curItem.IsSeparator ? YamuiThemeManager.Current.SubTextFore : foreColor, 1.5f) { DashStyle = DashStyle.Solid }) { + using (var linePen = new Pen(!(curItem.IsDisabled || curItem.IsSeparator) ? YamuiThemeManager.Current.SubTextFore : foreColor, 1.5f) { DashStyle = DashStyle.Solid }) { var pos = drawRect.X + TreeWidth / 2; if (curItem.Level >= 1) diff --git a/YamuiFramework/Controls/YamuiList/YamuiScrollList.cs b/YamuiFramework/Controls/YamuiList/YamuiScrollList.cs index f022e3ae..68e40959 100644 --- a/YamuiFramework/Controls/YamuiList/YamuiScrollList.cs +++ b/YamuiFramework/Controls/YamuiList/YamuiScrollList.cs @@ -193,7 +193,7 @@ public int SelectedItemIndex { public ListItem SelectedItem { get { var item = GetItem(SelectedItemIndex); - return item != null ? (item.IsDisabled ? null : item) : null; + return item != null ? (item.IsDisabled || item.IsSeparator ? null : item) : null; } } @@ -252,7 +252,7 @@ private set { public ListItem HotItem { get { var item = GetItem(TopIndex + HotRow); - return item != null ? (item.IsDisabled ? null : item) : null; + return item != null ? (item.IsDisabled || item.IsSeparator ? null : item) : null; } } @@ -531,15 +531,16 @@ public virtual void SetItems(List listItems) { // and an enabled item! if (_nbItems > SelectedItemIndex) { - if (GetItem(SelectedItemIndex).IsDisabled) { + var item = GetItem(SelectedItemIndex); + if (item.IsDisabled || item.IsSeparator) { var newIndex = SelectedItemIndex; do { newIndex++; if (newIndex > _nbItems - 1) newIndex = 0; - + item = GetItem(newIndex); } // do this while the current button is disabled and we didn't already try every button - while (GetItem(newIndex).IsDisabled && SelectedItemIndex != newIndex); + while ((item.IsDisabled || item.IsSeparator) && SelectedItemIndex != newIndex); SelectedItemIndex = newIndex; } } @@ -658,7 +659,9 @@ private void RefreshButtons() { /// Called by default to paint the row if no OnRowPaint is defined /// protected virtual void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { - var backColor = YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); + var backColor = item.IsSeparator ? + YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : + YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !item.IsDisabled); // background @@ -674,7 +677,7 @@ protected virtual void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs // foreground // left line - if (row.IsSelected && !item.IsDisabled) { + if (row.IsSelected) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.AccentColor)) { e.Graphics.FillRectangle(b, new Rectangle(0, 0, 3, row.ClientRectangle.Height)); } @@ -685,7 +688,7 @@ protected virtual void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs } protected virtual void RowPaintSeparator(Graphics g, Rectangle drawRect) { - using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.FormAltBack)) { + using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.MenuNormalAltBack)) { var width = (int)(drawRect.Width * 0.45); g.FillRectangle(b, new Rectangle(drawRect.X, drawRect.Y + drawRect.Height / 2 - 2, width, 4)); } @@ -878,6 +881,7 @@ private bool HandleKeyDown(KeyEventArgs e) { break; default: + ListItem newItem = null; do { switch (pressedKey) { @@ -921,8 +925,9 @@ private bool HandleKeyDown(KeyEventArgs e) { if (_nbItems == 0) return false; + newItem = GetItem(newIndex); } // do this while the current button is disabled and we didn't already try every button - while (GetItem(newIndex).IsDisabled && SelectedItemIndex != newIndex); + while ((newItem.IsDisabled || newItem.IsSeparator) && SelectedItemIndex != newIndex); break; } @@ -940,7 +945,7 @@ private void OnRowClick(object sender, EventArgs eventArgs) { // can't select a disabled item var rowIndex = int.Parse(((YamuiListRow) sender).Name); var newItem = GetItem(rowIndex + TopIndex); - if (newItem != null && newItem.IsDisabled) + if (newItem != null && (newItem.IsDisabled || newItem.IsSeparator)) return; // change the selected row diff --git a/YamuiFramework/Controls/YamuiPictureBox.cs b/YamuiFramework/Controls/YamuiPictureBox.cs index 66a68bb6..c2cf8cdf 100644 --- a/YamuiFramework/Controls/YamuiPictureBox.cs +++ b/YamuiFramework/Controls/YamuiPictureBox.cs @@ -65,15 +65,17 @@ protected override void OnPaint(PaintEventArgs e) { } // draw main image, in greyscale if not activated - var recImg = new Rectangle(new Point((ClientRectangle.Width - BackGrndImage.Width) / 2, (ClientRectangle.Height - BackGrndImage.Height) / 2), new Size(BackGrndImage.Width, BackGrndImage.Height)); - e.Graphics.DrawImage(BackGrndImage, recImg); + if (BackGrndImage != null) { + var recImg = new Rectangle(new Point((ClientRectangle.Width - BackGrndImage.Width)/2, (ClientRectangle.Height - BackGrndImage.Height)/2), new Size(BackGrndImage.Width, BackGrndImage.Height)); + e.Graphics.DrawImage(BackGrndImage, recImg); - // border - if (DrawBorder) { - recImg = ClientRectangle; - recImg.Inflate(-2, -2); - using (Pen b = new Pen(YamuiThemeManager.Current.ButtonNormalBorder, 2f)) { - e.Graphics.DrawRectangle(b, recImg); + // border + if (DrawBorder) { + recImg = ClientRectangle; + recImg.Inflate(-2, -2); + using (Pen b = new Pen(YamuiThemeManager.Current.ButtonNormalBorder, 2f)) { + e.Graphics.DrawRectangle(b, recImg); + } } } } catch { diff --git a/YamuiFramework/Forms/YamuiMenu.cs b/YamuiFramework/Forms/YamuiMenu.cs index 8e3a7dd1..d9080206 100644 --- a/YamuiFramework/Forms/YamuiMenu.cs +++ b/YamuiFramework/Forms/YamuiMenu.cs @@ -159,7 +159,7 @@ private void DrawContent() { Controls.Clear(); // evaluates the width needed to draw the control - var maxWidth = MenuList.Select(item => TextRenderer.MeasureText(item.SubText ?? "", FontManager.GetFont(FontFunction.Small)).Width + TextRenderer.MeasureText(item.DisplayText ?? "", FontManager.GetStandardFont()).Width).Concat(new[] { 0 }).Max(); + var maxWidth = MenuList.Select(item => item.Level * 8 + TextRenderer.MeasureText(item.SubText ?? "", FontManager.GetFont(FontFunction.Small)).Width + TextRenderer.MeasureText(item.DisplayText ?? "", FontManager.GetStandardFont()).Width).Concat(new[] { 0 }).Max(); maxWidth += MenuList.Exists(item => item.SubText != null) ? 10 : 0; maxWidth += (MenuList.Exists(item => item.ItemImage != null) ? 35 : 8) + 22; if (FormMaxSize.Width > 0) @@ -251,17 +251,31 @@ private void DrawContent() { } private void YamuiListOnRowClicked(YamuiScrollList yamuiScrollList, MouseEventArgs mouseEventArgs) { - Visible = false; - ClicItemWrapper((YamuiMenuItem) yamuiScrollList.SelectedItem); - Close(); - Dispose(); + var item = yamuiScrollList.SelectedItem as YamuiMenuItem; + if (item != null) { + if (item.CanExpand) { + ClicItemWrapper(item); + } else { + Visible = false; + ClicItemWrapper(item); + Close(); + Dispose(); + } + } } private void YamuiListOnEnterPressed(YamuiScrollList yamuiScrollList, KeyEventArgs e) { - Visible = false; - ClicItemWrapper((YamuiMenuItem) yamuiScrollList.SelectedItem); - Close(); - Dispose(); + var item = yamuiScrollList.SelectedItem as YamuiMenuItem; + if (item != null) { + if (item.CanExpand) { + ClicItemWrapper(item); + } else { + Visible = false; + ClicItemWrapper(item); + Close(); + Dispose(); + } + } } /// @@ -352,7 +366,9 @@ public class YamuiFilteredTypeTreeListForMenuPopup : YamuiFilteredTypeTreeList { protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { // background - var backColor = YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled || item.IsSeparator); + var backColor = item.IsSeparator ? + YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : + YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); e.Graphics.Clear(backColor); // foreground @@ -376,9 +392,9 @@ protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs shiftedDrawRect = RowPaintTree(e.Graphics, curItem, drawRect, row); // case of a separator - if (item.IsSeparator) + if (item.IsSeparator) { RowPaintSeparator(e.Graphics, curItem.Level == 0 ? drawRect : shiftedDrawRect); - else + } else DrawFilteredTypeRow(e.Graphics, curItem, NoCanExpandItem ? drawRect : shiftedDrawRect, row); } }