2 * @file PluginsListDlg.cpp
4 * @brief Implementation file for PluginsList dialog
6 // ID line follows -- this is updated by SVN
10 #include "PluginsListDlg.h"
11 #include "UnicodeString.h"
14 #include "OptionsDef.h"
15 #include "OptionsMgr.h"
17 IMPLEMENT_DYNAMIC(PluginsListDlg, CDialog)
19 BEGIN_MESSAGE_MAP(PluginsListDlg, CDialog)
20 ON_BN_CLICKED(IDOK, OnBnClickedOk)
21 ON_BN_CLICKED(IDC_PLUGIN_SETTINGS, OnBnClickedPluginSettings)
22 ON_NOTIFY(NM_DBLCLK, IDC_PLUGINSLIST_LIST, OnNMDblclkList)
28 PluginsListDlg::PluginsListDlg(CWnd* pParent /*=NULL*/)
29 : CDialog(PluginsListDlg::IDD, pParent)
36 PluginsListDlg::~PluginsListDlg()
40 void PluginsListDlg::DoDataExchange(CDataExchange* pDX)
42 CDialog::DoDataExchange(pDX);
43 DDX_Control(pDX, IDC_PLUGINSLIST_LIST, m_list);
47 * @brief Initialize the dialog.
49 BOOL PluginsListDlg::OnInitDialog()
51 theApp.TranslateDialog(m_hWnd);
52 CDialog::OnInitDialog();
56 m_list.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
58 bool pluginsEnabled = GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED);
61 CButton *btn = (CButton *)GetDlgItem(IDC_PLUGINS_ENABLE);
62 btn->SetCheck(BST_CHECKED);
65 return FALSE; // return TRUE unless you set the focus to a control
66 // EXCEPTION: OCX Property Pages should return FALSE
70 * @brief Set-up the list control.
72 void PluginsListDlg::InitList()
74 // Show selection across entire row.
75 // Also enable infotips.
76 m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
78 String title = _("Name");
79 m_list.InsertColumn(0, title.c_str(), LVCFMT_LEFT, 150);
81 m_list.InsertColumn(1, title.c_str(), LVCFMT_LEFT, 100);
82 title = _("Description");
83 m_list.InsertColumn(2, title.c_str(), LVCFMT_LEFT, 300);
87 * @brief Add found plugins to the list.
89 void PluginsListDlg::AddPlugins()
91 String type = _("Unpacker");
92 AddPluginsToList(L"FILE_PACK_UNPACK", type);
93 AddPluginsToList(L"BUFFER_PACK_UNPACK", type);
94 AddPluginsToList(L"FILE_FOLDER_PACK_UNPACK", type);
95 type = _("Prediffer");
96 AddPluginsToList(L"FILE_PREDIFF", type);
97 AddPluginsToList(L"BUFFER_PREDIFF", type);
98 type = _("Editor script");
99 AddPluginsToList(L"EDITOR_SCRIPT", type);
103 * @brief Add plugins of given event type to the list.
104 * @param [in] pluginEvent Event type for plugins to add.
105 * @param [in] pluginType String to use as type in the list.
107 void PluginsListDlg::AddPluginsToList(const wchar_t *pluginEvent, const String& pluginType)
109 PluginArray * piPluginArray =
110 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(pluginEvent);
112 for (int iPlugin = 0 ; iPlugin < piPluginArray->size() ; iPlugin++)
114 const PluginInfoPtr& plugin = piPluginArray->at(iPlugin);
115 int ind = m_list.InsertItem(m_list.GetItemCount(), plugin->m_name.c_str());
116 m_list.SetItemText(ind, 1, pluginType.c_str());
117 m_list.SetItemText(ind, 2, plugin->m_description.c_str());
122 * @brief Save plugins enabled setting when closing the dialog.
124 void PluginsListDlg::OnBnClickedOk()
126 CButton *btn = (CButton *)GetDlgItem(IDC_PLUGINS_ENABLE);
127 int check = btn->GetCheck();
128 if (check == BST_CHECKED)
130 GetOptionsMgr()->SaveOption(OPT_PLUGINS_ENABLED, true);
134 GetOptionsMgr()->SaveOption(OPT_PLUGINS_ENABLED, false);
139 void PluginsListDlg::OnBnClickedPluginSettings()
141 POSITION pos = m_list.GetFirstSelectedItemPosition();
144 String pluginName = static_cast<const TCHAR *>(m_list.GetItemText(m_list.GetNextSelectedItem(pos), 0));
145 for (int i = 0; TransformationCategories[i]; ++i)
147 PluginInfo * plugin = CAllThreadsScripts::GetActiveSet()->GetPluginByName(TransformationCategories[i], pluginName);
151 InvokeShowSettingsDialog(plugin->m_lpDispatch);
153 SetForegroundWindow();
160 void PluginsListDlg::OnNMDblclkList(NMHDR *pNMHDR, LRESULT *pResult)
162 OnBnClickedPluginSettings();