Skip to content

Commit

Permalink
- Added support for dynamic toolbar in the 'External Tools' plugin
Browse files Browse the repository at this point in the history
git-svn-id: https://codelite.svn.sourceforge.net/svnroot/codelite/trunk@2039 9da81c78-c036-0410-9e1f-a2b0375e4b5a
  • Loading branch information
eranif committed Aug 29, 2008
1 parent d76330c commit fd1f1df
Show file tree
Hide file tree
Showing 19 changed files with 1,748 additions and 683 deletions.
2 changes: 1 addition & 1 deletion ExternalTools/ExternalTools.project
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@
<File Name="externaltoolsbasedlg.cpp"/>
<File Name="externaltoolsbasedlg.h"/>
</VirtualDirectory>
<Dependencies Name="WinDebugUnicode"/>
<Dependencies Name="WinReleaseUnicode"/>
<Dependencies Name="WinDebugUnicode"/>
</CodeLite_Project>
78 changes: 51 additions & 27 deletions ExternalTools/externaltooldlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void ExternalToolDlg::OnItemSelected( wxListEvent& event )

void ExternalToolDlg::OnButtonNew( wxCommandEvent& event )
{
NewToolDlg dlg(this, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString );
NewToolDlg dlg(this, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString );
if (dlg.ShowModal() == wxID_OK) {
DoUpdateEntry(dlg.GetToolId(), dlg.GetPath(), dlg.GetWorkingDirectory(), dlg.GetArguments());
DoUpdateEntry(dlg.GetToolId(), dlg.GetToolName(), dlg.GetPath(), dlg.GetWorkingDirectory(), dlg.GetArguments(), dlg.GetIcon16(), dlg.GetIcon24());
}
}

Expand Down Expand Up @@ -64,19 +64,25 @@ void ExternalToolDlg::OnButtonDeleteUI( wxUpdateUIEvent& event )

