~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/Cccc/Cccc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************
 
2
 * Name:      Cccc.cpp
 
3
 * Purpose:   Code::Blocks Cccc plugin: main functions
 
4
 * Author:    Lieven de Cock (aka killerbot)
 
5
 * Created:   12/11/2009
 
6
 * Copyright: (c) Lieven de Cock (aka killerbot)
 
7
 * License:   GPL
 
8
  **************************************************************/
 
9
#include "sdk.h"
 
10
#ifndef CB_PRECOMP
 
11
#include <wx/arrstr.h>
 
12
#include <wx/dir.h>
 
13
#include <wx/fs_zip.h>
 
14
#include <wx/intl.h>
 
15
#include <wx/menu.h>
 
16
#include <wx/string.h>
 
17
#include <wx/xrc/xmlres.h>
 
18
#include "cbproject.h"
 
19
#include "manager.h"
 
20
#include "logmanager.h"
 
21
#include "projectmanager.h"
 
22
#endif
 
23
#include <wx/busyinfo.h>
 
24
#include <wx/filedlg.h>
 
25
#include <wx/filefn.h>
 
26
#include <wx/utils.h>
 
27
#include "loggers.h"
 
28
#include "Cccc.h"
 
29
 
 
30
// Register the plugin
 
31
namespace
 
32
{
 
33
    PluginRegistrant<Cccc> reg(_T("Cccc"));
 
34
};
 
35
 
 
36
Cccc::Cccc()
 
37
{
 
38
    if(!Manager::LoadResource(_T("Cccc.zip")))
 
39
    {
 
40
        NotifyMissingFile(_T("Cccc.zip"));
 
41
    }
 
42
    m_CcccLog = 0;
 
43
    m_LogPageIndex = 0; // good init value ???
 
44
    m_CcccApp = _T("cccc");
 
45
} // end of constructor
 
46
 
 
47
Cccc::~Cccc()
 
48
{
 
49
} // end of destruccor
 
50
 
 
51
void Cccc::OnAttach()
 
52
{
 
53
    // do whatever initialization you need for your plugin
 
54
    // NOTE: after this function, the inherited member variable
 
55
    // IsAttached() will be TRUE...
 
56
    // You should check for it in other functions, because if it
 
57
    // is FALSE, it means that the application did *not* "load"
 
58
    // (see: does not need) this plugin...
 
59
    if(LogManager* LogMan = Manager::Get()->GetLogManager())
 
60
    {
 
61
        m_CcccLog = new TextCtrlLogger();
 
62
        m_LogPageIndex = LogMan->SetLog(m_CcccLog);
 
63
        LogMan->Slot(m_LogPageIndex).title = _("Cccc");
 
64
        CodeBlocksLogEvent evtAdd1(cbEVT_ADD_LOG_WINDOW, m_CcccLog, LogMan->Slot(m_LogPageIndex).title);
 
65
        Manager::Get()->ProcessEvent(evtAdd1);
 
66
    }
 
67
} // end of OnAttach
 
68
 
 
69
void Cccc::OnRelease(bool appShutDown)
 
70
{
 
71
    // do de-initialization for your plugin
 
72
    // if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
 
73
    // which means you must not use any of the SDK Managers
 
74
    // NOTE: after this function, the inherited member variable
 
75
    // IsAttached() will be FALSE...
 
76
    if(Manager::Get()->GetLogManager())
 
77
    {
 
78
        if(m_CcccLog)
 
79
        {
 
80
            CodeBlocksLogEvent evt(cbEVT_REMOVE_LOG_WINDOW, m_CcccLog);
 
81
            Manager::Get()->ProcessEvent(evt);
 
82
        }
 
83
    }
 
84
    m_CcccLog = 0;
 
85
} // end of OnRelease
 
86
 
 
87
void Cccc::AppendToLog(const wxString& Text)
 
88
{
 
89
    if(LogManager* LogMan = Manager::Get()->GetLogManager())
 
90
    {
 
91
        CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_CcccLog);
 
92
        Manager::Get()->ProcessEvent(evtSwitch);
 
93
        LogMan->Log(Text, m_LogPageIndex);
 
94
    }
 
