示例#1
0
        public static void EnsureConfigured(Form fParent)
        {
            if(Program.Config.Application.Start.CheckForUpdateConfigured) return;

            // If the user has manually enabled the automatic update check
            // before, there's no need to ask him again
            if(!Program.Config.Application.Start.CheckForUpdate &&
                !Program.IsDevelopmentSnapshot())
            {
                string strHdr = KPRes.UpdateCheckInfo;
                string strSub = KPRes.UpdateCheckInfoRes + MessageService.NewParagraph +
                    KPRes.UpdateCheckInfoPriv;

                VistaTaskDialog dlg = new VistaTaskDialog((fParent != null) ?
                    fParent.Handle : IntPtr.Zero);
                dlg.CommandLinks = true;
                dlg.Content = strHdr;
                dlg.MainInstruction = KPRes.UpdateCheckEnableQ;
                dlg.WindowTitle = PwDefs.ShortProductName;
                dlg.AddButton((int)DialogResult.Yes, KPRes.Enable +
                    " (" + KPRes.Recommended + ")", null);
                dlg.AddButton((int)DialogResult.No, KPRes.Disable, null);
                dlg.SetIcon(VtdCustomIcon.Question);
                dlg.FooterText = strSub;
                dlg.SetFooterIcon(VtdIcon.Information);

                int iResult;
                if(dlg.ShowDialog()) iResult = dlg.Result;
                else
                {
                    string strMain = strHdr + MessageService.NewParagraph + strSub;
                    iResult = (MessageService.AskYesNo(strMain + MessageService.NewParagraph +
                        KPRes.UpdateCheckEnableQ, PwDefs.ShortProductName) ?
                        (int)DialogResult.Yes : (int)DialogResult.No);
                }

                Program.Config.Application.Start.CheckForUpdate = ((iResult ==
                    (int)DialogResult.OK) || (iResult == (int)DialogResult.Yes));
            }

            Program.Config.Application.Start.CheckForUpdateConfigured = true;
        }