void ExternalToolDlg::Initialize()
{
m_listCtrlTools->InsertColumn(0, wxT("ID"));
m_listCtrlTools->InsertColumn(1, wxT("Path"));
m_listCtrlTools->InsertColumn(2, wxT("Arguments"));
m_listCtrlTools->InsertColumn(3, wxT("Working directory"));
m_listCtrlTools->InsertColumn(0, wxT("ID"));
m_listCtrlTools->InsertColumn(1, wxT("Name"));
m_listCtrlTools->InsertColumn(2, wxT("Path"));
m_listCtrlTools->InsertColumn(3, wxT("Arguments"));
m_listCtrlTools->InsertColumn(4, wxT("Working directory"));
m_listCtrlTools->InsertColumn(5, wxT("Small Icon"));
m_listCtrlTools->InsertColumn(6, wxT("Large Icon"));

// TODO: populate the list from the settings
m_listCtrlTools->SetColumnWidth(0, 100);
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(2, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(4, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(5, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(6, wxLIST_AUTOSIZE);
}

void ExternalToolDlg::DoUpdateEntry(const wxString& id, const wxString& path, const wxString& workingDirectory, const wxString& arguments)
void ExternalToolDlg::DoUpdateEntry(const wxString& id, const wxString& name, const wxString& path, const wxString& workingDirectory, const wxString& arguments, const wxString &icon16, const wxString &icon24)
{
// try to see if 'id' already exist in the list control
long item(wxNOT_FOUND);
Expand All @@ -92,27 +98,36 @@ void ExternalToolDlg::DoUpdateEntry(const wxString& id, const wxString& path, co
item = AppendListCtrlRow(m_listCtrlTools);
}

SetColumnText(m_listCtrlTools, item, 0, id);
SetColumnText(m_listCtrlTools, item, 1, path);
SetColumnText(m_listCtrlTools, item, 2, arguments);
SetColumnText(m_listCtrlTools, item, 3, workingDirectory);
SetColumnText(m_listCtrlTools, item, 0, id);
SetColumnText(m_listCtrlTools, item, 1, name);
SetColumnText(m_listCtrlTools, item, 2, path);
SetColumnText(m_listCtrlTools, item, 3, arguments);
SetColumnText(m_listCtrlTools, item, 4, workingDirectory);
SetColumnText(m_listCtrlTools, item, 5, icon16);
SetColumnText(m_listCtrlTools, item, 6, icon24);

m_listCtrlTools->SetColumnWidth(0, 150);
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(2, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(4, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(5, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(6, wxLIST_AUTOSIZE);
}

void ExternalToolDlg::DoEditEntry(long item)
{
wxString id = GetColumnText(m_listCtrlTools, m_item, 0);
wxString path = GetColumnText(m_listCtrlTools, m_item, 1);
wxString args = GetColumnText(m_listCtrlTools, m_item, 2);
wxString wd = GetColumnText(m_listCtrlTools, m_item, 3);

NewToolDlg dlg(this, id, path, wd, args);
wxString id = GetColumnText(m_listCtrlTools, m_item, 0);
wxString name = GetColumnText(m_listCtrlTools, m_item, 1);
wxString path = GetColumnText(m_listCtrlTools, m_item, 2);
wxString args = GetColumnText(m_listCtrlTools, m_item, 3);
wxString wd = GetColumnText(m_listCtrlTools, m_item, 4);
wxString icon16 = GetColumnText(m_listCtrlTools, m_item, 5);
wxString icon24 = GetColumnText(m_listCtrlTools, m_item, 6);

NewToolDlg dlg(this, id, name, path, wd, args, icon16, icon24);
if (dlg.ShowModal() == wxID_OK) {
DoUpdateEntry(dlg.GetToolId(), dlg.GetPath(), dlg.GetWorkingDirectory(), dlg.GetArguments());
DoUpdateEntry(dlg.GetToolId(), dlg.GetToolName(), dlg.GetPath(), dlg.GetWorkingDirectory(), dlg.GetArguments(), dlg.GetIcon16(), dlg.GetIcon24());
}
}

Expand All @@ -122,9 +137,12 @@ std::vector<ToolInfo> ExternalToolDlg::GetTools()
for(size_t i=0; i<(size_t)m_listCtrlTools->GetItemCount(); i++){
ToolInfo ti;
ti.SetId(GetColumnText(m_listCtrlTools, i, 0));
ti.SetPath(GetColumnText(m_listCtrlTools, i, 1));
ti.SetArguments(GetColumnText(m_listCtrlTools, i, 2));
ti.SetWd(GetColumnText(m_listCtrlTools, i, 3));
ti.SetName(GetColumnText(m_listCtrlTools, i, 1));
ti.SetPath(GetColumnText(m_listCtrlTools, i, 2));
ti.SetArguments(GetColumnText(m_listCtrlTools, i, 3));
ti.SetWd(GetColumnText(m_listCtrlTools, i, 4));
ti.SetIcon16(GetColumnText(m_listCtrlTools, i, 5));
ti.SetIcon24(GetColumnText(m_listCtrlTools, i, 6));
tools.push_back(ti);
}
return tools;
Expand All @@ -139,15 +157,21 @@ void ExternalToolDlg::SetTools(const std::vector<ToolInfo>& tools)
ToolInfo ti = tools.at(i);
long item = AppendListCtrlRow(m_listCtrlTools);
SetColumnText(m_listCtrlTools, item, 0, ti.GetId());
SetColumnText(m_listCtrlTools, item, 1, ti.GetPath());
SetColumnText(m_listCtrlTools, item, 2, ti.GetArguments());
SetColumnText(m_listCtrlTools, item, 3, ti.GetWd());
SetColumnText(m_listCtrlTools, item, 1, ti.GetName());
SetColumnText(m_listCtrlTools, item, 2, ti.GetPath());
SetColumnText(m_listCtrlTools, item, 3, ti.GetArguments());
SetColumnText(m_listCtrlTools, item, 4, ti.GetWd());
SetColumnText(m_listCtrlTools, item, 5, ti.GetIcon16());
SetColumnText(m_listCtrlTools, item, 6, ti.GetIcon24());
}

m_listCtrlTools->SetColumnWidth(0, 150);
m_listCtrlTools->SetColumnWidth(1, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(2, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(3, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(4, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(5, wxLIST_AUTOSIZE);
m_listCtrlTools->SetColumnWidth(6, wxLIST_AUTOSIZE);

m_listCtrlTools->Thaw();
}
2 changes: 1 addition & 1 deletion ExternalTools/externaltooldlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExternalToolDlg : public ExternalToolBaseDlg
{
long m_item;
private:
void DoUpdateEntry(const wxString &id, const wxString &path, const wxString &workingDirectory, const wxString &arguments);
void DoUpdateEntry(const wxString& id, const wxString& name, const wxString& path, const wxString& workingDirectory, const wxString& arguments, const wxString &icon16, const wxString &icon24);
void DoEditEntry(long item);

protected:
Expand Down
99 changes: 69 additions & 30 deletions ExternalTools/externaltools.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <wx/aui/framemanager.h>
#include <wx/bitmap.h>
#include "dirsaver.h"
#include <wx/app.h>
#include "workspace.h"
Expand Down Expand Up @@ -41,7 +43,7 @@ ExternalToolsPlugin::ExternalToolsPlugin(IManager *manager)
m_longName = wxT("A plugin that allows user to launch external tools from within CodeLite");
m_shortName = wxT("ExternalTools");
topWin = m_mgr->GetTheApp();

topWin->Connect(XRCID("external_tool_0"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ExternalToolsPlugin::OnLaunchExternalTool), NULL, this);
topWin->Connect(XRCID("external_tool_1"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ExternalToolsPlugin::OnLaunchExternalTool), NULL, this);
topWin->Connect(XRCID("external_tool_2"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ExternalToolsPlugin::OnLaunchExternalTool), NULL, this);
Expand Down Expand Up @@ -71,39 +73,56 @@ ExternalToolsPlugin::~ExternalToolsPlugin()

wxToolBar *ExternalToolsPlugin::CreateToolBar(wxWindow *parent)
{
/*
//support both toolbars icon size
int size = m_mgr->GetToolbarIconSize();

wxToolBar *tb = new wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_NODIVIDER);
tb->SetToolBitmapSize(wxSize(size, size));
// TODO :: insert tools here to the toolbar, notice how the plugin should create code that supports 24x24 and 16x16 icons size
m_tb = new wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_NODIVIDER);
m_tb->SetToolBitmapSize(wxSize(size, size));

ExternalToolsData inData;
m_mgr->GetConfigTool()->ReadObject(wxT("ExternalTools"), &inData);

if (size == 24) {
tb->AddTool(XRCID("run_unit_tests"), wxT("Run Unit tests..."), wxXmlResource::Get()->LoadBitmap(wxT("run_unit_test24")), wxT("Run project as unit test project..."));
m_tb->AddTool(XRCID("external_tools_settings"), wxT("Configure external tools..."), wxXmlResource::Get()->LoadBitmap(wxT("configure_ext_tools24")), wxT("Configure external tools..."));
} else {
tb->AddTool(XRCID("run_unit_tests"), wxT("Run Unit tests..."), wxXmlResource::Get()->LoadBitmap(wxT("run_unit_test16")), wxT("Run project as unit test project..."));
m_tb->AddTool(XRCID("external_tools_settings"), wxT("Configure external tools..."), wxXmlResource::Get()->LoadBitmap(wxT("configure_ext_tools16")), wxT("Configure external tools..."));
}
m_tb->AddSeparator();

for (size_t i=0; i<inData.GetTools().size(); i++) {
ToolInfo ti = inData.GetTools().at(i);

wxFileName icon24(ti.GetIcon24());
wxFileName icon16(ti.GetIcon16());

if (size == 24 && icon24.FileExists()) {
wxBitmap bmp;
bmp.LoadFile(icon24.GetFullPath(), wxBITMAP_TYPE_PNG);
if (bmp.IsOk() && bmp.GetHeight() == 24) {
m_tb->AddTool(wxXmlResource::GetXRCID(ti.GetId().c_str()), ti.GetName(), bmp, ti.GetName());
}

} else if (size == 16 && icon16.FileExists()) {
wxBitmap bmp;
bmp.LoadFile(icon16.GetFullPath(), wxBITMAP_TYPE_PNG);
if (bmp.IsOk() && bmp.GetHeight() == 16) {
m_tb->AddTool(wxXmlResource::GetXRCID(ti.GetId().c_str()), ti.GetName(), bmp, ti.GetName());
}
}
}
tb->Realize();
//Connect the events to us
// TODO:: connect the events to parent window, but direct them to us using the Connect() method
parent->Connect(XRCID("run_unit_tests"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(UnitTestPP::OnRunUnitTests), NULL, (wxEvtHandler*)this);
parent->Connect(XRCID("run_unit_tests"), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(UnitTestPP::OnRunUnitTestsUI), NULL, (wxEvtHandler*)this);
return tb;
*/
return NULL;

m_tb->Realize();
return m_tb;
}

void ExternalToolsPlugin::CreatePluginMenu(wxMenu *pluginsMenu)
{
wxMenu *menu = new wxMenu();
wxMenuItem *item(NULL);
item = new wxMenuItem(menu, XRCID("external_tools_settings"), wxT("Settings..."), wxEmptyString, wxITEM_NORMAL);
item = new wxMenuItem(menu, XRCID("external_tools_settings"), wxT("Configure external tools..."), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
pluginsMenu->Append(wxID_ANY, wxT("External Tools"), menu);

topWin->Connect(XRCID("external_tools_settings"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(ExternalToolsPlugin::OnSettings), NULL, (wxEvtHandler*)this);
}

Expand All @@ -129,12 +148,14 @@ void ExternalToolsPlugin::OnSettings(wxCommandEvent& e)
m_mgr->GetConfigTool()->ReadObject(wxT("ExternalTools"), &inData);
ExternalToolDlg dlg(m_mgr->GetTheApp()->GetTopWindow());
dlg.SetTools(inData.GetTools());
if(dlg.ShowModal() == wxID_OK){

if (dlg.ShowModal() == wxID_OK) {
//Do something here
ExternalToolsData data;
data.SetTools(dlg.GetTools());
m_mgr->GetConfigTool()->WriteObject(wxT("ExternalTools"), &data);

DoRecreateToolbar();
}
}

Expand All @@ -143,9 +164,9 @@ void ExternalToolsPlugin::OnLaunchExternalTool(wxCommandEvent& e)
ExternalToolsData inData;
m_mgr->GetConfigTool()->ReadObject(wxT("ExternalTools"), &inData);

for(size_t i=0; i<inData.GetTools().size(); i++){
for (size_t i=0; i<inData.GetTools().size(); i++) {
ToolInfo ti = inData.GetTools().at(i);
if(wxXmlResource::GetXRCID(ti.GetId().c_str()) == e.GetId()){
if (wxXmlResource::GetXRCID(ti.GetId().c_str()) == e.GetId()) {
DoLaunchTool(ti);
}
}
Expand All @@ -155,22 +176,22 @@ void ExternalToolsPlugin::DoLaunchTool(const ToolInfo& ti)
{
wxString command, working_dir;
wxString current_file;
if(m_mgr->GetActiveEditor()){

if (m_mgr->GetActiveEditor()) {
current_file = m_mgr->GetActiveEditor()->GetFileName().GetFullPath();
}

command << wxT("\"") << ti.GetPath() << wxT("\" ") << ti.GetArguments();
working_dir = ti.GetWd();
if(m_mgr->IsWorkspaceOpen()){

if (m_mgr->IsWorkspaceOpen()) {
command = ExpandAllVariables(command, m_mgr->GetWorkspace(), m_mgr->GetWorkspace()->GetActiveProjectName(), wxEmptyString, current_file);
working_dir = ExpandAllVariables(working_dir, m_mgr->GetWorkspace(), m_mgr->GetWorkspace()->GetActiveProjectName(), wxEmptyString, current_file);
} else {
command = ExpandAllVariables(command, NULL, wxEmptyString, wxEmptyString, current_file);
working_dir = ExpandAllVariables(working_dir, NULL, wxEmptyString, wxEmptyString, current_file);
}

{
// change the directory to the requested working directory
DirSaver ds;
Expand All @@ -179,3 +200,21 @@ void ExternalToolsPlugin::DoLaunchTool(const ToolInfo& ti)
}
}

void ExternalToolsPlugin::DoRecreateToolbar()
{
wxWindow *parent(NULL);
if (m_tb) {
// we have a toolbar, remove it from the docking manager
m_mgr->GetDockingManager()->DetachPane(m_tb);
parent = m_tb->GetParent();
m_tb->Destroy();
} else {
parent = m_mgr->GetTheApp()->GetTopWindow();
}

m_tb = CreateToolBar(parent);
m_mgr->GetDockingManager()->AddPane(m_tb, wxAuiPaneInfo().Name(GetShortName()).LeftDockable( true ).RightDockable( true ).Caption(GetShortName()).ToolbarPane().Top() );

// Apply changes
m_mgr->GetDockingManager()->Update();
}
6 changes: 6 additions & 0 deletions ExternalTools/externaltools.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

#include "plugin.h"
#include "externaltoolsdata.h"
class wxToolBar;

class ExternalToolsPlugin : public IPlugin
{
wxToolBar *m_tb;
wxEvtHandler *topWin;

protected:
void OnSettings(wxCommandEvent &e);
void OnLaunchExternalTool(wxCommandEvent &e);
void DoLaunchTool(const ToolInfo &ti);
void DoRecreateToolbar();

public:
ExternalToolsPlugin(IManager *manager);
~ExternalToolsPlugin();
Expand Down
4 changes: 4 additions & 0 deletions ExternalTools/externaltoolsbasedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ExternalToolBaseDlg::ExternalToolBaseDlg( wxWindow* parent, wxWindowID id, const
wxBoxSizer* bSizer6;
bSizer6 = new wxBoxSizer( wxVERTICAL );

bSizer6->SetMinSize( wxSize( 700,250 ) );
wxBoxSizer* bSizer8;
bSizer8 = new wxBoxSizer( wxHORIZONTAL );

Expand Down Expand Up @@ -55,6 +56,9 @@ ExternalToolBaseDlg::ExternalToolBaseDlg( wxWindow* parent, wxWindowID id, const

this->SetSizer( bSizer6 );
this->Layout();
bSizer6->Fit( this );

this->Centre( wxBOTH );

// Connect Events
m_listCtrlTools->Connect( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler( ExternalToolBaseDlg::OnItemActivated ), NULL, this );
Expand Down
2 changes: 1 addition & 1 deletion ExternalTools/externaltoolsbasedlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ExternalToolBaseDlg : public wxDialog


public:
ExternalToolBaseDlg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("External Tools"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 592,275 ), long style = wxDEFAULT_DIALOG_STYLE );
ExternalToolBaseDlg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("External Tools"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE );
~ExternalToolBaseDlg();

};
Expand Down
Loading

0 comments on commit fd1f1df

Please sign in to comment.