コード例 #1
0
        public void CloseDatabase(PwDatabase pwDatabase)
        {
            int iFoundPos = -1;

            for (int i = 0; i < m_vDocs.Count; ++i)
            {
                if (m_vDocs[i].Database == pwDatabase)
                {
                    iFoundPos = i;
                    m_vDocs.RemoveAt(i);
                    break;
                }
            }

            if (iFoundPos != -1)
            {
                if (m_vDocs.Count == 0)
                {
                    m_vDocs.Add(new PwDocument());
                }

                if (iFoundPos == m_vDocs.Count)
                {
                    --iFoundPos;
                }
                m_dsActive = m_vDocs[iFoundPos];
                NotifyActiveDocumentSelected();
            }
            else
            {
                Debug.Assert(false);
            }
        }
コード例 #2
0
		public PwDocument CreateNewDocument(bool bMakeActive)
		{
			PwDocument ds = new PwDocument();

			if((m_vDocs.Count == 1) && (!m_vDocs[0].Database.IsOpen) &&
				(m_vDocs[0].LockedIoc.Path.Length == 0))
			{
				m_vDocs.RemoveAt(0);
				m_dsActive = ds;
			}

			m_vDocs.Add(ds);
			if(bMakeActive) m_dsActive = ds;

			NotifyActiveDocumentSelected();
			return ds;
		}
コード例 #3
0
        public PwDocument CreateNewDocument(bool bMakeActive)
        {
            PwDocument ds = new PwDocument();

            if ((m_vDocs.Count == 1) && (!m_vDocs[0].Database.IsOpen) &&
                (m_vDocs[0].LockedIoc.Path.Length == 0))
            {
                m_vDocs.RemoveAt(0);
                m_dsActive = ds;
            }

            m_vDocs.Add(ds);
            if (bMakeActive)
            {
                m_dsActive = ds;
            }

            NotifyActiveDocumentSelected();
            return(ds);
        }
コード例 #4
0
        public void CloseDatabase(PwDatabase pwDatabase)
        {
            int iFoundPos = -1;

            for (int i = 0; i < m_vDocs.Count; ++i)
            {
                if (m_vDocs[i].Database == pwDatabase)
                {
                    iFoundPos = i;
                    break;
                }
            }
            if (iFoundPos < 0)
            {
                Debug.Assert(false); return;
            }

            bool bClosingActive = (m_vDocs[iFoundPos] == m_dsActive);

            m_vDocs.RemoveAt(iFoundPos);
            if (m_vDocs.Count == 0)
            {
                m_vDocs.Add(new PwDocument());
            }

            if (bClosingActive)
            {
                int iNewActive = Math.Min(iFoundPos, m_vDocs.Count - 1);
                m_dsActive = m_vDocs[iNewActive];
                NotifyActiveDocumentSelected();
            }
            else
            {
                Debug.Assert(m_vDocs.Contains(m_dsActive));
            }
        }
コード例 #5
0
		internal void CloseDocument(PwDocument dsToClose, bool bLocking,
			bool bExiting, bool bUpdateUI)
		{
			PwDocument ds = (dsToClose ?? m_docMgr.ActiveDocument);
			PwDatabase pd = ds.Database;
			bool bIsActive = (ds == m_docMgr.ActiveDocument);

			Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePre,
				EcasProperty.Database, pd);
			if(this.FileClosingPre != null)
			{
				FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
				this.FileClosingPre(null, fcea);
				if(fcea.Cancel) return;
			}

			if(pd.Modified) // Implies pd.IsOpen
			{
				bool bInvokeSave = false;

				// https://sourceforge.net/p/keepass/discussion/329220/thread/c3c823c6/
				bool bCanAutoSave = AppPolicy.Current.SaveFile;

				if(Program.Config.Application.FileClosing.AutoSave && bCanAutoSave)
					bInvokeSave = true;
				else
				{
					FileSaveOrigin fso = FileSaveOrigin.Closing;
					if(bLocking) fso = FileSaveOrigin.Locking;
					if(bExiting) fso = FileSaveOrigin.Exiting;

					DialogResult dr = FileDialogsEx.ShowFileSaveQuestion(
						pd.IOConnectionInfo.GetDisplayName(), fso);

					if(dr == DialogResult.Cancel) return;
					else if(dr == DialogResult.Yes) bInvokeSave = true;
					else if(dr == DialogResult.No) { } // Changes are lost
				}

				if(bInvokeSave)
				{
					SaveDatabase(pd, null);
					if(pd.Modified) return;
				}
			}

			Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePost,
				EcasProperty.Database, pd);
			if(this.FileClosingPost != null)
			{
				FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
				this.FileClosingPost(null, fcea);
				if(fcea.Cancel) return;
			}

			IOConnectionInfo ioClosing = pd.IOConnectionInfo.CloneDeep();

			pd.Close();
			if(!bLocking) m_docMgr.CloseDatabase(pd);

			if(bIsActive)
			{
				m_tbQuickFind.Items.Clear();
				m_tbQuickFind.Text = string.Empty;

				if(!bLocking)
				{
					m_docMgr.ActiveDatabase.UINeedsIconUpdate = true;
					ResetDefaultFocus(null);
				}
			}
			if(bUpdateUI)
				UpdateUI(true, null, true, null, true, null, false);

			// NativeMethods.ClearIconicBitmaps(this.Handle);

			if(this.FileClosed != null)
			{
				FileClosedEventArgs fcea = new FileClosedEventArgs(ioClosing);
				this.FileClosed(null, fcea);
			}
		}