示例#2
0
		public static DialogResult ShowFileSaveQuestion(string strFile,
			FileSaveOrigin fsOrigin, IntPtr hParent)
		{
			bool bFile = ((strFile != null) && (strFile.Length > 0));

			if(WinUtil.IsAtLeastWindowsVista)
			{
				VistaTaskDialog dlg = new VistaTaskDialog(hParent);

				string strText = KPRes.DatabaseModifiedNoDot;
				if(bFile) strText += ":\r\n" + strFile;
				else strText += ".";

				dlg.CommandLinks = true;
				dlg.WindowTitle = PwDefs.ProductName;
				dlg.Content = strText;
				dlg.SetIcon(VtdCustomIcon.Question);

				bool bShowCheckBox = true;
				if(fsOrigin == FileSaveOrigin.Locking)
				{
					dlg.MainInstruction = KPRes.FileSaveQLocking;
					dlg.AddButton((int)DialogResult.Yes, KPRes.Save, KPRes.FileSaveQOpYesLocking);
					dlg.AddButton((int)DialogResult.No, KPRes.DiscardChanges, KPRes.FileSaveQOpNoLocking);
					dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
						" " + KPRes.FileSaveQOpCancelLocking);
				}
				else if(fsOrigin == FileSaveOrigin.Exiting)
				{
					dlg.MainInstruction = KPRes.FileSaveQExiting;
					dlg.AddButton((int)DialogResult.Yes, KPRes.Save, KPRes.FileSaveQOpYesExiting);
					dlg.AddButton((int)DialogResult.No, KPRes.DiscardChanges, KPRes.FileSaveQOpNoExiting);
					dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
						" " + KPRes.FileSaveQOpCancelExiting);
				}
				else
				{
					dlg.MainInstruction = KPRes.FileSaveQClosing;
					dlg.AddButton((int)DialogResult.Yes, KPRes.Save, KPRes.FileSaveQOpYesClosing);
					dlg.AddButton((int)DialogResult.No, KPRes.DiscardChanges, KPRes.FileSaveQOpNoClosing);
					dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
						" " + KPRes.FileSaveQOpCancelClosing);
					bShowCheckBox = false;
				}

				if(Program.Config.Application.FileClosing.AutoSave) bShowCheckBox = false;
				if(bShowCheckBox) dlg.VerificationText = KPRes.AutoSaveAtExit;

				if(dlg.ShowDialog())
				{
					if(bShowCheckBox && (dlg.Result == (int)DialogResult.Yes))
						Program.Config.Application.FileClosing.AutoSave = dlg.ResultVerificationChecked;

					return (DialogResult)dlg.Result;
				}
			}

			string strMessage = (bFile ? (strFile + MessageService.NewParagraph) : string.Empty);
			strMessage += KPRes.DatabaseModifiedNoDot + "." +
				MessageService.NewParagraph + KPRes.SaveBeforeCloseQuestion;
			return MessageService.Ask(strMessage, KPRes.SaveBeforeCloseTitle,
				MessageBoxButtons.YesNoCancel);
		}
		private static void ShowMessageBox(EcasAction a, EcasContext ctx)
		{
			VistaTaskDialog vtd = new VistaTaskDialog();

			string strMain = EcasUtil.GetParamString(a.Parameters, 0, true);
			if(!string.IsNullOrEmpty(strMain)) vtd.MainInstruction = strMain;

			string strText = EcasUtil.GetParamString(a.Parameters, 1, true);
			if(!string.IsNullOrEmpty(strText)) vtd.Content = strText;

			uint uIcon = EcasUtil.GetParamUInt(a.Parameters, 2, 0);
			if(uIcon == (uint)MessageBoxIcon.Information)
				vtd.SetIcon(VtdIcon.Information);
			else if(uIcon == (uint)MessageBoxIcon.Question)
				vtd.SetIcon(VtdCustomIcon.Question);
			else if(uIcon == (uint)MessageBoxIcon.Warning)
				vtd.SetIcon(VtdIcon.Warning);
			else if(uIcon == (uint)MessageBoxIcon.Error)
				vtd.SetIcon(VtdIcon.Error);
			else { Debug.Assert(uIcon == (uint)MessageBoxIcon.None); }

			vtd.CommandLinks = false;

			uint uBtns = EcasUtil.GetParamUInt(a.Parameters, 3, 0);
			bool bCanCancel = false;
			if(uBtns == (uint)MessageBoxButtons.OKCancel)
			{
				vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
				vtd.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);
				bCanCancel = true;
			}
			else if(uBtns == (uint)MessageBoxButtons.YesNo)
			{
				vtd.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
				vtd.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);
				bCanCancel = true;
			}
			else vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);

			uint uDef = EcasUtil.GetParamUInt(a.Parameters, 4, 0);
			ReadOnlyCollection<VtdButton> lButtons = vtd.Buttons;
			if(uDef < (uint)lButtons.Count)
				vtd.DefaultButtonID = lButtons[(int)uDef].ID;

			vtd.WindowTitle = PwDefs.ShortProductName;

			string strTrg = ctx.Trigger.Name;
			if(!string.IsNullOrEmpty(strTrg))
			{
				vtd.FooterText = KPRes.Trigger + @": '" + strTrg + @"'.";
				vtd.SetFooterIcon(VtdIcon.Information);
			}

			int dr;
			if(vtd.ShowDialog()) dr = vtd.Result;
			else
			{
				string str = (strMain ?? string.Empty);
				if(!string.IsNullOrEmpty(strText))
				{
					if(str.Length > 0) str += MessageService.NewParagraph;
					str += strText;
				}

				MessageBoxDefaultButton mbdb = MessageBoxDefaultButton.Button1;
				if(uDef == 1) mbdb = MessageBoxDefaultButton.Button2;
				else if(uDef == 2) mbdb = MessageBoxDefaultButton.Button3;

				MessageService.ExternalIncrementMessageCount();
				try
				{
					dr = (int)MessageService.SafeShowMessageBox(str,
						PwDefs.ShortProductName, (MessageBoxButtons)uBtns,
						(MessageBoxIcon)uIcon, mbdb);
				}
				finally { MessageService.ExternalDecrementMessageCount(); }
			}

			uint uActCondID = EcasUtil.GetParamUInt(a.Parameters, 5, 0);

			bool bDrY = ((dr == (int)DialogResult.OK) ||
				(dr == (int)DialogResult.Yes));
			bool bDrN = ((dr == (int)DialogResult.Cancel) ||
				(dr == (int)DialogResult.No));

			bool bPerformAction = (((uActCondID == IdMbcY) && bDrY) ||
				((uActCondID == IdMbcN) && bDrN));
			if(!bPerformAction) return;

			uint uActID = EcasUtil.GetParamUInt(a.Parameters, 6, 0);
			string strActionParam = EcasUtil.GetParamString(a.Parameters, 7, true);

			if(uActID == IdMbaNone) { }
			else if(uActID == IdMbaAbort)
			{
				if(bCanCancel) ctx.Cancel = true;
			}
			else if(uActID == IdMbaCmd)
			{
				if(!string.IsNullOrEmpty(strActionParam))
					WinUtil.OpenUrl(strActionParam, null);
			}
			else { Debug.Assert(false); }
		}
示例#4
0
		private void SetObjectsDeletedStatus(uint uDeleted, bool bDbMntnc)
		{
			string str = (StrUtil.ReplaceCaseInsensitive(KPRes.ObjectsDeleted,
				@"{PARAM}", uDeleted.ToString()) + ".");
			SetStatusEx(str);
			if(!bDbMntnc || !Program.Config.UI.ShowDbMntncResultsDialog) return;

			VistaTaskDialog dlg = new VistaTaskDialog();
			dlg.CommandLinks = false;
			dlg.Content = str;
			dlg.SetIcon(VtdIcon.Information);
			dlg.VerificationText = KPRes.DialogNoShowAgain;
			dlg.WindowTitle = PwDefs.ShortProductName;
			if(dlg.ShowDialog())
			{
				if(dlg.ResultVerificationChecked)
					Program.Config.UI.ShowDbMntncResultsDialog = false;
			}
			else MessageService.ShowInfo(str);
		}
示例#5
0
		private void EmptyRecycleBin()
		{
			PwDatabase pd = m_docMgr.ActiveDatabase;
			PwGroup pg = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
			if(pg == null) { Debug.Assert(false); return; }
			if(pg != GetSelectedGroup()) { Debug.Assert(false); return; }

			string strSummary = EntryUtil.CreateSummaryList(pg, false);

			VistaTaskDialog dlg = new VistaTaskDialog();
			dlg.CommandLinks = false;
			dlg.Content = strSummary;
			dlg.MainInstruction = KPRes.EmptyRecycleBinQuestion;
			dlg.SetIcon(VtdCustomIcon.Question);
			dlg.WindowTitle = PwDefs.ShortProductName;
			dlg.AddButton((int)DialogResult.OK, KPRes.DeleteCmd, null);
			dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);

			if(dlg.ShowDialog())
			{
				if(dlg.Result == (int)DialogResult.Cancel) return;
			}
			else
			{
				string strText = KPRes.EmptyRecycleBinQuestion;
				if(strSummary.Length > 0)
					strText += MessageService.NewParagraph + strSummary;

				if(!MessageService.AskYesNo(strText))
					return;
			}

			pg.DeleteAllObjects(pd);

			UpdateUI(false, null, true, pg, true, null, true);
		}
