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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : taskpanel.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 <wx/xrc/xmlres.h>
#include "editor_config.h"
#include "taskspaneldata.h"
#include <wx/fontmap.h>
#include "tasks_find_what_dlg.h"
#include <wx/tglbtn.h>
#include "frame.h"
#include "manager.h"
#include "macros.h"
#include "taskpanel.h"
#include "clWorkspaceManager.h"
#include "event_notifier.h"
#include "clStrings.h"
BEGIN_EVENT_TABLE(TaskPanel, FindResultsTab)
EVT_BUTTON(wxID_FIND, TaskPanel::OnSearch)
EVT_BUTTON(XRCID("find_what"), TaskPanel::OnFindWhat)
EVT_UPDATE_UI(wxID_FIND, TaskPanel::OnSearchUI)
EVT_UPDATE_UI(XRCID("hold_pane_open"), TaskPanel::OnHoldOpenUpdateUI)
END_EVENT_TABLE()
TaskPanel::TaskPanel(wxWindow* parent, wxWindowID id, const wxString& name)
: FindResultsTab(parent, id, name)
, m_scope(NULL)
{
wxArrayString filters;
filters.Add(wxString(wxT("C/C++ ")) + _("Sources"));
m_extensions.Add(wxT("*.c;*.cpp;*.cxx;*.cc;*.h;*.hpp;*.hxx;*.hh;*.inl;*.inc;*.hh;*.js;*.php;*.phtml"));
filters.Add(_("All Files"));
m_extensions.Add(wxT("*.*"));
m_tb->DeleteTool(XRCID("repeat_output"));
m_tb->DeleteTool(XRCID("recent_searches"));
m_tb->Realize();
wxBoxSizer* verticalPanelSizer = new wxBoxSizer(wxVERTICAL);
wxButton* btn = new wxButton(this, wxID_FIND, _("&Search"));
verticalPanelSizer->Add(btn, 0, wxEXPAND | wxALL, 5);
m_findWhat = new wxButton(this, XRCID("find_what"), _("Find What..."));
verticalPanelSizer->Add(m_findWhat, 0, wxEXPAND | wxALL, 5);
verticalPanelSizer->Add(new wxStaticLine(this), 0, wxEXPAND | wxALL, 5);
m_choiceEncoding = new wxChoice(this, wxID_ANY);
verticalPanelSizer->Add(m_choiceEncoding, 0, wxEXPAND | wxALL, 5);
m_choiceEncoding->SetToolTip(_("Encoding to use for the search"));
TasksPanelData d;
EditorConfigST::Get()->ReadObject(wxT("TasksPanelData"), &d);
// Set encoding
wxArrayString astrEncodings;
wxFontEncoding fontEnc;
int selection(0);
size_t iEncCnt = wxFontMapper::GetSupportedEncodingsCount();
for(size_t i = 0; i < iEncCnt; i++) {
fontEnc = wxFontMapper::GetEncoding(i);
if(wxFONTENCODING_SYSTEM == fontEnc) { // skip system, it is changed to UTF-8 in optionsconfig
continue;
}
wxString encodingName = wxFontMapper::GetEncodingName(fontEnc);
size_t pos = astrEncodings.Add(encodingName);
if(d.GetEncoding() == encodingName) selection = static_cast<int>(pos);
}
m_choiceEncoding->Append(astrEncodings);
if(m_choiceEncoding->IsEmpty() == false) m_choiceEncoding->SetSelection(selection);
m_choiceEncoding->Connect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(TaskPanel::OnEncodingSelected), NULL,
this);
wxBoxSizer* hSizer = new wxBoxSizer(wxHORIZONTAL);
// grab the base class scintilla and put our sizer in its place
wxSizer* mainSizer = m_vSizer;
mainSizer->Detach(m_sci);
hSizer->Add(m_sci, 1, wxEXPAND | wxALL, 1);
hSizer->Add(verticalPanelSizer, 0, wxEXPAND | wxALL, 1);
mainSizer->Add(hSizer, 1, wxEXPAND | wxALL, 1);
mainSizer->Layout();
}
TaskPanel::~TaskPanel()
{
m_choiceEncoding->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(TaskPanel::OnEncodingSelected),
NULL, this);
}
SearchData TaskPanel::DoGetSearchData()
{
SearchData data;
data.SetDisplayScope(true);
data.SetRegularExpression(true);
data.SetMatchCase(false);
data.SetMatchWholeWord(false);
data.SetEncoding(m_choiceEncoding->GetStringSelection());
data.SetOwner(this);
wxString sfind;
// Load all info from disk
TasksPanelData d;
EditorConfigST::Get()->ReadObject(wxT("TasksPanelData"), &d);
wxStringMap_t::const_iterator iter = d.GetTasks().begin();
for(; iter != d.GetTasks().end(); iter++) {
wxString name = iter->first;
wxString regex = iter->second;
bool enabled = (d.GetEnabledItems().Index(iter->first) != wxNOT_FOUND);
regex.Trim().Trim(false);
wxRegEx re(regex);
if(enabled && !regex.IsEmpty() && re.IsValid()) sfind << wxT("(") << regex << wxT(")|");
}
if(sfind.empty() == false) sfind.RemoveLast();
data.SetFindString(sfind);
wxString rootDir = clWorkspaceManager::Get().GetWorkspace()->GetFileName().GetPath();
wxArrayString rootDirs;
rootDirs.push_back(rootDir);
data.SetRootDirs(rootDirs);
data.SetExtensions(wxT("*.*"));
return data;
}
void TaskPanel::OnSearch(wxCommandEvent& e)
{
wxUnusedVar(e);
SearchData sd = DoGetSearchData();
SearchThreadST::Get()->PerformSearch(sd);
}
void TaskPanel::OnSearchUI(wxUpdateUIEvent& e) { e.Enable(clWorkspaceManager::Get().IsWorkspaceOpened()); }
void TaskPanel::OnRepeatOutput(wxCommandEvent& e) { OnSearch(e); }
void TaskPanel::OnFindWhat(wxCommandEvent& e)
{
TasksFindWhatDlg dlg(wxTheApp->GetTopWindow());
dlg.ShowModal();
}
void TaskPanel::OnHoldOpenUpdateUI(wxUpdateUIEvent& e)
{
int sel = clMainFrame::Get()->GetOutputPane()->GetNotebook()->GetSelection();
if(clMainFrame::Get()->GetOutputPane()->GetNotebook()->GetPage(sel) != this) {
return;
}
if(EditorConfigST::Get()->GetOptions()->GetHideOutpuPaneOnUserClick()) {
e.Enable(true);
e.Check(EditorConfigST::Get()->GetOptions()->GetHideOutputPaneNotIfTasks());
} else {
e.Enable(false);
e.Check(false);
}
}
void TaskPanel::OnEncodingSelected(wxCommandEvent& e)
{
wxUnusedVar(e);
TasksPanelData d;
EditorConfigST::Get()->ReadObject(wxT("TasksPanelData"), &d);
d.SetEncoding(m_choiceEncoding->GetStringSelection());
EditorConfigST::Get()->WriteObject(wxT("TasksPanelData"), &d);
}
void TaskPanel::OnSearchStart(wxCommandEvent& e)
{
m_searchInProgress = true;
Clear();
SetStyles(m_sci);
SearchData* data = (SearchData*)e.GetClientData();
wxDELETE(data);
// Make sure that the Output view & the "Replace" tab
// are visible
clCommandEvent event(wxEVT_SHOW_OUTPUT_TAB);
event.SetSelected(true).SetString(TASKS);
EventNotifier::Get()->AddPendingEvent(event);
}
|