Skip to content

Commit

Permalink
add copy MPN context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Aug 12, 2019
1 parent 81eb34e commit 50208eb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pool-prj-mgr/pool-mgr/pool_notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void PoolNotebook::add_context_menu(PoolBrowser *br)
auto clip = Gtk::Clipboard::get();
clip->set_text((std::string)uu);
});
br->add_copy_name_context_menu_item();
br->add_context_menu_item("Update this item", [this, ty](const UUID &uu) {
auto filename = pool.get_filename(ty, uu);
pool_update(nullptr, {filename});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ PoolBrowserPart *PartBrowserWindow::add_search(const UUID &part)
void PartBrowserWindow::add_search_parametric(const std::string &table_name)
{
auto ch = Gtk::manage(new PoolBrowserParametric(&pool, &pool_parametric, table_name));
ch->add_copy_name_context_menu_item();
ch->get_style_context()->add_class("background");
auto tab_label = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
auto la = Gtk::manage(new Gtk::Label(pool_parametric.get_tables().at(table_name).display_name));
Expand Down
1 change: 1 addition & 0 deletions src/widgets/pool_browser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PoolBrowser : public Gtk::Box, public SelectionProvider {
void set_show_none(bool v);
void set_show_path(bool v);
void add_context_menu_item(const std::string &label, sigc::slot1<void, UUID> cb);
virtual void add_copy_name_context_menu_item(){};
virtual void search() = 0;
virtual ObjectType get_type() const
{
Expand Down
11 changes: 11 additions & 0 deletions src/widgets/pool_browser_parametric.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pool_browser_parametric.hpp"
#include "pool/pool.hpp"
#include "pool/part.hpp"
#include "util/util.hpp"

namespace horizon {
Expand Down Expand Up @@ -490,4 +491,14 @@ PoolBrowser::PoolItemSource PoolBrowserParametric::pool_item_source_from_row(con
{
return row[list_columns.source];
}

void PoolBrowserParametric::add_copy_name_context_menu_item()
{
add_context_menu_item("Copy MPN", [this](const UUID &uu) {
auto part = pool->get_part(uu);
auto clip = Gtk::Clipboard::get();
clip->set_text(part->get_MPN());
});
}

} // namespace horizon
3 changes: 2 additions & 1 deletion src/widgets/pool_browser_parametric.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include "pool_browser.hpp"
#include "pool/pool_parametric.hpp"

Expand All @@ -14,6 +13,8 @@ class PoolBrowserParametric : public PoolBrowser {
{
return ObjectType::PART;
}
void add_copy_name_context_menu_item() override;


protected:
Glib::RefPtr<Gtk::ListStore> create_list_store() override;
Expand Down
11 changes: 11 additions & 0 deletions src/widgets/pool_browser_part.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pool_browser_part.hpp"
#include "pool/pool.hpp"
#include "pool/part.hpp"
#include "widgets/tag_entry.hpp"
#include <set>

Expand Down Expand Up @@ -167,4 +168,14 @@ PoolBrowser::PoolItemSource PoolBrowserPart::pool_item_source_from_row(const Gtk
{
return row[list_columns.source];
}

void PoolBrowserPart::add_copy_name_context_menu_item()
{
add_context_menu_item("Copy MPN", [this](const UUID &uu) {
auto part = pool->get_part(uu);
auto clip = Gtk::Clipboard::get();
clip->set_text(part->get_MPN());
});
}

} // namespace horizon
1 change: 1 addition & 0 deletions src/widgets/pool_browser_part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PoolBrowserPart : public PoolBrowser {
{
return ObjectType::PART;
}
void add_copy_name_context_menu_item() override;

protected:
Glib::RefPtr<Gtk::ListStore> create_list_store() override;
Expand Down

0 comments on commit 50208eb

Please sign in to comment.