示例#6
0
		private void DeleteSelectedGroup()
		{
			PwGroup pg = GetSelectedGroup();
			if(pg == null) { Debug.Assert(false); return; }

			PwGroup pgParent = pg.ParentGroup;
			if(pgParent == null) return; // Can't remove virtual or root group

			PwDatabase pd = m_docMgr.ActiveDatabase;
			PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
			bool bShiftPressed = ((Control.ModifierKeys & Keys.Shift) != Keys.None);

			bool bPermanent = false;
			if(pd.RecycleBinEnabled == false) bPermanent = true;
			else if(bShiftPressed) bPermanent = true;
			else if(pgRecycleBin == null) { }
			else if(pg == pgRecycleBin) bPermanent = true;
			else if(pg.IsContainedIn(pgRecycleBin)) bPermanent = true;
			else if(pgRecycleBin.IsContainedIn(pg)) bPermanent = true;

			string strContent = EntryUtil.CreateSummaryList(pg, false);
			if(strContent.Length > 0)
				strContent = KPRes.DeleteGroupInfo + MessageService.NewParagraph +
					strContent;

			if(bPermanent)
			{
				VistaTaskDialog dlg = new VistaTaskDialog();
				dlg.CommandLinks = false;
				dlg.Content = strContent;
				dlg.MainInstruction = KPRes.DeleteGroupQuestion;
				dlg.SetIcon(VtdCustomIcon.Question);
				dlg.WindowTitle = PwDefs.ShortProductName;
				dlg.AddButton((int)DialogResult.OK, KPRes.DeleteCmd, null);
				dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);

				if(dlg.ShowDialog())
				{
					if(dlg.Result == (int)DialogResult.Cancel) return;
				}
				else
				{
					string strText = KPRes.DeleteGroupQuestion;
					if(strContent.Length > 0)
						strText += MessageService.NewParagraph + strContent;

					if(!MessageService.AskYesNo(strText, KPRes.DeleteGroupTitle))
						return;
				}
			}
			else if(Program.Config.UI.ShowRecycleConfirmDialog)
			{
				VistaTaskDialog dlg = new VistaTaskDialog();
				dlg.CommandLinks = false;
				dlg.Content = strContent;
				dlg.MainInstruction = KPRes.RecycleGroupConfirm;
				dlg.SetIcon(VtdCustomIcon.Question);
				dlg.VerificationText = KPRes.DialogNoShowAgain;
				dlg.WindowTitle = PwDefs.ShortProductName;
				dlg.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
				dlg.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);

				if(dlg.ShowDialog())
				{
					if(dlg.Result == (int)DialogResult.Cancel) return;

					if(dlg.ResultVerificationChecked)
						Program.Config.UI.ShowRecycleConfirmDialog = false;
				}
				else
				{
					string strText = KPRes.RecycleGroupConfirm;
					if(strContent.Length > 0)
						strText += MessageService.NewParagraph + strContent;

					if(!MessageService.AskYesNo(strText, KPRes.DeleteGroupTitle))
						return;
				}
			}

			pgParent.Groups.Remove(pg);

			if(bPermanent)
			{
				pg.DeleteAllObjects(pd);

				PwDeletedObject pdo = new PwDeletedObject(pg.Uuid, DateTime.Now);
				pd.DeletedObjects.Add(pdo);
			}
			else // Recycle
			{
				bool bDummy = false;
				EnsureRecycleBin(ref pgRecycleBin, pd, ref bDummy);

				pgRecycleBin.AddGroup(pg, true, true);
				pg.Touch(false);
			}

			UpdateUI(false, null, true, pgParent, true, null, true);
		}
