diff --git a/Source/Core/Config/ProgramConfiguration.cs b/Source/Core/Config/ProgramConfiguration.cs index e7d1e32..942de72 100644 --- a/Source/Core/Config/ProgramConfiguration.cs +++ b/Source/Core/Config/ProgramConfiguration.cs @@ -85,7 +85,8 @@ namespace CodeImp.DoomBuilder.Config private float filteranisotropy; private bool showtexturesizes; private bool locatetexturegroup; //mxd - private SplitLineBehavior splitlinebehavior; //mxd + private bool keeptexturefilterfocused; //mxd + private SplitLineBehavior splitlinebehavior; //mxd //mxd. Script editor settings private string scriptfontname; @@ -194,6 +195,7 @@ namespace CodeImp.DoomBuilder.Config public float FilterAnisotropy { get { return filteranisotropy; } internal set { filteranisotropy = value; } } public bool ShowTextureSizes { get { return showtexturesizes; } internal set { showtexturesizes = value; } } public bool LocateTextureGroup { get { return locatetexturegroup; } internal set { locatetexturegroup = value; } } //mxd + public bool KeepTextureFilterFocused { get { return keeptexturefilterfocused; } internal set { keeptexturefilterfocused = value; } } //mxd public SplitLineBehavior SplitLineBehavior { get { return splitlinebehavior; } set { splitlinebehavior = value; } } //mxd //mxd. Script editor settings @@ -326,6 +328,7 @@ namespace CodeImp.DoomBuilder.Config filteranisotropy = cfg.ReadSetting("filteranisotropy", 8.0f); showtexturesizes = cfg.ReadSetting("showtexturesizes", true); locatetexturegroup = cfg.ReadSetting("locatetexturegroup", true); //mxd + keeptexturefilterfocused = cfg.ReadSetting("keeptexturefilterfocused", true); //mxd splitlinebehavior = (SplitLineBehavior) General.Clamp(cfg.ReadSetting("splitlinebehavior", 0), 0, 3); //mxd //mxd. Script editor @@ -438,6 +441,7 @@ namespace CodeImp.DoomBuilder.Config cfg.WriteSetting("filteranisotropy", filteranisotropy); cfg.WriteSetting("showtexturesizes", showtexturesizes); cfg.WriteSetting("locatetexturegroup", locatetexturegroup); //mxd + cfg.WriteSetting("keeptexturefilterfocused", keeptexturefilterfocused); //mxd cfg.WriteSetting("splitlinebehavior", (int)splitlinebehavior); //mxd //mxd. Script editor diff --git a/Source/Core/Controls/ImageBrowserControl.Designer.cs b/Source/Core/Controls/ImageBrowserControl.Designer.cs index 567270c..2549132 100644 --- a/Source/Core/Controls/ImageBrowserControl.Designer.cs +++ b/Source/Core/Controls/ImageBrowserControl.Designer.cs @@ -116,6 +116,7 @@ namespace CodeImp.DoomBuilder.Controls this.list.DoubleClick += new System.EventHandler(this.list_DoubleClick); this.list.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.list_ItemSelectionChanged); this.list.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.list_KeyPress); + this.list.KeyDown += new System.Windows.Forms.KeyEventHandler(this.list_KeyDown); // // showsubdirtextures // diff --git a/Source/Core/Controls/ImageBrowserControl.cs b/Source/Core/Controls/ImageBrowserControl.cs index ede2166..076f746 100644 --- a/Source/Core/Controls/ImageBrowserControl.cs +++ b/Source/Core/Controls/ImageBrowserControl.cs @@ -237,6 +237,20 @@ namespace CodeImp.DoomBuilder.Controls } } + //mxd. Handle keyboard navigation the same way regardless of list being focused... + private void list_KeyDown(object sender, KeyEventArgs e) + { + // Check what key is pressed + switch(e.KeyData) + { + // Cursor keys + case Keys.Left: SelectNextItem(SearchDirectionHint.Left); e.SuppressKeyPress = true; break; + case Keys.Right: SelectNextItem(SearchDirectionHint.Right); e.SuppressKeyPress = true; break; + case Keys.Up: SelectNextItem(SearchDirectionHint.Up); e.SuppressKeyPress = true; break; + case Keys.Down: SelectNextItem(SearchDirectionHint.Down); e.SuppressKeyPress = true; break; + } + } + //mxd private void filterSize_WhenTextChanged(object sender, EventArgs e) { @@ -277,6 +291,8 @@ namespace CodeImp.DoomBuilder.Controls //mxd. Transfer focus to Filter textbox private void list_KeyPress(object sender, KeyPressEventArgs e) { + if(!General.Settings.KeepTextureFilterFocused) return; + objectname.Focus(); if(e.KeyChar == '\b') // Any better way to check for Backspace?.. { @@ -388,36 +404,107 @@ namespace CodeImp.DoomBuilder.Controls } else { - // Get selected item - ListViewItem lvi = list.SelectedItems[0]; - Rectangle lvirect = list.GetItemRect(lvi.Index, ItemBoundsPortion.Entire); - Point spos = new Point(lvirect.Location.X + lvirect.Width / 2, lvirect.Y + lvirect.Height / 2); + //mxd + int index = list.SelectedItems[0].Index; + int targetindex = -1; + ListViewGroup startgroup = list.SelectedItems[0].Group; + Rectangle startrect = list.GetItemRect(index, ItemBoundsPortion.Entire); - // Try finding 5 times in the given direction - for(int i = 0; i < 5; i++) + switch(dir) { - // Move point in given direction - switch(dir) - { - case SearchDirectionHint.Left: spos.X -= list.TileSize.Width / 2; break; - case SearchDirectionHint.Right: spos.X += list.TileSize.Width / 2; break; - case SearchDirectionHint.Up: spos.Y -= list.TileSize.Height / 2; break; - case SearchDirectionHint.Down: spos.Y += list.TileSize.Height / 2; break; - } - - // Test position - lvi = list.GetItemAt(spos.X, spos.Y); - if(lvi != null) - { - // Select item - list.SelectedItems.Clear(); - lvi.Selected = true; + // Check previous items untill groups match... + case SearchDirectionHint.Left: + if(list.SelectedIndices[0] > 0) + { + while(--index > -1) + { + if(list.Items[index].Group == startgroup) + { + targetindex = index; + break; + } + } + } break; + + // Same thing, other direction... + case SearchDirectionHint.Right: + if(list.SelectedIndices[0] < list.Items.Count - 1) + { + while(++index < list.Items.Count) + { + if(list.Items[index].Group == startgroup) + { + targetindex = index; + break; + } + } + } + break; + + // Check previous items untill X coordinate match and Y coordinate is less than the start ones... + case SearchDirectionHint.Up: + while(--index > -1) + { + Rectangle rect = list.GetItemRect(index, ItemBoundsPortion.Entire); + if(list.Items[index].Group == startgroup && rect.X == startrect.X && rect.Y < startrect.Y) + { + targetindex = index; + break; + } + } + break; + + // Same thing, other direction... + case SearchDirectionHint.Down: + if(list.SelectedIndices[0] < list.Items.Count - 1) + { + while(++index < list.Items.Count) + { + Rectangle rect = list.GetItemRect(index, ItemBoundsPortion.Entire); + if(list.Items[index].Group == startgroup && rect.X == startrect.X && rect.Y > startrect.Y) + { + targetindex = index; + break; + } + } + } + break; + } + + //mxd. Use the old method for Up/Down keys, becaue it can jump between Groups... + if(targetindex == -1 && (dir == SearchDirectionHint.Up || dir == SearchDirectionHint.Down)) + { + Point spos = new Point(startrect.Location.X + startrect.Width / 2, startrect.Y + startrect.Height / 2); + + // Try finding 5 times in the given direction + for(int i = 0; i < 5; i++) + { + // Move point in given direction + switch(dir) + { + case SearchDirectionHint.Up: spos.Y -= list.TileSize.Height / 2; break; + case SearchDirectionHint.Down: spos.Y += list.TileSize.Height / 2; break; + } + + // Test position + ListViewItem lvi = list.GetItemAt(spos.X, spos.Y); + if(lvi != null) + { + targetindex = lvi.Index; + break; + } } } - - // Make selection visible - if(list.SelectedItems.Count > 0) list.SelectedItems[0].EnsureVisible(); + + //mxd. Found something?.. + if(targetindex != -1) + { + // Select item + list.SelectedItems.Clear(); + list.Items[targetindex].Selected = true; + list.SelectedItems[0].EnsureVisible(); + } } } @@ -514,6 +601,15 @@ namespace CodeImp.DoomBuilder.Controls private void RefillList(bool selectfirst) { visibleitems = new List(); + + //mxd. Store info about currently selected item + string selectedname = string.Empty; + ListViewGroup selecteditemgroup = null; + if(!selectfirst && keepselected == -1 && list.SelectedIndices.Count > 0) + { + selectedname = list.Items[list.SelectedIndices[0]].Text; + selecteditemgroup = list.Items[list.SelectedIndices[0]].Group; + } // Begin updating list updating = true; @@ -569,6 +665,56 @@ namespace CodeImp.DoomBuilder.Controls { SelectFirstItem(); } + //mxd. Try reselecting the same/next closest item + else if(selecteditemgroup != null && !string.IsNullOrEmpty(selectedname)) + { + ListViewItem bestmatch = null; + int charsmatched = 1; + foreach(ListViewItem item in list.Items) + { + if(item.Group == selecteditemgroup && item.Text[0] == selectedname[0]) + { + if(item.Text == selectedname) + { + bestmatch = item; + break; + } + + for(int i = 1; i < Math.Min(item.Text.Length, selectedname.Length); i++) + { + if(item.Text[i] != selectedname[i]) + { + if(i > charsmatched) + { + bestmatch = item; + charsmatched = i; + } + break; + } + } + } + } + + // Select the first item from the same group... + if(bestmatch == null) + { + foreach(ListViewItem item in list.Items) + { + if(item.Group == selecteditemgroup) + { + bestmatch = item; + break; + } + } + } + + // Select found item + if(bestmatch != null) + { + bestmatch.Selected = true; + bestmatch.EnsureVisible(); + } + } } // Raise event @@ -605,7 +751,10 @@ namespace CodeImp.DoomBuilder.Controls // This sends the focus to the textbox public void FocusTextbox() { - objectname.Focus(); + if(General.Settings.KeepTextureFilterFocused) //mxd + objectname.Focus(); + else + list.Focus(); } #endregion diff --git a/Source/Core/Windows/PreferencesForm.Designer.cs b/Source/Core/Windows/PreferencesForm.Designer.cs index b9fafc3..4871b4d 100644 --- a/Source/Core/Windows/PreferencesForm.Designer.cs +++ b/Source/Core/Windows/PreferencesForm.Designer.cs @@ -40,10 +40,10 @@ namespace CodeImp.DoomBuilder.Windows System.Windows.Forms.Label label21; System.Windows.Forms.Label label29; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PreferencesForm)); + this.keepfilterfocused = new System.Windows.Forms.CheckBox(); this.maxBackups = new System.Windows.Forms.TrackBar(); this.labelBackups = new System.Windows.Forms.Label(); this.label27 = new System.Windows.Forms.Label(); - this.checkforupdates = new System.Windows.Forms.CheckBox(); this.cbStoreEditTab = new System.Windows.Forms.CheckBox(); this.locatetexturegroup = new System.Windows.Forms.CheckBox(); this.recentFiles = new System.Windows.Forms.TrackBar(); @@ -215,7 +215,6 @@ namespace CodeImp.DoomBuilder.Windows this.colorliterals = new CodeImp.DoomBuilder.Controls.ColorControl(); this.colorconstants = new CodeImp.DoomBuilder.Controls.ColorControl(); this.previewgroup = new System.Windows.Forms.GroupBox(); - this.scriptedit = new CodeImp.DoomBuilder.Controls.ScriptEditorPreviewControl(); this.tabpasting = new System.Windows.Forms.TabPage(); this.label16 = new System.Windows.Forms.Label(); this.pasteoptions = new CodeImp.DoomBuilder.Controls.PasteOptionsControl(); @@ -266,7 +265,6 @@ namespace CodeImp.DoomBuilder.Windows this.groupBox8.SuspendLayout(); this.groupBox7.SuspendLayout(); this.groupBox6.SuspendLayout(); - this.previewgroup.SuspendLayout(); this.tabpasting.SuspendLayout(); this.SuspendLayout(); // @@ -299,10 +297,10 @@ namespace CodeImp.DoomBuilder.Windows // // groupBox1 // + groupBox1.Controls.Add(this.keepfilterfocused); groupBox1.Controls.Add(this.maxBackups); groupBox1.Controls.Add(this.labelBackups); groupBox1.Controls.Add(this.label27); - groupBox1.Controls.Add(this.checkforupdates); groupBox1.Controls.Add(this.cbStoreEditTab); groupBox1.Controls.Add(this.locatetexturegroup); groupBox1.Controls.Add(this.recentFiles); @@ -332,6 +330,18 @@ namespace CodeImp.DoomBuilder.Windows groupBox1.TabStop = false; groupBox1.Text = " Options "; // + // keepfilterfocused + // + this.keepfilterfocused.AutoSize = true; + this.keepfilterfocused.Location = new System.Drawing.Point(32, 356); + this.keepfilterfocused.Name = "keepfilterfocused"; + this.keepfilterfocused.Size = new System.Drawing.Size(280, 17); + this.keepfilterfocused.TabIndex = 52; + this.keepfilterfocused.Text = "Keep Filter input focused when image browser is open"; + this.toolTip1.SetToolTip(this.keepfilterfocused, "When enabled, all key presses in \r\nimage browsers will be redirected \r\nto the Fil" + + "ter textbox."); + this.keepfilterfocused.UseVisualStyleBackColor = true; + // // maxBackups // this.maxBackups.BackColor = System.Drawing.SystemColors.Window; @@ -364,21 +374,10 @@ namespace CodeImp.DoomBuilder.Windows this.label27.Text = "Max. backups:"; this.toolTip1.SetToolTip(this.label27, "Controls how many backups \r\nare made when a map is saved."); // - // checkforupdates - // - this.checkforupdates.AutoSize = true; - this.checkforupdates.Location = new System.Drawing.Point(32, 440); - this.checkforupdates.Name = "checkforupdates"; - this.checkforupdates.Size = new System.Drawing.Size(160, 17); - this.checkforupdates.TabIndex = 51; - this.checkforupdates.Text = "Check for updates at startup"; - this.checkforupdates.UseVisualStyleBackColor = true; - this.checkforupdates.Visible = false; - // // cbStoreEditTab // this.cbStoreEditTab.AutoSize = true; - this.cbStoreEditTab.Location = new System.Drawing.Point(32, 419); + this.cbStoreEditTab.Location = new System.Drawing.Point(32, 440); this.cbStoreEditTab.Name = "cbStoreEditTab"; this.cbStoreEditTab.Size = new System.Drawing.Size(203, 17); this.cbStoreEditTab.TabIndex = 50; @@ -388,7 +387,7 @@ namespace CodeImp.DoomBuilder.Windows // locatetexturegroup // this.locatetexturegroup.AutoSize = true; - this.locatetexturegroup.Location = new System.Drawing.Point(32, 377); + this.locatetexturegroup.Location = new System.Drawing.Point(32, 398); this.locatetexturegroup.Name = "locatetexturegroup"; this.locatetexturegroup.Size = new System.Drawing.Size(267, 17); this.locatetexturegroup.TabIndex = 49; @@ -465,7 +464,7 @@ namespace CodeImp.DoomBuilder.Windows // cbSynchCameras // this.cbSynchCameras.AutoSize = true; - this.cbSynchCameras.Location = new System.Drawing.Point(32, 398); + this.cbSynchCameras.Location = new System.Drawing.Point(32, 419); this.cbSynchCameras.Name = "cbSynchCameras"; this.cbSynchCameras.Size = new System.Drawing.Size(260, 17); this.cbSynchCameras.TabIndex = 42; @@ -475,7 +474,7 @@ namespace CodeImp.DoomBuilder.Windows // showtexturesizes // this.showtexturesizes.AutoSize = true; - this.showtexturesizes.Location = new System.Drawing.Point(32, 356); + this.showtexturesizes.Location = new System.Drawing.Point(32, 377); this.showtexturesizes.Name = "showtexturesizes"; this.showtexturesizes.Size = new System.Drawing.Size(208, 17); this.showtexturesizes.TabIndex = 41; @@ -612,7 +611,7 @@ namespace CodeImp.DoomBuilder.Windows label1.AutoSize = true; label1.Location = new System.Drawing.Point(28, 29); label1.Name = "label1"; - label1.Size = new System.Drawing.Size(143, 13); + label1.Size = new System.Drawing.Size(135, 13); label1.TabIndex = 20; label1.Text = "Texture and flat brightness:"; label1.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -2100,6 +2099,7 @@ namespace CodeImp.DoomBuilder.Windows this.scripttabwidth.ButtonStepsUseModifierKeys = false; this.scripttabwidth.ButtonStepsWrapAround = false; this.scripttabwidth.Location = new System.Drawing.Point(181, 22); + this.scripttabwidth.MaximumValue = 2147483647; this.scripttabwidth.Name = "scripttabwidth"; this.scripttabwidth.Size = new System.Drawing.Size(71, 24); this.scripttabwidth.StepValues = null; @@ -2464,7 +2464,6 @@ namespace CodeImp.DoomBuilder.Windows // this.previewgroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.previewgroup.Controls.Add(this.scriptedit); this.previewgroup.Location = new System.Drawing.Point(217, 344); this.previewgroup.Name = "previewgroup"; this.previewgroup.Size = new System.Drawing.Size(457, 157); @@ -2472,13 +2471,6 @@ namespace CodeImp.DoomBuilder.Windows this.previewgroup.TabStop = false; this.previewgroup.Text = " Preview "; // - // scriptedit - // - this.scriptedit.Location = new System.Drawing.Point(6, 19); - this.scriptedit.Name = "scriptedit"; - this.scriptedit.Size = new System.Drawing.Size(445, 132); - this.scriptedit.TabIndex = 0; - // // tabpasting // this.tabpasting.Controls.Add(this.label16); @@ -2589,7 +2581,6 @@ namespace CodeImp.DoomBuilder.Windows this.groupBox7.PerformLayout(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); - this.previewgroup.ResumeLayout(false); this.tabpasting.ResumeLayout(false); this.ResumeLayout(false); @@ -2715,7 +2706,6 @@ namespace CodeImp.DoomBuilder.Windows private System.Windows.Forms.Label label26; private System.Windows.Forms.CheckBox locatetexturegroup; private System.Windows.Forms.CheckBox cbStoreEditTab; - private System.Windows.Forms.CheckBox checkforupdates; private System.Windows.Forms.TrackBar maxBackups; private System.Windows.Forms.Label labelBackups; private System.Windows.Forms.Label label27; @@ -2778,5 +2768,6 @@ namespace CodeImp.DoomBuilder.Windows private System.Windows.Forms.CheckBox cbDrawThingsFixedSize; private System.Windows.Forms.Label labelDefaultThingSize; private System.Windows.Forms.TrackBar tbDefaultThingSize; + private System.Windows.Forms.CheckBox keepfilterfocused; } } \ No newline at end of file diff --git a/Source/Core/Windows/PreferencesForm.cs b/Source/Core/Windows/PreferencesForm.cs index 6e0aab3..3b77025 100644 --- a/Source/Core/Windows/PreferencesForm.cs +++ b/Source/Core/Windows/PreferencesForm.cs @@ -90,8 +90,8 @@ namespace CodeImp.DoomBuilder.Windows //mxd locatetexturegroup.Checked = General.Settings.LocateTextureGroup; + keepfilterfocused.Checked = General.Settings.KeepTextureFilterFocused; cbStoreEditTab.Checked = General.Settings.StoreSelectedEditTab; - checkforupdates.Checked = General.Settings.CheckForUpdates; toolbar_gzdoom.Checked = General.Settings.GZToolbarGZDoom; cbSynchCameras.Checked = General.Settings.GZSynchCameras; tbDynLightCount.Value = General.Clamp(General.Settings.GZMaxDynamicLights, tbDynLightCount.Minimum, tbDynLightCount.Maximum); @@ -298,8 +298,8 @@ namespace CodeImp.DoomBuilder.Windows General.Settings.GZToolbarGZDoom = toolbar_gzdoom.Checked; //mxd General.Settings.ShowTextureSizes = showtexturesizes.Checked; General.Settings.StoreSelectedEditTab = cbStoreEditTab.Checked; //mxd - General.Settings.CheckForUpdates = checkforupdates.Checked; //mxd General.Settings.LocateTextureGroup = locatetexturegroup.Checked; //mxd + General.Settings.KeepTextureFilterFocused = keepfilterfocused.Checked; //mxd General.Settings.MaxRecentFiles = recentFiles.Value; //mxd General.Settings.MaxBackups = maxBackups.Value; General.Settings.ScreenshotsPath = screenshotsfolderpath.Text.Trim(); //mxd