Ejemplo n.º 1
0
 private void InitializeInlineEditing()
 {
     // Add control to listview
     m_textBoxComment             = new PaddedTextBox();
     m_textBoxComment.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     m_textBoxComment.Location    = new System.Drawing.Point(32, 104);
     m_textBoxComment.Name        = "m_textBoxComment";
     m_textBoxComment.Size        = new System.Drawing.Size(80, 16);
     m_textBoxComment.TabIndex    = 3;
     m_textBoxComment.Text        = string.Empty;
     m_textBoxComment.AutoSize    = false;
     m_textBoxComment.Padding     = new Padding(6, 1, 1, 0);
     m_textBoxComment.Visible     = false;
     m_lvEntries.Controls.Add(m_textBoxComment);
 }
Ejemplo n.º 2
0
            private void SetEditBox(PaddedTextBox c, Rectangle rcSubItem, int SubItem)
            {
                if (rcSubItem.X < 0)
                {
                    // Left edge of SubItem not visible - adjust rectangle position and width
                    rcSubItem.Width += rcSubItem.X;
                    rcSubItem.X      = 0;
                }

                if (rcSubItem.X + rcSubItem.Width > m_lvEntries.ClientRectangle.Width)
                {
                    // Right edge of SubItem not visible - adjust rectangle width
                    rcSubItem.Width = m_lvEntries.ClientRectangle.Width - rcSubItem.Left;
                }

                // Calculate editbox height
                //if (c.Lines.Length > 1)
                if (c.Multiline)
                {
                    // Always display only 1 line
                    //rcSubItem.Height *= 1;

                    // Set height depending on lines
                    //rcSubItem.Height *= c.LineCount;
                    rcSubItem.Height = c.CalculateHeight;

                    //c.ScrollBars(true);
                }
                else
                {
                    c.ScrollBars(false);
                }

                // Subitem bounds are relative to the location of the ListView!
                rcSubItem.Offset(m_lvEntries.Left, m_lvEntries.Top);

                // In case the editing control and the listview are on different parents,
                // account for different origins
                Point origin    = new Point(0, 0);
                Point lvOrigin  = m_lvEntries.Parent.PointToScreen(origin);
                Point ctlOrigin = c.Parent.PointToScreen(origin);

                rcSubItem.Offset(lvOrigin.X - ctlOrigin.X, lvOrigin.Y - ctlOrigin.Y);

                // Padding
                Padding pdSubItem = new Padding(6, 1, 1, 0);

                if (SubItem == 0)
                {
                    pdSubItem.Left = 1;
                }
                else if (c.Multiline)
                {
                    pdSubItem.Left = 5;
                }

                // Position, padding and show editor
                if (!c.Bounds.Equals(rcSubItem))
                {
                    c.Bounds = rcSubItem;
                }

                if (!c.Padding.Equals(pdSubItem))
                {
                    c.Padding = pdSubItem;
                }
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Accept or discard current value of cell editor control
            /// </summary>
            /// <param name="AcceptChanges">Use the _editingControl's Text as new SubItem text or discard changes?</param>
            private void EndEditing(bool AcceptChanges, bool ContinueEdit)
            {
                mutEdit.WaitOne();

                //if (_editingControl == null)
                //{
                //    mutEdit.ReleaseMutex();
                //    return;
                //}

                ListViewItem  Item    = _editItem;
                int           SubItem = _editSubItem;
                PaddedTextBox c       = _editingControl;

                PwListItem pli = (((ListViewItem)Item).Tag as PwListItem);

                if (pli == null)
                {
                    Debug.Assert(false); return;
                }
                PwEntry pe = pli.Entry;

                if (AcceptChanges == true)
                {
                    // Check if item and textbox contain different text
                    if (Util.GetEntryFieldEx(pe, SubItem, false) != c.Text)
                    {
                        // Save changes
                        //MAYBE save only if editing is stopped or another item will be edited next
                        //if (ContinueEdit == false)
                        AcceptChanges = Util.SaveEntry(m_host.Database, Item, SubItem, c.Text);

                        //TODO TEST maybe it wont flickr if we set visible false later
                        // Avoid flickering
                        // Set item text manually before calling RefreshEntriesList
                        // If Item is protected
                        if (!_editItem.SubItems[_editSubItem].Text.Equals(PwDefs.HiddenPassword))
                        {
                            // Updating the listview item
                            _editItem.SubItems[_editSubItem].Text = Util.GetEntryFieldEx(pe, SubItem, true);
                        }
                    }
                    else
                    {
                        // No changes detected
                        AcceptChanges = false;
                    }
                }
                else
                {
                    // Cancel
                    // Nothing todo
                    // AcceptChanges is false
                }

                //TODO Should be part of the textbox and inlineedit should be notified by event
                c.Leave     -= new EventHandler(_editControl_Leave);
                c.LostFocus -= new EventHandler(_editControl_LostFocus);
                c.KeyPress  -= new KeyPressEventHandler(_editControl_KeyPress);

                if (ContinueEdit == false)
                {
                    // Check sub plugin state
                    if (!m_bEnabled)
                    {
                        // Function has to be disabled
                        RemoveHandler();
                    }

                    _editingControl = null;
                    _editItem       = null;
                    _editSubItem    = -1;

                    c.Visible = false;

                    //Util.SelectEntry((PwEntry)Item.Tag, true);
                    //m_lvEntries.Update();
                    m_lvEntries.Select();
                    m_lvEntries.HideSelection = false;
                    m_lvEntries.Focus();

                    if (AcceptChanges == true)
                    {
                        // The number of visible entries has not changed, so we can call RefreshEntriesList
                        Util.UpdateSaveState();
                        m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);
                        //TEST m_host.MainWindow.RefreshEntriesList();
                    }
                }

                // Add/Resume UIStateUpdated Event Handler
                //m_evMainWindow.Resume("OnPwListCustomColumnUpdate");
                //m_host.MainWindow.UIStateUpdated += new EventHandler(OnPwListCustomColumnUpdate);

                mutEdit.ReleaseMutex();
            }
