2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
* http://www.gnu.org/licenses/gpl-3.0.html
6
* $Id: cb_koders.cpp 10245 2015-05-02 14:45:07Z mortenmacfly $
7
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/plugins/contrib/cb_koders/cb_koders.cpp $
10
#include "sdk.h" // Code::Blocks SDK
14
#include <wx/string.h>
15
#include <wx/utils.h> // wxLaunchDefaultBrowser
18
#include "editormanager.h"
21
#include "cbstyledtextctrl.h"
23
#include "cb_koders.h"
24
#include "kodersdialog.h"
26
// Register the plugin
29
PluginRegistrant<CB_Koders> reg(_T("CB_Koders"));
32
const int idSearchKoders = wxNewId();
34
BEGIN_EVENT_TABLE(CB_Koders, cbToolPlugin)
35
EVT_MENU(idSearchKoders, CB_Koders::OnSearchKoders)
39
CB_Koders::CB_Koders() :
45
CB_Koders::~CB_Koders()
51
void CB_Koders::OnAttach()
53
// do whatever initialization you need for your plugin
54
// NOTE: after this function, the inherited member variable
55
// m_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...
61
void CB_Koders::OnRelease(bool /*appShutDown*/)
63
// do de-initialization for your plugin
64
// if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
65
// which means you must not use any of the SDK Managers
66
// NOTE: after this function, the inherited member variable
67
// m_IsAttached will be FALSE...
70
int CB_Koders::Execute()
72
if (IsReady() && TheDialog->ShowModal()==wxID_OK)
74
const wxString search = TheDialog->GetSearch();
77
cbMessageBox(_("Cannot search for an empty expression."), _("Error"), wxICON_ERROR);
81
const wxString language = TheDialog->GetLanguage();
84
if ( language.IsEmpty() )
86
query.Printf(_("http://code.openhub.net/search?s=%s"), search.c_str());
90
query.Printf(_("http://code.openhub.net/search?s=%s&fl=%s"),
91
search.c_str(), language.c_str());
94
if (!wxLaunchDefaultBrowser(query))
95
cbMessageBox(_("Could not launch the default browser of your system."), _("Error"), wxICON_ERROR);
102
void CB_Koders::BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* /*data*/)
104
if (!menu || !IsAttached())
107
if (type == mtEditorManager)
109
menu->AppendSeparator();
110
menu->Append(idSearchKoders, _("Search at BlackDuck..."), _("Search keyword at BlackDuck webpage..."));
114
bool CB_Koders::IsReady()
120
TheDialog = new KodersDialog(Manager::Get()->GetAppWindow());
125
cbMessageBox(_("Could not initialise CB_Koders plugin."), _("Error"), wxICON_ERROR);
130
void CB_Koders::OnSearchKoders(wxCommandEvent& /*event*/)
134
wxString search(_T("")); // the word to search for (if any)
135
cbEditor *ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
139
// check if there is any text selected
140
cbStyledTextCtrl *control = ed->GetControl();
141
search = control->GetSelectedText();
143
// if no selection, take the word under the cursor
144
if (search.IsEmpty())
146
int origPos = control->GetCurrentPos();
147
int start = control->WordStartPosition(origPos, true);
148
int end = control->WordEndPosition(origPos, true);
149
search = control->GetTextRange(start, end);
153
TheDialog->SetSearch(search);