Skip to content

Commit

Permalink
improve tag search and input
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Dec 23, 2018
1 parent 67f660d commit ef8ece8
Show file tree
Hide file tree
Showing 23 changed files with 594 additions and 165 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ SRC_IMP = \
src/util/pool_completion.cpp\
src/export_bom/export_bom.cpp\
src/widgets/unplaced_box.cpp\
src/widgets/tag_entry.cpp\

SRC_ROUTER = \
3rd_party/router/router/pns_router.cpp \
Expand Down Expand Up @@ -471,6 +472,7 @@ SRC_POOL_PRJ_MGR = \
src/widgets/unit_info_box.cpp\
src/widgets/entity_info_box.cpp\
src/widgets/padstack_preview.cpp\
src/widgets/tag_entry.cpp\

SRC_PGM_TEST = \
src/pgm-test/pgm-test.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@
.bus-toolbar {
border-right: 1px solid @borders;
}

.tag-entry-tiny-button {
min-width: 0px;
padding: 0px;
}
15 changes: 6 additions & 9 deletions src/imp/imp_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "widgets/pool_browser.hpp"
#include "widgets/spin_button_dim.hpp"
#include "widgets/parameter_set_editor.hpp"
#include "widgets/tag_entry.hpp"
#include "hud_util.hpp"

namespace horizon {
Expand Down Expand Up @@ -663,7 +664,9 @@ void ImpPackage::construct()
auto entry_manufacturer = header_button->add_entry("Manufacturer");
entry_manufacturer->set_completion(create_pool_manufacturer_completion(pool.get()));

auto entry_tags = header_button->add_entry("Tags");
auto entry_tags = Gtk::manage(new TagEntry(*pool.get(), ObjectType::PACKAGE, true));
entry_tags->show();
header_button->add_widget("Tags", entry_tags);

auto browser_alt_button = Gtk::manage(new PoolBrowserButton(ObjectType::PACKAGE, pool.get()));
browser_alt_button->get_browser()->set_show_none(true);
Expand All @@ -674,8 +677,7 @@ void ImpPackage::construct()
entry_name->set_text(pkg->name);
entry_manufacturer->set_text(pkg->manufacturer);
std::stringstream s;
std::copy(pkg->tags.begin(), pkg->tags.end(), std::ostream_iterator<std::string>(s, " "));
entry_tags->set_text(s.str());
entry_tags->set_tags(pkg->tags);
if (pkg->alternate_for)
browser_alt_button->property_selected_uuid() = pkg->alternate_for->uuid;
}
Expand Down Expand Up @@ -712,12 +714,7 @@ void ImpPackage::construct()
core_package.signal_save().connect(
[this, entry_name, entry_manufacturer, entry_tags, header_button, browser_alt_button] {
auto pkg = core_package.get_package(false);
std::stringstream ss(entry_tags->get_text());
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> tags(begin, end);
pkg->tags.clear();
pkg->tags.insert(tags.begin(), tags.end());
pkg->tags = entry_tags->get_tags();
pkg->name = entry_name->get_text();
pkg->manufacturer = entry_manufacturer->get_text();
UUID alt_uuid = browser_alt_button->property_selected_uuid();
Expand Down
26 changes: 11 additions & 15 deletions src/pool-prj-mgr/pool-mgr/editors/entity_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <glibmm.h>
#include "dialogs/pool_browser_dialog.hpp"
#include "widgets/pool_browser.hpp"
#include "widgets/tag_entry.hpp"
#include "util/pool_completion.hpp"
#include "util/gtk_util.hpp"

Expand Down Expand Up @@ -93,35 +94,30 @@ EntityEditor::EntityEditor(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Buil
{
x->get_widget("entity_name", name_entry);
x->get_widget("entity_manufacturer", manufacturer_entry);
x->get_widget("entity_tags", tags_entry);
{
Gtk::Box *tag_box;
x->get_widget("entity_tags", tag_box);
tag_entry = Gtk::manage(new TagEntry(*pool, ObjectType::ENTITY, true));
tag_entry->show();
tag_box->pack_start(*tag_entry, true, true, 0);
}
x->get_widget("entity_prefix", prefix_entry);
x->get_widget("entity_gates", gates_listbox);
x->get_widget("entity_gates_refresh", refresh_button);
x->get_widget("gate_add", add_button);
x->get_widget("gate_delete", delete_button);
entry_add_sanitizer(name_entry);
entry_add_sanitizer(manufacturer_entry);
entry_add_sanitizer(tags_entry);
entry_add_sanitizer(prefix_entry);

bind_entry(name_entry, entity->name, needs_save);
bind_entry(manufacturer_entry, entity->manufacturer, needs_save);
manufacturer_entry->set_completion(create_pool_manufacturer_completion(pool));
bind_entry(prefix_entry, entity->prefix, needs_save);

{
std::stringstream s;
std::copy(entity->tags.begin(), entity->tags.end(), std::ostream_iterator<std::string>(s, " "));
tags_entry->set_text(s.str());
}

tags_entry->signal_changed().connect([this] {
std::stringstream ss(tags_entry->get_text());
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> tags(begin, end);
entity->tags.clear();
entity->tags.insert(tags.begin(), tags.end());
tag_entry->set_tags(entity->tags);
tag_entry->signal_changed().connect([this] {
entity->tags = tag_entry->get_tags();
needs_save = true;
});

Expand Down
2 changes: 1 addition & 1 deletion src/pool-prj-mgr/pool-mgr/editors/entity_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EntityEditor : public Gtk::Box, public PoolEditorInterface {
Gtk::Entry *name_entry = nullptr;
Gtk::Entry *manufacturer_entry = nullptr;
Gtk::Entry *prefix_entry = nullptr;
Gtk::Entry *tags_entry = nullptr;
class TagEntry *tag_entry = nullptr;

Gtk::ListBox *gates_listbox = nullptr;
Gtk::ToolButton *refresh_button = nullptr;
Expand Down
11 changes: 7 additions & 4 deletions src/pool-prj-mgr/pool-mgr/editors/entity_editor.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="adjustment1">
Expand Down Expand Up @@ -253,10 +253,13 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entity_tags">
<object class="GtkBox" id="entity_tags">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
Expand Down
26 changes: 11 additions & 15 deletions src/pool-prj-mgr/pool-mgr/editors/part_editor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "part_editor.hpp"
#include "dialogs/pool_browser_dialog.hpp"
#include "widgets/pool_browser_package.hpp"
#include "widgets/tag_entry.hpp"
#include <iostream>
#include "pool/part.hpp"
#include "util/util.hpp"
Expand Down Expand Up @@ -127,7 +128,13 @@ PartEditor::PartEditor(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder>
x->get_widget("model_combo", w_model_combo);
x->get_widget("model_inherit", w_model_inherit);
x->get_widget("base_label", w_base_label);
x->get_widget("tags", w_tags);
{
Gtk::Box *tag_box;
x->get_widget("tags", tag_box);
w_tags = Gtk::manage(new TagEntry(*pool, ObjectType::PART, true));
w_tags->show();
tag_box->pack_start(*w_tags, true, true, 0);
}
x->get_widget("tags_inherit", w_tags_inherit);
x->get_widget("tags_inherited", w_tags_inherited);
x->get_widget("tv_pins", w_tv_pins);
Expand Down Expand Up @@ -196,12 +203,8 @@ PartEditor::PartEditor(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder>
w_tags_inherit->set_active(part->inherit_tags);
w_tags_inherit->signal_toggled().connect([this] { needs_save = true; });

{
std::stringstream s;
std::copy(part->tags.begin(), part->tags.end(), std::ostream_iterator<std::string>(s, " "));
w_tags->set_text(s.str());
w_tags->signal_changed().connect([this] { needs_save = true; });
}
w_tags->set_tags(part->tags);
w_tags->signal_changed().connect([this] { needs_save = true; });

pin_store = Gtk::ListStore::create(pin_list_columns);
pin_store->set_sort_func(pin_list_columns.pin_name,
Expand Down Expand Up @@ -500,14 +503,7 @@ void PartEditor::save()
else
part->model = UUID();

{
std::stringstream ss(w_tags->get_text());
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> tags(begin, end);
part->tags.clear();
part->tags.insert(tags.begin(), tags.end());
}
part->tags = w_tags->get_tags();
part->inherit_tags = w_tags_inherit->get_active();

part->parametric.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/pool-prj-mgr/pool-mgr/editors/part_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PartEditor : public Gtk::Box, public PoolEditorInterface {
Gtk::ComboBoxText *w_model_combo = nullptr;
Gtk::ToggleButton *w_model_inherit = nullptr;

Gtk::Entry *w_tags = nullptr;
class TagEntry *w_tags = nullptr;
Gtk::Entry *w_tags_inherited = nullptr;
Gtk::ToggleButton *w_tags_inherit = nullptr;

Expand Down
24 changes: 14 additions & 10 deletions src/pool-prj-mgr/pool-mgr/editors/part_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tags">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkBox" id="part_mpn_box">
<property name="visible">True</property>
Expand Down Expand Up @@ -418,6 +408,20 @@
<property name="top_attach">10</property>
</packing>
</child>
<child>
<object class="GtkBox" id="tags">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<placeholder/>
</child>
Expand Down
34 changes: 17 additions & 17 deletions src/pool-prj-mgr/pool-mgr/part_wizard/part_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nlohmann/json.hpp"
#include "pool-prj-mgr/pool-prj-mgr-app_win.hpp"
#include "util/csv.hpp"
#include "widgets/tag_entry.hpp"

namespace horizon {
LocationEntry *PartWizard::pack_location_entry(const Glib::RefPtr<Gtk::Builder> &x, const std::string &w,
Expand Down Expand Up @@ -49,26 +50,36 @@ PartWizard::PartWizard(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder>
x->get_widget("entity_name", entity_name_entry);
x->get_widget("entity_name_from_mpn", entity_name_from_mpn_button);
x->get_widget("entity_prefix", entity_prefix_entry);
x->get_widget("entity_tags", entity_tags_entry);
{
Gtk::Box *tag_box;
x->get_widget("entity_tags", tag_box);
entity_tags_entry = Gtk::manage(new TagEntry(*pool, ObjectType::ENTITY, true));
entity_tags_entry->show();
tag_box->pack_start(*entity_tags_entry, true, true, 0);
}

x->get_widget("part_mpn", part_mpn_entry);
x->get_widget("part_value", part_value_entry);
x->get_widget("part_manufacturer", part_manufacturer_entry);
x->get_widget("part_description", part_description_entry);
x->get_widget("part_datasheet", part_datasheet_entry);
x->get_widget("part_tags", part_tags_entry);
{
Gtk::Box *tag_box;
x->get_widget("part_tags", tag_box);
part_tags_entry = Gtk::manage(new TagEntry(*pool, ObjectType::PART, true));
part_tags_entry->show();
tag_box->pack_start(*part_tags_entry, true, true, 0);
}
x->get_widget("part_autofill", part_autofill_button);
x->get_widget("steps_grid", steps_grid);

entry_add_sanitizer(entity_name_entry);
entry_add_sanitizer(entity_prefix_entry);
entry_add_sanitizer(entity_tags_entry);
entry_add_sanitizer(part_mpn_entry);
entry_add_sanitizer(part_value_entry);
entry_add_sanitizer(part_manufacturer_entry);
entry_add_sanitizer(part_description_entry);
entry_add_sanitizer(part_datasheet_entry);
entry_add_sanitizer(part_tags_entry);

part_manufacturer_entry->set_completion(create_pool_manufacturer_completion(pool));

Expand Down Expand Up @@ -280,17 +291,6 @@ bool PartWizard::get_has_finished() const
return has_finished;
}

std::set<std::string> tags_from_string(const std::string &s)
{
std::stringstream ss(s);
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
std::vector<std::string> tags(begin, end);
std::set<std::string> tagss;
tagss.insert(tags.begin(), tags.end());
return tagss;
}

std::string PartWizard::get_rel_part_filename()
{
auto part_fn = Gio::File::create_for_path(part_location_entry->get_filename());
Expand All @@ -303,14 +303,14 @@ void PartWizard::finish()
{
entity.name = entity_name_entry->get_text();
entity.prefix = entity_prefix_entry->get_text();
entity.tags = tags_from_string(entity_tags_entry->get_text());
entity.tags = entity_tags_entry->get_tags();

part.attributes[Part::Attribute::MPN] = {false, part_mpn_entry->get_text()};
part.attributes[Part::Attribute::VALUE] = {false, part_value_entry->get_text()};
part.attributes[Part::Attribute::MANUFACTURER] = {false, part_manufacturer_entry->get_text()};
part.attributes[Part::Attribute::DATASHEET] = {false, part_datasheet_entry->get_text()};
part.attributes[Part::Attribute::DESCRIPTION] = {false, part_description_entry->get_text()};
part.tags = tags_from_string(part_tags_entry->get_text());
part.tags = part_tags_entry->get_tags();

entity.manufacturer = part.get_manufacturer();

Expand Down
4 changes: 2 additions & 2 deletions src/pool-prj-mgr/pool-mgr/part_wizard/part_wizard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class PartWizard : public Gtk::Window {
Gtk::Entry *entity_name_entry = nullptr;
Gtk::Button *entity_name_from_mpn_button = nullptr;
Gtk::Entry *entity_prefix_entry = nullptr;
Gtk::Entry *entity_tags_entry = nullptr;
class TagEntry *entity_tags_entry = nullptr;

Gtk::Entry *part_mpn_entry = nullptr;
Gtk::Entry *part_value_entry = nullptr;
Gtk::Entry *part_manufacturer_entry = nullptr;
Gtk::Entry *part_datasheet_entry = nullptr;
Gtk::Entry *part_description_entry = nullptr;
Gtk::Entry *part_tags_entry = nullptr;
class TagEntry *part_tags_entry = nullptr;
Gtk::Button *part_autofill_button = nullptr;

class LocationEntry *entity_location_entry = nullptr;
Expand Down
Loading

0 comments on commit ef8ece8

Please sign in to comment.