示例#7
0
		private void DeleteSelectedEntries()
		{
			PwEntry[] vSelected = GetSelectedEntries();
			if((vSelected == null) || (vSelected.Length == 0)) return;

			PwDatabase pd = m_docMgr.ActiveDatabase;
			PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
			bool bShiftPressed = ((Control.ModifierKeys & Keys.Shift) != Keys.None);

			bool bAtLeastOnePermanent = false;
			if(pd.RecycleBinEnabled == false) bAtLeastOnePermanent = true;
			else if(bShiftPressed) bAtLeastOnePermanent = true;
			else if(pgRecycleBin == null) { } // Not permanent
			else
			{
				foreach(PwEntry peEnum in vSelected)
				{
					if((peEnum.ParentGroup == pgRecycleBin) ||
						peEnum.ParentGroup.IsContainedIn(pgRecycleBin))
					{
						bAtLeastOnePermanent = true;
						break;
					}
				}
			}

			bool bSingle = (vSelected.Length == 1);
			string strSummary = EntryUtil.CreateSummaryList(null, vSelected);

			if(bAtLeastOnePermanent)
			{
				VistaTaskDialog dlg = new VistaTaskDialog();
				dlg.CommandLinks = false;
				dlg.Content = strSummary;
				dlg.MainInstruction = (bSingle ? KPRes.DeleteEntriesQuestionSingle :
					KPRes.DeleteEntriesQuestion);
				dlg.SetIcon(VtdCustomIcon.Question);
				dlg.WindowTitle = PwDefs.ShortProductName;
				dlg.AddButton((int)DialogResult.OK, KPRes.DeleteCmd, null);
				dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);

				if(dlg.ShowDialog())
				{
					if(dlg.Result == (int)DialogResult.Cancel) return;
				}
				else
				{
					string strText = (bSingle ? KPRes.DeleteEntriesQuestionSingle :
						KPRes.DeleteEntriesQuestion);
					if(strSummary.Length > 0)
						strText += MessageService.NewParagraph + strSummary;

					if(!MessageService.AskYesNo(strText, (bSingle ?
						KPRes.DeleteEntriesTitleSingle : KPRes.DeleteEntriesTitle)))
						return;
				}
			}
			else if(Program.Config.UI.ShowRecycleConfirmDialog)
			{
				VistaTaskDialog dlg = new VistaTaskDialog();
				dlg.CommandLinks = false;
				dlg.Content = strSummary;
				dlg.MainInstruction = (bSingle ? KPRes.RecycleEntryConfirmSingle :
					KPRes.RecycleEntryConfirm);
				dlg.SetIcon(VtdCustomIcon.Question);
				dlg.VerificationText = KPRes.DialogNoShowAgain;
				dlg.WindowTitle = PwDefs.ShortProductName;
				dlg.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
				dlg.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);

				if(dlg.ShowDialog())
				{
					if(dlg.Result == (int)DialogResult.Cancel) return;

					if(dlg.ResultVerificationChecked)
						Program.Config.UI.ShowRecycleConfirmDialog = false;
				}
				else
				{
					string strText = (bSingle ? KPRes.RecycleEntryConfirmSingle :
						KPRes.RecycleEntryConfirm);
					if(strSummary.Length > 0)
						strText += MessageService.NewParagraph + strSummary;

					if(!MessageService.AskYesNo(strText, (bSingle ?
						KPRes.DeleteEntriesTitleSingle : KPRes.DeleteEntriesTitle)))
						return;
				}
			}

			bool bUpdateGroupList = false;
			DateTime dtNow = DateTime.Now;
			foreach(PwEntry pe in vSelected)
			{
				PwGroup pgParent = pe.ParentGroup;
				if(pgParent == null) continue; // Can't remove

				pgParent.Entries.Remove(pe);

				bool bPermanent = false;
				if(pd.RecycleBinEnabled == false) bPermanent = true;
				else if(bShiftPressed) bPermanent = true;
				else if(pgRecycleBin == null) { } // Recycle
				else if(pgParent == pgRecycleBin) bPermanent = true;
				else if(pgParent.IsContainedIn(pgRecycleBin)) bPermanent = true;

				if(bPermanent)
				{
					PwDeletedObject pdo = new PwDeletedObject(pe.Uuid, dtNow);
					pd.DeletedObjects.Add(pdo);
				}
				else // Recycle
				{
					EnsureRecycleBin(ref pgRecycleBin, pd, ref bUpdateGroupList);

					pgRecycleBin.AddEntry(pe, true, true);
					pe.Touch(false);
				}
			}

			RemoveEntriesFromList(vSelected, true);
			UpdateUI(false, null, bUpdateGroupList, null, false, null, true);
		}
示例#8
0
		private static DialogResult AskIfSynchronizeInstead(IOConnectionInfo ioc)
		{
			VistaTaskDialog dlg = new VistaTaskDialog();

			string strText = string.Empty;
			if(ioc.GetDisplayName().Length > 0)
				strText += ioc.GetDisplayName() + MessageService.NewParagraph;
			strText += KPRes.FileChanged;

			dlg.CommandLinks = true;
			dlg.WindowTitle = PwDefs.ShortProductName;
			dlg.Content = strText;
			dlg.SetIcon(VtdCustomIcon.Question);

			dlg.MainInstruction = KPRes.OverwriteExistingFileQuestion;
			dlg.AddButton((int)DialogResult.Yes, KPRes.Synchronize, KPRes.FileChangedSync);
			dlg.AddButton((int)DialogResult.No, KPRes.Overwrite, KPRes.FileChangedOverwrite);
			dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel);

			DialogResult dr;
			if(dlg.ShowDialog()) dr = (DialogResult)dlg.Result;
			else
			{
				strText += MessageService.NewParagraph;
				strText += @"[" + KPRes.Yes + @"]: " + KPRes.Synchronize + @". " +
					KPRes.FileChangedSync + MessageService.NewParagraph;
				strText += @"[" + KPRes.No + @"]: " + KPRes.Overwrite + @". " +
					KPRes.FileChangedOverwrite + MessageService.NewParagraph;
				strText += @"[" + KPRes.Cancel + @"]: " + KPRes.FileSaveQOpCancel;

				dr = MessageService.Ask(strText, PwDefs.ShortProductName,
					MessageBoxButtons.YesNoCancel);
			}

			return dr;
		}
示例#9
0
		private PwDatabase OpenDatabaseInternal(IOConnectionInfo ioc,
			CompositeKey cmpKey, out bool bAbort)
		{
			bAbort = false;

			PerformSelfTest();

			ShowWarningsLogger swLogger = CreateShowWarningsLogger();
			swLogger.StartLogging(KPRes.OpeningDatabase, true);

			PwDocument ds = null;
			string strPathNrm = ioc.Path.Trim().ToLower();
			for(int iScan = 0; iScan < m_docMgr.Documents.Count; ++iScan)
			{
				if(m_docMgr.Documents[iScan].LockedIoc.Path.Trim().ToLower() == strPathNrm)
					ds = m_docMgr.Documents[iScan];
				else if(m_docMgr.Documents[iScan].Database.IOConnectionInfo.Path == strPathNrm)
					ds = m_docMgr.Documents[iScan];
			}

			PwDatabase pwDb;
			if(ds == null) pwDb = m_docMgr.CreateNewDocument(true).Database;
			else pwDb = ds.Database;

			Exception ex = null;
			try
			{
				pwDb.Open(ioc, cmpKey, swLogger);

#if DEBUG
				byte[] pbDiskDirect = WinUtil.HashFile(ioc);
				Debug.Assert(MemUtil.ArraysEqual(pbDiskDirect, pwDb.HashOfFileOnDisk));
#endif
			}
			catch(Exception exLoad)
			{
				ex = exLoad;
				pwDb = null;
			}

			swLogger.EndLogging();

			if(pwDb == null)
			{
				if(ds == null) m_docMgr.CloseDatabase(m_docMgr.ActiveDatabase);
			}

			if(ex != null)
			{
				string strMsg = MessageService.GetLoadWarningMessage(
					ioc.GetDisplayName(), ex,
					(Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null));

				bool bShowStd = true;
				if(!ioc.IsLocalFile())
				{
					VistaTaskDialog vtd = new VistaTaskDialog();
					vtd.CommandLinks = false;
					vtd.Content = strMsg;
					vtd.DefaultButtonID = (int)DialogResult.Cancel;
					// vtd.VerificationText = KPRes.CredSpecifyDifferent;
					vtd.WindowTitle = PwDefs.ShortProductName;

					vtd.SetIcon(VtdIcon.Warning);
					vtd.AddButton((int)DialogResult.Cancel, KPRes.Ok, null);
					vtd.AddButton((int)DialogResult.Retry,
						KPRes.CredSpecifyDifferent, null);

					if(vtd.ShowDialog(this))
					{
						bShowStd = false;

						// if(vtd.ResultVerificationChecked)
						if(vtd.Result == (int)DialogResult.Retry)
						{
							IOConnectionInfo iocNew = ioc.CloneDeep();
							// iocNew.ClearCredentials(false);
							iocNew.CredSaveMode = IOCredSaveMode.NoSave;
							iocNew.IsComplete = false;
							// iocNew.Password = string.Empty;

							OpenDatabase(iocNew, null, false);

							bAbort = true;
						}
					}
				}

				if(bShowStd) MessageService.ShowWarning(strMsg);
				// MessageService.ShowLoadWarning(ioc.GetDisplayName(), ex,
				//	(Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null));
			}

			return pwDb;
		}
示例#10
0
		/* private static void OnHotKey(string strKey, IntPtr lpUserData)
		{
			if(string.IsNullOrEmpty(strKey)) return;
			if(strKey.IndexOf(@"<Release>", StrUtil.CaseIgnoreCmp) >= 0) return;

			if(m_fRecvWnd != null)
			{
				MainForm mf = (m_fRecvWnd as MainForm);
				if(mf == null) { Debug.Assert(false); return; }

				Keys k = EggAccStringToKeys(strKey);
				foreach(KeyValuePair<int, Keys> kvp in m_vRegKeys)
				{
					if(kvp.Value == k) mf.HandleHotKey(kvp.Key);
				}
			}
			else { Debug.Assert(false); }
		}

		private static Keys EggAccStringToKeys(string strKey)
		{
			if(string.IsNullOrEmpty(strKey)) return Keys.None;

			Keys k = Keys.None;

			if(strKey.IndexOf(@"<Alt>", StrUtil.CaseIgnoreCmp) >= 0)
				k |= Keys.Alt;
			if((strKey.IndexOf(@"<Ctl>", StrUtil.CaseIgnoreCmp) >= 0) ||
				(strKey.IndexOf(@"<Ctrl>", StrUtil.CaseIgnoreCmp) >= 0) ||
				(strKey.IndexOf(@"<Control>", StrUtil.CaseIgnoreCmp) >= 0))
				k |= Keys.Control;
			if((strKey.IndexOf(@"<Shft>", StrUtil.CaseIgnoreCmp) >= 0) ||
				(strKey.IndexOf(@"<Shift>", StrUtil.CaseIgnoreCmp) >= 0))
				k |= Keys.Shift;

			string strKeyCode = strKey;
			while(strKeyCode.IndexOf('<') >= 0)
			{
				int nStart = strKeyCode.IndexOf('<');
				int nEnd = strKeyCode.IndexOf('>');
				if((nStart < 0) || (nEnd < 0) || (nEnd <= nStart)) { Debug.Assert(false); break; }

				strKeyCode = strKeyCode.Remove(nStart, nEnd - nStart + 1);
			}
			strKeyCode = strKeyCode.Trim();

			try { k |= (Keys)Enum.Parse(typeof(Keys), strKeyCode, true); }
			catch(Exception) { Debug.Assert(false); }

			return k;
		}

		private static string EggAccKeysToString(Keys k)
		{
			StringBuilder sb = new StringBuilder();

			if((k & Keys.Shift) != Keys.None) sb.Append(@"<Shift>");
			if((k & Keys.Control) != Keys.None) sb.Append(@"<Control>");
			if((k & Keys.Alt) != Keys.None) sb.Append(@"<Alt>");

			sb.Append((k & Keys.KeyCode).ToString());
			return sb.ToString();
		} */

		internal static void CheckCtrlAltA(Form fParent)
		{
			try
			{
				if(!Program.Config.Integration.CheckHotKeys) return;
				if(NativeLib.IsUnix()) return;

				// Check for a conflict only in the very specific case of
				// Ctrl+Alt+A; in all other cases we assume that the user
				// is aware of a possible conflict and intentionally wants
				// to override any system key combination
				if(Program.Config.Integration.HotKeyGlobalAutoType !=
					(ulong)(Keys.Control | Keys.Alt | Keys.A)) return;

				// Check for a conflict only on Polish systems; other
				// languages typically don't use Ctrl+Alt+A frequently
				// and a conflict warning would just be confusing for
				// most users
				IntPtr hKL = NativeMethods.GetKeyboardLayout(0);
				ushort uLangID = (ushort)(hKL.ToInt64() & 0xFFFFL);
				ushort uPriLangID = NativeMethods.GetPrimaryLangID(uLangID);
				if(uPriLangID != NativeMethods.LANG_POLISH) return;

				int vk = (int)Keys.A;

				// We actually check for RAlt (which maps to Ctrl+Alt)
				// instead of LCtrl+LAlt
				byte[] pbState = new byte[256];
				pbState[NativeMethods.VK_CONTROL] = 0x80;
				pbState[NativeMethods.VK_LCONTROL] = 0x80;
				pbState[NativeMethods.VK_MENU] = 0x80;
				pbState[NativeMethods.VK_RMENU] = 0x80;
				pbState[NativeMethods.VK_NUMLOCK] = 0x01; // Toggled
				// pbState[vk] = 0x80;

				string strUni = NativeMethods.ToUnicode3(vk, pbState, IntPtr.Zero);
				if(string.IsNullOrEmpty(strUni)) return;
				if(strUni.EndsWith("a") || strUni.EndsWith("A")) return;

				if(char.IsControl(strUni, 0)) { Debug.Assert(false); strUni = "?"; }

				string str = KPRes.CtrlAltAConflict.Replace(@"{PARAM}", strUni) +
					MessageService.NewParagraph + KPRes.CtrlAltAConflictHint;

				VistaTaskDialog dlg = new VistaTaskDialog();
				dlg.AddButton((int)DialogResult.Cancel, KPRes.Ok, null);
				dlg.CommandLinks = false;
				dlg.Content = str;
				dlg.DefaultButtonID = (int)DialogResult.Cancel;
				dlg.MainInstruction = KPRes.KeyboardKeyCtrl + "+" +
					KPRes.KeyboardKeyAlt + "+A - " + KPRes.Warning;
				dlg.SetIcon(VtdIcon.Warning);
				dlg.VerificationText = KPRes.DialogNoShowAgain;
				dlg.WindowTitle = PwDefs.ShortProductName;

				if(dlg.ShowDialog(fParent))
				{
					if(dlg.ResultVerificationChecked)
						Program.Config.Integration.CheckHotKeys = false;
				}
				else MessageService.ShowWarning(str);
			}
			catch(Exception) { Debug.Assert(false); }
		}
示例#11
0
        public static int ShowMessageBoxEx(string strContent, string strMainInstruction,
            string strWindowTitle, VtdIcon vtdIcon, Form fParent,
            string strButton1, int iResult1, string strButton2, int iResult2)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            vtd.CommandLinks = false;

            if(strContent != null) vtd.Content = strContent;
            if(strMainInstruction != null) vtd.MainInstruction = strMainInstruction;
            if(strWindowTitle != null) vtd.WindowTitle = strWindowTitle;

            vtd.SetIcon(vtdIcon);

            bool bCustomButton = false;
            if(!string.IsNullOrEmpty(strButton1))
            {
                vtd.AddButton(iResult1, strButton1, null);
                bCustomButton = true;
            }
            if(!string.IsNullOrEmpty(strButton2))
            {
                vtd.AddButton(iResult2, strButton2, null);
                bCustomButton = true;
            }

            if(!vtd.ShowDialog(fParent)) return -1;
            return (bCustomButton ? vtd.Result : 0);
        }
示例#12
0
		public static bool ShowMessageBox(string strContent, string strMainInstruction,
			string strWindowTitle, VtdIcon vtdIcon, IntPtr hParent)
		{
			VistaTaskDialog vtd = new VistaTaskDialog(hParent);

			vtd.CommandLinks = false;

			if(strContent != null) vtd.Content = strContent;
			if(strMainInstruction != null) vtd.MainInstruction = strMainInstruction;
			if(strWindowTitle != null) vtd.WindowTitle = strWindowTitle;

			vtd.SetIcon(vtdIcon);

			return vtd.ShowDialog();
		}
示例#13
0
        private void DeleteSelectedGroup()
        {
            PwGroup pg = GetSelectedGroup();
            if(pg == null) { Debug.Assert(false); return; }

            PwGroup pgParent = pg.ParentGroup;
            if(pgParent == null) return; // Can't remove virtual or root group

            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
            bool bShiftPressed = ((Control.ModifierKeys & Keys.Shift) != Keys.None);

            bool bPermanent = false;
            if(pd.RecycleBinEnabled == false) bPermanent = true;
            else if(bShiftPressed) bPermanent = true;
            else if(pgRecycleBin == null) { }
            else if(pg == pgRecycleBin) bPermanent = true;
            else if(pg.IsContainedIn(pgRecycleBin)) bPermanent = true;
            else if(pgRecycleBin.IsContainedIn(pg)) bPermanent = true;

            if(bPermanent)
            {
                VistaTaskDialog dlg = new VistaTaskDialog(this.Handle);
                dlg.CommandLinks = false;
                dlg.Content = KPRes.DeleteGroupInfo;
                dlg.MainInstruction = KPRes.DeleteGroupQuestion;
                dlg.SetIcon(VtdCustomIcon.Question);
                dlg.WindowTitle = PwDefs.ProductName;
                dlg.AddButton((int)DialogResult.OK, KPRes.DeleteCmd, null);
                dlg.AddButton((int)DialogResult.Cancel, KPRes.DontDeleteCmd, null);

                if(dlg.ShowDialog())
                {
                    if(dlg.Result == (int)DialogResult.Cancel) return;
                }
                else
                {
                    string strText = KPRes.DeleteGroupInfo + MessageService.NewParagraph +
                        KPRes.DeleteGroupQuestion;
                    if(!MessageService.AskYesNo(strText, KPRes.DeleteGroupTitle))
                        return;
                }
            }

            pgParent.Groups.Remove(pg);

            if(bPermanent)
            {
                PwDeletedObject pdo = new PwDeletedObject();
                pdo.Uuid = pg.Uuid;
                pdo.DeletionTime = DateTime.Now;
                pd.DeletedObjects.Add(pdo);
            }
            else // Recycle
            {
                bool bDummy = false;
                EnsureRecycleBin(ref pgRecycleBin, pd, ref bDummy);

                pgRecycleBin.AddGroup(pg, true, true);
                pg.Touch(false);
            }

            UpdateUI(false, null, true, pgParent, true, null, true);
        }
示例#14
0
        private void DeleteSelectedEntries()
        {
            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true);
            bool bShiftPressed = ((Control.ModifierKeys & Keys.Shift) != Keys.None);

            bool bAtLeastOnePermanent = false;
            if(pd.RecycleBinEnabled == false) bAtLeastOnePermanent = true;
            else if(bShiftPressed) bAtLeastOnePermanent = true;
            else if(pgRecycleBin == null) { } // Not permanent
            else
            {
                foreach(PwEntry peEnum in vSelected)
                {
                    if((peEnum.ParentGroup == pgRecycleBin) ||
                        peEnum.ParentGroup.IsContainedIn(pgRecycleBin))
                    {
                        bAtLeastOnePermanent = true;
                        break;
                    }
                }
            }

            if(bAtLeastOnePermanent)
            {
                bool bSingle = (vSelected.Length == 1);

                int nSummaryShow = Math.Min(10, vSelected.Length);
                if(nSummaryShow == (vSelected.Length - 1)) --nSummaryShow; // Plural msg
                string strSummary = string.Empty;
                for(int iSumEnum = 0; iSumEnum < nSummaryShow; ++iSumEnum)
                {
                    if(strSummary.Length > 0) strSummary += MessageService.NewLine;

                    PwEntry peDel = vSelected[iSumEnum];
                    strSummary += ("- " + StrUtil.CompactString3Dots(
                        peDel.Strings.ReadSafe(PwDefs.TitleField), 39));
                    if(PwDefs.IsTanEntry(peDel))
                    {
                        string strTanIdx = peDel.Strings.ReadSafe(PwDefs.UserNameField);
                        if(!string.IsNullOrEmpty(strTanIdx))
                            strSummary += (@" (#" + strTanIdx + @")");
                    }
                }
                if(nSummaryShow != vSelected.Length)
                    strSummary += (MessageService.NewLine + "- " +
                        KPRes.MoreEntries.Replace(@"{PARAM}", (vSelected.Length -
                        nSummaryShow).ToString()));

                VistaTaskDialog dlg = new VistaTaskDialog(this.Handle);
                dlg.CommandLinks = false;
                dlg.Content = strSummary;
                dlg.MainInstruction = (bSingle ? KPRes.DeleteEntriesQuestionSingle :
                    KPRes.DeleteEntriesQuestion);
                dlg.SetIcon(VtdCustomIcon.Question);
                dlg.WindowTitle = PwDefs.ProductName;
                dlg.AddButton((int)DialogResult.OK, KPRes.DeleteCmd, null);
                dlg.AddButton((int)DialogResult.Cancel, KPRes.DontDeleteCmd, null);

                if(dlg.ShowDialog())
                {
                    if(dlg.Result == (int)DialogResult.Cancel) return;
                }
                else
                {
                    if(!MessageService.AskYesNo(bSingle ? KPRes.DeleteEntriesQuestionSingle :
                        KPRes.DeleteEntriesQuestion, bSingle ? KPRes.DeleteEntriesTitleSingle :
                        KPRes.DeleteEntriesTitle))
                        return;
                }
            }

            bool bUpdateGroupList = false;
            DateTime dtNow = DateTime.Now;
            foreach(PwEntry pe in vSelected)
            {
                PwGroup pgParent = pe.ParentGroup;
                if(pgParent == null) continue; // Can't remove

                pgParent.Entries.Remove(pe);

                bool bPermanent = false;
                if(pd.RecycleBinEnabled == false) bPermanent = true;
                else if(bShiftPressed) bPermanent = true;
                else if(pgRecycleBin == null) { } // Recycle
                else if(pgParent == pgRecycleBin) bPermanent = true;
                else if(pgParent.IsContainedIn(pgRecycleBin)) bPermanent = true;

                if(bPermanent)
                {
                    PwDeletedObject pdo = new PwDeletedObject();
                    pdo.Uuid = pe.Uuid;
                    pdo.DeletionTime = dtNow;
                    pd.DeletedObjects.Add(pdo);
                }
                else // Recycle
                {
                    EnsureRecycleBin(ref pgRecycleBin, pd, ref bUpdateGroupList);

                    pgRecycleBin.AddEntry(pe, true, true);
                    pe.Touch(false);
                }
            }

            RemoveEntriesFromList(vSelected, true);
            UpdateUI(false, null, bUpdateGroupList, null, false, null, true);
        }
