source: filezilla/trunk/fuentes/src/interface/settings/optionspage_edit_associations.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 1.9 KB
Line 
1#include <filezilla.h>
2
3#include "../Options.h"
4#include "settingsdialog.h"
5#include "optionspage.h"
6#include "optionspage_edit_associations.h"
7
8bool COptionsPageEditAssociations::LoadPage()
9{
10        bool failure = false;
11
12        COptions* pOptions = COptions::Get();
13
14        SetTextFromOption(XRCID("ID_ASSOCIATIONS"), OPTION_EDIT_CUSTOMASSOCIATIONS, failure);
15        SetCheck(XRCID("ID_INHERIT"), pOptions->GetOptionVal(OPTION_EDIT_INHERITASSOCIATIONS) != 0, failure);
16
17        return !failure;
18}
19
20bool COptionsPageEditAssociations::SavePage()
21{
22        COptions* pOptions = COptions::Get();
23
24        SetOptionFromText(XRCID("ID_ASSOCIATIONS"), OPTION_EDIT_CUSTOMASSOCIATIONS);
25
26        pOptions->SetOption(OPTION_EDIT_INHERITASSOCIATIONS, GetCheck(XRCID("ID_INHERIT")) ? 1 : 0);
27
28        return true;
29}
30
31// optionspage_edit.cpp
32extern bool UnquoteCommand(wxString& command, wxString& arguments, bool is_dde = false);
33extern bool ProgramExists(const wxString& editor);
34
35bool COptionsPageEditAssociations::Validate()
36{
37        wxString associations = GetText(XRCID("ID_ASSOCIATIONS")) + _T("\n");
38        associations.Replace(_T("\r"), wxString());
39        int pos;
40        while ((pos = associations.Find('\n')) != -1) {
41                wxString assoc = associations.Left(pos);
42                associations = associations.Mid(pos + 1);
43
44                if (assoc.empty())
45                        continue;
46
47                wxString command;
48                if (!UnquoteCommand(assoc, command))
49                        return DisplayError(_T("ID_ASSOCIATIONS"), _("Improperly quoted association."));
50
51                if (assoc.empty())
52                        return DisplayError(_T("ID_ASSOCIATIONS"), _("Empty file extension."));
53
54                wxString args;
55                if (!UnquoteCommand(command, args))
56                        return DisplayError(_T("ID_ASSOCIATIONS"), _("Improperly quoted association."));
57
58                if (command.empty())
59                        return DisplayError(_T("ID_ASSOCIATIONS"), _("Empty command."));
60
61                if (!ProgramExists(command))
62                {
63                        wxString error = _("Associated program not found:");
64                        error += '\n';
65                        error += command;
66                        return DisplayError(_T("ID_ASSOCIATIONS"), error);
67                }
68        }
69
70        return true;
71}
Note: See TracBrowser for help on using the repository browser.