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