diff --git a/NppNavigateTo/Forms/FrmNavigateTo.cs b/NppNavigateTo/Forms/FrmNavigateTo.cs index 4ff9796..2029503 100644 --- a/NppNavigateTo/Forms/FrmNavigateTo.cs +++ b/NppNavigateTo/Forms/FrmNavigateTo.cs @@ -42,6 +42,14 @@ partial class FrmNavigateTo : Form public List SelectedFiles { get; set; } + public string[] filesInCurrentDirectory { get; set; } + + public bool shouldReloadFilesInDirectory { get; set; } + + public long lastDirectoryReloadTimeTicks { get; set; } + + public bool isShuttingDown { get; set; } + public bool IsFuzzyResult { get; set; } public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad) @@ -49,30 +57,51 @@ public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad) this.editor = editor; this.notepad = notepad; this.SelectedFiles = new List(); + filesInCurrentDirectory = null; + shouldReloadFilesInDirectory = true; IsFuzzyResult = false; InitializeComponent(); ReloadFileList(); this.notepad.ReloadMenuItems(); } - void SearchInCurrentDirectory(string s, string searchPattern1) + private static bool MatchesAllWordsInFilter(string s, string[] words) + { + return words.All(word => + s.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) >= 0 + ); + } + + void SearchInCurrentDirectory(string[] words) { string currentFilePath = notepad.GetCurrentFileDirectory(); - if (!String.IsNullOrWhiteSpace(currentFilePath)) - { - bool searchInSubDirs = FrmSettings.Settings.GetBoolSetting(Settings.searchInSubDirs); - foreach (var filePath in Directory.GetFiles(currentFilePath, searchPattern1, - searchInSubDirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) - .AsParallel().Where(e => - e.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0 || - e.Contains(s)) - .ToList()) + if (string.IsNullOrWhiteSpace(currentFilePath)) + return; + bool searchInSubDirs = FrmSettings.Settings.GetBoolSetting(Settings.searchInSubDirs); + long nextTimeToRefresh = lastDirectoryReloadTimeTicks + + 10_000_000 * FrmSettings.Settings.GetIntSetting(Settings.secondsBetweenDirectoryScans); // 10 million ticks/sec + if (shouldReloadFilesInDirectory || + filesInCurrentDirectory == null || + DateTime.UtcNow.Ticks >= nextTimeToRefresh) + { + // only load the files in current directory as needed + // the correct files to load will depend on the active buffer + filesInCurrentDirectory = Directory.GetFiles( + currentFilePath, + "*.*", + searchInSubDirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly + ); + shouldReloadFilesInDirectory = false; + lastDirectoryReloadTimeTicks = DateTime.UtcNow.Ticks; + } + foreach (var filePath in filesInCurrentDirectory + .AsParallel().Where(fname => MatchesAllWordsInFilter(fname, words)) + .ToList()) + { + if (!FilteredFileList.Exists(file => file.FilePath.Equals(filePath))) { - if (!FilteredFileList.Exists(file => file.FilePath.Equals(filePath))) - { - FilteredFileList.Add(new FileModel(Path.GetFileName(filePath), filePath, -1, -1, - searchInSubDirs ? FOLDER_SUB : FOLDER_TOP, 0)); - } + FilteredFileList.Add(new FileModel(Path.GetFileName(filePath), filePath, -1, -1, + searchInSubDirs ? FOLDER_SUB : FOLDER_TOP, 0)); } } } @@ -117,16 +146,17 @@ public void FilterDataGrid(string filter) } else { + var words = filter.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); searchInTabs(filter); if (FrmSettings.Settings.GetBoolSetting(Settings.searchInCurrentFolder)) { - SearchInCurrentDirectory(filter, searchPattern); + SearchInCurrentDirectory(words); } if (FrmSettings.Settings.GetBoolSetting(Settings.searchMenuCommands)) { - FilterMenuCommands(filter); + FilterMenuCommands(words); } FilteredFileList.ForEach(file => @@ -181,13 +211,11 @@ private void searchInTabs(string filter) if (FrmSettings.Settings.GetBoolSetting(Settings.preferFilenameResults)) { FilteredFileList = FileList.AsParallel() - .Where(e => words.All(word => - e.FileName.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) >= 0)) + .Where(e => MatchesAllWordsInFilter(e.FileName, words)) .ToList(); FileList.AsParallel() - .Where(e => words.All(word => - e.FilePath.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0)) + .Where(e => MatchesAllWordsInFilter(e.FilePath, words)) .ToList().ForEach(filePath => { if (!FilteredFileList.Exists(file => file.FilePath.Equals(filePath.FilePath))) @@ -200,10 +228,10 @@ private void searchInTabs(string filter) else { FilteredFileList = FileList.AsParallel() - .Where(e => words.All(word => - e.FilePath.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) >= 0 || - e.FileName.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) >= 0)) - .ToList(); + .Where(e => + MatchesAllWordsInFilter(e.FilePath, words) || + MatchesAllWordsInFilter(e.FileName, words) + ).ToList(); } } @@ -236,11 +264,11 @@ private void searchInTabs(string filter) } } - private void FilterMenuCommands(string filter) + private void FilterMenuCommands(string[] filterWords) { - foreach (var nppMenuCmd in notepad.MainMenuItems.AsParallel().Where(e => e.Value.IndexOf(filter, - StringComparison.CurrentCultureIgnoreCase) >= 0 || - e.Value.Contains(filter)).ToList()) + foreach (var nppMenuCmd in notepad.MainMenuItems.AsParallel().Where(e => + MatchesAllWordsInFilter(e.Value, filterWords) + ).ToList()) { FilteredFileList.Add(new FileModel( nppMenuCmd.Key.ToString(), diff --git a/NppNavigateTo/Forms/FrmSettings.cs b/NppNavigateTo/Forms/FrmSettings.cs index 7e993b1..e15e7c4 100644 --- a/NppNavigateTo/Forms/FrmSettings.cs +++ b/NppNavigateTo/Forms/FrmSettings.cs @@ -62,6 +62,7 @@ private void frmSettings_Shown(object sender, EventArgs e) numericUpDownMinGridWidth.Value = Settings.GetIntSetting(Settings.gridMinWidth); checkBoxSearchInFolder.Checked = Settings.GetBoolSetting(Settings.searchInCurrentFolder); checkBoxSearchInSubDirs.Checked = Settings.GetBoolSetting(Settings.searchInSubDirs); + numUpDownSecsBetweenDirectoryScans.Value = Settings.GetIntSetting(Settings.secondsBetweenDirectoryScans); checkBoxSearchMenu.Checked = Settings.GetBoolSetting(Settings.searchMenuCommands); checkBoxCleanSearch.Checked = Settings.GetBoolSetting(Settings.clearOnClose); checkBoxKeepSelected.Checked = Settings.GetBoolSetting(Settings.selectFirstRowOnFilter); @@ -333,5 +334,10 @@ private void buttonRowBackgroud_Click(object sender, EventArgs e) RefreshDataGridStyles(); } + + private void secondsBetweenDirectoryScans_ValueChanged(object sender, EventArgs e) + { + Settings.SetIntSetting(Settings.secondsBetweenDirectoryScans, (int)numUpDownSecsBetweenDirectoryScans.Value); + } } } \ No newline at end of file diff --git a/NppNavigateTo/Forms/FrmSettings.designer.cs b/NppNavigateTo/Forms/FrmSettings.designer.cs index 3acab75..54726c5 100644 --- a/NppNavigateTo/Forms/FrmSettings.designer.cs +++ b/NppNavigateTo/Forms/FrmSettings.designer.cs @@ -44,11 +44,14 @@ private void InitializeComponent() this.label5 = new System.Windows.Forms.Label(); this.numericUpDownCharSearchLimit = new System.Windows.Forms.NumericUpDown(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.numUpDownSecsBetweenDirectoryScans = new System.Windows.Forms.NumericUpDown(); + this.label7 = new System.Windows.Forms.Label(); this.numericUpDownFuzzyness = new System.Windows.Forms.NumericUpDown(); this.checkBoxFuzzySearch = new System.Windows.Forms.CheckBox(); this.checkBoxFileNameResults = new System.Windows.Forms.CheckBox(); this.checkBoxSearchMenu = new System.Windows.Forms.CheckBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.buttonRowBackgroud = new System.Windows.Forms.Button(); this.gridBackground = new System.Windows.Forms.Button(); this.buttonResetStyle = new System.Windows.Forms.Button(); this.buttonSelectedRowText = new System.Windows.Forms.Button(); @@ -63,12 +66,12 @@ private void InitializeComponent() this.ColumnPath = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnView = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.label2 = new System.Windows.Forms.Label(); - this.buttonRowBackgroud = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMinGridWidth)).BeginInit(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCharSearchLimit)).BeginInit(); this.groupBox3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numUpDownSecsBetweenDirectoryScans)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownFuzzyness)).BeginInit(); this.groupBox4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridFileListPreview)).BeginInit(); @@ -77,9 +80,10 @@ private void InitializeComponent() // keepOpenDlgCheckBox // this.keepOpenDlgCheckBox.AutoSize = true; - this.keepOpenDlgCheckBox.Location = new System.Drawing.Point(6, 28); + this.keepOpenDlgCheckBox.Location = new System.Drawing.Point(8, 34); + this.keepOpenDlgCheckBox.Margin = new System.Windows.Forms.Padding(4); this.keepOpenDlgCheckBox.Name = "keepOpenDlgCheckBox"; - this.keepOpenDlgCheckBox.Size = new System.Drawing.Size(114, 17); + this.keepOpenDlgCheckBox.Size = new System.Drawing.Size(144, 20); this.keepOpenDlgCheckBox.TabIndex = 2; this.keepOpenDlgCheckBox.Text = "Keep dialog visible"; this.keepOpenDlgCheckBox.UseVisualStyleBackColor = true; @@ -90,9 +94,11 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.checkBoxKeepSelected); this.groupBox1.Controls.Add(this.checkBoxCleanSearch); this.groupBox1.Controls.Add(this.keepOpenDlgCheckBox); - this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Location = new System.Drawing.Point(16, 15); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(283, 111); + this.groupBox1.Padding = new System.Windows.Forms.Padding(4); + this.groupBox1.Size = new System.Drawing.Size(377, 137); this.groupBox1.TabIndex = 4; this.groupBox1.TabStop = false; this.groupBox1.Text = "General"; @@ -100,9 +106,10 @@ private void InitializeComponent() // checkBoxKeepSelected // this.checkBoxKeepSelected.AutoSize = true; - this.checkBoxKeepSelected.Location = new System.Drawing.Point(6, 74); + this.checkBoxKeepSelected.Location = new System.Drawing.Point(8, 91); + this.checkBoxKeepSelected.Margin = new System.Windows.Forms.Padding(4); this.checkBoxKeepSelected.Name = "checkBoxKeepSelected"; - this.checkBoxKeepSelected.Size = new System.Drawing.Size(143, 17); + this.checkBoxKeepSelected.Size = new System.Drawing.Size(176, 20); this.checkBoxKeepSelected.TabIndex = 4; this.checkBoxKeepSelected.Text = "Keep First Row Selected"; this.checkBoxKeepSelected.UseVisualStyleBackColor = true; @@ -111,9 +118,10 @@ private void InitializeComponent() // checkBoxCleanSearch // this.checkBoxCleanSearch.AutoSize = true; - this.checkBoxCleanSearch.Location = new System.Drawing.Point(6, 51); + this.checkBoxCleanSearch.Location = new System.Drawing.Point(8, 63); + this.checkBoxCleanSearch.Margin = new System.Windows.Forms.Padding(4); this.checkBoxCleanSearch.Name = "checkBoxCleanSearch"; - this.checkBoxCleanSearch.Size = new System.Drawing.Size(111, 17); + this.checkBoxCleanSearch.Size = new System.Drawing.Size(136, 20); this.checkBoxCleanSearch.TabIndex = 3; this.checkBoxCleanSearch.Text = "Clear search input"; this.checkBoxCleanSearch.UseVisualStyleBackColor = true; @@ -122,9 +130,10 @@ private void InitializeComponent() // checkBoxSearchInFolder // this.checkBoxSearchInFolder.AutoSize = true; - this.checkBoxSearchInFolder.Location = new System.Drawing.Point(6, 19); + this.checkBoxSearchInFolder.Location = new System.Drawing.Point(8, 23); + this.checkBoxSearchInFolder.Margin = new System.Windows.Forms.Padding(4); this.checkBoxSearchInFolder.Name = "checkBoxSearchInFolder"; - this.checkBoxSearchInFolder.Size = new System.Drawing.Size(251, 17); + this.checkBoxSearchInFolder.Size = new System.Drawing.Size(337, 21); this.checkBoxSearchInFolder.TabIndex = 5; this.checkBoxSearchInFolder.Text = "Search in current file folder ( Top directory only )"; this.checkBoxSearchInFolder.UseVisualStyleBackColor = true; @@ -133,9 +142,10 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(67, 29); + this.label1.Location = new System.Drawing.Point(89, 36); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(77, 13); + this.label1.Size = new System.Drawing.Size(93, 16); this.label1.TabIndex = 5; this.label1.Text = "Min Grid Width"; // @@ -146,7 +156,8 @@ private void InitializeComponent() 0, 0, 0}); - this.numericUpDownMinGridWidth.Location = new System.Drawing.Point(12, 25); + this.numericUpDownMinGridWidth.Location = new System.Drawing.Point(16, 31); + this.numericUpDownMinGridWidth.Margin = new System.Windows.Forms.Padding(4); this.numericUpDownMinGridWidth.Maximum = new decimal(new int[] { 5000, 0, @@ -158,7 +169,7 @@ private void InitializeComponent() 0, 0}); this.numericUpDownMinGridWidth.Name = "numericUpDownMinGridWidth"; - this.numericUpDownMinGridWidth.Size = new System.Drawing.Size(49, 20); + this.numericUpDownMinGridWidth.Size = new System.Drawing.Size(65, 22); this.numericUpDownMinGridWidth.TabIndex = 4; this.numericUpDownMinGridWidth.Value = new decimal(new int[] { 250, @@ -170,9 +181,10 @@ private void InitializeComponent() // checkBoxSearchInSubDirs // this.checkBoxSearchInSubDirs.AutoSize = true; - this.checkBoxSearchInSubDirs.Location = new System.Drawing.Point(26, 42); + this.checkBoxSearchInSubDirs.Location = new System.Drawing.Point(35, 52); + this.checkBoxSearchInSubDirs.Margin = new System.Windows.Forms.Padding(4); this.checkBoxSearchInSubDirs.Name = "checkBoxSearchInSubDirs"; - this.checkBoxSearchInSubDirs.Size = new System.Drawing.Size(160, 17); + this.checkBoxSearchInSubDirs.Size = new System.Drawing.Size(211, 21); this.checkBoxSearchInSubDirs.TabIndex = 5; this.checkBoxSearchInSubDirs.Text = "Search in sub directories too"; this.checkBoxSearchInSubDirs.UseVisualStyleBackColor = true; @@ -187,9 +199,11 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.numericUpDownCharSearchLimit); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.numericUpDownMinGridWidth); - this.groupBox2.Location = new System.Drawing.Point(311, 12); + this.groupBox2.Location = new System.Drawing.Point(415, 15); + this.groupBox2.Margin = new System.Windows.Forms.Padding(4); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(256, 111); + this.groupBox2.Padding = new System.Windows.Forms.Padding(4); + this.groupBox2.Size = new System.Drawing.Size(341, 137); this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; this.groupBox2.Text = "File List"; @@ -201,9 +215,10 @@ private void InitializeComponent() this.comboBoxSortOrder.Items.AddRange(new object[] { "ASC", "DESC"}); - this.comboBoxSortOrder.Location = new System.Drawing.Point(179, 80); + this.comboBoxSortOrder.Location = new System.Drawing.Point(239, 98); + this.comboBoxSortOrder.Margin = new System.Windows.Forms.Padding(4); this.comboBoxSortOrder.Name = "comboBoxSortOrder"; - this.comboBoxSortOrder.Size = new System.Drawing.Size(53, 21); + this.comboBoxSortOrder.Size = new System.Drawing.Size(69, 24); this.comboBoxSortOrder.TabIndex = 10; this.comboBoxSortOrder.SelectedIndexChanged += new System.EventHandler(this.comboBoxSortOrder_SelectedIndexChanged); // @@ -215,33 +230,37 @@ private void InitializeComponent() "-", "Name", "Path"}); - this.comboBoxSortedByAfterFilter.Location = new System.Drawing.Point(120, 80); + this.comboBoxSortedByAfterFilter.Location = new System.Drawing.Point(160, 98); + this.comboBoxSortedByAfterFilter.Margin = new System.Windows.Forms.Padding(4); this.comboBoxSortedByAfterFilter.Name = "comboBoxSortedByAfterFilter"; - this.comboBoxSortedByAfterFilter.Size = new System.Drawing.Size(53, 21); + this.comboBoxSortedByAfterFilter.Size = new System.Drawing.Size(69, 24); this.comboBoxSortedByAfterFilter.TabIndex = 9; this.comboBoxSortedByAfterFilter.SelectedIndexChanged += new System.EventHandler(this.comboBoxSortedByAfterFilter_SelectedIndexChanged); // // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(12, 83); + this.label6.Location = new System.Drawing.Point(16, 102); + this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(102, 13); + this.label6.Size = new System.Drawing.Size(125, 16); this.label6.TabIndex = 8; this.label6.Text = "Sort after search by:"; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(67, 58); + this.label5.Location = new System.Drawing.Point(89, 71); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(86, 13); + this.label5.Size = new System.Drawing.Size(105, 16); this.label5.TabIndex = 7; this.label5.Text = "Min Char Search"; // // numericUpDownCharSearchLimit // - this.numericUpDownCharSearchLimit.Location = new System.Drawing.Point(12, 56); + this.numericUpDownCharSearchLimit.Location = new System.Drawing.Point(16, 69); + this.numericUpDownCharSearchLimit.Margin = new System.Windows.Forms.Padding(4); this.numericUpDownCharSearchLimit.Maximum = new decimal(new int[] { 10, 0, @@ -253,7 +272,7 @@ private void InitializeComponent() 0, 0}); this.numericUpDownCharSearchLimit.Name = "numericUpDownCharSearchLimit"; - this.numericUpDownCharSearchLimit.Size = new System.Drawing.Size(49, 20); + this.numericUpDownCharSearchLimit.Size = new System.Drawing.Size(65, 22); this.numericUpDownCharSearchLimit.TabIndex = 6; this.numericUpDownCharSearchLimit.Value = new decimal(new int[] { 2, @@ -264,6 +283,8 @@ private void InitializeComponent() // // groupBox3 // + this.groupBox3.Controls.Add(this.numUpDownSecsBetweenDirectoryScans); + this.groupBox3.Controls.Add(this.label7); this.groupBox3.Controls.Add(this.numericUpDownFuzzyness); this.groupBox3.Controls.Add(this.checkBoxFuzzySearch); this.groupBox3.Controls.Add(this.checkBoxFileNameResults); @@ -271,23 +292,59 @@ private void InitializeComponent() this.groupBox3.Controls.Add(this.checkBoxSearchInFolder); this.groupBox3.Controls.Add(this.checkBoxSearchInSubDirs); this.groupBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.groupBox3.Location = new System.Drawing.Point(12, 129); + this.groupBox3.Location = new System.Drawing.Point(16, 159); + this.groupBox3.Margin = new System.Windows.Forms.Padding(4); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(283, 137); + this.groupBox3.Padding = new System.Windows.Forms.Padding(4); + this.groupBox3.Size = new System.Drawing.Size(377, 185); this.groupBox3.TabIndex = 7; this.groupBox3.TabStop = false; this.groupBox3.Text = "Search behavior"; // + // numUpDownSecsBetweenDirectoryScans + // + this.numUpDownSecsBetweenDirectoryScans.Location = new System.Drawing.Point(288, 75); + this.numUpDownSecsBetweenDirectoryScans.Margin = new System.Windows.Forms.Padding(4); + this.numUpDownSecsBetweenDirectoryScans.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numUpDownSecsBetweenDirectoryScans.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numUpDownSecsBetweenDirectoryScans.Name = "numUpDownSecsBetweenDirectoryScans"; + this.numUpDownSecsBetweenDirectoryScans.Size = new System.Drawing.Size(53, 23); + this.numUpDownSecsBetweenDirectoryScans.TabIndex = 13; + this.numUpDownSecsBetweenDirectoryScans.Value = new decimal(new int[] { + 5, + 0, + 0, + 0}); + this.numUpDownSecsBetweenDirectoryScans.ValueChanged += new System.EventHandler(this.secondsBetweenDirectoryScans_ValueChanged); + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(7, 77); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(241, 17); + this.label7.TabIndex = 12; + this.label7.Text = "Refresh file list how often? (seconds)"; + // // numericUpDownFuzzyness // - this.numericUpDownFuzzyness.Location = new System.Drawing.Point(217, 107); + this.numericUpDownFuzzyness.Location = new System.Drawing.Point(288, 153); + this.numericUpDownFuzzyness.Margin = new System.Windows.Forms.Padding(4); this.numericUpDownFuzzyness.Maximum = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDownFuzzyness.Name = "numericUpDownFuzzyness"; - this.numericUpDownFuzzyness.Size = new System.Drawing.Size(40, 20); + this.numericUpDownFuzzyness.Size = new System.Drawing.Size(53, 23); this.numericUpDownFuzzyness.TabIndex = 11; this.numericUpDownFuzzyness.Value = new decimal(new int[] { 1, @@ -299,9 +356,10 @@ private void InitializeComponent() // checkBoxFuzzySearch // this.checkBoxFuzzySearch.AutoSize = true; - this.checkBoxFuzzySearch.Location = new System.Drawing.Point(6, 110); + this.checkBoxFuzzySearch.Location = new System.Drawing.Point(7, 156); + this.checkBoxFuzzySearch.Margin = new System.Windows.Forms.Padding(4); this.checkBoxFuzzySearch.Name = "checkBoxFuzzySearch"; - this.checkBoxFuzzySearch.Size = new System.Drawing.Size(205, 17); + this.checkBoxFuzzySearch.Size = new System.Drawing.Size(274, 21); this.checkBoxFuzzySearch.TabIndex = 8; this.checkBoxFuzzySearch.Text = "Fuzzy search (Tabs Only) - Tolerance:"; this.checkBoxFuzzySearch.UseVisualStyleBackColor = true; @@ -310,9 +368,10 @@ private void InitializeComponent() // checkBoxFileNameResults // this.checkBoxFileNameResults.AutoSize = true; - this.checkBoxFileNameResults.Location = new System.Drawing.Point(6, 87); + this.checkBoxFileNameResults.Location = new System.Drawing.Point(7, 128); + this.checkBoxFileNameResults.Margin = new System.Windows.Forms.Padding(4); this.checkBoxFileNameResults.Name = "checkBoxFileNameResults"; - this.checkBoxFileNameResults.Size = new System.Drawing.Size(144, 17); + this.checkBoxFileNameResults.Size = new System.Drawing.Size(190, 21); this.checkBoxFileNameResults.TabIndex = 7; this.checkBoxFileNameResults.Text = "Prefer filename over path"; this.checkBoxFileNameResults.UseVisualStyleBackColor = true; @@ -321,9 +380,10 @@ private void InitializeComponent() // checkBoxSearchMenu // this.checkBoxSearchMenu.AutoSize = true; - this.checkBoxSearchMenu.Location = new System.Drawing.Point(6, 65); + this.checkBoxSearchMenu.Location = new System.Drawing.Point(7, 101); + this.checkBoxSearchMenu.Margin = new System.Windows.Forms.Padding(4); this.checkBoxSearchMenu.Name = "checkBoxSearchMenu"; - this.checkBoxSearchMenu.Size = new System.Drawing.Size(211, 17); + this.checkBoxSearchMenu.Size = new System.Drawing.Size(280, 21); this.checkBoxSearchMenu.TabIndex = 6; this.checkBoxSearchMenu.Text = "Search menu commands (experimental)"; this.checkBoxSearchMenu.UseVisualStyleBackColor = true; @@ -340,18 +400,32 @@ private void InitializeComponent() this.groupBox4.Controls.Add(this.label3); this.groupBox4.Controls.Add(this.buttonGridTextColor); this.groupBox4.Controls.Add(this.button1); - this.groupBox4.Location = new System.Drawing.Point(311, 129); + this.groupBox4.Location = new System.Drawing.Point(415, 159); + this.groupBox4.Margin = new System.Windows.Forms.Padding(4); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(256, 137); + this.groupBox4.Padding = new System.Windows.Forms.Padding(4); + this.groupBox4.Size = new System.Drawing.Size(341, 184); this.groupBox4.TabIndex = 8; this.groupBox4.TabStop = false; this.groupBox4.Text = "Appearance"; // + // buttonRowBackgroud + // + this.buttonRowBackgroud.Location = new System.Drawing.Point(16, 135); + this.buttonRowBackgroud.Margin = new System.Windows.Forms.Padding(4); + this.buttonRowBackgroud.Name = "buttonRowBackgroud"; + this.buttonRowBackgroud.Size = new System.Drawing.Size(152, 28); + this.buttonRowBackgroud.TabIndex = 9; + this.buttonRowBackgroud.Text = "Row Background"; + this.buttonRowBackgroud.UseVisualStyleBackColor = true; + this.buttonRowBackgroud.Click += new System.EventHandler(this.buttonRowBackgroud_Click); + // // gridBackground // - this.gridBackground.Location = new System.Drawing.Point(12, 83); + this.gridBackground.Location = new System.Drawing.Point(16, 102); + this.gridBackground.Margin = new System.Windows.Forms.Padding(4); this.gridBackground.Name = "gridBackground"; - this.gridBackground.Size = new System.Drawing.Size(114, 23); + this.gridBackground.Size = new System.Drawing.Size(152, 28); this.gridBackground.TabIndex = 8; this.gridBackground.Text = "Grid Background"; this.gridBackground.UseVisualStyleBackColor = true; @@ -359,9 +433,10 @@ private void InitializeComponent() // // buttonResetStyle // - this.buttonResetStyle.Location = new System.Drawing.Point(203, 94); + this.buttonResetStyle.Location = new System.Drawing.Point(271, 116); + this.buttonResetStyle.Margin = new System.Windows.Forms.Padding(4); this.buttonResetStyle.Name = "buttonResetStyle"; - this.buttonResetStyle.Size = new System.Drawing.Size(47, 23); + this.buttonResetStyle.Size = new System.Drawing.Size(63, 28); this.buttonResetStyle.TabIndex = 7; this.buttonResetStyle.Text = "Reset"; this.buttonResetStyle.UseVisualStyleBackColor = true; @@ -369,9 +444,10 @@ private void InitializeComponent() // // buttonSelectedRowText // - this.buttonSelectedRowText.Location = new System.Drawing.Point(179, 53); + this.buttonSelectedRowText.Location = new System.Drawing.Point(239, 65); + this.buttonSelectedRowText.Margin = new System.Windows.Forms.Padding(4); this.buttonSelectedRowText.Name = "buttonSelectedRowText"; - this.buttonSelectedRowText.Size = new System.Drawing.Size(40, 23); + this.buttonSelectedRowText.Size = new System.Drawing.Size(53, 28); this.buttonSelectedRowText.TabIndex = 6; this.buttonSelectedRowText.Text = "Text"; this.buttonSelectedRowText.UseVisualStyleBackColor = true; @@ -379,9 +455,10 @@ private void InitializeComponent() // // buttonSelectedRowBack // - this.buttonSelectedRowBack.Location = new System.Drawing.Point(99, 53); + this.buttonSelectedRowBack.Location = new System.Drawing.Point(132, 65); + this.buttonSelectedRowBack.Margin = new System.Windows.Forms.Padding(4); this.buttonSelectedRowBack.Name = "buttonSelectedRowBack"; - this.buttonSelectedRowBack.Size = new System.Drawing.Size(74, 23); + this.buttonSelectedRowBack.Size = new System.Drawing.Size(99, 28); this.buttonSelectedRowBack.TabIndex = 5; this.buttonSelectedRowBack.Text = "Background"; this.buttonSelectedRowBack.UseVisualStyleBackColor = true; @@ -390,26 +467,29 @@ private void InitializeComponent() // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(9, 58); + this.label4.Location = new System.Drawing.Point(12, 71); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(74, 13); + this.label4.Size = new System.Drawing.Size(91, 16); this.label4.TabIndex = 4; this.label4.Text = "Selected Row"; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(9, 24); + this.label3.Location = new System.Drawing.Point(12, 30); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(48, 13); + this.label3.Size = new System.Drawing.Size(59, 16); this.label3.TabIndex = 3; this.label3.Text = "Highlight"; // // buttonGridTextColor // - this.buttonGridTextColor.Location = new System.Drawing.Point(179, 19); + this.buttonGridTextColor.Location = new System.Drawing.Point(239, 23); + this.buttonGridTextColor.Margin = new System.Windows.Forms.Padding(4); this.buttonGridTextColor.Name = "buttonGridTextColor"; - this.buttonGridTextColor.Size = new System.Drawing.Size(40, 23); + this.buttonGridTextColor.Size = new System.Drawing.Size(53, 28); this.buttonGridTextColor.TabIndex = 2; this.buttonGridTextColor.Text = "Text"; this.buttonGridTextColor.UseVisualStyleBackColor = true; @@ -417,9 +497,10 @@ private void InitializeComponent() // // button1 // - this.button1.Location = new System.Drawing.Point(99, 19); + this.button1.Location = new System.Drawing.Point(132, 23); + this.button1.Margin = new System.Windows.Forms.Padding(4); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(74, 23); + this.button1.Size = new System.Drawing.Size(99, 28); this.button1.TabIndex = 1; this.button1.Text = "Background"; this.button1.UseVisualStyleBackColor = true; @@ -449,13 +530,15 @@ private void InitializeComponent() dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridFileListPreview.DefaultCellStyle = dataGridViewCellStyle1; - this.dataGridFileListPreview.Location = new System.Drawing.Point(12, 285); + this.dataGridFileListPreview.Location = new System.Drawing.Point(16, 378); + this.dataGridFileListPreview.Margin = new System.Windows.Forms.Padding(4); this.dataGridFileListPreview.Name = "dataGridFileListPreview"; this.dataGridFileListPreview.ReadOnly = true; this.dataGridFileListPreview.RowHeadersVisible = false; + this.dataGridFileListPreview.RowHeadersWidth = 51; this.dataGridFileListPreview.RowTemplate.ReadOnly = true; this.dataGridFileListPreview.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridFileListPreview.Size = new System.Drawing.Size(555, 144); + this.dataGridFileListPreview.Size = new System.Drawing.Size(740, 195); this.dataGridFileListPreview.TabIndex = 9; this.dataGridFileListPreview.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.dataGridFileListPreview_CellPainting); this.dataGridFileListPreview.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.dataGridFileListPreview_ColumnWidthChanged); @@ -490,33 +573,25 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(15, 269); + this.label2.Location = new System.Drawing.Point(20, 353); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(48, 13); + this.label2.Size = new System.Drawing.Size(58, 16); this.label2.TabIndex = 10; this.label2.Text = "Preview:"; // - // buttonRowBackgroud - // - this.buttonRowBackgroud.Location = new System.Drawing.Point(12, 110); - this.buttonRowBackgroud.Name = "buttonRowBackgroud"; - this.buttonRowBackgroud.Size = new System.Drawing.Size(114, 23); - this.buttonRowBackgroud.TabIndex = 9; - this.buttonRowBackgroud.Text = "Row Background"; - this.buttonRowBackgroud.UseVisualStyleBackColor = true; - this.buttonRowBackgroud.Click += new System.EventHandler(this.buttonRowBackgroud_Click); - // // FrmSettings // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(579, 443); + this.ClientSize = new System.Drawing.Size(772, 583); this.Controls.Add(this.label2); this.Controls.Add(this.dataGridFileListPreview); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "FrmSettings"; this.ShowIcon = false; this.Text = "Navigate To - Settings"; @@ -532,6 +607,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCharSearchLimit)).EndInit(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numUpDownSecsBetweenDirectoryScans)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownFuzzyness)).EndInit(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); @@ -577,5 +653,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox checkBoxFuzzySearch; private System.Windows.Forms.NumericUpDown numericUpDownFuzzyness; private System.Windows.Forms.Button buttonRowBackgroud; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.NumericUpDown numUpDownSecsBetweenDirectoryScans; } } \ No newline at end of file diff --git a/NppNavigateTo/NppNavigateTo.cs b/NppNavigateTo/NppNavigateTo.cs index f74ef09..95cd40d 100644 --- a/NppNavigateTo/NppNavigateTo.cs +++ b/NppNavigateTo/NppNavigateTo.cs @@ -1,6 +1,7 @@ // NPP plugin platform for .Net v0.91.57 by Kasper B. Graversen etc. using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Drawing; @@ -46,25 +47,33 @@ static internal void SetToolBarIcon() public static void OnNotification(ScNotification notification) { - if (NavigateTo.Plugin.Namespace.Main.frmNavigateTo != null) + switch (notification.Header.Code) { - switch (notification.Header.Code) - { - case (uint)NppMsg.NPPN_FILEOPENED: - case (uint)NppMsg.NPPN_FILECLOSED: - case (uint)NppMsg.NPPN_FILERENAMED: - case (uint)NppMsg.NPPN_FILELOADFAILED: - case (uint)NppMsg.NPPN_FILEDELETED: - case (uint)NppMsg.NPPN_DOCORDERCHANGED: - case (uint)NppMsg.NPPN_BUFFERACTIVATED: - NavigateTo.Plugin.Namespace.Main.frmNavigateTo.ReloadFileList(); - NavigateTo.Plugin.Namespace.Main.frmNavigateTo.FilterDataGrid(""); - // if the user has multiple instances or views open, - // having a static unchanging editor object no longer works. - // this makes the editor track the current instance. - NavigateTo.Plugin.Namespace.Main.editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); - break; - } + case (uint)NppMsg.NPPN_BEFORESHUTDOWN: + NavigateTo.Plugin.Namespace.Main.isShuttingDown = true; + break; + case (uint)NppMsg.NPPN_FILEOPENED: + case (uint)NppMsg.NPPN_FILECLOSED: + case (uint)NppMsg.NPPN_FILERENAMED: + case (uint)NppMsg.NPPN_FILELOADFAILED: + case (uint)NppMsg.NPPN_FILEDELETED: + case (uint)NppMsg.NPPN_DOCORDERCHANGED: + case (uint)NppMsg.NPPN_BUFFERACTIVATED: + // if the user has multiple instances or views open, + // having a static unchanging editor object no longer works. + // this makes the editor track the current instance. + NavigateTo.Plugin.Namespace.Main.editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); + var frmNavigateTo = NavigateTo.Plugin.Namespace.Main.frmNavigateTo; + if (frmNavigateTo == null || NavigateTo.Plugin.Namespace.Main.isShuttingDown) + // a bunch of NPPN_BUFFERACTIVATED events fire when Notepad++ is shutting down + // which will lead to this being called repeatedly + return; + frmNavigateTo.shouldReloadFilesInDirectory = notification.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED; + if (!frmNavigateTo.Visible) + return; + frmNavigateTo.ReloadFileList(); + frmNavigateTo.FilterDataGrid(""); + break; } } @@ -97,6 +106,7 @@ class Main static INotepadPPGateway notepad = new NotepadPPGateway(); public static FrmNavigateTo frmNavigateTo = null; public static FrmSettings frmSettings = new FrmSettings(editor, notepad); + public static bool isShuttingDown = false; #endregion diff --git a/NppNavigateTo/NppNavigateTo.csproj b/NppNavigateTo/NppNavigateTo.csproj index b8f7dac..c3d5bd3 100644 --- a/NppNavigateTo/NppNavigateTo.csproj +++ b/NppNavigateTo/NppNavigateTo.csproj @@ -10,7 +10,7 @@ Properties NppPluginNET NavigateTo - v4.0 + v4.8 3.5 {EB8FC3A3-93E8-457B-B281-FAFA5119611A} diff --git a/NppNavigateTo/Settings.cs b/NppNavigateTo/Settings.cs index 3f2fbf2..6b2be22 100644 --- a/NppNavigateTo/Settings.cs +++ b/NppNavigateTo/Settings.cs @@ -33,6 +33,7 @@ internal class Settings public static string sortOrderAfterFilterBy = "sortOrderAfterFilterBy"; public static string fuzzySearch = "fuzzySearch"; public static string fuzzynessTolerance = "fuzzynessTolerance"; + public static string secondsBetweenDirectoryScans = "secondsBetweenDirectoryScans"; static string iniFilePath; static string lpAppName = "NavigateTo"; @@ -146,6 +147,7 @@ public void LoadConfigValues() Win32.GetPrivateProfileInt(lpAppName, fuzzynessTolerance, 1, iniFilePath)); LoadIntSetting(rowBackgroundColor, Win32.GetPrivateProfileInt(lpAppName, rowBackgroundColor, -1, iniFilePath)); + LoadIntSetting(secondsBetweenDirectoryScans, Win32.GetPrivateProfileInt(lpAppName, secondsBetweenDirectoryScans, 5, iniFilePath)); } public void SetColorSetting(String name, Color color)