summaryrefslogtreecommitdiff
path: root/CodeLite/fileextmanager.cpp
blob: a343c4511b7d1d1b87f0a84625447ba724582962 (plain)
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : fileextmanager.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "fileextmanager.h"
#include <wx/filename.h>

std::map<wxString, FileExtManager::FileType> FileExtManager::m_map;

void FileExtManager::Init()
{
    static bool init_done(false);

    if ( !init_done ) {
        init_done = true;

        m_map[wxT("cc") ] = TypeSourceCpp;
        m_map[wxT("cpp")] = TypeSourceCpp;
        m_map[wxT("cxx")] = TypeSourceCpp;
        m_map[wxT("c++")] = TypeSourceCpp;
        m_map[wxT("c")  ] = TypeSourceC;

        m_map[wxT("h")   ] = TypeHeader;
        m_map[wxT("hpp") ] = TypeHeader;
        m_map[wxT("hxx") ] = TypeHeader;
        m_map[wxT("hh")  ] = TypeHeader;
        m_map[wxT("h++") ] = TypeHeader;
        m_map[wxT("inl") ] = TypeHeader;

        m_map[wxT("rc")  ] = TypeResource;
        m_map[wxT("res") ] = TypeResource;

        m_map[wxT("y")   ] = TypeYacc;
        m_map[wxT("l")   ] = TypeLex;
        m_map[wxT("ui")  ] = TypeQtForm;
        m_map[wxT("qrc") ] = TypeQtResource;

        m_map[wxT("project") ]   = TypeProject;
        m_map[wxT("workspace") ] = TypeWorkspace;
        m_map[wxT("fbp") ] = TypeFormbuilder;
        m_map[wxT("cdp") ] = TypeCodedesigner;
        m_map[wxT("erd") ] = TypeErd;

        m_map[wxT("php")]   = TypePhp;
        m_map[wxT("inc")]   = TypePhp;
        m_map[wxT("phtml")] = TypePhp;

        m_map[wxT("xml")] = TypeXml;
        m_map[wxT("xrc")] = TypeXRC;
        m_map[wxT("css")] = TypeCSS;
        m_map[wxT("js")]  = TypeJS;
        m_map[wxT("javascript")]  = TypeJS;
        m_map[wxT("py")]  = TypePython;

        m_map[wxT("exe")] = TypeExe;
        m_map[wxT("html")] = TypeHtml;
        m_map[wxT("htm")] = TypeHtml;

        m_map[wxT("tar")]   = TypeArchive;
        m_map[wxT("a")]     = TypeArchive;
        m_map[wxT("lib")]   = TypeArchive;
        m_map[wxT("zip")]   = TypeArchive;
        m_map[wxT("rar")]   = TypeArchive;
        m_map[wxT("targz")] = TypeArchive;

        m_map[wxT("dll")]    = TypeDll;
        m_map[wxT("so")]     = TypeDll;
        m_map[wxT("dylib")]  = TypeDll;

        m_map[wxT("bmp")]  = TypeBmp;
        m_map[wxT("jpeg")] = TypeBmp;
        m_map[wxT("jpg")]  = TypeBmp;
        m_map[wxT("png")]  = TypeBmp;
        m_map[wxT("ico")]  = TypeBmp;
        m_map[wxT("xpm")]  = TypeBmp;

        m_map[wxT("mk")] = TypeMakefile;

        m_map[wxT("log")] = TypeText;
        m_map[wxT("txt")] = TypeText;
        m_map[wxT("ini")] = TypeText;

        m_map[wxT("script")] = TypeScript;
        m_map[wxT("sh")]     = TypeScript;
        m_map[wxT("bat")]    = TypeScript;
        m_map[wxT("bash")]   = TypeScript;

        m_map[wxT("wxcp")] = TypeWxCrafter;
        m_map[wxT("xrc") ] = TypeXRC;

        m_map[wxT("sql")]     = TypeSQL;
        m_map[wxT("phpwsp")]  = TypeWorkspacePHP;
        m_map[wxT("phptags")] = TypeWorkspacePHPTags;

        m_map["s"] = TypeAsm;
    }
}

FileExtManager::FileType FileExtManager::GetType(const wxString& filename, FileExtManager::FileType defaultType)
{
    Init();

    wxFileName fn( filename );
    if ( fn.IsOk() == false ) {
        return defaultType;
    }

    wxString e ( fn.GetExt() );
    e.MakeLower();
    e.Trim().Trim(false);

    std::map<wxString, FileType>::iterator iter = m_map.find(e);
    if ( iter == m_map.end() ) {
        // try to see if the file is a makefile
        if(fn.GetFullName().CmpNoCase(wxT("makefile")) == 0) {
            return TypeMakefile;
        }
        return defaultType;
    }
    return iter->second;
}

bool FileExtManager::IsCxxFile(const wxString& filename)
{
    FileType ft = GetType(filename);
    return ft == TypeSourceC || ft == TypeSourceCpp || ft == TypeHeader;
}

bool FileExtManager::IsJavascriptFile(const wxString& filename)
{
    FileType ft = GetType(filename);
    return ft == TypeJS;
}