File: clJSCTags.cpp

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (108 lines) | stat: -rw-r--r-- 3,167 bytes parent folder | download | duplicates (2)
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
#include "clJSCTags.h"
#include "event_notifier.h"
#include "codelite_events.h"
#include <wx/filename.h>
#include "clZipReader.h"
#include "jobqueue.h"
#include "job.h"
#include "cl_standard_paths.h"
#include "globals.h"
#include "ieditor.h"
#include "macros.h"
#include <imanager.h>
#include "file_logger.h"

class clJSCTagsZipJob : public Job
{
protected:
    clJSCTags* m_jsctags;
    wxString m_zipfile;
    wxString m_targetFolder;

public:
    clJSCTagsZipJob(const wxString& zipfile, const wxString& targetFolder)
        : Job()
        , m_zipfile(zipfile)
        , m_targetFolder(targetFolder)
    {
    }

    virtual ~clJSCTagsZipJob() {}

    void Process(wxThread* thread)
    {
        wxUnusedVar(thread);
        // Extract the zip file
        wxFileName::Mkdir(m_targetFolder, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
        clZipReader zipReader(m_zipfile);
        clDEBUG() << "Extracting zip file:" << m_zipfile << clEndl;
        zipReader.Extract("*", m_targetFolder);
        clDEBUG() << "Extracting zip file:" << m_zipfile << "...done" << clEndl;
    }
};

clJSCTags::clJSCTags()
    : m_zipExtracted(false)
{
    EventNotifier::Get()->Bind(wxEVT_ACTIVE_EDITOR_CHANGED, &clJSCTags::OnEditorChanged, this);
    EventNotifier::Get()->Bind(wxEVT_FILE_SAVED, &clJSCTags::OnEditorSaved, this);
    EventNotifier::Get()->Bind(wxEVT_INIT_DONE, &clJSCTags::OnInitDone, this);
    EventNotifier::Get()->Bind(wxEVT_EDITOR_CLOSING, &clJSCTags::OnEditorClosing, this);
}

clJSCTags::~clJSCTags()
{
    EventNotifier::Get()->Unbind(wxEVT_ACTIVE_EDITOR_CHANGED, &clJSCTags::OnEditorChanged, this);
    EventNotifier::Get()->Unbind(wxEVT_FILE_SAVED, &clJSCTags::OnEditorSaved, this);
    EventNotifier::Get()->Unbind(wxEVT_INIT_DONE, &clJSCTags::OnInitDone, this);
    EventNotifier::Get()->Unbind(wxEVT_EDITOR_CLOSING, &clJSCTags::OnEditorClosing, this);
}

void clJSCTags::OnEditorSaved(clCommandEvent& event)
{
    event.Skip();
    if(!m_zipExtracted) return;

    wxString filename = event.GetFileName();
}

void clJSCTags::OnEditorChanged(wxCommandEvent& event)
{
    event.Skip();
    if(!m_zipExtracted) return;

    IEditor* editor = clGetManager()->GetActiveEditor();
    CHECK_PTR_RET(editor);
}

void clJSCTags::ZipExtractCompleted() { m_zipExtracted = true; }

void clJSCTags::OnInitDone(wxCommandEvent& event)
{
    event.Skip();
    // Extract the zip file
    wxFileName jsctagsZip(clStandardPaths::Get().GetDataDir(), "jsctags.zip");
    if(!jsctagsZip.Exists()) return;
    wxFileName targetDir(clStandardPaths::Get().GetUserDataDir(), "");
    targetDir.AppendDir("webtools");
    targetDir.AppendDir("jsctags");
#if 0
#ifndef __WXGTK__
    JobQueueSingleton::Instance()->PushJob(new clJSCTagsZipJob(jsctagsZip.GetFullPath(), targetDir.GetPath()));
#else
    clJSCTagsZipJob job(jsctagsZip.GetFullPath(), targetDir.GetPath());
    job.Process(NULL);
#endif
#endif
    ZipExtractCompleted();
}

void clJSCTags::OnEditorClosing(wxCommandEvent& e)
{
    e.Skip();
    IEditor* editor = (IEditor*)e.GetClientData();
    CHECK_PTR_RET(editor);

    wxString closingpath = editor->GetFileName().GetFullPath();
    // Clear this file's cache
}