示例#15
0
        public static DialogResult ShowFileSaveQuestion(string strFile,
                                                        FileSaveOrigin fsOrigin)
        {
            bool bFile = ((strFile != null) && (strFile.Length > 0));

            if (WinUtil.IsAtLeastWindowsVista)
            {
                VistaTaskDialog dlg = new VistaTaskDialog();

                string strText = KPRes.DatabaseModifiedNoDot;
                if (bFile)
                {
                    strText += ":\r\n" + strFile;
                }
                else
                {
                    strText += ".";
                }

                dlg.CommandLinks = true;
                dlg.WindowTitle  = PwDefs.ShortProductName;
                dlg.Content      = strText;
                dlg.SetIcon(VtdCustomIcon.Question);

                bool bShowCheckBox = true;
                if (fsOrigin == FileSaveOrigin.Locking)
                {
                    dlg.MainInstruction = KPRes.FileSaveQLocking;
                    dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesLocking);
                    dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoLocking);
                    dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
                                  " " + KPRes.FileSaveQOpCancelLocking);
                }
                else if (fsOrigin == FileSaveOrigin.Exiting)
                {
                    dlg.MainInstruction = KPRes.FileSaveQExiting;
                    dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesExiting);
                    dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoExiting);
                    dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
                                  " " + KPRes.FileSaveQOpCancelExiting);
                }
                else
                {
                    dlg.MainInstruction = KPRes.FileSaveQClosing;
                    dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesClosing);
                    dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoClosing);
                    dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel +
                                  " " + KPRes.FileSaveQOpCancelClosing);
                    bShowCheckBox = false;
                }

                if (Program.Config.Application.FileClosing.AutoSave)
                {
                    bShowCheckBox = false;
                }
                if (bShowCheckBox)
                {
                    dlg.VerificationText = KPRes.AutoSaveAtExit;
                }

                if (dlg.ShowDialog())
                {
                    if (bShowCheckBox && (dlg.Result == (int)DialogResult.Yes))
                    {
                        Program.Config.Application.FileClosing.AutoSave = dlg.ResultVerificationChecked;
                    }

                    return((DialogResult)dlg.Result);
                }
            }

            string strMessage = (bFile ? (strFile + MessageService.NewParagraph) : string.Empty);

            strMessage += KPRes.DatabaseModifiedNoDot + "." +
                          MessageService.NewParagraph + KPRes.SaveBeforeCloseQuestion;
            return(MessageService.Ask(strMessage, KPRes.SaveBeforeCloseTitle,
                                      MessageBoxButtons.YesNoCancel));
        }
示例#16
0
        internal static void ShowConfigError(string strPath, string strError,
                                             bool bSaving, bool bCreateBackup)
        {
            if (string.IsNullOrEmpty(strError))
            {
                Debug.Assert(false); return;
            }

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(strPath))
            {
                sb.AppendLine(VistaTaskDialog.CreateLink("c", strPath));
                sb.AppendLine();
            }

            sb.AppendLine(bSaving ? KLRes.FileSaveFailed : KLRes.FileLoadFailed);
            sb.AppendLine();
            sb.Append(strError);

            string strText = sb.ToString();

            VistaTaskDialog dlg = new VistaTaskDialog();

            dlg.AddButton((int)DialogResult.Cancel, KPRes.Ok, null);
            dlg.CommandLinks     = false;
            dlg.Content          = strText;
            dlg.DefaultButtonID  = (int)DialogResult.Cancel;
            dlg.EnableHyperlinks = true;
            dlg.MainInstruction  = KPRes.ConfigError;
            dlg.SetIcon(VtdIcon.Warning);
            dlg.WindowTitle = PwDefs.ShortProductName;

            string strBackupText = null;
            string strBackupPath = (bCreateBackup ? AppConfigSerializer.TryCreateBackup(
                                        strPath) : null);

            if (!string.IsNullOrEmpty(strBackupPath))
            {
                strBackupText = KPRes.ConfigOverwriteBackup + MessageService.NewLine +
                                VistaTaskDialog.CreateLink("b", strBackupPath);
                dlg.FooterText = strBackupText;
                dlg.SetFooterIcon(VtdIcon.Information);
            }

            dlg.LinkClicked += delegate(object sender, LinkClickedEventArgs e)
            {
                string str = (e.LinkText ?? string.Empty);
                if (str.Equals("c", StrUtil.CaseIgnoreCmp))
                {
                    WinUtil.ShowFileInFileManager(strPath, false);
                }
                else if (str.Equals("b", StrUtil.CaseIgnoreCmp))
                {
                    WinUtil.ShowFileInFileManager(strBackupPath, false);
                }
                else
                {
                    Debug.Assert(false);
                }
            };

            if (!dlg.ShowDialog())
            {
                if (!string.IsNullOrEmpty(strBackupText))
                {
                    strText += MessageService.NewParagraph + strBackupText;
                }
                strText = VistaTaskDialog.Unlink(strText);

                MessageService.ShowWarning(KPRes.ConfigError + "!", strText);
            }
        }