Ejemplo n.º 4
0
            /// <summary>
            /// Begin in-place editing of given cell
            /// </summary>
            /// <param name="c">Control used as cell editor</param>
            /// <param name="Item">ListViewItem to edit</param>
            /// <param name="SubItem">SubItem index to edit</param>
            private void StartEditing(PwEntry pe, ListViewItem Item, int SubItem, bool ContinueEdit)
            {
                if (!this.GetEnable())
                {
                    return;
                }

                mutEdit.WaitOne();

                if (Item.Index == -1)
                {
                    mutEdit.ReleaseMutex();
                    return;
                }

                //if (_editingControl != null)
                //{
                //    mutEdit.ReleaseMutex();
                //    return;
                //}

                m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);
                Util.SelectEntry(pe, true, true);

                int           colID   = SubItem;
                AceColumn     col     = Util.GetAceColumn(colID);
                AceColumnType colType = col.Type;
                PaddedTextBox c       = m_textBoxComment;

                // Set Multiline property
                //TODO separate function
                switch (colType)
                {
                case AceColumnType.Notes:
                case AceColumnType.CustomString:
                    c.Multiline = true;
                    break;

                case AceColumnType.PluginExt:
                    //TODO
                    c.Multiline = false;
                    break;

                default:
                    c.Multiline = false;
                    break;
                }

                // Set editing allowed
                //TODO separate function
                switch (colType)
                {
                case AceColumnType.CreationTime:
                case AceColumnType.LastAccessTime:
                case AceColumnType.LastModificationTime:
                case AceColumnType.ExpiryTime:
                case AceColumnType.Uuid:
                case AceColumnType.Attachment:
                case AceColumnType.ExpiryTimeDateOnly:
                case AceColumnType.Size:
                case AceColumnType.HistoryCount:
                    // No editing allowed
                    c.ReadOnly = true;
                    break;

                case AceColumnType.PluginExt:
                    //TODO No editing allowed
                    c.ReadOnly = true;
                    break;

                default:
                    // Editing allowed
                    c.ReadOnly = false;
                    break;
                }

                // Read SubItem text and set textbox property

                // TODO Optionally PasswordChar *** during editing for protected strings

                // Read entry
                c.Text = Util.GetEntryFieldEx(pe, SubItem, false);

                // Set control location, bounding, padding
                SetEditBox(c, GetSubItemBounds(Item, SubItem), SubItem);

                //c.ScrollToTop();
                c.SelectAll();

                _editingControl = c;
                _editItem       = Item;
                _editSubItem    = SubItem;

                if (ContinueEdit == false)
                {
                    //c.Invalidate();
                    c.Visible = true;
                    c.BringToFront();
                    c.Select();
                    c.Focus();

                    m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);

                    // Check sub plugin state
                    if (!m_bEnabled)
                    {
                        // Function has to be enabled
                        AddHandler();
                    }
                }

                // Should be in the textbox
                c.Leave     += new EventHandler(_editControl_Leave);
                c.LostFocus += new EventHandler(_editControl_LostFocus);
                c.KeyPress  += new KeyPressEventHandler(_editControl_KeyPress);

                mutEdit.ReleaseMutex();
            }
            private void SetEditBox(PaddedTextBox c, Rectangle rcSubItem, int SubItem)
            {
                if (rcSubItem.X < 0)
                {
                    // Left edge of SubItem not visible - adjust rectangle position and width
                    rcSubItem.Width += rcSubItem.X;
                    rcSubItem.X = 0;
                }

                if (rcSubItem.X + rcSubItem.Width > m_lvEntries.ClientRectangle.Width)
                {
                    // Right edge of SubItem not visible - adjust rectangle width
                    rcSubItem.Width = m_lvEntries.ClientRectangle.Width - rcSubItem.Left;
                }

                // Calculate editbox height
                //if (c.Lines.Length > 1)
                if (c.Multiline)
                {
                    // Always display only 1 line
                    //rcSubItem.Height *= 1;
                    
                    // Set height depending on lines
                    //rcSubItem.Height *= c.LineCount;
                    rcSubItem.Height = c.CalculateHeight;

                    //c.ScrollBars(true);
                }
                else
                {
                    c.ScrollBars(false);
                }

                // Subitem bounds are relative to the location of the ListView!
                rcSubItem.Offset(m_lvEntries.Left, m_lvEntries.Top);

                // In case the editing control and the listview are on different parents,
                // account for different origins
                Point origin = new Point(0, 0);
                Point lvOrigin = m_lvEntries.Parent.PointToScreen(origin);
                Point ctlOrigin = c.Parent.PointToScreen(origin);

                rcSubItem.Offset(lvOrigin.X - ctlOrigin.X, lvOrigin.Y - ctlOrigin.Y);

                // Padding
                Padding pdSubItem = new Padding(6, 1, 1, 0);
                if (SubItem == 0)
                {
                    pdSubItem.Left = 1;
                }
                else if (c.Multiline)
                {
                    pdSubItem.Left = 5;
                }

                // Position, padding and show editor
                if (!c.Bounds.Equals(rcSubItem))
                    c.Bounds = rcSubItem;

                if (!c.Padding.Equals(pdSubItem))
                    c.Padding = pdSubItem;
            }
            /// <summary>
            /// Accept or discard current value of cell editor control
            /// </summary>
            /// <param name="AcceptChanges">Use the _editingControl's Text as new SubItem text or discard changes?</param>
            private void EndEditing(bool AcceptChanges, bool ContinueEdit)
            {
                mutEdit.WaitOne();

                //if (_editingControl == null)
                //{
                //    mutEdit.ReleaseMutex();
                //    return;
                //}

                ListViewItem Item = _editItem;
                int SubItem = _editSubItem;
                PaddedTextBox c = _editingControl;

                PwListItem pli = (((ListViewItem)Item).Tag as PwListItem);
                if (pli == null) { Debug.Assert(false); return; }
                PwEntry pe = pli.Entry;

                if (AcceptChanges == true)
                {
                    // Check if item and textbox contain different text
                    if (Util.GetEntryFieldEx(pe, SubItem, false) != c.Text)
                    {
                        // Save changes
                        //MAYBE save only if editing is stopped or another item will be edited next
                        //if (ContinueEdit == false)
                        AcceptChanges = Util.SaveEntry(m_host.Database, Item, SubItem, c.Text);

                        //TODO TEST maybe it wont flickr if we set visible false later
                        // Avoid flickering
                        // Set item text manually before calling RefreshEntriesList
                        // If Item is protected
                        if (!_editItem.SubItems[_editSubItem].Text.Equals(PwDefs.HiddenPassword))
                        {
                            // Updating the listview item
                            _editItem.SubItems[_editSubItem].Text = Util.GetEntryFieldEx(pe, SubItem, true);
                        }
                    }
                    else
                    {
                        // No changes detected
                        AcceptChanges = false;
                    }
                }
                else
                {
                    // Cancel 
                    // Nothing todo 
                    // AcceptChanges is false
                }

                //TODO Should be part of the textbox and inlineedit should be notified by event
                c.Leave -= new EventHandler(_editControl_Leave);
                c.LostFocus -= new EventHandler(_editControl_LostFocus);
                c.KeyPress -= new KeyPressEventHandler(_editControl_KeyPress);

                if (ContinueEdit == false)
                {
                    // Check sub plugin state
                    if (!m_bEnabled)
                    {
                        // Function has to be disabled
                        RemoveHandler();
                    }

                    _editingControl = null;
                    _editItem = null;
                    _editSubItem = -1;

                    c.Visible = false;

                    //Util.SelectEntry((PwEntry)Item.Tag, true);            
                    //m_lvEntries.Update();
                    m_lvEntries.Select();
                    m_lvEntries.HideSelection = false;
                    m_lvEntries.Focus();

                    if (AcceptChanges == true)
                    {
                        // The number of visible entries has not changed, so we can call RefreshEntriesList
                        Util.UpdateSaveState();
                        m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);
                        //TEST m_host.MainWindow.RefreshEntriesList();
                    }
                }
                
                // Add/Resume UIStateUpdated Event Handler
                //m_evMainWindow.Resume("OnPwListCustomColumnUpdate");
                //m_host.MainWindow.UIStateUpdated += new EventHandler(OnPwListCustomColumnUpdate);

                mutEdit.ReleaseMutex();
            }
            /// <summary>
            /// Begin in-place editing of given cell
            /// </summary>
            /// <param name="c">Control used as cell editor</param>
            /// <param name="Item">ListViewItem to edit</param>
            /// <param name="SubItem">SubItem index to edit</param>
            private void StartEditing(PwEntry pe, ListViewItem Item, int SubItem, bool ContinueEdit)
            {
                if (!this.GetEnable())
                {
                    return;
                }

                mutEdit.WaitOne();

                if (Item.Index == -1)
                {
                    mutEdit.ReleaseMutex();
                    return;
                }

                //if (_editingControl != null)
                //{
                //    mutEdit.ReleaseMutex();
                //    return;
                //}

                m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);
                Util.SelectEntry(pe, true, true);

                int colID = SubItem;
                AceColumn col = Util.GetAceColumn(colID);
                AceColumnType colType = col.Type;
                PaddedTextBox c = m_textBoxComment;

                // Set Multiline property
                //TODO separate function
                switch (colType)
                {
                    case AceColumnType.Notes:
                    case AceColumnType.CustomString:
                        c.Multiline = true;
                        break;
                    case AceColumnType.PluginExt:
                        //TODO
                        c.Multiline = false;
                        break;
                    default:
                        c.Multiline = false;
                        break;
                }

                // Set editing allowed
                //TODO separate function
                switch (colType)
                {
                    case AceColumnType.CreationTime:
                    case AceColumnType.LastAccessTime:
                    case AceColumnType.LastModificationTime:
                    case AceColumnType.ExpiryTime:
                    case AceColumnType.Uuid:
                    case AceColumnType.Attachment:
                    case AceColumnType.ExpiryTimeDateOnly:
                    case AceColumnType.Size:
                    case AceColumnType.HistoryCount:
                        // No editing allowed
                        c.ReadOnly = true;
                        break;
                    case AceColumnType.PluginExt:
                        //TODO No editing allowed
                        c.ReadOnly = true;
                        break;
                    default:
                        // Editing allowed
                        c.ReadOnly = false;
                        break;
                }

                // Read SubItem text and set textbox property

                // TODO Optionally PasswordChar *** during editing for protected strings

                // Read entry
                c.Text = Util.GetEntryFieldEx(pe, SubItem, false);

                // Set control location, bounding, padding
                SetEditBox(c, GetSubItemBounds(Item, SubItem), SubItem);
                
                //c.ScrollToTop();
                c.SelectAll();

                _editingControl = c;
                _editItem = Item;
                _editSubItem = SubItem;

                if (ContinueEdit == false)
                {
                    //c.Invalidate();
                    c.Visible = true;
                    c.BringToFront();
                    c.Select();
                    c.Focus();

                    m_host.MainWindow.EnsureVisibleEntry(pe.Uuid);

                    // Check sub plugin state
                    if (!m_bEnabled)
                    {
                        // Function has to be enabled
                        AddHandler();
                    }
                }

                // Should be in the textbox
                c.Leave += new EventHandler(_editControl_Leave);
                c.LostFocus += new EventHandler(_editControl_LostFocus);
                c.KeyPress += new KeyPressEventHandler(_editControl_KeyPress);

                mutEdit.ReleaseMutex();
            }
 private void InitializeInlineEditing()
 {
     // Add control to listview
     m_textBoxComment = new PaddedTextBox();
     m_textBoxComment.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     m_textBoxComment.Location = new System.Drawing.Point(32, 104);
     m_textBoxComment.Name = "m_textBoxComment";
     m_textBoxComment.Size = new System.Drawing.Size(80, 16);
     m_textBoxComment.TabIndex = 3;
     m_textBoxComment.Text = string.Empty;
     m_textBoxComment.AutoSize = false;
     m_textBoxComment.Padding = new Padding(6, 1, 1, 0);
     m_textBoxComment.Visible = false;
     m_lvEntries.Controls.Add(m_textBoxComment);
 }