OSDN Git Service

Merge with stable
[winmerge-jp/winmerge-jp.git] / Src / PluginsListDlg.cpp
1 /**
2  * @file  PluginsListDlg.cpp
3  *
4  * @brief Implementation file for PluginsList dialog
5  */
6 // ID line follows -- this is updated by SVN
7 // $Id$
8
9 #include "stdafx.h"
10 #include "UnicodeString.h"
11 #include "Merge.h"
12 #include "Plugins.h"
13 #include "PluginsListDlg.h"
14 #include "OptionsDef.h"
15
16 IMPLEMENT_DYNAMIC(PluginsListDlg, CDialog)
17
18 BEGIN_MESSAGE_MAP(PluginsListDlg, CDialog)
19         ON_BN_CLICKED(IDOK, OnBnClickedOk)
20 END_MESSAGE_MAP()
21
22 /**
23  * @brief Constructor.
24  */
25 PluginsListDlg::PluginsListDlg(CWnd* pParent /*=NULL*/)
26         : CDialog(PluginsListDlg::IDD, pParent)
27 {
28 }
29
30 /**
31  * @brief Destructor.
32  */
33 PluginsListDlg::~PluginsListDlg()
34 {
35 }
36
37 void PluginsListDlg::DoDataExchange(CDataExchange* pDX)
38 {
39         CDialog::DoDataExchange(pDX);
40         DDX_Control(pDX, IDC_PLUGINSLIST_LIST, m_list);
41 }
42
43 /**
44  * @brief Initialize the dialog.
45  */
46 BOOL PluginsListDlg::OnInitDialog()
47 {
48         theApp.TranslateDialog(m_hWnd);
49         CDialog::OnInitDialog();
50         
51         InitList();
52         AddPlugins();
53
54         bool pluginsEnabled = GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED);
55         if (pluginsEnabled)
56         {
57                 CButton *btn = (CButton *)GetDlgItem(IDC_PLUGINS_ENABLE);
58                 btn->SetCheck(BST_CHECKED);
59         }
60
61         return FALSE;  // return TRUE unless you set the focus to a control
62                       // EXCEPTION: OCX Property Pages should return FALSE
63 }
64
65 /**
66  * @brief Set-up the list control.
67  */
68 void PluginsListDlg::InitList()
69 {
70         // Show selection across entire row.
71         // Also enable infotips.
72         m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
73
74         String title = _("Name");
75         m_list.InsertColumn(0, title.c_str(), LVCFMT_LEFT, 150);
76         title = _("Type");
77         m_list.InsertColumn(1, title.c_str(), LVCFMT_LEFT, 100);
78         title = _("Description");
79         m_list.InsertColumn(2, title.c_str(), LVCFMT_LEFT, 300);
80 }
81
82 /**
83  * @brief Add found plugins to the list.
84  */
85 void PluginsListDlg::AddPlugins()
86 {
87         String type = _("Unpacker");
88         AddPluginsToList(L"FILE_PACK_UNPACK", type);
89         AddPluginsToList(L"BUFFER_PACK_UNPACK", type);
90         type = _("Prediffer");
91         AddPluginsToList(L"FILE_PREDIFF", type);
92         AddPluginsToList(L"BUFFER_PREDIFF", type);
93         type = _("Editor script");
94         AddPluginsToList(L"EDITOR_SCRIPT", type);
95 }
96
97 /**
98  * @brief Add plugins of given event type to the list.
99  * @param [in] pluginEvent Event type for plugins to add.
100  * @param [in] pluginType String to use as type in the list.
101  */
102 void PluginsListDlg::AddPluginsToList(const wchar_t *pluginEvent, const String& pluginType)
103 {
104         PluginArray * piPluginArray = 
105                 CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(pluginEvent);
106
107         for (int iPlugin = 0 ; iPlugin < piPluginArray->size() ; iPlugin++)
108         {
109                 const PluginInfoPtr& plugin = piPluginArray->at(iPlugin);
110                 int ind = m_list.InsertItem(m_list.GetItemCount(), plugin->m_name.c_str());
111                 m_list.SetItemText(ind, 1, pluginType.c_str());
112                 m_list.SetItemText(ind, 2, plugin->m_description.c_str());
113         }
114 }
115
116 /**
117  * @brief Save plugins enabled setting when closing the dialog.
118  */
119 void PluginsListDlg::OnBnClickedOk()
120 {
121         CButton *btn = (CButton *)GetDlgItem(IDC_PLUGINS_ENABLE);
122         int check = btn->GetCheck();
123         if (check == BST_CHECKED)
124         {
125                 GetOptionsMgr()->SaveOption(OPT_PLUGINS_ENABLED, true);
126         }
127         else
128         {
129                 GetOptionsMgr()->SaveOption(OPT_PLUGINS_ENABLED, false);
130         }
131         OnOK();
132 }