95
} // end of AppendToLog
 
96
 
 
97
bool CheckRequirements()
 
98
{
 
99
    cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
 
100
    // if no project open, exit
 
101
    if (!Project)
 
102
    {
 
103
        wxString msg = _("You need to open a project\nbefore using the plugin!");
 
104
        cbMessageBox(msg, _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
 
105
        Manager::Get()->GetLogManager()->DebugLog(msg);
 
106
        return false;
 
107
    }
 
108
    return true;
 
109
}  // end of CheckRequirements
 
110
 
 
111
int Cccc::Execute()
 
112
{
 
113
    if(!CheckRequirements())
 
114
    {
 
115
        return -1;
 
116
    }
 
117
 
 
118
    cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
 
119
    ::wxSetWorkingDirectory(Project->GetBasePath());
 
120
    const long Files = Project->GetFilesCount();
 
121
    wxString ListOfFileNames;
 
122
    for (int File = 0; File < Files; ++File)
 
123
    {
 
124
        ProjectFile* pf = Project->GetFile(File);
 
125
        ListOfFileNames += _T("\"") + pf->relativeFilename + _T("\" ");
 
126
    }
 
127
 
 
128
    wxString CommandLine = m_CcccApp + _T(" ") + ListOfFileNames.Trim();
 
129
    AppendToLog(CommandLine);
 
130
    wxArrayString Output, Errors;
 
131
    long pid = -1;
 
132
    {
 
133
        wxWindowDisabler disableAll;
 
134
        wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
 
135
                           Manager::Get()->GetAppWindow());
 
136
        pid = wxExecute(CommandLine, Output, Errors);
 
137
    } // end lifetime of wxWindowDisabler, wxBusyInfo
 
138
    if (pid==-1)
 
139
    {
 
140
        bool failed = true;
 
141
        if (cbMessageBox(_("Failed to lauch cccc.\nDo you want to select the cccc executable?"),
 
142
                         _("Question"), wxICON_QUESTION | wxYES_NO, Manager::Get()->GetAppWindow()) == wxID_YES)
 
143
        {
 
144
            wxString filename = wxFileSelector(_("Select the cccc executable"));
 
145
            if (!filename.empty()) // otherwise the user selected cancel
 
146
            {
 
147
                // try again using the user-provided executable
 
148
                CommandLine = filename + _T(" ") + ListOfFileNames.Trim();
 
149
                AppendToLog(CommandLine);
 
150
                {
 
151
                    wxWindowDisabler disableAll;
 
152
                    wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
 
153
                                       Manager::Get()->GetAppWindow());
 
154
                    pid = wxExecute(CommandLine, Output, Errors);
 
155
                } // end lifetime of wxWindowDisabler, wxBusyInfo
 
156
                if (pid==-1)
 
157
                {
 
158
                    failed = true;
 
159
                }
 
160
                else
 
161
                {
 
162
                    m_CcccApp = filename;
 
163
                    failed = false;
 
164
                }
 
165
            }
 
166
        }
 
167
        if (failed)
 
168
        {
 
169
            AppendToLog(_("Failed to lauch cccc."));
 
170
            cbMessageBox(_("Failed to lauch cccc."), _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
 
171
            return -1;
 
172
        }
 
173
    }
 
174
 
 
175
    size_t Count = Output.GetCount();
 
176
    for(size_t idxCount = 0; idxCount < Count; ++idxCount)
 
177
    {
 
178
        AppendToLog(Output[idxCount]);
 
179
    } // end for : idx: idxCount
 
180
    Count = Errors.GetCount();
 
181
    for(size_t idxCount = 0; idxCount < Count; ++idxCount)
 
182
    {
 
183
        AppendToLog(Errors[idxCount]);
 
184
    } // end for : idx: idxCount
 
185
    const wxString FileName = _T("./.cccc/cccc.html");
 
186
    if(wxFile::Exists(FileName))
 
187
    {
 
188
        if (cbMimePlugin* p = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(FileName))
 
189
        {
 
190
            p->OpenFile(FileName);
 
191
        }
 
192
    }
 
193
 
 
194
    return 0;
 
195
} // end of Execute