Skip to content
Permalink
Browse files

Bug 582: Toolbar buttons can be hidden (reimplemented using explicit …

…"Customize Toolbar" submenu)

https://winscp.net/tracker/582

Source commit: 16b82bd015262798e8b627b909334221e5f277c9
  • Loading branch information...
martinprikryl committed Mar 12, 2018
1 parent cdcd01b commit b6a612c6140f6d1125e854290904cf18f548f2ee
@@ -9387,3 +9387,20 @@ void __fastcall TCustomScpExplorerForm::ChangeScale(int M, int D)
GUIConfiguration->ChangeResourceModule(ResourceModule);
}
}
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::DockContextPopup(TObject * Sender, TPoint & MousePos, bool & /*Handled*/)
{
NonVisualDataModule->ControlContextPopup(Sender, MousePos);
}
//---------------------------------------------------------------------
class TPublicControl : public TControl
{
friend class TCustomScpExplorerForm;
};
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::CopyPopup(TControl * DestControl, TControl * SourceControl)
{
static_cast<TPublicControl *>(DestControl)->PopupMenu = static_cast<TPublicControl *>(SourceControl)->PopupMenu;
static_cast<TPublicControl *>(DestControl)->OnContextPopup = static_cast<TPublicControl *>(SourceControl)->OnContextPopup;
}
//---------------------------------------------------------------------------
@@ -186,6 +186,7 @@ class TCustomScpExplorerForm : public TForm
void __fastcall EditMenuItemPopup(TTBCustomItem *Sender, bool FromLink);
void __fastcall DirViewBusy(TObject *Sender, int Busy, bool & Allow);
void __fastcall SessionsPageControlContextPopup(TObject *Sender, TPoint &MousePos, bool &Handled);
void __fastcall DockContextPopup(TObject *Sender, TPoint &MousePos, bool &Handled);

private:
TTerminal * FTerminal;
@@ -341,6 +342,7 @@ class TCustomScpExplorerForm : public TForm
bool __fastcall RemoteTransferFiles(TStrings * FileList, bool NoConfirmation,
bool Move, TTerminal * Session);
virtual void __fastcall DoDirViewExecFile(TObject * Sender, TListItem * Item, bool & AllowExec);
virtual TControl * __fastcall GetComponent(Byte Component);
bool __fastcall GetComponentVisible(Byte Component);
virtual Boolean __fastcall GetHasDirView(TOperationSide Side);
DYNAMIC void __fastcall KeyDown(Word & Key, Classes::TShiftState Shift);
@@ -590,6 +592,7 @@ class TCustomScpExplorerForm : public TForm
DYNAMIC void __fastcall ChangeScale(int M, int D);
virtual void __fastcall UpdateImages();
void __fastcall UpdatePixelsPerInchMainWindowCounter();
void __fastcall CopyPopup(TControl * DestControl, TControl * SourceControl);

public:
virtual __fastcall ~TCustomScpExplorerForm();
@@ -619,7 +622,6 @@ class TCustomScpExplorerForm : public TForm
void __fastcall UnlockWindow();
void __fastcall SuspendWindowLock();
void __fastcall ResumeWindowLock();
virtual TControl * __fastcall GetComponent(Byte Component);

