📄 gmops.c
字号:
{
PGPGetIndGroupItem (pas->pGM->groupsetMain,
id, index, &groupitem);
groupitem.userValue = 0;
err = PGPAddItemToGroup (pas->pGM->groupsetMain,
&groupitem, pas->groupidDest);
if (IsntPGPError (err))
pas->bAdded = TRUE;
}
return TRUE;
}
}
// _______________________________________________
//
// add selected items to focused group
BOOL
GMAddSelectedToFocused (PGROUPMAN pGM)
{
PGPGroupID groupidDest;
TL_TREEITEM tli;
ADDSTRUCT as;
tli.hItem = GMFocusedItem (pGM);
tli.mask = TLIF_IMAGE|TLIF_PARAM;
TreeList_GetItem (pGM->hwndTree, &tli);
// if selected item is a group then get the groupid
if (tli.iImage == IDX_GROUP)
{
groupidDest = HIWORD(tli.lParam);
if (!groupidDest)
groupidDest = LOWORD(tli.lParam);
}
// otherwise it's a key, get the parent groupid
else
groupidDest = HIWORD(tli.lParam);
if (groupidDest)
{
as.pfnCallback = sAddSingleObject;
as.pGM = pGM;
as.groupidDest = groupidDest;
as.bAdded = FALSE;
TreeList_IterateSelected (pGM->hwndTree, &as);
}
if (as.bAdded)
{
GMSortGroupSet (pGM);
GMCommitGroupChanges (pGM, TRUE);
GMLoadGroupsIntoTree (pGM, FALSE, TRUE, FALSE);
InvalidateRect (pGM->hwndTree, NULL, TRUE);
UpdateWindow (pGM->hwndTree);
}
return TRUE;
}
// _______________________________________________
//
// add keys to selected group
BOOL
GMAddKeysToGroup (
PGROUPMAN pGM,
PGPKeyDBRef keydb)
{
PGPKeyIterRef keyiter;
PGPKeyDBObjRef key;
PGPGroupID groupid;
PGPGroupItem groupitem;
TL_TREEITEM tli;
tli.hItem = GMFocusedItem (pGM);
tli.mask = TLIF_IMAGE|TLIF_PARAM;
TreeList_GetItem (pGM->hwndTree, &tli);
// if selected item is a group then get the groupid
if (tli.iImage == IDX_GROUP)
{
groupid = HIWORD(tli.lParam);
if (!groupid)
groupid = LOWORD(tli.lParam);
}
// otherwise it's a key, get the parent groupid
else
groupid = HIWORD(tli.lParam);
if (groupid)
{
PGPNewKeyIterFromKeyDB (keydb, &keyiter);
PGPKeyIterNextKeyDBObj (keyiter, kPGPKeyDBObjType_Key, &key);
while (key)
{
groupitem.type = kPGPGroupItem_KeyID;
groupitem.userValue = 0;
PGPGetKeyID (key, &groupitem.u.keyID);
PGPAddItemToGroup (pGM->groupsetMain, &groupitem, groupid);
PGPKeyIterNextKeyDBObj (keyiter, kPGPKeyDBObjType_Key, &key);
}
PGPFreeKeyIter (keyiter);
}
return TRUE;
}
// _______________________________________________
//
// Drop text key(s)
BOOL
GMDropKeys (
PGROUPMAN pGM,
HANDLE hMem)
{
PGPKeyDBRef keydb;
PGPError err;
BOOL bAdded;
LPSTR pMem;
size_t sLen;
bAdded = FALSE;
if (hMem)
{
pMem = GlobalLock (hMem);
if (pMem)
{
sLen = lstrlen (pMem);
err = PGPImport (pGM->context, &keydb,
PGPOInputBuffer (pGM->context, pMem, sLen),
PGPOLastOption (pGM->context));
if (IsntPGPError (PGPclErrorBox (NULL, err) &&
PGPKeyDBRefIsValid (keydb)))
{
PGPUInt32 numKeys;
PGPCountKeys (PGPPeekKeyDBRootKeySet (keydb), &numKeys);
if (numKeys > 0)
{
GMAddKeysToGroup (pGM, keydb);
TreeList_Select (pGM->hwndTree, NULL, TRUE);
GMSetFocus (pGM, NULL, FALSE, FALSE);
bAdded = TRUE;
}
PGPFreeKeyDB (keydb);
}
GlobalUnlock (hMem);
}
}
if (bAdded)
{
GMSortGroupSet (pGM);
GMCommitGroupChanges (pGM, TRUE);
GMLoadGroupsIntoTree (pGM, FALSE, TRUE, FALSE);
InvalidateRect (pGM->hwndTree, NULL, TRUE);
UpdateWindow (pGM->hwndTree);
}
return bAdded;
}
// _______________________________________________
//
// Paste key(s) from clipboard
BOOL
GMPasteKeys (PGROUPMAN pGM)
{
BOOL bAdded;
HANDLE hMem;
bAdded = FALSE;
if (OpenClipboard (NULL))
{
hMem = GetClipboardData (CF_TEXT);
if (hMem)
bAdded = GMDropKeys (pGM, hMem);
CloseClipboard ();
}
if (!bAdded)
{
PGPgmMessageBox (pGM->hwndParent, IDS_CAPTIONINFO,
IDS_NOPASTEKEYS, MB_OK|MB_ICONINFORMATION);
}
return bAdded;
}
// ___________________________________________________
//
// Locate (ie. select) a single object
// routine called as a callback function from the TreeList control to
// delete a single item.
//
// lptli = pointer to TreeList item to delete
static BOOL CALLBACK
sLocateSingleObject (
TL_TREEITEM* lptli,
LPARAM lParam)
{
LOCATESTRUCT* pls = (LOCATESTRUCT*)lParam;
PGPKeyDBObjRef key;
PGPUInt32 index;
PGPGroupID id;
PGPGroupItem groupitem;
PGPError err;
switch (lptli->iImage) {
// is it a group ?
case IDX_GROUP :
return TRUE;
// otherwise it's a key
default:
id = HIWORD(lptli->lParam);
index = LOWORD(lptli->lParam);
if (id)
{
PGPGetIndGroupItem (pls->pGM->groupsetMain,
id, index, &groupitem);
err = PGPFindKeyByKeyID (pls->pGM->keydbMain,
&groupitem.u.keyID, &key);
if (IsntPGPError (err))
{
if (pls->bFirst)
{
PGPclKeyListSetTree (pls->pGM->hKL,
kPGPclSelectSpecifiedOnly, key);
pls->bFirst = FALSE;
}
else
{
PGPclKeyListSetTree (pls->pGM->hKL,
kPGPclSelectSpecified, key);
}
}
return TRUE;
}
}
return FALSE;
}
// ___________________________________________________
//
// select keys in main keys window
BOOL
GMLocateKeys (PGROUPMAN pGM)
{
LOCATESTRUCT ls;
ls.pfnCallback = sLocateSingleObject;
ls.pGM = pGM;
ls.bFirst = TRUE;
pGM->bLocatingKeys = TRUE;
TreeList_IterateSelected (pGM->hwndTree, &ls);
pGM->bLocatingKeys = FALSE;
return TRUE;
}
// _______________________________________________
//
// Import groups from group file
//
// hDrop == NULL => prompt user for file name
// != NULL => hDrop is a handle passed in from
// the WM_DROPFILE message
//
BOOL
GMImportGroups (
PGROUPMAN pGM,
LPSTR pszFile,
HDROP hDrop)
{
PGPGroupSetRef groupset = NULL;
OPENFILENAME OpenFileName;
CHAR szFile[MAX_PATH];
CHAR szInitDir[MAX_PATH];
CHAR szFilter[256];
CHAR szTitle[64];
CHAR* p;
INT iIndex;
BOOL bImport;
PGPFileSpecRef filespec;
PGPError err;
// file was specified
if (pszFile)
{
PGPNewFileSpecFromFullPath (pGM->context, pszFile, &filespec);
if (filespec)
{
groupset = NULL;
err = PGPNewGroupSetFromFile (
pGM->context, filespec, &groupset);
if (IsntPGPError (err))
{
err = PGPMergeGroupSets (groupset, pGM->groupsetMain);
if (IsntPGPError (err))
bImport = TRUE;
}
if (groupset)
PGPFreeGroupSet (groupset);
PGPFreeFileSpec (filespec);
}
if (!bImport)
{
PGPgmMessageBox (pGM->hwndParent, IDS_CAPTIONINFO,
IDS_NOIMPORTGROUPS, MB_OK|MB_ICONINFORMATION);
}
}
// file was dropped
else if (hDrop)
{
iIndex = 0;
bImport = FALSE;
while (DragQueryFile (hDrop, iIndex, szFile, sizeof(szFile)))
{
PGPNewFileSpecFromFullPath (pGM->context, szFile, &filespec);
if (filespec)
{
groupset = NULL;
err = PGPNewGroupSetFromFile (
pGM->context, filespec, &groupset);
if (IsntPGPError (err))
{
err = PGPMergeGroupSets (groupset, pGM->groupsetMain);
if (IsntPGPError (err))
bImport = TRUE;
}
if (groupset)
PGPFreeGroupSet (groupset);
PGPFreeFileSpec (filespec);
}
iIndex++;
}
if (!bImport)
{
PGPgmMessageBox (pGM->hwndParent, IDS_CAPTIONINFO,
IDS_NOIMPORTGROUPS, MB_OK|MB_ICONINFORMATION);
}
}
// file wasn't dropped, prompt user for file name
else
{
lstrcpy (szFile, "");
LoadString (g_hinst,
IDS_GROUPIMPORTFILTER, szFilter, sizeof(szFilter));
while (p = strrchr (szFilter, '@')) *p = '\0';
LoadString (g_hinst,
IDS_GROUPIMPORTCAPTION, szTitle, sizeof(szTitle));
PGPclGetPath (kPGPclDefaultOpenFolder, szInitDir, sizeof(szInitDir));
OpenFileName.lStructSize = sizeof (OPENFILENAME);
OpenFileName.hwndOwner = pGM->hwndParent;
OpenFileName.hInstance = (HANDLE)g_hinst;
OpenFileName.lpstrFilter = szFilter;
OpenFileName.lpstrCustomFilter = (LPTSTR)NULL;
OpenFileName.nMaxCustFilter = 0L;
OpenFileName.nFilterIndex = 1L;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof (szFile);
OpenFileName.lpstrFileTitle = NULL;
OpenFileName.nMaxFileTitle = 0;
OpenFileName.lpstrInitialDir = szInitDir;
OpenFileName.lpstrTitle = szTitle;
OpenFileName.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR;
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = "";
OpenFileName.lCustData = 0;
bImport = FALSE;
if (GetOpenFileName (&OpenFileName))
{
PGPNewFileSpecFromFullPath (pGM->context, szFile, &filespec);
if (filespec)
{
groupset = NULL;
err = PGPNewGroupSetFromFile (
pGM->context, filespec, &groupset);
if (IsntPGPError (err))
{
err = PGPMergeGroupSets (groupset, pGM->groupsetMain);
if (IsntPGPError (err)) bImport = TRUE;
}
if (groupset)
PGPFreeGroupSet (groupset);
PGPFreeFileSpec (filespec);
}
if (!bImport)
{
PGPgmMessageBox (pGM->hwndParent, IDS_CAPTIONINFO,
IDS_NOIMPORTGROUPS, MB_OK|MB_ICONINFORMATION);
}
}
}
if (bImport)
{
GMSortGroupSet (pGM);
GMCommitGroupChanges (pGM, TRUE);
GMLoadGroupsIntoTree (pGM, FALSE, TRUE, FALSE);
InvalidateRect (pGM->hwndTree, NULL, TRUE);
UpdateWindow (pGM->hwndTree);
}
return bImport;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -