From c94457731f1fbddbb3e659a3682f705b260b249f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 3 Jun 2009 01:44:57 +0000 Subject: BreadCrumbBox => BreadCrumbs. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2072 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/BreadCrumbBox.cpp | 213 ---------------------------------------------- src/gui/BreadCrumbBox.hpp | 70 --------------- src/gui/BreadCrumbs.cpp | 213 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/BreadCrumbs.hpp | 70 +++++++++++++++ src/gui/PatchWindow.cpp | 2 +- src/gui/wscript | 2 +- 6 files changed, 285 insertions(+), 285 deletions(-) delete mode 100644 src/gui/BreadCrumbBox.cpp delete mode 100644 src/gui/BreadCrumbBox.hpp create mode 100644 src/gui/BreadCrumbs.cpp create mode 100644 src/gui/BreadCrumbs.hpp (limited to 'src/gui') diff --git a/src/gui/BreadCrumbBox.cpp b/src/gui/BreadCrumbBox.cpp deleted file mode 100644 index 0a48cc47..00000000 --- a/src/gui/BreadCrumbBox.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen 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. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "BreadCrumbBox.hpp" -#include "BreadCrumb.hpp" -#include "App.hpp" -#include "client/SigClientInterface.hpp" - -namespace Ingen { -namespace GUI { - -using namespace std; -using namespace Raul; - -BreadCrumbBox::BreadCrumbBox() - : Gtk::HBox() - , _active_path("/") - , _full_path("/") - , _enable_signal(true) -{ - App::instance().client()->signal_object_deleted.connect( - sigc::mem_fun(this, &BreadCrumbBox::object_destroyed)); -} - - -SharedPtr -BreadCrumbBox::view(const Path& path) -{ - for (std::list::const_iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) - if ((*i)->path() == path) - return (*i)->view(); - - return SharedPtr(); -} - - -/** Sets up the crumbs to display @a path. - * - * If @a path is already part of the shown path, it will be selected and the - * children preserved. - */ -void -BreadCrumbBox::build(Path path, SharedPtr view) -{ - bool old_enable_signal = _enable_signal; - _enable_signal = false; - - // Moving to a path we already contain, just switch the active button - if (_breadcrumbs.size() > 0 && (path.is_parent_of(_full_path) || path == _full_path)) { - - for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { - if ((*i)->path() == path) { - (*i)->set_active(true); - if (!(*i)->view()) - (*i)->set_view(view); - - // views are expensive, having two around for the same patch is a bug - assert((*i)->view() == view); - - } else { - (*i)->set_active(false); - } - } - - _active_path = path; - _enable_signal = old_enable_signal; - - - // Moving to a child of the full path, just append crumbs (preserve view cache) - } else if (_breadcrumbs.size() > 0 && (path.is_child_of(_full_path))) { - - string suffix = path.substr(_full_path.length()); - while (suffix.length() > 0) { - if (suffix[0] == '/') - suffix = suffix.substr(1); - const string name = suffix.substr(0, suffix.find("/")); - _full_path = _full_path.base() + name; - BreadCrumb* but = create_crumb(_full_path, view); - pack_start(*but, false, false, 1); - _breadcrumbs.push_back(but); - but->show(); - if (suffix.find("/") == string::npos) - break; - else - suffix = suffix.substr(suffix.find("/")+1); - } - - for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) - (*i)->set_active(false); - _breadcrumbs.back()->set_active(true); - - - // Rebuild from scratch - // Getting here is bad unless absolutely necessary, since the PatchView cache is lost - } else { - - _full_path = path; - _active_path = path; - - // Empty existing breadcrumbs - for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) - remove(**i); - _breadcrumbs.clear(); - - // Add root - BreadCrumb* root_but = create_crumb("/", view); - pack_start(*root_but, false, false, 1); - _breadcrumbs.push_front(root_but); - root_but->set_active(root_but->path() == _active_path); - - Path working_path = "/"; - string suffix = path.chop_scheme().substr(1); - while (suffix.length() > 0) { - if (suffix[0] == '/') - suffix = suffix.substr(1); - const string name = suffix.substr(0, suffix.find("/")); - working_path = working_path.base() + name; - BreadCrumb* but = create_crumb(working_path, view); - pack_start(*but, false, false, 1); - _breadcrumbs.push_back(but); - but->set_active(working_path == _active_path); - but->show(); - if (suffix.find("/") == string::npos) - break; - else - suffix = suffix.substr(suffix.find("/")+1); - } - } - - _enable_signal = old_enable_signal; -} - - -/** Create a new crumb, assigning it a reference to @a view if their paths - * match, otherwise ignoring @a view. - */ -BreadCrumb* -BreadCrumbBox::create_crumb(const Path& path, - SharedPtr view) -{ - BreadCrumb* but = manage(new BreadCrumb(path, - (view && path == view->patch()->path()) ? view : SharedPtr())); - - but->signal_toggled().connect(sigc::bind(sigc::mem_fun( - this, &BreadCrumbBox::breadcrumb_clicked), but)); - - return but; -} - - -void -BreadCrumbBox::breadcrumb_clicked(BreadCrumb* crumb) -{ - if (_enable_signal) { - _enable_signal = false; - - if (!crumb->get_active()) { - // Tried to turn off the current active button, bad user, no cookie - crumb->set_active(true); - } else { - signal_patch_selected.emit(crumb->path(), crumb->view()); - if (crumb->path() != _active_path) - crumb->set_active(false); - } - _enable_signal = true; - } -} - - -void -BreadCrumbBox::object_destroyed(const Path& path) -{ - for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { - if ((*i)->path() == path) { - // Remove all crumbs after the removed one (inclusive) - for (std::list::iterator j = i; j != _breadcrumbs.end(); ) { - BreadCrumb* bc = *j; - j = _breadcrumbs.erase(j); - remove(*bc); - } - break; - } - } -} - - -void -BreadCrumbBox::object_moved(const Path& old_path, const Path& new_path) -{ - for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { - if ((*i)->path() == old_path) - (*i)->set_path(new_path); - } -} - - -} // namespace GUI -} // namespace Ingen - diff --git a/src/gui/BreadCrumbBox.hpp b/src/gui/BreadCrumbBox.hpp deleted file mode 100644 index 6938c154..00000000 --- a/src/gui/BreadCrumbBox.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen 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. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef BREADCRUMBBOX_H -#define BREADCRUMBBOX_H - -#include -#include -#include -#include -#include "raul/Path.hpp" -#include "raul/SharedPtr.hpp" -#include "PatchView.hpp" - -namespace Ingen { -namespace GUI { - -class BreadCrumb; - - -/** Collection of breadcrumb buttons forming a path. - * - * This doubles as a cache for PatchViews. - * - * \ingroup GUI - */ -class BreadCrumbBox : public Gtk::HBox -{ -public: - BreadCrumbBox(); - - SharedPtr view(const Raul::Path& path); - - void build(Raul::Path path, SharedPtr view); - - sigc::signal > signal_patch_selected; - -private: - BreadCrumb* create_crumb(const Raul::Path& path, - SharedPtr view = SharedPtr()); - - void breadcrumb_clicked(BreadCrumb* crumb); - - void object_destroyed(const Raul::Path& path); - void object_moved(const Raul::Path& old_path, const Raul::Path& new_path); - - Raul::Path _active_path; - Raul::Path _full_path; - bool _enable_signal; - std::list _breadcrumbs; -}; - -} // namespace GUI -} // namespace Ingen - -#endif // BREADCRUMBBOX_H diff --git a/src/gui/BreadCrumbs.cpp b/src/gui/BreadCrumbs.cpp new file mode 100644 index 00000000..8e9dd629 --- /dev/null +++ b/src/gui/BreadCrumbs.cpp @@ -0,0 +1,213 @@ +/* This file is part of Ingen. + * Copyright (C) 2007-2009 Dave Robillard + * + * Ingen 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. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "BreadCrumbs.hpp" +#include "BreadCrumb.hpp" +#include "App.hpp" +#include "client/SigClientInterface.hpp" + +namespace Ingen { +namespace GUI { + +using namespace std; +using namespace Raul; + +BreadCrumbBox::BreadCrumbBox() + : Gtk::HBox() + , _active_path("/") + , _full_path("/") + , _enable_signal(true) +{ + App::instance().client()->signal_object_deleted.connect( + sigc::mem_fun(this, &BreadCrumbBox::object_destroyed)); +} + + +SharedPtr +BreadCrumbBox::view(const Path& path) +{ + for (std::list::const_iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) + if ((*i)->path() == path) + return (*i)->view(); + + return SharedPtr(); +} + + +/** Sets up the crumbs to display @a path. + * + * If @a path is already part of the shown path, it will be selected and the + * children preserved. + */ +void +BreadCrumbBox::build(Path path, SharedPtr view) +{ + bool old_enable_signal = _enable_signal; + _enable_signal = false; + + // Moving to a path we already contain, just switch the active button + if (_breadcrumbs.size() > 0 && (path.is_parent_of(_full_path) || path == _full_path)) { + + for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { + if ((*i)->path() == path) { + (*i)->set_active(true); + if (!(*i)->view()) + (*i)->set_view(view); + + // views are expensive, having two around for the same patch is a bug + assert((*i)->view() == view); + + } else { + (*i)->set_active(false); + } + } + + _active_path = path; + _enable_signal = old_enable_signal; + + + // Moving to a child of the full path, just append crumbs (preserve view cache) + } else if (_breadcrumbs.size() > 0 && (path.is_child_of(_full_path))) { + + string suffix = path.substr(_full_path.length()); + while (suffix.length() > 0) { + if (suffix[0] == '/') + suffix = suffix.substr(1); + const string name = suffix.substr(0, suffix.find("/")); + _full_path = _full_path.base() + name; + BreadCrumb* but = create_crumb(_full_path, view); + pack_start(*but, false, false, 1); + _breadcrumbs.push_back(but); + but->show(); + if (suffix.find("/") == string::npos) + break; + else + suffix = suffix.substr(suffix.find("/")+1); + } + + for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) + (*i)->set_active(false); + _breadcrumbs.back()->set_active(true); + + + // Rebuild from scratch + // Getting here is bad unless absolutely necessary, since the PatchView cache is lost + } else { + + _full_path = path; + _active_path = path; + + // Empty existing breadcrumbs + for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) + remove(**i); + _breadcrumbs.clear(); + + // Add root + BreadCrumb* root_but = create_crumb("/", view); + pack_start(*root_but, false, false, 1); + _breadcrumbs.push_front(root_but); + root_but->set_active(root_but->path() == _active_path); + + Path working_path = "/"; + string suffix = path.chop_scheme().substr(1); + while (suffix.length() > 0) { + if (suffix[0] == '/') + suffix = suffix.substr(1); + const string name = suffix.substr(0, suffix.find("/")); + working_path = working_path.base() + name; + BreadCrumb* but = create_crumb(working_path, view); + pack_start(*but, false, false, 1); + _breadcrumbs.push_back(but); + but->set_active(working_path == _active_path); + but->show(); + if (suffix.find("/") == string::npos) + break; + else + suffix = suffix.substr(suffix.find("/")+1); + } + } + + _enable_signal = old_enable_signal; +} + + +/** Create a new crumb, assigning it a reference to @a view if their paths + * match, otherwise ignoring @a view. + */ +BreadCrumb* +BreadCrumbBox::create_crumb(const Path& path, + SharedPtr view) +{ + BreadCrumb* but = manage(new BreadCrumb(path, + (view && path == view->patch()->path()) ? view : SharedPtr())); + + but->signal_toggled().connect(sigc::bind(sigc::mem_fun( + this, &BreadCrumbBox::breadcrumb_clicked), but)); + + return but; +} + + +void +BreadCrumbBox::breadcrumb_clicked(BreadCrumb* crumb) +{ + if (_enable_signal) { + _enable_signal = false; + + if (!crumb->get_active()) { + // Tried to turn off the current active button, bad user, no cookie + crumb->set_active(true); + } else { + signal_patch_selected.emit(crumb->path(), crumb->view()); + if (crumb->path() != _active_path) + crumb->set_active(false); + } + _enable_signal = true; + } +} + + +void +BreadCrumbBox::object_destroyed(const Path& path) +{ + for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { + if ((*i)->path() == path) { + // Remove all crumbs after the removed one (inclusive) + for (std::list::iterator j = i; j != _breadcrumbs.end(); ) { + BreadCrumb* bc = *j; + j = _breadcrumbs.erase(j); + remove(*bc); + } + break; + } + } +} + + +void +BreadCrumbBox::object_moved(const Path& old_path, const Path& new_path) +{ + for (std::list::iterator i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) { + if ((*i)->path() == old_path) + (*i)->set_path(new_path); + } +} + + +} // namespace GUI +} // namespace Ingen + diff --git a/src/gui/BreadCrumbs.hpp b/src/gui/BreadCrumbs.hpp new file mode 100644 index 00000000..6938c154 --- /dev/null +++ b/src/gui/BreadCrumbs.hpp @@ -0,0 +1,70 @@ +/* This file is part of Ingen. + * Copyright (C) 2007-2009 Dave Robillard + * + * Ingen 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. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef BREADCRUMBBOX_H +#define BREADCRUMBBOX_H + +#include +#include +#include +#include +#include "raul/Path.hpp" +#include "raul/SharedPtr.hpp" +#include "PatchView.hpp" + +namespace Ingen { +namespace GUI { + +class BreadCrumb; + + +/** Collection of breadcrumb buttons forming a path. + * + * This doubles as a cache for PatchViews. + * + * \ingroup GUI + */ +class BreadCrumbBox : public Gtk::HBox +{ +public: + BreadCrumbBox(); + + SharedPtr view(const Raul::Path& path); + + void build(Raul::Path path, SharedPtr view); + + sigc::signal > signal_patch_selected; + +private: + BreadCrumb* create_crumb(const Raul::Path& path, + SharedPtr view = SharedPtr()); + + void breadcrumb_clicked(BreadCrumb* crumb); + + void object_destroyed(const Raul::Path& path); + void object_moved(const Raul::Path& old_path, const Raul::Path& new_path); + + Raul::Path _active_path; + Raul::Path _full_path; + bool _enable_signal; + std::list _breadcrumbs; +}; + +} // namespace GUI +} // namespace Ingen + +#endif // BREADCRUMBBOX_H diff --git a/src/gui/PatchWindow.cpp b/src/gui/PatchWindow.cpp index 3b5c3f9b..e1992d1e 100644 --- a/src/gui/PatchWindow.cpp +++ b/src/gui/PatchWindow.cpp @@ -35,7 +35,7 @@ #include "Configuration.hpp" #include "MessagesWindow.hpp" #include "PatchTreeWindow.hpp" -#include "BreadCrumbBox.hpp" +#include "BreadCrumbs.hpp" #include "ConnectWindow.hpp" #include "ThreadedLoader.hpp" #include "WindowFactory.hpp" diff --git a/src/gui/wscript b/src/gui/wscript index 443c500e..6ae349c2 100644 --- a/src/gui/wscript +++ b/src/gui/wscript @@ -5,7 +5,7 @@ def build(bld): obj = bld.new_task_gen('cxx', 'shlib') obj.source = ''' App.cpp - BreadCrumbBox.cpp + BreadCrumbs.cpp Configuration.cpp ConnectWindow.cpp ControlPanel.cpp -- cgit v1.2.1