コード例 #6
0
		public bool IsFileLocked(PwDocument ds)
		{
			if(ds == null) ds = m_docMgr.ActiveDocument;

			return (ds.LockedIoc.Path.Length != 0);
		}
コード例 #7
0
ファイル: EntryMenu.cs プロジェクト: ashwingj/keepass2
        private static void MenuProcessGroup(PwDocument ds,
            ToolStripMenuItem tsmiContainer, PwGroup pgSource)
        {
            if((pgSource.Groups.UCount == 0) && (pgSource.Entries.UCount == 0))
                return;

            foreach(PwGroup pg in pgSource.Groups)
            {
                ToolStripMenuItem tsmi = MenuCreateGroup(ds, pg);
                tsmiContainer.DropDownItems.Add(tsmi);
                MenuProcessGroup(ds, tsmi, pg);
            }

            foreach(PwEntry pe in pgSource.Entries)
                MenuAddEntry(ds, tsmiContainer, pe);
        }
コード例 #8
0
ファイル: MainForm_Functions.cs プロジェクト: saadware/kpn
        internal void CloseDocument(PwDocument dsToClose, bool bLocking, bool bExiting)
        {
            PwDocument ds = (dsToClose ?? m_docMgr.ActiveDocument);
            bool bIsActive = object.ReferenceEquals(ds, m_docMgr.ActiveDocument);
            PwDatabase pd = ds.Database;

            Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePre,
                pd.IOConnectionInfo.Path);
            if(this.FileClosingPre != null)
            {
                FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
                this.FileClosingPre(null, fcea);
                if(fcea.Cancel) return;
            }

            if(pd.Modified) // Implies pd.IsOpen
            {
                bool bInvokeSave = false;

                if(Program.Config.Application.FileClosing.AutoSave)
                    bInvokeSave = true;
                else
                {
                    FileSaveOrigin fso = FileSaveOrigin.Closing;
                    if(bLocking) fso = FileSaveOrigin.Locking;
                    if(bExiting) fso = FileSaveOrigin.Exiting;

                    DialogResult dr = FileDialogsEx.ShowFileSaveQuestion(
                        pd.IOConnectionInfo.GetDisplayName(), fso);

                    if(dr == DialogResult.Cancel) return;
                    else if(dr == DialogResult.Yes) bInvokeSave = true;
                    else if(dr == DialogResult.No) { } // Changes are lost
                }

                if(bInvokeSave)
                {
                    SaveDatabase(pd, null);
                    if(pd.Modified) return;
                }
            }

            Program.TriggerSystem.RaiseEvent(EcasEventIDs.ClosingDatabaseFilePost,
                pd.IOConnectionInfo.Path);
            if(this.FileClosingPost != null)
            {
                FileClosingEventArgs fcea = new FileClosingEventArgs(pd);
                this.FileClosingPost(null, fcea);
                if(fcea.Cancel) return;
            }

            IOConnectionInfo ioClosing = pd.IOConnectionInfo.CloneDeep();

            pd.Close();
            if(!bLocking) m_docMgr.CloseDatabase(pd);

            if(bIsActive)
            {
                m_tbQuickFind.Items.Clear();
                m_tbQuickFind.Text = string.Empty;
            }

            if(!bLocking)
            {
                m_docMgr.ActiveDatabase.UINeedsIconUpdate = true;
                UpdateUI(true, null, true, null, true, null, false);
                ResetDefaultFocus(null);
            }

            // NativeMethods.ClearIconicBitmaps(this.Handle);

            if(this.FileClosed != null)
            {
                FileClosedEventArgs fcea = new FileClosedEventArgs(ioClosing);
                this.FileClosed(null, fcea);
            }
        }
コード例 #9
0
		public void UpdateUI(bool bRecreateTabBar, PwDocument dsSelect,
			bool bUpdateGroupList, PwGroup pgSelect, bool bUpdateEntryList,
			PwGroup pgEntrySource, bool bSetModified)
		{
			UpdateUI(bRecreateTabBar, dsSelect, bUpdateGroupList, pgSelect,
				bUpdateEntryList, pgEntrySource, bSetModified, null);
		}
コード例 #10
0
ファイル: EntryMenu.cs プロジェクト: ashwingj/keepass2
        private static void MenuAddEntry(PwDocument ds, ToolStripMenuItem tsmiContainer,
            PwEntry pe)
        {
            ToolStripMenuItem tsmiEntry = new ToolStripMenuItem();
            string strTitle = pe.Strings.ReadSafe(PwDefs.TitleField);
            string strUser = pe.Strings.ReadSafe(PwDefs.UserNameField);
            string strText = string.Empty;
            if((strTitle.Length > 0) && (strUser.Length > 0))
                strText = strTitle + ": " + strUser;
            else if(strTitle.Length > 0) strText = strTitle;
            else if(strUser.Length > 0) strText = strUser;
            tsmiEntry.Text = strText;
            tsmiEntry.ImageIndex = MenuGetImageIndex(ds, pe.IconId, pe.CustomIconUuid);
            tsmiContainer.DropDownItems.Add(tsmiEntry);

            ToolStripMenuItem tsmi;

            tsmi = new ToolStripMenuItem(KPRes.AutoType);
            tsmi.ImageIndex = (int)PwIcon.Run;
            tsmi.Tag = pe;
            tsmi.Click += OnAutoType;
            tsmi.Enabled = pe.GetAutoTypeEnabled();
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmiEntry.DropDownItems.Add(new ToolStripSeparator());

            tsmi = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.UserName);
            tsmi.ImageIndex = (int)PwIcon.UserKey;
            tsmi.Tag = pe;
            tsmi.Click += OnCopyUserName;
            tsmiEntry.DropDownItems.Add(tsmi);

            tsmi = new ToolStripMenuItem(KPRes.Copy + " " + KPRes.Password);
            tsmi.ImageIndex = (int)PwIcon.Key;
            tsmi.Tag = pe;
            tsmi.Click += OnCopyPassword;
            tsmiEntry.DropDownItems.Add(tsmi);
        }
コード例 #11
0
		public void CloseDatabase(PwDatabase pwDatabase)
		{
			int iFoundPos = -1;
			for(int i = 0; i < m_vDocs.Count; ++i)
			{
				if(m_vDocs[i].Database == pwDatabase)
				{
					iFoundPos = i;
					m_vDocs.RemoveAt(i);
					break;
				}
			}

			if(iFoundPos != -1)
			{
				if(m_vDocs.Count == 0)
					m_vDocs.Add(new PwDocument());

				if(iFoundPos == m_vDocs.Count) --iFoundPos;
				m_dsActive = m_vDocs[iFoundPos];
				NotifyActiveDocumentSelected();
			}
			else { Debug.Assert(false); }
		}
コード例 #12
0
		public void CloseDatabase(PwDatabase pwDatabase)
		{
			int iFoundPos = -1;
			for(int i = 0; i < m_vDocs.Count; ++i)
			{
				if(m_vDocs[i].Database == pwDatabase)
				{
					iFoundPos = i;
					break;
				}
			}
			if(iFoundPos < 0) { Debug.Assert(false); return; }

			bool bClosingActive = (m_vDocs[iFoundPos] == m_dsActive);

			m_vDocs.RemoveAt(iFoundPos);
			if(m_vDocs.Count == 0)
				m_vDocs.Add(new PwDocument());

			if(bClosingActive)
			{
				int iNewActive = Math.Min(iFoundPos, m_vDocs.Count - 1);
				m_dsActive = m_vDocs[iNewActive];
				NotifyActiveDocumentSelected();
			}
			else { Debug.Assert(m_vDocs.Contains(m_dsActive)); }
		}
コード例 #13
0
ファイル: MainForm_Functions.cs プロジェクト: elitak/keepass
        private void CloseDocument(PwDocument ds, bool bLocking, bool bExiting)
        {
            if(ds == null) ds = m_docMgr.ActiveDocument;

            PwDatabase pd = ds.Database;
            IOConnectionInfo ioClosing = pd.IOConnectionInfo.CloneDeep();

            if(pd.Modified) // Implies pd.IsOpen
            {
                if(Program.Config.Application.FileClosing.AutoSave)
                {
                    OnFileSave(null, EventArgs.Empty);
                    if(pd.Modified) return;
                }
                else
                {
                    FileSaveOrigin fso = FileSaveOrigin.Closing;
                    if(bLocking) fso = FileSaveOrigin.Locking;
                    if(bExiting) fso = FileSaveOrigin.Exiting;

                    DialogResult dr = FileDialogsEx.ShowFileSaveQuestion(
                        pd.IOConnectionInfo.GetDisplayName(), fso, this.Handle);

                    if(dr == DialogResult.Cancel) return;
                    else if(dr == DialogResult.Yes)
                    {
                        OnFileSave(null, EventArgs.Empty);
                        if(pd.Modified) return;
                    }
                    else if(dr == DialogResult.No) { } // Changes are lost
                }
            }

            pd.Close();
            if(!bLocking) m_docMgr.CloseDatabase(pd);

            m_tbQuickFind.Items.Clear();
            m_tbQuickFind.Text = string.Empty;

            if(!bLocking)
            {
                m_docMgr.ActiveDatabase.UINeedsIconUpdate = true;
                UpdateUI(true, null, true, null, true, null, false);
            }

            // NativeMethods.ClearIconicBitmaps(this.Handle);

            if(FileClosed != null)
            {
                FileClosedEventArgs fcea = new FileClosedEventArgs(ioClosing);
                FileClosed(null, fcea);
            }
        }
