OSDN Git Service

AppliStation-GUI,検索用テキストボックスをToolStripWeb2LikeTextBoxとして独立コンポーネントとして分離
authorttp <ttp@users.sourceforge.jp>
Fri, 2 May 2008 12:54:44 +0000 (12:54 +0000)
committerttp <ttp@users.sourceforge.jp>
Fri, 2 May 2008 12:54:44 +0000 (12:54 +0000)
git-svn-id: http://localhost/svn/AppliStation/trunk@894 34ed2c89-c49f-4a4b-abdb-c318350108cf

AppliStation/AppliStation.Util/ToolStripWeb2LikeTextBox.cs [new file with mode: 0644]
AppliStation/AppliStation.csproj
AppliStation/PackageListViewForm.Designer.cs
AppliStation/PackageListViewForm.cs

diff --git a/AppliStation/AppliStation.Util/ToolStripWeb2LikeTextBox.cs b/AppliStation/AppliStation.Util/ToolStripWeb2LikeTextBox.cs
new file mode 100644 (file)
index 0000000..88d48fe
--- /dev/null
@@ -0,0 +1,187 @@
+using System;\r
+using System.ComponentModel;\r
+using System.Windows.Forms;\r
+using System.Drawing;\r
+\r
+namespace AppliStation.Util\r
+{\r
+       public class ToolStripWeb2LikeTextBox : ToolStripTextBox\r
+       {\r
+               public ToolStripWeb2LikeTextBox() : base()\r
+               {\r
+                       this.Text = string.Empty;\r
+               }\r
+                               \r
+               [Category("Action")]\r
+               public event EventHandler TextChangedTriggerFired;\r
+               \r
+               private int textChangedTriggerInterval = 500;\r
+               \r
+               /// <summary>\r
+               /// Interval time for TextChangedTriggerFired.\r
+               /// </summary>\r
+               [Category("Behavior")]\r
+               [DefaultValue(500)]\r
+               public virtual int TextChangedTriggerInterval {\r
+                       get { return textChangedTriggerInterval; }\r
+                       set { textChangedTriggerInterval = value; }\r
+               }\r
+               \r
+               \r
+               private string oldText = null;\r
+               public void FireTextChangedTrigger(EventArgs e)\r
+               {\r
+                       textChangeTriggerTimerStop();\r
+                       \r
+                       if (oldText != this.Text) {\r
+                               if (TextChangedTriggerFired != null) {\r
+                                       TextChangedTriggerFired(this, e);\r
+                               }\r
+                               oldText = this.Text;\r
+                       }\r
+               }\r
+               public void FireTextChangedTrigger()\r
+               {\r
+                       FireTextChangedTrigger(EventArgs.Empty);\r
+               }\r
+               \r
+               #region TextChange Timers\r
+               \r
+               /// <summary>\r
+               /// Timer for TextChangedTriggerFired.\r
+               /// </summary>\r
+               protected Timer textChangeTriggerTimer = null;\r
+               \r
+               private void onTextUpdate(bool force)\r
+               {\r
+                       textChangeTriggerTimerStop();\r
+                       \r
+                       textChangeTriggerTimer = new Timer();\r
+                       textChangeTriggerTimer.Tick += textChangeTriggerTimerTick;\r
+                       textChangeTriggerTimer.Interval = TextChangedTriggerInterval;\r
+                       textChangeTriggerTimer.Start();\r
+               }\r
+                               \r
+               private void textChangeTriggerTimerTick(object sender, EventArgs e)\r
+               {\r
+                       FireTextChangedTrigger(e);\r
+               }\r
+               \r
+               private void textChangeTriggerTimerStop()\r
+               {\r
+                       if (textChangeTriggerTimer != null) {\r
+                               textChangeTriggerTimer.Stop();\r
+                               textChangeTriggerTimer = null;\r
+                       }\r
+               }\r
+               \r
+               protected override void OnTextChanged(EventArgs e)\r
+               {\r
+                       base.OnTextChanged(e);\r
+                       \r
+                       if (Focused) {\r
+                               onTextUpdate(false);\r
+                       }\r
+               }\r
+               \r
+               #endregion\r
+               \r
+               protected bool textIsEmpty = true;\r
+               \r
+               public override string Text {\r
+                       get { return textIsEmpty? string.Empty : base.Text; }\r
+                       set {\r
+                               bool changed = false;\r
+                               if (string.IsNullOrEmpty(value)) {\r
+                                       if (! textIsEmpty) {\r
+                                               changed = true;\r
+                                       \r
+                                               textIsEmpty = true;\r
+                                               base.Text = EmptyText;\r
+                                       }\r
+                               } else if (this.Text != value) {\r
+                                       changed = true;\r
+                                       \r
+                                       textIsEmpty = false;\r
+                                       base.Text = value;\r
+                               }\r
+                               \r
+                               if (changed) {\r
+                                       FireTextChangedTrigger(EventArgs.Empty);\r
+                                       base.OnTextChanged(EventArgs.Empty);\r
+                                       \r
+                                       updateForeColorInternal();\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               private string emptyText = "(none)";\r
+               \r
+               /// <summary>\r
+               /// Gray text when textbox is empty and has not focus\r
+               /// </summary>\r
+               [Category("Appearance")]\r
+               public virtual string EmptyText {\r
+                       get { return emptyText; }\r
+                       set {\r
+                               emptyText = value;\r
+                               \r
+                               if (textIsEmpty) {\r
+                                       base.Text = emptyText;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               private Color emptyForeColor = SystemColors.GrayText;\r
+               \r
+               /// <summary>\r
+               /// Gray text color when textbox is empty and has not focus\r
+               /// </summary>\r
+               [Category("Appearance")]\r
+               [DefaultValue(typeof(Color), "GrayText")]\r
+               public virtual Color EmptyForeColor {\r
+                       get { return emptyForeColor; }\r
+                       set {\r
+                               emptyForeColor = value;\r
+                               updateForeColorInternal();\r
+                       }\r
+               }\r
+               \r
+               private Color foreColor = SystemColors.WindowText;\r
+               \r
+               public override Color ForeColor {\r
+                       get { return foreColor; }\r
+                       set {\r
+                               foreColor = value;\r
+                               updateForeColorInternal();\r
+                       }\r
+               }\r
+               \r
+               protected override void OnEnter(EventArgs e)\r
+               {\r
+                       if (textIsEmpty) {\r
+                               base.Text = string.Empty;\r
+                               textIsEmpty = false;\r
+                               updateForeColorInternal();\r
+                       }\r
+                       \r
+                       base.OnEnter(e);\r
+               }\r
+               \r
+               protected override void OnLeave(EventArgs e)\r
+               {\r
+                       if (string.IsNullOrEmpty(base.Text)) {\r
+                               base.Text = EmptyText;\r
+                               textIsEmpty = true;\r
+                               updateForeColorInternal();\r
+                       }\r
+                       \r
+                       base.OnLeave(e);\r
+               }\r
+               \r
+               private void updateForeColorInternal()\r
+               {\r
+                       base.ForeColor = textIsEmpty? EmptyForeColor : ForeColor;\r
+               }\r
+       }\r
+}\r
index 29cc854..19a005e 100644 (file)
@@ -68,6 +68,7 @@
     <Compile Include="AppliStation.Util\ListViewItemSortComparer.cs" />\r
     <Compile Include="AppliStation.Util\NativeMethods.cs" />\r
     <Compile Include="AppliStation.Util\PackageUtils.cs" />\r
+    <Compile Include="AppliStation.Util\ToolStripWeb2LikeTextBox.cs" />\r
     <Compile Include="AssemblyInfo.cs" />\r
     <Compile Include="ArgParse.cs" />\r
     <Compile Include="InstallerInfoForm.cs" />\r
index 0463240..cb56088 100644 (file)
@@ -39,7 +39,7 @@
                        this.notInstalledPackageFilterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.installedASPackageFilterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.installedSysPackageFilterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
-                       this.searchTextBox = new System.Windows.Forms.ToolStripTextBox();\r
+                       this.searchTextBox = new AppliStation.Util.ToolStripWeb2LikeTextBox();\r
                        this.packageCommandsToolStrip = new System.Windows.Forms.ToolStrip();\r
                        this.updateToolStripButton = new System.Windows.Forms.ToolStripSplitButton();\r
                        this.localUpdateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        // \r
                        // searchTextBox\r
                        // \r
-                       this.searchTextBox.ForeColor = System.Drawing.SystemColors.GrayText;\r
+                       this.searchTextBox.EmptyForeColor = System.Drawing.SystemColors.GrayText;\r
                        this.searchTextBox.Name = "searchTextBox";\r
                        this.searchTextBox.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;\r
                        this.searchTextBox.Size = new System.Drawing.Size(150, 25);\r
-                       this.searchTextBox.Text = "検索";\r
+                       this.searchTextBox.EmptyText = "検索";\r
                        this.searchTextBox.ToolTipText = "検索する語を入力";\r
-                       this.searchTextBox.Enter += new System.EventHandler(this.SearchTextBoxEnter);\r
-                       this.searchTextBox.Leave += new System.EventHandler(this.SearchTextBoxLeave);\r
                        this.searchTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.SearchTextBoxKeyPress);\r
-                       this.searchTextBox.TextChanged += new System.EventHandler(this.SearchTextBoxTextChanged);\r
+                       this.searchTextBox.TextChangedTriggerFired += new System.EventHandler(this.SearchTextBoxTextChangedTriggerFired);\r
                        // \r
                        // packageCommandsToolStrip\r
                        // \r
                private System.Windows.Forms.ToolStripButton installToolStripButton;\r
                private System.Windows.Forms.ToolStrip packageCommandsToolStrip;\r
                private System.Windows.Forms.ToolStrip packageListFilterToolStrip;\r
-               private System.Windows.Forms.ToolStripTextBox searchTextBox;\r
+               private AppliStation.Util.ToolStripWeb2LikeTextBox searchTextBox;\r
                private System.Windows.Forms.ColumnHeader versionHeader;\r
                private System.Windows.Forms.ListView packageListView;\r
                private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;\r
index 474c2ea..ff86c68 100644 (file)
@@ -215,23 +215,18 @@ namespace AppliStation
                        }\r
                        \r
                        updatePackageFilterToolStripMenuItemCheckState();\r
-                       searchTextBoxUpdate(false);\r
+                       searchTextBox.FireTextChangedTrigger();\r
+                       PackageListViewUpdate();\r
                }\r
                \r
                #endregion\r
                \r
-               private string oldSearchKeywords = null;\r
                void PackageListViewUpdate()\r
                {\r
-                       string searchKeywords = this.SearchKeyword;\r
-                       if (oldSearchKeywords == searchKeywords) { // \8dX\90V\82³\82ê\82Ä\82¢\82È\82¢\8fê\8d\87\82Í\8c\9f\8dõ\82µ\82È\82¢\r
-                               return;\r
-                       }\r
-                       \r
                        this.packageListView.Items.Clear();\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
-                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchKeywords)) {\r
+                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
                                        if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // \83C\83\93\83X\83g\81[\83\8b\89Â\94\\r
                                                if (currentPackageFilter == PackageFilterIndex.NotInstalled &&\r
                                                    (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null||\r
@@ -249,7 +244,7 @@ namespace AppliStation
                        }\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledAS) {\r
-                               foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(this.SearchKeyword)) {\r
+                               foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(searchTextBox.Text)) {\r
                                        ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
                                        item.Tag = pkg;\r
                                        item.ToolTipText = pkg.Summary;\r
@@ -260,7 +255,7 @@ namespace AppliStation
                        }\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledSys) {\r
-                               foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(this.SearchKeyword)) {\r
+                               foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(searchTextBox.Text)) {\r
                                        ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
                                        item.Tag = pkg;\r
                                        item.ToolTipText = pkg.Summary;\r
@@ -274,8 +269,6 @@ namespace AppliStation
                        detailBox.Refresh();\r
                        \r
                        //this.packageListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);\r
-                       \r
-                       oldSearchKeywords = searchKeywords; // \89ß\8b\8e\82Ì\8c\9f\8dõ\83L\81[\83\8f\81[\83h\82Æ\82µ\82Ä\8ao\82¦\82Ä\82¨\82­\r
                }\r
                \r
                void PackageDetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
@@ -313,72 +306,20 @@ namespace AppliStation
                \r
                #region searchTextBox\82Ü\82í\82è\r
                \r
-               private bool searchTextBoxIsEmpty = true;\r
-               \r
-               private Timer searchUpdateTimer = null;\r
-               \r
-               string SearchKeyword {\r
-                       get {\r
-                               return searchTextBoxIsEmpty? string.Empty : searchTextBox.Text;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxEnter(object sender, EventArgs e)\r
-               {\r
-                       if (searchTextBoxIsEmpty) {\r
-                               searchTextBox.Text = string.Empty;\r
-                               searchTextBox.ForeColor = DefaultForeColor;\r
-                               searchTextBoxIsEmpty = false;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxLeave(object sender, EventArgs e)\r
-               {\r
-                       if (string.IsNullOrEmpty(searchTextBox.Text)) {\r
-                               searchTextBox.Text = "\8c\9f\8dõ";\r
-                               searchTextBox.ForeColor = SystemColors.GrayText;\r
-                               searchTextBoxIsEmpty = true;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxTextChanged(object sender, EventArgs e)\r
-               {\r
-                       if (searchTextBox.Focused) {\r
-                               searchTextBoxUpdate(false);\r
-                       }\r
-               }\r
-               \r
                void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e)\r
                {\r
                        switch (e.KeyChar) {\r
                                case (char)Keys.Enter:\r
-                                       searchTextBoxUpdate(true);\r
+                                       searchTextBox.FireTextChangedTrigger();\r
                                        break;\r
                                case (char)Keys.Escape:\r
-                                       searchTextBox.Text = "";\r
+                                       searchTextBox.Text = string.Empty;\r
                                        break;\r
                        }\r
                }\r
                \r
-               private void searchTextBoxUpdate(bool force)\r
+               void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
                {\r
-                       if (! this.Created) return;\r
-                       \r
-                       if (searchUpdateTimer != null) {\r
-                               searchUpdateTimer.Stop();\r
-                       } else {\r
-                               searchUpdateTimer = new Timer();\r
-                               searchUpdateTimer.Tick += searchUpdateTimerTick;\r
-                       }\r
-                       searchUpdateTimer.Interval = (force)? 10 : 500;\r
-                       searchUpdateTimer.Start();\r
-               }\r
-               \r
-               private void searchUpdateTimerTick(object sender, EventArgs e)\r
-               {\r
-                       searchUpdateTimer.Stop();\r
-                       searchUpdateTimer = null;\r
-                       \r
                        PackageListViewUpdate();\r
                }\r
                \r