1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
#ifndef FOLDER_PAIR_H_89341750847252345
#define FOLDER_PAIR_H_89341750847252345
#include <wx/event.h>
//#include <wx/menu.h>
#include <wx+/context_menu.h>
//#include <wx+/bitmap_button.h>
#include <wx+/image_tools.h>
#include <wx+/image_resources.h>
//#include "folder_selector.h"
//#include "small_dlgs.h"
//#include "sync_cfg.h"
#include "../base/norm_filter.h"
//#include "../base_tools.h"
namespace fff
{
//basic functionality for handling alternate folder pair configuration: change sync-cfg/filter cfg, right-click context menu, button icons...
template <class GuiPanel>
class FolderPairPanelBasic : private wxEvtHandler
{
public:
explicit FolderPairPanelBasic(GuiPanel& basicPanel) : //takes reference on basic panel to be enhanced
basicPanel_(basicPanel)
{
using namespace zen;
//register events for removal of alternate configuration
basicPanel_.m_bpButtonLocalCompCfg ->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent& event) { onLocalCompCfgContext (event); });
basicPanel_.m_bpButtonLocalSyncCfg ->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent& event) { onLocalSyncCfgContext (event); });
basicPanel_.m_bpButtonLocalFilter ->Bind(wxEVT_RIGHT_DOWN, [this](wxMouseEvent& event) { onLocalFilterCfgContext(event); });
setImage(*basicPanel_.m_bpButtonRemovePair, loadImage("item_remove"));
}
void setConfig(const std::optional<CompConfig>& compConfig, const std::optional<SyncConfig>& syncCfg, const FilterConfig& filter)
{
localCmpCfg_ = compConfig;
localSyncCfg_ = syncCfg;
localFilter_ = filter;
refreshButtons();
}
std::optional<CompConfig> getCompConfig () const { return localCmpCfg_; }
std::optional<SyncConfig> getSyncConfig () const { return localSyncCfg_; }
FilterConfig getFilterConfig() const { return localFilter_; }
private:
void refreshButtons()
{
using namespace zen;
setImage(*basicPanel_.m_bpButtonLocalCompCfg, greyScaleIfDisabled(imgCmp_, !!localCmpCfg_));
basicPanel_.m_bpButtonLocalCompCfg->SetToolTip(localCmpCfg_ ?
_("Local comparison settings") + L" (" + getVariantName(localCmpCfg_->compareVar) + L')' :
_("Local comparison settings"));
setImage(*basicPanel_.m_bpButtonLocalSyncCfg, greyScaleIfDisabled(imgSync_, !!localSyncCfg_));
basicPanel_.m_bpButtonLocalSyncCfg->SetToolTip(localSyncCfg_ ?
_("Local synchronization settings") + L" (" + getVariantName(getSyncVariant(localSyncCfg_->directionCfg)) + L')' :
_("Local synchronization settings"));
setImage(*basicPanel_.m_bpButtonLocalFilter, greyScaleIfDisabled(imgFilter_, !isNullFilter(localFilter_)));
basicPanel_.m_bpButtonLocalFilter->SetToolTip(!isNullFilter(localFilter_) ?
_("Local filter") + L" (" + _("Active") + L')' :
_("Local filter") + L" (" + _("None") + L')');
}
void onLocalCompCfgContext(wxEvent& event)
{
auto removeLocalCompCfg = [&]
{
this->localCmpCfg_ = {}; //"this->" galore: workaround GCC compiler bugs
this->refreshButtons();
this->onLocalCompCfgChange();
};
zen::ContextMenu menu;
menu.addItem(_("Remove local settings"), removeLocalCompCfg, wxNullImage, static_cast<bool>(localCmpCfg_));
menu.popup(*basicPanel_.m_bpButtonLocalCompCfg, {basicPanel_.m_bpButtonLocalCompCfg->GetSize().x, 0});
}
void onLocalSyncCfgContext(wxEvent& event)
{
auto removeLocalSyncCfg = [&]
{
this->localSyncCfg_ = {};
this->refreshButtons();
this->onLocalSyncCfgChange();
};
zen::ContextMenu menu;
menu.addItem(_("Remove local settings"), removeLocalSyncCfg, wxNullImage, static_cast<bool>(localSyncCfg_));
menu.popup(*basicPanel_.m_bpButtonLocalSyncCfg, {basicPanel_.m_bpButtonLocalSyncCfg->GetSize().x, 0});
}
void onLocalFilterCfgContext(wxEvent& event)
{
using namespace zen;
std::optional<FilterConfig> filterCfgOnClipboard;
if (std::optional<wxString> clipTxt = getClipboardText())
filterCfgOnClipboard = parseFilterBuf(utfTo<std::string>(*clipTxt));
auto cutFilter = [&]
{
setClipboardText(utfTo<wxString>(serializeFilter(this->localFilter_)));
this->localFilter_ = FilterConfig();
this->refreshButtons();
this->onLocalFilterCfgChange();
};
auto copyFilter = [&] { setClipboardText(utfTo<wxString>(serializeFilter(this->localFilter_))); };
auto pasteFilter = [&]
{
this->localFilter_ = *filterCfgOnClipboard;
this->refreshButtons();
this->onLocalFilterCfgChange();
};
zen::ContextMenu menu;
menu.addItem( _("Cu&t"), cutFilter, loadImage("item_cut_sicon"), !isNullFilter(localFilter_));
menu.addSeparator();
menu.addItem( _("&Copy"), copyFilter, loadImage("item_copy_sicon"), !isNullFilter(localFilter_));
menu.addItem( _("&Paste"), pasteFilter, loadImage("item_paste_sicon"), filterCfgOnClipboard.has_value());
menu.popup(*basicPanel_.m_bpButtonLocalFilter, {basicPanel_.m_bpButtonLocalFilter->GetSize().x, 0});
}
virtual MainConfiguration getMainConfig() const = 0;
virtual wxWindow* getParentWindow() = 0;
virtual void onLocalCompCfgChange () = 0;
virtual void onLocalSyncCfgChange () = 0;
virtual void onLocalFilterCfgChange() = 0;
GuiPanel& basicPanel_; //panel to be enhanced by this template
//alternate configuration attached to it
std::optional<CompConfig> localCmpCfg_;
std::optional<SyncConfig> localSyncCfg_;
FilterConfig localFilter_;
const wxImage imgCmp_ = zen::loadImage("options_compare", zen::dipToScreen(20));
const wxImage imgSync_ = zen::loadImage("options_sync", zen::dipToScreen(20));
const wxImage imgFilter_ = zen::loadImage("options_filter", zen::dipToScreen(20));
};
}
#endif //FOLDER_PAIR_H_89341750847252345
|