void __fastcall NewSession(bool FromSite, const UnicodeString & SessionUrl = L"");
void __fastcall DuplicateSession();
@@ -114,6 +114,7 @@ __fastcall TNonVisualDataModule::TNonVisualDataModule(TComponent* Owner)
{
FListColumn = NULL;
FSessionIdleTimerExecuting = false;
FCustomizedToolbar = NULL;
FBusy = 0;

QueueSpeedComboBoxItem(QueuePopupSpeedComboBoxItem);
@@ -338,6 +339,7 @@ void __fastcall TNonVisualDataModule::ExplorerActionsUpdate(
UPDCOMP(CustomCommandsBand)
UPD(ColorMenuAction, HasTerminal)
UPD(GoToAddressAction, true)
UPD(CustomizeToolbarAction, IsToolbarCustomizable())

// SORT
UPDSORTA(Local)
@@ -649,6 +651,7 @@ void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
EXECOMP(CustomCommandsBand)
EXE(ColorMenuAction, CreateSessionColorMenu(ColorMenuAction))
EXE(GoToAddressAction, ScpExplorer->GoToAddress())
EXE(CustomizeToolbarAction, CreateToolbarButtonsList())

#define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
// SORT
@@ -1811,43 +1814,75 @@ void __fastcall TNonVisualDataModule::ToolbarButtonItemClick(TObject * Sender)
ButtonItem->Visible = !ButtonItem->Visible;
}
//---------------------------------------------------------------------------
void __fastcall TNonVisualDataModule::ToolbarComponentPopup(TTBCustomItem * Sender, bool /*FromLink*/)
bool __fastcall TNonVisualDataModule::IsCustomizableToolbarItem(TTBCustomItem * Item)
{
Byte Component = 0;
#define EMIT_BAND_COMPONENT(COMP) if (Sender->Action == COMP ## Action) { Component = fc ## COMP; }
BAND_COMPONENTS
#undef EMIT_BAND_COMPONENT

if (DebugAlwaysTrue(Component != 0))
return
(dynamic_cast<TTBXItem *>(Item) != NULL) ||
(dynamic_cast<TTBXSubmenuItem *>(Item) != NULL);
}
//---------------------------------------------------------------------------
bool __fastcall TNonVisualDataModule::IsToolbarCustomizable()
{
bool Result = false;
if (FCustomizedToolbar != NULL)
{
TTBCustomToolbar * Toolbar = dynamic_cast<TTBCustomToolbar *>(ScpExplorer->GetComponent(Component));
if (DebugAlwaysTrue(Toolbar != NULL))
for (int Index = 0; Index < FCustomizedToolbar->Items->Count; Index++)
{
Sender->Clear();

for (int Index = 0; Index < Toolbar->Items->Count; Index++)
if (IsCustomizableToolbarItem(FCustomizedToolbar->Items->Items[Index]))
{
TTBCustomItem * ButtonItem = Toolbar->Items->Items[Index];
Result = true;
break;
}
}
}
return Result;
}
//---------------------------------------------------------------------------
void __fastcall TNonVisualDataModule::CreateToolbarButtonsList()
{
if (FCustomizedToolbar != NULL)
{
TTBCustomItem * CustomizeItem = DebugNotNull(dynamic_cast<TTBCustomItem *>(CustomizeToolbarAction->ActionComponent));
CustomizeItem->Clear();

TTBCustomItem * Item;
if (dynamic_cast<TTBSeparatorItem *>(ButtonItem) != NULL)
{
Item = new TTBSeparatorItem(Sender);
}
else
{
Item = new TTBXItem(Sender);
Item->Caption = StripEllipsis(ButtonItem->Caption);
Item->ImageIndex = ButtonItem->ImageIndex;
Item->Tag = reinterpret_cast<int>(ButtonItem);
Item->OnClick = ToolbarButtonItemClick;
Item->Checked = ButtonItem->Visible;
Item->Enabled = Toolbar->Visible;
}
for (int Index = 0; Index < FCustomizedToolbar->Items->Count; Index++)
{
TTBCustomItem * ButtonItem = FCustomizedToolbar->Items->Items[Index];

Sender->Insert(Sender->Count, Item);
TTBCustomItem * Item = NULL;
if (dynamic_cast<TTBSeparatorItem *>(ButtonItem) != NULL)
{
Item = new TTBSeparatorItem(CustomizeItem);
}
else if (IsCustomizableToolbarItem(ButtonItem))
{
Item = new TTBXItem(CustomizeItem);
Item->Caption = StripEllipsis(ButtonItem->Caption);
Item->ImageIndex = ButtonItem->ImageIndex;
Item->Tag = reinterpret_cast<int>(ButtonItem);
Item->OnClick = ToolbarButtonItemClick;
Item->Checked = ButtonItem->Visible;
}

if (Item != NULL)
{
CustomizeItem->Insert(CustomizeItem->Count, Item);
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TNonVisualDataModule::ControlContextPopup(TObject * Sender, const TPoint & MousePos)
{
TTBDock * Dock = dynamic_cast<TTBDock *>(Sender);
if (Dock != NULL)
{
// While we can identify toolbar for which context menu is popping up in OnExecute,
// we cannot in OnUpdate, so we have to remeber it here.
FCustomizedToolbar = dynamic_cast<TTBCustomToolbar *>(Dock->ControlAtPos(MousePos, true, true, false));
}
else
{
FCustomizedToolbar = NULL;
}
}

0 comments on commit b6a612c

Please sign in to comment.
You can’t perform that action at this time.