コード例 #14
0
		public void MakeDocumentActive(PwDocument ds)
		{
			if(ds == null) { Debug.Assert(false); return; }

			ds.Database.UINeedsIconUpdate = true;

			UpdateUI(false, ds, true, null, true, null, false);

			RestoreWindowState(ds.Database);
			UpdateUIState(false);
		}
コード例 #15
0
ファイル: EntryMenu.cs プロジェクト: ashwingj/keepass2
 private static ToolStripMenuItem MenuCreateGroup(PwDocument ds,
     PwGroup pg)
 {
     ToolStripMenuItem tsmi = new ToolStripMenuItem();
     tsmi.Text = pg.Name;
     tsmi.ImageIndex = MenuGetImageIndex(ds, pg.IconId, pg.CustomIconUuid);
     return tsmi;
 }
コード例 #16
0
		private void GetTabText(PwDocument dsInfo, out string strName,
			out string strTip)
		{
			if(!IsFileLocked(dsInfo))
			{
				string strPath = dsInfo.Database.IOConnectionInfo.Path;
				strName = UrlUtil.GetFileName(strPath);

				if(dsInfo.Database.Modified) strName += "*";

				strTip = StrUtil.EncodeToolTipText(strPath);
				if(dsInfo.Database.IsOpen)
				{
					if(dsInfo.Database.Name.Length > 0)
						strTip += "\r\n" + StrUtil.EncodeToolTipText(
							dsInfo.Database.Name);
				}
			}
			else // Locked
			{
				string strPath = dsInfo.LockedIoc.Path;
				strName = UrlUtil.GetFileName(strPath);
				strName += " [" + KPRes.Locked + "]";
				strTip = StrUtil.EncodeToolTipText(strPath);
			}
		}
コード例 #17
0
ファイル: EntryMenu.cs プロジェクト: ashwingj/keepass2
        private static int MenuGetImageIndex(PwDocument ds, PwIcon pwID,
            PwUuid pwCustomID)
        {
            if((pwCustomID != PwUuid.Zero) && (ds ==
                Program.MainForm.DocumentManager.ActiveDocument))
            {
                return (int)PwIcon.Count +
                    Program.MainForm.DocumentManager.ActiveDatabase.GetCustomIconIndex(
                    pwCustomID);
            }

            if((int)pwID < (int)PwIcon.Count) return (int)pwID;

            return (int)PwIcon.Key;
        }
コード例 #18
0
		public void UpdateUI(bool bRecreateTabBar, PwDocument dsSelect,
			bool bUpdateGroupList, PwGroup pgSelect, bool bUpdateEntryList,
			PwGroup pgEntrySource, bool bSetModified, Control cOptFocus)
		{
			if(bRecreateTabBar) RecreateUITabs();

			if(dsSelect != null) m_docMgr.ActiveDocument = dsSelect;
			SelectUITab();

			UpdateImageLists(false);

			if(bUpdateGroupList) UpdateGroupList(pgSelect);

			if(bUpdateEntryList) UpdateEntryList(pgEntrySource, false);
			else { Debug.Assert(pgEntrySource == null); }

			UpdateUIState(bSetModified, cOptFocus);
		}
コード例 #19
0
		private void GetTabText(PwDocument dsInfo, out string strName,
			out string strTip)
		{
			if(IsFileLocked(dsInfo) == false) // Not locked
			{
				strTip = dsInfo.Database.IOConnectionInfo.Path;
				strName = UrlUtil.GetFileName(strTip);

				if(dsInfo.Database.Modified) strName += "*";

				if(dsInfo.Database.IsOpen)
				{
					if(dsInfo.Database.Name.Length > 0)
						strTip += "\r\n" + dsInfo.Database.Name;
				}
			}
			else // Locked
			{
				strTip = dsInfo.LockedIoc.Path;
				strName = UrlUtil.GetFileName(strTip);
				strName += " [" + KPRes.Locked + "]";
			}
		}