📄 mainunit.cpp
字号:
{
// Check if we should minimize the file name
if (ZipBuilder->ZipFileName != "")
Caption = "JZip - "+MinimizeName( ZipBuilder->ZipFileName, Canvas, ClientWidth-Canvas->TextWidth("JZip - ")-140);
// NB: This should be improved some more. Was just a quick hack!
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Configuration1Click(TObject *Sender)
{
/* --- Set the correct settings in the dialog --- */
// View
ConfigForm->FullRowCheckBox->Checked = bFullRowSelect;
ConfigForm->GridLinesCheckBox->Checked = bGridLines;
ConfigForm->FlatScroolbarsCheckBox->Checked = bFlatScroolBars;
// Kept for later use (not implemented yet)
// ConfigForm->UserCurrentRowCheckBox->Checked = bUseCurrentFolderSettings;
if (bSingleClick)
{
ConfigForm->SingleRadioButton->Enabled = true;
ConfigForm->DoubleRadioButton->Enabled = true;
ConfigForm->AlwaysRadioButton->Enabled = true;
ConfigForm->UnderlineRadioButton->Enabled = true;
ConfigForm->NeverRadioButton->Enabled = true;
ConfigForm->SingleRadioButton->Checked = true;
}
else // bDoubleClick
{
ConfigForm->SingleRadioButton->Enabled = true;
ConfigForm->DoubleRadioButton->Enabled = true;
ConfigForm->AlwaysRadioButton->Enabled = false;
ConfigForm->UnderlineRadioButton->Enabled = false;
ConfigForm->NeverRadioButton->Enabled = false;
ConfigForm->DoubleRadioButton->Checked = true;
}
// Set SingleClick sub radiobuttons under all circumstances
switch(iSingleClickOption)
{
case 0: // Never underline file names
ConfigForm->NeverRadioButton->Checked = true;
break;
case 1: // Underline file names when I point at them
ConfigForm->UnderlineRadioButton->Checked = true;
break;
case 2: // Always underline file names
ConfigForm->AlwaysRadioButton->Checked = true;
break;
}
// Toolbar
ConfigForm->ShowButtonTextCheckBox->Checked = bShowButtonText;
ConfigForm->ShowToolTipCheckBox->Checked = bShowToolTip;
ConfigForm->FlatButtonsCheckBox->Checked = bFlatButtons;
// System
ConfigForm->AssociateCheckBox->Checked = bAssociateWithZIP;
ConfigForm->IncludeInStartMenuCheckBox->Checked = bIncludeInStartMenu;
ConfigForm->IncludeOnDesktopCheckBox->Checked = bIncludeOnDesktop;
// -----------------------------------------------------------------------
ConfigForm->ShowModal();
if (ConfigForm->ModalResult == mrCancel)
return;
// -----------------------------------------------------------------------
// Save settings ;)
// View
bFullRowSelect = ConfigForm->FullRowCheckBox->Checked;
bGridLines = ConfigForm->GridLinesCheckBox->Checked;
bFlatScroolBars = ConfigForm->FlatScroolbarsCheckBox->Checked;
// Kept for later use (not implemented yet)
// bUseCurrentFolderSettings = ConfigForm->UserCurrentRowCheckBox->Checked;
bSingleClick = ConfigForm->SingleRadioButton->Checked;
if (bSingleClick)
{
if (ConfigForm->NeverRadioButton->Checked)
iSingleClickOption = 0;
else
if (ConfigForm->UnderlineRadioButton->Checked)
iSingleClickOption = 1;
else
if (ConfigForm->AlwaysRadioButton->Checked)
iSingleClickOption = 2;
bDoubleClick = false;
}
else // bDoubleClick
{
bDoubleClick = true;
}
// Toolbar
bShowButtonText = ConfigForm->ShowButtonTextCheckBox->Checked;
bShowToolTip = ConfigForm->ShowToolTipCheckBox->Checked;
bFlatButtons = ConfigForm->FlatButtonsCheckBox->Checked;
// System
bAssociateWithZIP = ConfigForm->AssociateCheckBox->Checked;
bIncludeInStartMenu = ConfigForm->IncludeInStartMenuCheckBox->Checked;
bIncludeOnDesktop = ConfigForm->IncludeOnDesktopCheckBox->Checked;
// Make the changes effective
SetConfiguration();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ReadConfiguration()
{
TRegistry* thisReg = new TRegistry();
thisReg->OpenKey("SOFTWARE\\JZip", true);
// Read View settings
if (thisReg->ValueExists("Full Row Select"))
bFullRowSelect = thisReg->ReadBool("Full Row Select");
else
bFullRowSelect = true; // Default value
if (thisReg->ValueExists("Grid Lines"))
bGridLines = thisReg->ReadBool("Grid Lines");
else
bGridLines = false; // Default value
if (thisReg->ValueExists("Flat Scroolbars"))
bFlatScroolBars = thisReg->ReadBool("Flat Scrollbars");
else
bFlatScroolBars = false; // Default value
if (thisReg->ValueExists("Use Current Folder Settings"))
bUseCurrentFolderSettings = thisReg->ReadBool("Use Current Folder Settings");
else
bUseCurrentFolderSettings = false; // Default value
if (thisReg->ValueExists("Use Current Folder Settings"))
bUseCurrentFolderSettings = thisReg->ReadBool("Use Current Folder Settings");
else
bUseCurrentFolderSettings = false; // Default value
if (thisReg->ValueExists("Single Click"))
bSingleClick = thisReg->ReadBool("Single Click");
else
bSingleClick = false; // Default value
if (thisReg->ValueExists("Single Click Option"))
iSingleClickOption = thisReg->ReadInteger("Single Click Option");
else
iSingleClickOption = 1; // Default value
if (thisReg->ValueExists("Double Click"))
bDoubleClick = thisReg->ReadBool("Double Click");
else
bDoubleClick = true; // Default value
// Toolbar
if (thisReg->ValueExists("Show Button Text"))
bShowButtonText = thisReg->ReadBool("Show Button Text");
else
bShowButtonText = true; // Default value
if (thisReg->ValueExists("Show ToolTip"))
bShowToolTip = thisReg->ReadBool("Show ToolTip");
else
bShowToolTip = true; // Default value
if (thisReg->ValueExists("Flat Toolbar Buttons"))
bFlatButtons = thisReg->ReadBool("Flat Toolbar Buttons");
else
bFlatButtons = true; // Default value
// System
if (thisReg->ValueExists("Associate JZip with ZIP archives"))
bAssociateWithZIP = thisReg->ReadBool("Associate JZip with ZIP archives");
else
bAssociateWithZIP = true; // Default value
if (thisReg->ValueExists("Include JZip in the Start Menu"))
bIncludeInStartMenu = thisReg->ReadBool("Include JZip in the Start Menu");
else
bIncludeInStartMenu = true; // Default value
if (thisReg->ValueExists("Include JZip on the Desktop"))
bIncludeOnDesktop = thisReg->ReadBool("Include JZip on the Desktop");
else
bIncludeOnDesktop = true; // Default value
// Clean up
thisReg->CloseKey();
delete thisReg;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SetConfiguration()
{
// View
if (bFullRowSelect)
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxFullRowSelect;
else
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxFullRowSelect;
if (bGridLines)
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxGridLines;
else
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxGridLines;
if (bFlatScroolBars)
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxFlatScrollBar;
else
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxFlatScrollBar;
//bUseCurrentFolderSettings (not implemented);
if (bSingleClick)
{
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxOneClickActivate;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxTwoClickActivate;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxTrackSelect;
switch (iSingleClickOption)
{
case 0: // Never underline file names
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxUnderlineHot;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxUnderlineCold;
break;
case 1: // Underline file names when I point at them
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxUnderlineHot;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxUnderlineCold;
break;
case 2: // Always underline file names
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles << lvxUnderlineCold;
break;
} // end switch
}
else // bDoubleClick
{
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxTrackSelect;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxUnderlineHot;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxUnderlineCold;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxOneClickActivate;
ExtListView->ExtendedStyles = ExtListView->ExtendedStyles >> lvxTwoClickActivate;
}
// Toolbar
ToolBar->ShowCaptions = bShowButtonText;
Application->ShowHint = bShowToolTip;
ToolBar->Flat = bFlatButtons;
// System
if (bAssociateWithZIP)
{
/* --- Check who owns the ZIP file --- */
TRegistry* thisReg = new TRegistry();
// Register zip file format
thisReg->RootKey = HKEY_CLASSES_ROOT;
thisReg->OpenKey(".zip", true);
if (thisReg->ReadString("") == "JZip")
{
// We already own the extension
thisReg->CloseKey();
delete thisReg;
goto CONTINUE;
}
thisReg->WriteString("", "JZip");
thisReg->CloseKey();
// Check in the Open command
thisReg->OpenKey("JZip", true);
thisReg->WriteString("", "JZip Archive");
thisReg->OpenKey("shell", true);
thisReg->WriteString("", "open");
thisReg->OpenKey("open", true);
thisReg->WriteString("", "&Open");
thisReg->OpenKey("command", true);
thisReg->WriteString("", ParamStr(0)+" \"\%1\"");
thisReg->CloseKey();
// Set default icon
thisReg->OpenKey("JZip", true);
thisReg->OpenKey("DefaultIcon", true);
thisReg->WriteString("", ParamStr(0)+",0");
thisReg->CloseKey();
delete thisReg;
}
CONTINUE:
if (bIncludeInStartMenu)
{
CreateShortCut(ParamStr(0), iStartMenu);
}
else
{
// Delete the shortcut (if it exists)
DeleteShortCut(iStartMenu);
}
if (bIncludeOnDesktop)
{
CreateShortCut(ParamStr(0), iDesktop);
}
else
{
// Delete the shortcut (if it exists)
DeleteShortCut(iDesktop);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WriteConfiguration()
{
TRegistry* thisReg = new TRegistry();
thisReg->OpenKey("SOFTWARE\\JZip", true);
// Write View settings
thisReg->WriteBool("Full Row Select", bFullRowSelect);
thisReg->WriteBool("Grid Lines", bGridLines);
thisReg->WriteBool("Flat Scrollbars", bFlatScroolBars);
thisReg->WriteBool("Use Current Folder Settings", bUseCurrentFolderSettings);
thisReg->WriteBool("Single Click", bSingleClick);
thisReg->WriteInteger("Single Click Option", iSingleClickOption);
thisReg->WriteBool("Double Click", bDoubleClick);
// Toolbar
thisReg->WriteBool("Show Button Text", bShowButtonText);
thisReg->WriteBool("Show ToolTip", bShowToolTip);
thisReg->WriteBool("Flat Toolbar Buttons", bFlatButtons);
// System
thisReg->WriteBool("Associate JZip with ZIP archives", bAssociateWithZIP);
thisReg->WriteBool("Include JZip in the Start Menu", bIncludeInStartMenu);
thisReg->WriteBool("Include JZip on the Desktop", bIncludeOnDesktop );
// Clean up
thisReg->CloseKey();
delete thisReg;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DeleteShortCut(int iDestination)
{
LPMALLOC ShellMalloc;
LPITEMIDLIST DesktopPidl;
char DesktopDir[MAX_PATH];
// We are going to create a pidl, and it will need to be
// freed by the shell mallocator. Get the shell mallocator
// object using API SHGetMalloc function. Return if failure.
if(FAILED(SHGetMalloc(&ShellMalloc)))
return;
// Check for the destination of our shortcut
switch(iDestination)
{
case 0: // Desktop
// use the API to get a pidl for the desktop directory
// if function fails, return without proceeding
if(FAILED(SHGetSpecialFolderLocation(NULL,
CSIDL_DESKTOPDIRECTORY,
&DesktopPidl)))
return;
break;
case 1: // Startmenu
if(FAILED(SHGetSpecialFolderLocation(NULL,
CSIDL_S
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -