From aa33189524513d54d049ee866c126c892461c62c Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Wed, 18 Oct 2017 11:59:53 +0200 Subject: Add search to symbols dialog --- share/symbols/search.svg | 8 +++++ src/ui/dialog/symbols.cpp | 78 +++++++++++++++++++++++++++++++++++++++-------- src/ui/dialog/symbols.h | 11 ++++--- 3 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 share/symbols/search.svg diff --git a/share/symbols/search.svg b/share/symbols/search.svg new file mode 100644 index 000000000..74567f039 --- /dev/null +++ b/share/symbols/search.svg @@ -0,0 +1,8 @@ + + Search + + " + diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 558b0b19e..28fd491fd 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -84,11 +84,14 @@ public: Gtk::TreeModelColumn symbol_id; Gtk::TreeModelColumn symbol_title; + Gtk::TreeModelColumn symbol_doc_title; Gtk::TreeModelColumn< Glib::RefPtr > symbol_image; + SymbolColumns() { add(symbol_id); add(symbol_title); + add(symbol_doc_title); add(symbol_image); } }; @@ -182,7 +185,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : addSymbol->set_tooltip_text(_("Add Symbol from the current document.")); addSymbol->set_relief( Gtk::RELIEF_NONE ); addSymbol->set_focus_on_click( false ); - addSymbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); + addSymbol->signal_activate().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); tools->pack_start(* addSymbol, Gtk::PACK_SHRINK); auto removeSymbolImage = Gtk::manage(new Gtk::Image()); @@ -198,7 +201,10 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : Gtk::Label* spacer = Gtk::manage(new Gtk::Label("")); tools->pack_start(* Gtk::manage(spacer)); - + search = Gtk::manage(new Gtk::SearchEntry()); // Search + tools->pack_start(* search, Gtk::PACK_SHRINK); + sigc::connection connSetSearch = search->signal_key_press_event().connect_notify(sigc::bind<0>(sigc::mem_fun(*this, &SymbolsDialog::find_symbols), search)); + // Pack size (controls display area) pack_size = 2; // Default 32px @@ -422,8 +428,10 @@ void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) SPDocument* SymbolsDialog::selectedSymbols() { /* OK, we know symbol name... now we need to copy it to clipboard, bon chance! */ - Glib::ustring symbolSetString = symbolSet->get_active_text(); - + Glib::ustring symbolSetString = selectedSymbolDocTitle(); + if (symbolSetString.empty()) { + symbolSetString = symbolSet->get_active_text(); + } SPDocument* symbolDocument = symbolSets[symbolSetString]; if( !symbolDocument ) { // Symbol must be from Current Document (this method of checking should be language independent). @@ -444,6 +452,18 @@ Glib::ustring SymbolsDialog::selectedSymbolId() { return Glib::ustring(""); } +Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { + + auto iconArray = iconView->get_selected_items(); + + if( !iconArray.empty() ) { + Gtk::TreeModel::Path const & path = *iconArray.begin(); + Gtk::ListStore::iterator row = store->get_iter(path); + return (*row)[getColumns()->symbol_doc_title]; + } + return Glib::ustring(""); +} + void SymbolsDialog::iconChanged() { Glib::ustring symbol_id = selectedSymbolId(); @@ -635,7 +655,7 @@ void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument ) +std::vector SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument) { std::vector l; @@ -655,8 +675,7 @@ void SymbolsDialog::use_in_doc_recursive (SPObject *r, std::vector &l) } } -std::vector SymbolsDialog::use_in_doc( SPDocument* useDocument ) { - +std::vector SymbolsDialog::use_in_doc( SPDocument* useDocument) { std::vector l; use_in_doc_recursive (useDocument->getRoot(), l); return l; @@ -685,17 +704,46 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen return style; } -void SymbolsDialog::add_symbols( SPDocument* symbolDocument ) { +void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { + if (symbol_document) { + std::vector l = symbols_in_doc( symbol_document ); + Glib::ustring doc_title = ""; + if (symbol_document->getRoot()->title()) { + doc_title = symbol_document->getRoot()->title(); + } + for(auto symbol:l) { + if (symbol) { + add_symbol( symbol, doc_title); + } + } + } +} - std::vector l = symbols_in_doc( symbolDocument ); - for(auto symbol:l) { - if (symbol) { - add_symbol( symbol ); +void SymbolsDialog::find_symbols(Gtk::SearchEntry* search, GdkEventKey* evt) { + store->clear(); + Glib::ustring title = search->get_text(); + if (evt->keyval != GDK_KEY_Return || title.empty()) { + return; + } + symbolSet->set_active_text(_("Search")); + for(auto const &symbol_document_map : symbolSets) { + SPDocument* symbol_document = symbol_document_map.second; + std::vector l = symbols_in_doc( symbol_document); + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + if (symbol_title_char) { + Glib::ustring symbol_title = Glib::ustring(symbol_title_char); + auto pos = symbol_title.rfind(title); + if (symbol && pos != std::string::npos) { + Glib::ustring doc_title = symbol_document_map.first; // From doc title element + add_symbol( symbol, doc_title); + } + } } } } -void SymbolsDialog::add_symbol( SPObject* symbol ) { +void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { SymbolColumns* columns = getColumns(); @@ -704,6 +752,9 @@ void SymbolsDialog::add_symbol( SPObject* symbol ) { if( !title ) { title = id; } + if( doc_title.empty() ) { + return; + } Glib::RefPtr pixbuf = draw_symbol( symbol ); @@ -711,6 +762,7 @@ void SymbolsDialog::add_symbol( SPObject* symbol ) { Gtk::ListStore::iterator row = store->append(); (*row)[columns->symbol_id] = Glib::ustring( id ); (*row)[columns->symbol_title] = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); + (*row)[columns->symbol_doc_title] = Glib::Markup::escape_text(doc_title); (*row)[columns->symbol_image] = pixbuf; } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 747e5c6c9..1ce826f4b 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -18,7 +18,7 @@ #include "ui/widget/panel.h" #include "sp-symbol.h" #include "sp-use.h" - +#include #include class SPObject; @@ -77,18 +77,20 @@ private: void documentReplaced(SPDesktop *desktop, SPDocument *document); SPDocument* selectedSymbols(); Glib::ustring selectedSymbolId(); + Glib::ustring selectedSymbolDocTitle(); void iconChanged(); void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void get_symbols(); void add_symbols( SPDocument* symbol_document ); - void add_symbol( SPObject* symbol_document ); + void add_symbol( SPObject* symbol, Glib::ustring doc_title); SPDocument* symbols_preview_doc(); void symbols_in_doc_recursive(SPObject *r, std::vector &l); - std::vector symbols_in_doc( SPDocument* document ); + std::vector symbols_in_doc( SPDocument* document); void use_in_doc_recursive(SPObject *r, std::vector &l); - std::vector use_in_doc( SPDocument* document ); + std::vector use_in_doc( SPDocument* document); + void find_symbols(Gtk::SearchEntry* search, GdkEventKey* evt); gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr draw_symbol(SPObject *symbol); @@ -104,6 +106,7 @@ private: Glib::RefPtr store; Gtk::ComboBoxText* symbolSet; + Gtk::SearchEntry* search; Gtk::IconView* iconView; Gtk::Button* addSymbol; Gtk::Button* removeSymbol; -- cgit v1.2.3 From f515f9cb276b1fb5027cf592ed07c1f0b660d03c Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Wed, 18 Oct 2017 22:45:05 +0200 Subject: Working on speed improvements --- src/ui/dialog/symbols.cpp | 120 +++++++++++++++++++++++++++++++++------------- src/ui/dialog/symbols.h | 1 + 2 files changed, 89 insertions(+), 32 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 28fd491fd..152c1e7e3 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -202,6 +202,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : Gtk::Label* spacer = Gtk::manage(new Gtk::Label("")); tools->pack_start(* Gtk::manage(spacer)); search = Gtk::manage(new Gtk::SearchEntry()); // Search + search->set_tooltip_text(_("Search trought all symbols. Use * to get all (slow).")); tools->pack_start(* search, Gtk::PACK_SHRINK); sigc::connection connSetSearch = search->signal_key_press_event().connect_notify(sigc::bind<0>(sigc::mem_fun(*this, &SymbolsDialog::find_symbols), search)); @@ -359,18 +360,24 @@ void SymbolsDialog::rebuild() { store->clear(); Glib::ustring symbolSetString = symbolSet->get_active_text(); - SPDocument* symbolDocument = symbolSets[symbolSetString]; - if( !symbolDocument ) { - // Symbol must be from Current Document (this method of - // checking should be language independent). - symbolDocument = currentDocument; - addSymbol->set_sensitive( true ); - removeSymbol->set_sensitive( true ); + SPDocument* symbol_document = symbolSets[symbolSetString]; + if( !symbol_document ) { + get_symbols(symbolSetString); + symbolSetString = symbolSet->get_active_text(); + symbol_document = symbolSets[symbolSetString]; + // Symbol must be from Current Document (this method of checking should be language independent). + if( !symbol_document ) { + // Symbol must be from Current Document (this method of + // checking should be language independent). + symbol_document = currentDocument; + addSymbol->set_sensitive( true ); + removeSymbol->set_sensitive( true ); + } } else { addSymbol->set_sensitive( false ); removeSymbol->set_sensitive( false ); } - add_symbols( symbolDocument ); + add_symbols( symbol_document ); } void SymbolsDialog::insertSymbol() { @@ -411,8 +418,8 @@ void SymbolsDialog::defsModified(SPObject * /*object*/, guint /*flags*/) void SymbolsDialog::selectionChanged(Inkscape::Selection *selection) { Glib::ustring symbol_id = selectedSymbolId(); - SPDocument* symbolDocument = selectedSymbols(); - SPObject* symbol = symbolDocument->getObjectById(symbol_id); + SPDocument* symbol_document = selectedSymbols(); + SPObject* symbol = symbol_document->getObjectById(symbol_id); if(symbol && !selection->includes(symbol)) { iconView->unselect_all(); @@ -432,12 +439,17 @@ SPDocument* SymbolsDialog::selectedSymbols() { if (symbolSetString.empty()) { symbolSetString = symbolSet->get_active_text(); } - SPDocument* symbolDocument = symbolSets[symbolSetString]; - if( !symbolDocument ) { + SPDocument* symbol_document = symbolSets[symbolSetString]; + if( !symbol_document ) { + get_symbols(symbolSetString); + symbolSetString = symbolSet->get_active_text(); + symbol_document = symbolSets[symbolSetString]; // Symbol must be from Current Document (this method of checking should be language independent). - return currentDocument; + if( !symbol_document ) { + return currentDocument; + } } - return symbolDocument; + return symbol_document; } Glib::ustring SymbolsDialog::selectedSymbolId() { @@ -467,8 +479,8 @@ Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { void SymbolsDialog::iconChanged() { Glib::ustring symbol_id = selectedSymbolId(); - SPDocument* symbolDocument = selectedSymbols(); - SPObject* symbol = symbolDocument->getObjectById(symbol_id); + SPDocument* symbol_document = selectedSymbols(); + SPObject* symbol = symbol_document->getObjectById(symbol_id); if( symbol ) { // Find style for use in @@ -476,15 +488,15 @@ void SymbolsDialog::iconChanged() { gchar const* style = symbol->getAttribute("inkscape:symbol-style"); if( !style ) { // If no default style in , look in documents. - if( symbolDocument == currentDocument ) { + if( symbol_document == currentDocument ) { style = style_from_use( symbol_id.c_str(), currentDocument ); } else { - style = symbolDocument->getReprRoot()->attribute("style"); + style = symbol_document->getReprRoot()->attribute("style"); } } ClipboardManager *cm = ClipboardManager::get(); - cm->copySymbol(symbol->getRepr(), style, symbolDocument == currentDocument); + cm->copySymbol(symbol->getRepr(), style, symbol_document == currentDocument); } } @@ -610,29 +622,68 @@ SPDocument* read_vss(Glib::ustring filename, Glib::ustring name ) { void SymbolsDialog::get_symbols() { using namespace Inkscape::IO::Resource; - SPDocument* symbol_doc = NULL; Glib::ustring title; - for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { if(Glib::str_has_suffix(filename, ".svg")) { + title = filename.erase(filename.rfind('.')); + if(title.empty()) { + title = _("Unnamed Symbols"); + } + symbolSets[title]= NULL; + symbolSet->append(title); + } +#ifdef WITH_LIBVISIO + if(Glib::str_has_suffix(filename, ".vss")) { + title = filename.erase(filename.rfind('.')); + if(title.empty()) { + title = _("Unnamed Symbols"); + } + symbolSets[title]= NULL; + symbolSet->append(title); + } +#endif + } +} + +/* Hunts preference directories for symbol files */ +void SymbolsDialog::get_symbols(Glib::ustring title) { + + using namespace Inkscape::IO::Resource; + SPDocument* symbol_doc = NULL; + Glib::ustring new_title; + size_t i = 0; + for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { + if(filename == title + ".svg") { symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); if(symbol_doc) { - title = symbol_doc->getRoot()->title(); - if(title.empty()) { - title = _("Unnamed Symbols"); + new_title = symbol_doc->getRoot()->title(); + if(new_title.empty()) { + new_title = _("Unnamed Symbols"); } } - + } + if(Glib::str_has_suffix(filename, ".svg")) { + i++; } #ifdef WITH_LIBVISIO if(Glib::str_has_suffix(filename, ".vss")) { - Glib::ustring title = filename.erase(filename.rfind('.')); + i++; + } + if(filename == title + ".vss") { symbol_doc = read_vss(filename, title); + if(symbol_doc) { + new_title = symbol_doc->getRoot()->title(); + if(new_title.empty()) { + new_title = _("Unnamed Symbols"); + } + } } #endif if(symbol_doc) { - symbolSets[title]= symbol_doc; - symbolSet->append(title); + symbolSets.erase(title); + symbolSets[new_title]= symbol_doc; + symbolSet->set_active(i); + symbolSet->set_active_text(new_title); } } } @@ -655,11 +706,11 @@ void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector SymbolsDialog::symbols_in_doc( SPDocument* symbolDocument) +std::vector SymbolsDialog::symbols_in_doc( SPDocument* symbol_document) { std::vector l; - symbols_in_doc_recursive (symbolDocument->getRoot(), l ); + symbols_in_doc_recursive (symbol_document->getRoot(), l ); return l; } @@ -725,22 +776,27 @@ void SymbolsDialog::find_symbols(Gtk::SearchEntry* search, GdkEventKey* evt) { if (evt->keyval != GDK_KEY_Return || title.empty()) { return; } - symbolSet->set_active_text(_("Search")); for(auto const &symbol_document_map : symbolSets) { SPDocument* symbol_document = symbol_document_map.second; + if (!symbol_document) { + get_symbols(symbol_document_map.first); + Glib::ustring symbolSetString = symbolSet->get_active_text(); + symbol_document = symbolSets[symbolSetString]; + } std::vector l = symbols_in_doc( symbol_document); for(auto symbol:l) { gchar const *symbol_title_char = symbol->title(); if (symbol_title_char) { Glib::ustring symbol_title = Glib::ustring(symbol_title_char); auto pos = symbol_title.rfind(title); - if (symbol && pos != std::string::npos) { + if (title == "*" || symbol && pos != std::string::npos) { Glib::ustring doc_title = symbol_document_map.first; // From doc title element add_symbol( symbol, doc_title); } } } } + symbolSet->set_active_text(_("Search")); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 1ce826f4b..96c9585f5 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -82,6 +82,7 @@ private: void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void get_symbols(); + void get_symbols(Glib::ustring title); void add_symbols( SPDocument* symbol_document ); void add_symbol( SPObject* symbol, Glib::ustring doc_title); SPDocument* symbols_preview_doc(); -- cgit v1.2.3 From 62a1c37f667a8095a834deef50134af8ec477592 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Thu, 19 Oct 2017 03:25:18 +0200 Subject: Improving speed --- share/symbols/search.svg | 2 +- src/ui/dialog/symbols.cpp | 105 ++++++++++++++++++++++++++++------------------ src/ui/dialog/symbols.h | 6 ++- 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/share/symbols/search.svg b/share/symbols/search.svg index 74567f039..3dced798d 100644 --- a/share/symbols/search.svg +++ b/share/symbols/search.svg @@ -4,5 +4,5 @@ xmlns:xlink="http://www.w3.org/1999/xlink"> Search - " + diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 152c1e7e3..d4b460d1d 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -204,7 +204,8 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search = Gtk::manage(new Gtk::SearchEntry()); // Search search->set_tooltip_text(_("Search trought all symbols. Use * to get all (slow).")); tools->pack_start(* search, Gtk::PACK_SHRINK); - sigc::connection connSetSearch = search->signal_key_press_event().connect_notify(sigc::bind<0>(sigc::mem_fun(*this, &SymbolsDialog::find_symbols), search)); + + search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::find_symbols)); // Pack size (controls display area) pack_size = 2; // Default 32px @@ -273,6 +274,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; /**********************************************************/ + sensitive = true; currentDesktop = SP_ACTIVE_DESKTOP; currentDocument = currentDesktop->getDocument(); @@ -349,6 +351,9 @@ void SymbolsDialog::zoomout() { void SymbolsDialog::rebuild() { + if (!sensitive) { + return; + } if( fitSymbol->get_active() ) { zoomIn->set_sensitive( false ); zoomOut->set_sensitive( false ); @@ -358,26 +363,22 @@ void SymbolsDialog::rebuild() { } store->clear(); - Glib::ustring symbolSetString = symbolSet->get_active_text(); - - SPDocument* symbol_document = symbolSets[symbolSetString]; + SPDocument* symbol_document = selectedSymbols(); if( !symbol_document ) { - get_symbols(symbolSetString); - symbolSetString = symbolSet->get_active_text(); - symbol_document = symbolSets[symbolSetString]; - // Symbol must be from Current Document (this method of checking should be language independent). - if( !symbol_document ) { // Symbol must be from Current Document (this method of // checking should be language independent). symbol_document = currentDocument; addSymbol->set_sensitive( true ); removeSymbol->set_sensitive( true ); - } } else { addSymbol->set_sensitive( false ); removeSymbol->set_sensitive( false ); } - add_symbols( symbol_document ); + if (symbolSet->get_active_text() == "Search") { + find_symbols_overload(); + } else { + add_symbols( symbol_document ); + } } void SymbolsDialog::insertSymbol() { @@ -435,15 +436,14 @@ void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) SPDocument* SymbolsDialog::selectedSymbols() { /* OK, we know symbol name... now we need to copy it to clipboard, bon chance! */ - Glib::ustring symbolSetString = selectedSymbolDocTitle(); - if (symbolSetString.empty()) { - symbolSetString = symbolSet->get_active_text(); + Glib::ustring doc_title = selectedSymbolDocTitle(); + if (doc_title.empty()) { + doc_title = symbolSet->get_active_text(); } - SPDocument* symbol_document = symbolSets[symbolSetString]; + SPDocument* symbol_document = symbolSets[doc_title]; if( !symbol_document ) { - get_symbols(symbolSetString); - symbolSetString = symbolSet->get_active_text(); - symbol_document = symbolSets[symbolSetString]; + doc_title = get_symbols(doc_title); + symbol_document = symbolSets[doc_title]; // Symbol must be from Current Document (this method of checking should be language independent). if( !symbol_document ) { return currentDocument; @@ -625,6 +625,9 @@ void SymbolsDialog::get_symbols() { Glib::ustring title; for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { if(Glib::str_has_suffix(filename, ".svg")) { + //TODO: find a way to get real title without loading all SPDocument + std::size_t found = filename.find_last_of("/\\"); + filename = filename.substr(found+1); title = filename.erase(filename.rfind('.')); if(title.empty()) { title = _("Unnamed Symbols"); @@ -634,6 +637,8 @@ void SymbolsDialog::get_symbols() { } #ifdef WITH_LIBVISIO if(Glib::str_has_suffix(filename, ".vss")) { + std::size_t found = filename.find_last_of("/\\"); + filename = filename.substr(found+1); title = filename.erase(filename.rfind('.')); if(title.empty()) { title = _("Unnamed Symbols"); @@ -646,14 +651,16 @@ void SymbolsDialog::get_symbols() { } /* Hunts preference directories for symbol files */ -void SymbolsDialog::get_symbols(Glib::ustring title) { +Glib::ustring SymbolsDialog::get_symbols(Glib::ustring title) { using namespace Inkscape::IO::Resource; SPDocument* symbol_doc = NULL; Glib::ustring new_title; size_t i = 0; for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { - if(filename == title + ".svg") { + std::size_t found = filename.find_last_of("/\\"); + Glib::ustring filename_short = filename.substr(found+1); + if(filename_short == title + ".svg") { symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); if(symbol_doc) { new_title = symbol_doc->getRoot()->title(); @@ -666,10 +673,7 @@ void SymbolsDialog::get_symbols(Glib::ustring title) { i++; } #ifdef WITH_LIBVISIO - if(Glib::str_has_suffix(filename, ".vss")) { - i++; - } - if(filename == title + ".vss") { + if(filename_short == title + ".vss") { symbol_doc = read_vss(filename, title); if(symbol_doc) { new_title = symbol_doc->getRoot()->title(); @@ -678,14 +682,23 @@ void SymbolsDialog::get_symbols(Glib::ustring title) { } } } + if(Glib::str_has_suffix(filename, ".vss")) { + i++; + } #endif if(symbol_doc) { - symbolSets.erase(title); + symbolSets.erase(title); symbolSets[new_title]= symbol_doc; + sensitive = false; + symbolSet->remove_text(i); + symbolSet->insert (i, new_title); symbolSet->set_active(i); symbolSet->set_active_text(new_title); + sensitive = true; + break; } } + return new_title; } void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector &l) @@ -770,33 +783,45 @@ void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { } } -void SymbolsDialog::find_symbols(Gtk::SearchEntry* search, GdkEventKey* evt) { +void SymbolsDialog::find_symbols(GdkEventKey* evt) { + if (evt->keyval != GDK_KEY_Return) { + return; + } + find_symbols_overload(); +} + +void SymbolsDialog::find_symbols_overload() { store->clear(); Glib::ustring title = search->get_text(); - if (evt->keyval != GDK_KEY_Return || title.empty()) { + if (title.empty()) { return; } - for(auto const &symbol_document_map : symbolSets) { + std::map symbolSetsCopy = symbolSets; + for(auto const &symbol_document_map : symbolSetsCopy) { SPDocument* symbol_document = symbol_document_map.second; + Glib::ustring doc_title = symbol_document_map.first; if (!symbol_document) { - get_symbols(symbol_document_map.first); - Glib::ustring symbolSetString = symbolSet->get_active_text(); - symbol_document = symbolSets[symbolSetString]; + doc_title = get_symbols(symbol_document_map.first); + search->set_text(doc_title); + symbol_document = symbolSets[doc_title]; } - std::vector l = symbols_in_doc( symbol_document); - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - if (symbol_title_char) { - Glib::ustring symbol_title = Glib::ustring(symbol_title_char); - auto pos = symbol_title.rfind(title); - if (title == "*" || symbol && pos != std::string::npos) { - Glib::ustring doc_title = symbol_document_map.first; // From doc title element - add_symbol( symbol, doc_title); + if (symbol_document) { + std::vector l = symbols_in_doc(symbol_document); + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + if (symbol_title_char) { + Glib::ustring symbol_title = Glib::ustring(symbol_title_char); + auto pos = symbol_title.rfind(title); + if (symbol && (title == "*" || pos != std::string::npos)) { + add_symbol( symbol, doc_title); + } } } } } + search->set_text(title); symbolSet->set_active_text(_("Search")); + symbolSetsCopy.clear(); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 96c9585f5..0ae8c4fcc 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -82,7 +82,7 @@ private: void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void get_symbols(); - void get_symbols(Glib::ustring title); + Glib::ustring get_symbols(Glib::ustring title); void add_symbols( SPDocument* symbol_document ); void add_symbol( SPObject* symbol, Glib::ustring doc_title); SPDocument* symbols_preview_doc(); @@ -91,7 +91,8 @@ private: std::vector symbols_in_doc( SPDocument* document); void use_in_doc_recursive(SPObject *r, std::vector &l); std::vector use_in_doc( SPDocument* document); - void find_symbols(Gtk::SearchEntry* search, GdkEventKey* evt); + void find_symbols(GdkEventKey* evt); + void find_symbols_overload(); gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr draw_symbol(SPObject *symbol); @@ -107,6 +108,7 @@ private: Glib::RefPtr store; Gtk::ComboBoxText* symbolSet; + bool sensitive; Gtk::SearchEntry* search; Gtk::IconView* iconView; Gtk::Button* addSymbol; -- cgit v1.2.3 From d1b095af84220d7f46123cdd2a2fae1de79d184e Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Thu, 19 Oct 2017 11:15:11 +0200 Subject: Working on current document --- src/ui/dialog/symbols.cpp | 32 +++++++++++++++++++------------- src/ui/dialog/symbols.h | 3 ++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index d4b460d1d..ccaacd6a3 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -363,7 +363,7 @@ void SymbolsDialog::rebuild() { } store->clear(); - SPDocument* symbol_document = selectedSymbols(); + SPDocument* symbol_document = selectedSymbols(true); if( !symbol_document ) { // Symbol must be from Current Document (this method of // checking should be language independent). @@ -434,7 +434,7 @@ void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) rebuild(); } -SPDocument* SymbolsDialog::selectedSymbols() { +SPDocument* SymbolsDialog::selectedSymbols(bool ignorecurrent) { /* OK, we know symbol name... now we need to copy it to clipboard, bon chance! */ Glib::ustring doc_title = selectedSymbolDocTitle(); if (doc_title.empty()) { @@ -446,6 +446,9 @@ SPDocument* SymbolsDialog::selectedSymbols() { symbol_document = symbolSets[doc_title]; // Symbol must be from Current Document (this method of checking should be language independent). if( !symbol_document ) { + if (ignorecurrent) { + return NULL; + } return currentDocument; } } @@ -769,16 +772,14 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen } void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { - if (symbol_document) { - std::vector l = symbols_in_doc( symbol_document ); - Glib::ustring doc_title = ""; - if (symbol_document->getRoot()->title()) { - doc_title = symbol_document->getRoot()->title(); - } - for(auto symbol:l) { - if (symbol) { - add_symbol( symbol, doc_title); - } + std::vector l = symbols_in_doc( symbol_document ); + Glib::ustring doc_title = ""; + if (symbol_document->getRoot()->title()) { + doc_title = symbol_document->getRoot()->title(); + } + for(auto symbol:l) { + if (symbol) { + add_symbol( symbol, doc_title); } } } @@ -790,6 +791,12 @@ void SymbolsDialog::find_symbols(GdkEventKey* evt) { find_symbols_overload(); } +void SymbolsDialog::update_search_box(gpointer data) +{ + Glib::ustring doc_title = *reinterpret_cast(data); + search->set_text(doc_title); +} + void SymbolsDialog::find_symbols_overload() { store->clear(); Glib::ustring title = search->get_text(); @@ -802,7 +809,6 @@ void SymbolsDialog::find_symbols_overload() { Glib::ustring doc_title = symbol_document_map.first; if (!symbol_document) { doc_title = get_symbols(symbol_document_map.first); - search->set_text(doc_title); symbol_document = symbolSets[doc_title]; } if (symbol_document) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 0ae8c4fcc..585e8f98f 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -75,7 +75,8 @@ private: void defsModified(SPObject *object, guint flags); void selectionChanged(Inkscape::Selection *selection); void documentReplaced(SPDesktop *desktop, SPDocument *document); - SPDocument* selectedSymbols(); + SPDocument* selectedSymbols(bool ignorecurrent = false); + void update_search_box(gpointer data); Glib::ustring selectedSymbolId(); Glib::ustring selectedSymbolDocTitle(); void iconChanged(); -- cgit v1.2.3 From 5b1b6e8cf111c4c7c691f9e87bc52dd3626e29cb Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Thu, 19 Oct 2017 19:43:46 +0200 Subject: Finish speed improvements --- src/ui/dialog/symbols.cpp | 82 ++++++++++++++++++++++++++++------------------- src/ui/dialog/symbols.h | 3 +- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index ccaacd6a3..00796e096 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -17,14 +17,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -202,7 +194,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : Gtk::Label* spacer = Gtk::manage(new Gtk::Label("")); tools->pack_start(* Gtk::manage(spacer)); search = Gtk::manage(new Gtk::SearchEntry()); // Search - search->set_tooltip_text(_("Search trought all symbols. Use * to get all (slow).")); + search->set_tooltip_text(_("Return to start search. Use * to get all symbols (slow).")); tools->pack_start(* search, Gtk::PACK_SHRINK); search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::find_symbols)); @@ -275,6 +267,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /**********************************************************/ sensitive = true; + finded = false; currentDesktop = SP_ACTIVE_DESKTOP; currentDocument = currentDesktop->getDocument(); @@ -798,36 +791,57 @@ void SymbolsDialog::update_search_box(gpointer data) } void SymbolsDialog::find_symbols_overload() { - store->clear(); Glib::ustring title = search->get_text(); if (title.empty()) { return; } - std::map symbolSetsCopy = symbolSets; - for(auto const &symbol_document_map : symbolSetsCopy) { - SPDocument* symbol_document = symbol_document_map.second; - Glib::ustring doc_title = symbol_document_map.first; - if (!symbol_document) { - doc_title = get_symbols(symbol_document_map.first); - symbol_document = symbolSets[doc_title]; + if (!finded) { + Gtk::Dialog search_dialog(_("Slow process please read")); + search_dialog.set_border_width(10); + Gtk::Label explanation; + explanation.set_markup(_("First time search is slow, next searchs are fast")); + explanation.set_line_wrap(true); + Gtk::Box *content = search_dialog.get_content_area(); + content->pack_start(explanation, false, false, 5); + Gtk::Button *ko_button = search_dialog.add_button(_("Cancel"), GTK_RESPONSE_CLOSE); + ko_button->grab_focus(); + Gtk::Button *ok_button = search_dialog.add_button(_("Search"), GTK_RESPONSE_ACCEPT); + ok_button->grab_focus(); + ko_button->grab_focus(); + search_dialog.show_all_children(); + int status = search_dialog.run(); + if ( status == GTK_RESPONSE_ACCEPT ) { + finded = true; } - if (symbol_document) { - std::vector l = symbols_in_doc(symbol_document); - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - if (symbol_title_char) { - Glib::ustring symbol_title = Glib::ustring(symbol_title_char); - auto pos = symbol_title.rfind(title); - if (symbol && (title == "*" || pos != std::string::npos)) { - add_symbol( symbol, doc_title); + } + if (finded) { + store->clear(); + std::map symbolSetsCopy = symbolSets; + for(auto const &symbol_document_map : symbolSetsCopy) { + SPDocument* symbol_document = symbol_document_map.second; + Glib::ustring doc_title = symbol_document_map.first; + if (!symbol_document) { + doc_title = get_symbols(symbol_document_map.first); + symbol_document = symbolSets[doc_title]; + } + if (symbol_document) { + std::vector l = symbols_in_doc(symbol_document); + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + if (symbol_title_char) { + Glib::ustring symbol_title = Glib::ustring(symbol_title_char); + auto pos = symbol_title.rfind(title); + if (symbol && (title == "*" || pos != std::string::npos)) { + add_symbol( symbol, doc_title); + } } } } } + search->set_text(title); + symbolSet->set_active_text(_("Search")); + symbolSetsCopy.clear(); } - search->set_text(title); - symbolSet->set_active_text(_("Search")); - symbolSetsCopy.clear(); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { @@ -839,16 +853,18 @@ void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { if( !title ) { title = id; } - if( doc_title.empty() ) { - return; + Glib::ustring symbol_title = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); + if (doc_title.empty()) { + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(" [") +_("Current Document") + Glib::ustring("]")); + } else { + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(" [") + doc_title + Glib::ustring("]")); } - Glib::RefPtr pixbuf = draw_symbol( symbol ); if( pixbuf ) { Gtk::ListStore::iterator row = store->append(); (*row)[columns->symbol_id] = Glib::ustring( id ); - (*row)[columns->symbol_title] = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); + (*row)[columns->symbol_title] = symbol_title; (*row)[columns->symbol_doc_title] = Glib::Markup::escape_text(doc_title); (*row)[columns->symbol_image] = pixbuf; } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 585e8f98f..9a28da1a0 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -12,13 +12,13 @@ #ifndef INKSCAPE_UI_DIALOG_SYMBOLS_H #define INKSCAPE_UI_DIALOG_SYMBOLS_H +#include #include "display/drawing.h" #include "ui/dialog/desktop-tracker.h" #include "ui/widget/panel.h" #include "sp-symbol.h" #include "sp-use.h" -#include #include class SPObject; @@ -110,6 +110,7 @@ private: Glib::RefPtr store; Gtk::ComboBoxText* symbolSet; bool sensitive; + bool finded; Gtk::SearchEntry* search; Gtk::IconView* iconView; Gtk::Button* addSymbol; -- cgit v1.2.3 From f2149d04cdff6c8278fef20928b1bbee6bcbb06f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 20 Oct 2017 05:51:55 +0200 Subject: Add case insensitive and no dialog loading --- src/ui/dialog/symbols.cpp | 91 +++++++++++++++++++---------------------------- src/ui/dialog/symbols.h | 6 ++-- 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 00796e096..a098d64c1 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -197,8 +197,9 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search->set_tooltip_text(_("Return to start search. Use * to get all symbols (slow).")); tools->pack_start(* search, Gtk::PACK_SHRINK); - search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::find_symbols)); - + search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::prepare_find_symbols)); + search->signal_key_release_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::find_symbols)); + // Pack size (controls display area) pack_size = 2; // Default 32px @@ -267,7 +268,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /**********************************************************/ sensitive = true; - finded = false; currentDesktop = SP_ACTIVE_DESKTOP; currentDocument = currentDesktop->getDocument(); @@ -368,7 +368,7 @@ void SymbolsDialog::rebuild() { removeSymbol->set_sensitive( false ); } if (symbolSet->get_active_text() == "Search") { - find_symbols_overload(); + find_symbols_overloaded(); } else { add_symbols( symbol_document ); } @@ -781,67 +781,48 @@ void SymbolsDialog::find_symbols(GdkEventKey* evt) { if (evt->keyval != GDK_KEY_Return) { return; } - find_symbols_overload(); + find_symbols_overloaded(); } -void SymbolsDialog::update_search_box(gpointer data) -{ - Glib::ustring doc_title = *reinterpret_cast(data); - search->set_text(doc_title); +void SymbolsDialog::prepare_find_symbols(GdkEventKey* evt) { + if (evt->keyval != GDK_KEY_Return) { + return; + } + search_str = search->get_text().lowercase(); + search->set_text(_("Loading...")); + } -void SymbolsDialog::find_symbols_overload() { - Glib::ustring title = search->get_text(); - if (title.empty()) { +void SymbolsDialog::find_symbols_overloaded() { + if (search_str.empty()) { return; } - if (!finded) { - Gtk::Dialog search_dialog(_("Slow process please read")); - search_dialog.set_border_width(10); - Gtk::Label explanation; - explanation.set_markup(_("First time search is slow, next searchs are fast")); - explanation.set_line_wrap(true); - Gtk::Box *content = search_dialog.get_content_area(); - content->pack_start(explanation, false, false, 5); - Gtk::Button *ko_button = search_dialog.add_button(_("Cancel"), GTK_RESPONSE_CLOSE); - ko_button->grab_focus(); - Gtk::Button *ok_button = search_dialog.add_button(_("Search"), GTK_RESPONSE_ACCEPT); - ok_button->grab_focus(); - ko_button->grab_focus(); - search_dialog.show_all_children(); - int status = search_dialog.run(); - if ( status == GTK_RESPONSE_ACCEPT ) { - finded = true; + store->clear(); + std::map symbolSetsCopy = symbolSets; + for(auto const &symbol_document_map : symbolSetsCopy) { + SPDocument* symbol_document = symbol_document_map.second; + Glib::ustring doc_title = symbol_document_map.first; + if (!symbol_document) { + doc_title = get_symbols(symbol_document_map.first); + symbol_document = symbolSets[doc_title]; } - } - if (finded) { - store->clear(); - std::map symbolSetsCopy = symbolSets; - for(auto const &symbol_document_map : symbolSetsCopy) { - SPDocument* symbol_document = symbol_document_map.second; - Glib::ustring doc_title = symbol_document_map.first; - if (!symbol_document) { - doc_title = get_symbols(symbol_document_map.first); - symbol_document = symbolSets[doc_title]; - } - if (symbol_document) { - std::vector l = symbols_in_doc(symbol_document); - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - if (symbol_title_char) { - Glib::ustring symbol_title = Glib::ustring(symbol_title_char); - auto pos = symbol_title.rfind(title); - if (symbol && (title == "*" || pos != std::string::npos)) { - add_symbol( symbol, doc_title); - } + if (symbol_document) { + std::vector l = symbols_in_doc(symbol_document); + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + if (symbol_title_char) { + Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); + auto pos = symbol_title.rfind(search_str); + if (symbol && (search_str == "*" || pos != std::string::npos)) { + add_symbol( symbol, doc_title); } } } } - search->set_text(title); - symbolSet->set_active_text(_("Search")); - symbolSetsCopy.clear(); } + search->set_text(search_str); + symbolSet->set_active_text(_("Search")); + symbolSetsCopy.clear(); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { @@ -855,9 +836,9 @@ void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { } Glib::ustring symbol_title = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); if (doc_title.empty()) { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(" [") +_("Current Document") + Glib::ustring("]")); + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" [") +_("Current Document") + Glib::ustring("]")).c_str()))); } else { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(" [") + doc_title + Glib::ustring("]")); + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" [") + doc_title + Glib::ustring("]")).c_str()))); } Glib::RefPtr pixbuf = draw_symbol( symbol ); diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 9a28da1a0..e2e467cd6 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -76,7 +76,6 @@ private: void selectionChanged(Inkscape::Selection *selection); void documentReplaced(SPDesktop *desktop, SPDocument *document); SPDocument* selectedSymbols(bool ignorecurrent = false); - void update_search_box(gpointer data); Glib::ustring selectedSymbolId(); Glib::ustring selectedSymbolDocTitle(); void iconChanged(); @@ -93,7 +92,8 @@ private: void use_in_doc_recursive(SPObject *r, std::vector &l); std::vector use_in_doc( SPDocument* document); void find_symbols(GdkEventKey* evt); - void find_symbols_overload(); + void prepare_find_symbols(GdkEventKey* evt); + void find_symbols_overloaded(); gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr draw_symbol(SPObject *symbol); @@ -110,8 +110,8 @@ private: Glib::RefPtr store; Gtk::ComboBoxText* symbolSet; bool sensitive; - bool finded; Gtk::SearchEntry* search; + Glib::ustring search_str; Gtk::IconView* iconView; Gtk::Button* addSymbol; Gtk::Button* removeSymbol; -- cgit v1.2.3 From f99611197da52e8854719e1bd10d14f1f00d074f Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 20 Oct 2017 09:53:04 +0200 Subject: Add description search and icon if no results --- share/symbols/search.svg | 62 ++++++++++++++++++++++++++++++++++++++++++++--- src/ui/dialog/symbols.cpp | 26 ++++++++++++++++++-- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/share/symbols/search.svg b/share/symbols/search.svg index 3dced798d..5ef63f31c 100644 --- a/share/symbols/search.svg +++ b/share/symbols/search.svg @@ -1,8 +1,62 @@ + - Search + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:ns2="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:xlink="http://www.w3.org/1999/xlink" > + Search + + + + image/svg+xml + + Suru Icon Not Found + 2015-10-05 + + + Sam Hewitt + + + + + Creative Commons Attribution-ShareAlike + + + English + + https://github.com/snwh/suru-icons + Ubuntu icons + + + + + clear-search + + + + + + + + + + diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index a098d64c1..434dcf3b9 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -799,6 +799,8 @@ void SymbolsDialog::find_symbols_overloaded() { } store->clear(); std::map symbolSetsCopy = symbolSets; + bool icons_found = false; + SPDocument* searchdoc; for(auto const &symbol_document_map : symbolSetsCopy) { SPDocument* symbol_document = symbol_document_map.second; Glib::ustring doc_title = symbol_document_map.first; @@ -806,22 +808,42 @@ void SymbolsDialog::find_symbols_overloaded() { doc_title = get_symbols(symbol_document_map.first); symbol_document = symbolSets[doc_title]; } + if (doc_title == "Search") { + searchdoc = symbol_document; + continue; + } if (symbol_document) { std::vector l = symbols_in_doc(symbol_document); for(auto symbol:l) { gchar const *symbol_title_char = symbol->title(); + gchar const *symbol_desc_char = symbol->description(); if (symbol_title_char) { + bool found = false; Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); auto pos = symbol_title.rfind(search_str); - if (symbol && (search_str == "*" || pos != std::string::npos)) { + if (pos != std::string::npos) { + found = true; + } + if (!found && symbol_desc_char) { + Glib::ustring symbol_desc = Glib::ustring(symbol_title_char).lowercase(); + auto pos = symbol_desc.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + } + if (symbol && (search_str == "*" || found)) { add_symbol( symbol, doc_title); + icons_found = true; } } } } } + if (!icons_found) { + add_symbols(searchdoc); + } + symbolSet->set_active_text(_("Search")); search->set_text(search_str); - symbolSet->set_active_text(_("Search")); symbolSetsCopy.clear(); } -- cgit v1.2.3 From cd617235986381ed4de6cba8ba4cf6c74a6cf2d3 Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 20 Oct 2017 12:58:40 +0200 Subject: Add progress bar to loading, currently not working but all the base code is done. need to look into idle methods --- src/ui/dialog/symbols.cpp | 27 +++++++++++++++++++++------ src/ui/dialog/symbols.h | 8 +++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 434dcf3b9..77a9b8ca5 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -20,7 +20,7 @@ #include #include #include -#include + #include "path-prefix.h" #include "io/sys.h" #include "io/resource.h" @@ -63,6 +63,7 @@ #include "verbs.h" #include "helper/action.h" +#include namespace Inkscape { namespace UI { @@ -109,7 +110,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : { /******************** Table *************************/ - auto table = new Gtk::Grid(); + table = new Gtk::Grid(); // panel is a cloked Gtk::VBox _getContents()->pack_start(*Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); @@ -152,13 +153,12 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : sigc::mem_fun(*this, &SymbolsDialog::iconChanged)); instanceConns.push_back(connIconChanged); - Gtk::ScrolledWindow *scroller = new Gtk::ScrolledWindow(); + scroller = new Gtk::ScrolledWindow(); scroller->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); scroller->add(*Gtk::manage(iconView)); scroller->set_hexpand(); scroller->set_vexpand(); table->attach(*Gtk::manage(scroller),0,row,2,1); - ++row; /******************** Tools *******************************/ @@ -266,6 +266,14 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; + /******************** Progress *******************************/ + progress = new Gtk::HBox(); + progressbar = Gtk::manage(new Gtk::ProgressBar()); + table->attach(*Gtk::manage(progress),0,row, 2, 1); + progress->pack_start(* progressbar, Gtk::PACK_EXPAND_WIDGET); + progress->set_margin_top(5); + ++row; + /**********************************************************/ sensitive = true; currentDesktop = SP_ACTIVE_DESKTOP; @@ -289,7 +297,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : sigc::connection documentReplacedConn = currentDesktop->connectDocumentReplaced( sigc::mem_fun(*this, &SymbolsDialog::documentReplaced)); instanceConns.push_back(documentReplacedConn); - get_symbols(); add_symbols( currentDocument ); /* Defaults to current document */ @@ -619,6 +626,7 @@ void SymbolsDialog::get_symbols() { using namespace Inkscape::IO::Resource; Glib::ustring title; + number_docs = 0; for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { if(Glib::str_has_suffix(filename, ".svg")) { //TODO: find a way to get real title without loading all SPDocument @@ -630,6 +638,7 @@ void SymbolsDialog::get_symbols() { } symbolSets[title]= NULL; symbolSet->append(title); + ++number_docs; } #ifdef WITH_LIBVISIO if(Glib::str_has_suffix(filename, ".vss")) { @@ -641,6 +650,7 @@ void SymbolsDialog::get_symbols() { } symbolSets[title]= NULL; symbolSet->append(title); + ++number_docs; } #endif } @@ -788,9 +798,9 @@ void SymbolsDialog::prepare_find_symbols(GdkEventKey* evt) { if (evt->keyval != GDK_KEY_Return) { return; } + progressbar->set_fraction(0.0); search_str = search->get_text().lowercase(); search->set_text(_("Loading...")); - } void SymbolsDialog::find_symbols_overloaded() { @@ -801,7 +811,9 @@ void SymbolsDialog::find_symbols_overloaded() { std::map symbolSetsCopy = symbolSets; bool icons_found = false; SPDocument* searchdoc; + size_t counter = 0; for(auto const &symbol_document_map : symbolSetsCopy) { + ++counter; SPDocument* symbol_document = symbol_document_map.second; Glib::ustring doc_title = symbol_document_map.first; if (!symbol_document) { @@ -813,6 +825,8 @@ void SymbolsDialog::find_symbols_overloaded() { continue; } if (symbol_document) { + progressbar->set_fraction(((100.0/number_docs) * counter)/100.0); + progressbar->set_text(doc_title); std::vector l = symbols_in_doc(symbol_document); for(auto symbol:l) { gchar const *symbol_title_char = symbol->title(); @@ -845,6 +859,7 @@ void SymbolsDialog::find_symbols_overloaded() { symbolSet->set_active_text(_("Search")); search->set_text(search_str); symbolSetsCopy.clear(); + progressbar->set_fraction(1.0); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index e2e467cd6..1b7d04acd 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -107,9 +107,13 @@ private: // Scale factor int scale_factor; + bool sensitive; + size_t number_docs; + Glib::RefPtr store; Gtk::ComboBoxText* symbolSet; - bool sensitive; + Gtk::ProgressBar* progressbar; + Gtk::HBox* progress; Gtk::SearchEntry* search; Glib::ustring search_str; Gtk::IconView* iconView; @@ -117,6 +121,8 @@ private: Gtk::Button* removeSymbol; Gtk::Button* zoomIn; Gtk::Button* zoomOut; + Gtk::Grid* table; + Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fitSymbol; void setTargetDesktop(SPDesktop *desktop); -- cgit v1.2.3 From eda9c670f48804bf43707de3001300496e9cf809 Mon Sep 17 00:00:00 2001 From: Jabiertxo Arraiza Cenoz Date: Fri, 20 Oct 2017 16:01:49 +0200 Subject: Fiz the MR note note_44059492. Thanks Eduard --- src/ui/dialog/symbols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 77a9b8ca5..7f2c69ffd 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -839,7 +839,7 @@ void SymbolsDialog::find_symbols_overloaded() { found = true; } if (!found && symbol_desc_char) { - Glib::ustring symbol_desc = Glib::ustring(symbol_title_char).lowercase(); + Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); auto pos = symbol_desc.rfind(search_str); if (pos != std::string::npos) { found = true; -- cgit v1.2.3 From 4bcc974f13115b19f2b320b98355ef1431e4f9ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 21 Oct 2017 00:20:40 +0200 Subject: Progress Bar workinggit add .git add . --- src/ui/dialog/symbols.cpp | 96 +++++++++++++++++++++++++---------------------- src/ui/dialog/symbols.h | 7 +++- 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 7f2c69ffd..eb787387a 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -198,7 +198,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : tools->pack_start(* search, Gtk::PACK_SHRINK); search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::prepare_find_symbols)); - search->signal_key_release_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::find_symbols)); // Pack size (controls display area) pack_size = 2; // Default 32px @@ -276,6 +275,8 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /**********************************************************/ sensitive = true; + processed = false; + search_str = ""; currentDesktop = SP_ACTIVE_DESKTOP; currentDocument = currentDesktop->getDocument(); @@ -303,7 +304,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : sigc::connection desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); instanceConns.push_back( desktopChangeConn ); - + Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::parse_documents) ); deskTrack.connect(GTK_WIDGET(gobj())); } @@ -375,7 +376,7 @@ void SymbolsDialog::rebuild() { removeSymbol->set_sensitive( false ); } if (symbolSet->get_active_text() == "Search") { - find_symbols_overloaded(); + find_symbols(); } else { add_symbols( symbol_document ); } @@ -787,68 +788,76 @@ void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { } } -void SymbolsDialog::find_symbols(GdkEventKey* evt) { - if (evt->keyval != GDK_KEY_Return) { - return; - } - find_symbols_overloaded(); -} - void SymbolsDialog::prepare_find_symbols(GdkEventKey* evt) { if (evt->keyval != GDK_KEY_Return) { return; } progressbar->set_fraction(0.0); search_str = search->get_text().lowercase(); - search->set_text(_("Loading...")); + search->set_text(_("Searching...")); + if(processed) { + find_symbols(); + } } -void SymbolsDialog::find_symbols_overloaded() { - if (search_str.empty()) { - return; +bool SymbolsDialog::parse_documents(){ + if (search->get_text() != _("Searching...")) { + return true; } - store->clear(); - std::map symbolSetsCopy = symbolSets; + size_t counter = 0; + for(auto const &symbol_document_map : symbolSets) { + ++counter; + SPDocument* symbol_document = symbol_document_map.second; + if (symbol_document) { + continue; + } + get_symbols(symbol_document_map.first); + progressbar->set_fraction(((100.0/number_docs) * counter)/100.0); + return true; + } + find_symbols(); + processed = true; + progressbar->set_fraction(1.0); + return false; +} + +void SymbolsDialog::find_symbols() { bool icons_found = false; SPDocument* searchdoc; size_t counter = 0; - for(auto const &symbol_document_map : symbolSetsCopy) { + store->clear(); + for(auto const &symbol_document_map : symbolSets) { ++counter; SPDocument* symbol_document = symbol_document_map.second; - Glib::ustring doc_title = symbol_document_map.first; if (!symbol_document) { - doc_title = get_symbols(symbol_document_map.first); - symbol_document = symbolSets[doc_title]; + return; } + Glib::ustring doc_title = symbol_document_map.first; if (doc_title == "Search") { searchdoc = symbol_document; continue; } - if (symbol_document) { - progressbar->set_fraction(((100.0/number_docs) * counter)/100.0); - progressbar->set_text(doc_title); - std::vector l = symbols_in_doc(symbol_document); - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - gchar const *symbol_desc_char = symbol->description(); - if (symbol_title_char) { - bool found = false; - Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); - auto pos = symbol_title.rfind(search_str); + std::vector l = symbols_in_doc(symbol_document); + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + gchar const *symbol_desc_char = symbol->description(); + if (symbol_title_char) { + bool found = false; + Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); + auto pos = symbol_title.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + if (!found && symbol_desc_char) { + Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); + auto pos = symbol_desc.rfind(search_str); if (pos != std::string::npos) { found = true; } - if (!found && symbol_desc_char) { - Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); - auto pos = symbol_desc.rfind(search_str); - if (pos != std::string::npos) { - found = true; - } - } - if (symbol && (search_str == "*" || found)) { - add_symbol( symbol, doc_title); - icons_found = true; - } + } + if (symbol && (search_str == "*" || found)) { + add_symbol( symbol, doc_title); + icons_found = true; } } } @@ -858,8 +867,7 @@ void SymbolsDialog::find_symbols_overloaded() { } symbolSet->set_active_text(_("Search")); search->set_text(search_str); - symbolSetsCopy.clear(); - progressbar->set_fraction(1.0); + dynamic_cast(progress)->hide(); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 1b7d04acd..23a81c68c 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -91,9 +91,9 @@ private: std::vector symbols_in_doc( SPDocument* document); void use_in_doc_recursive(SPObject *r, std::vector &l); std::vector use_in_doc( SPDocument* document); - void find_symbols(GdkEventKey* evt); void prepare_find_symbols(GdkEventKey* evt); - void find_symbols_overloaded(); + void find_symbols(); + bool parse_documents(); gchar const* style_from_use( gchar const* id, SPDocument* document); Glib::RefPtr draw_symbol(SPObject *symbol); @@ -108,6 +108,9 @@ private: int scale_factor; bool sensitive; + + bool processed; + size_t number_docs; Glib::RefPtr store; -- cgit v1.2.3 From f9ff5a331dc63f23d6992520cf077a0b55afcebc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 21 Oct 2017 01:43:51 +0200 Subject: Force reload resource --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4732766c1..7ee549631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,13 @@ include(CMakeScripts/ConfigPaths.cmake) # ----------------------------------------------------------------------------- # CMake Configuration # ----------------------------------------------------------------------------- +#Sometimes we need to force refresh resources update putting one new file reconfigure CMake +#https://cmake.org/pipermail/cmake/2010-November/041072.html +SET_SOURCE_FILES_PROPERTIES( + main.cpp PROPERTIES OBJECT_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/share/symbols/search.svg +) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules") # avoid having empty buildtype -- cgit v1.2.3 From 3bd9472b2498d5a0a33026260c64d2cac8ad2878 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 21 Oct 2017 02:44:59 +0200 Subject: Fis come things pointed by Eduard in the MR --- CMakeLists.txt | 6 ------ src/ui/dialog/symbols.cpp | 13 +++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee549631..65c5fa83f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,6 @@ include(CMakeScripts/ConfigPaths.cmake) # ----------------------------------------------------------------------------- # CMake Configuration # ----------------------------------------------------------------------------- -#Sometimes we need to force refresh resources update putting one new file reconfigure CMake -#https://cmake.org/pipermail/cmake/2010-November/041072.html -SET_SOURCE_FILES_PROPERTIES( - main.cpp PROPERTIES OBJECT_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/share/symbols/search.svg -) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules") diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index eb787387a..5e9a5ae2b 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -355,6 +355,7 @@ void SymbolsDialog::rebuild() { if (!sensitive) { return; } + if( fitSymbol->get_active() ) { zoomIn->set_sensitive( false ); zoomOut->set_sensitive( false ); @@ -789,19 +790,23 @@ void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { } void SymbolsDialog::prepare_find_symbols(GdkEventKey* evt) { - if (evt->keyval != GDK_KEY_Return) { + search_str = search->get_text().lowercase(); + if (evt->keyval != GDK_KEY_Return || search_str.empty()) { return; } progressbar->set_fraction(0.0); - search_str = search->get_text().lowercase(); search->set_text(_("Searching...")); + search->set_sensitive(false); if(processed) { find_symbols(); + } else { + dynamic_cast(progressbar)->set_visible(true); } } bool SymbolsDialog::parse_documents(){ if (search->get_text() != _("Searching...")) { + dynamic_cast(progressbar)->set_visible(false); return true; } size_t counter = 0; @@ -867,7 +872,8 @@ void SymbolsDialog::find_symbols() { } symbolSet->set_active_text(_("Search")); search->set_text(search_str); - dynamic_cast(progress)->hide(); + search->set_sensitive(true); + dynamic_cast(progressbar)->set_visible(false); } void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { @@ -1010,7 +1016,6 @@ SPDocument* SymbolsDialog::symbols_preview_doc() " " " " ""; - return SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); } -- cgit v1.2.3 From 5d8948b99524245009680f3af3013f15bc8e8086 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 22 Oct 2017 11:21:17 +0200 Subject: Add discarted switch mode, working on global search --- src/ui/dialog/symbols.cpp | 533 ++++++++++++++++++++++++++-------------------- src/ui/dialog/symbols.h | 66 +++--- 2 files changed, 342 insertions(+), 257 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 5e9a5ae2b..56af2256b 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -101,11 +101,11 @@ SymbolColumns* SymbolsDialog::getColumns() SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : UI::Widget::Panel("", prefsPath, SP_VERB_DIALOG_SYMBOLS), store(Gtk::ListStore::create(*getColumns())), - iconView(0), - currentDesktop(0), - deskTrack(), - currentDocument(0), - previewDocument(0), + icon_view(0), + current_desktop(0), + desk_track(), + current_document(0), + preview_document(0), instanceConns() { @@ -119,43 +119,87 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /******************** Symbol Sets *************************/ Gtk::Label* labelSet = new Gtk::Label(_("Symbol set: ")); table->attach(*Gtk::manage(labelSet),0,row,1,1); - symbolSet = new Gtk::ComboBoxText(); // Fill in later - symbolSet->append(_("Current Document")); - symbolSet->set_active_text(_("Current Document")); - symbolSet->set_hexpand(); - table->attach(*Gtk::manage(symbolSet),1,row,1,1); - sigc::connection connSet = symbolSet->signal_changed().connect( + symbol_set = new Gtk::ComboBoxText(); // Fill in later + symbol_set->append(_("Current Document")); + symbol_set->set_active_text(_("Current Document")); + symbol_set->set_hexpand(); + table->attach(*Gtk::manage(symbol_set),1,row,1,1); + sigc::connection connSet = symbol_set->signal_changed().connect( sigc::mem_fun(*this, &SymbolsDialog::rebuild)); instanceConns.push_back(connSet); ++row; + + Gtk::Separator* separator_sets = new Gtk::Separator(); + separator_sets->set_margin_top(3); + separator_sets->set_margin_bottom(3); + table->attach(*Gtk::manage(separator_sets),0,row,2,1); + + ++row; + /******************** Search *************************/ + + Gtk::Label* label_global = new Gtk::Label(_("Global Search: ")); + table->attach(*Gtk::manage(label_global),0,row,1,1); + Gtk::HBox * global_container = new Gtk::HBox(); + global = new Gtk::Switch(); + global->set_state(false); + global_container->pack_start(* global, Gtk::PACK_SHRINK); + Gtk::Separator* separator_global = new Gtk::Separator(Gtk::ORIENTATION_VERTICAL); + separator_global->set_margin_right(3); + separator_global->set_margin_left(3); + global_container->pack_start(* separator_global, Gtk::PACK_SHRINK); + search = Gtk::manage(new Gtk::SearchEntry()); // Search + search->set_tooltip_text(_("Return to start search.")); + search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::prepareFindSymbols)); + search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); + global_container->pack_start(* search, Gtk::PACK_EXPAND_WIDGET); + table->attach(*Gtk::manage(global_container),1,row,1,1); + + ++row; + + /******************** Progress *******************************/ + progress = new Gtk::HBox(); + progress_bar = Gtk::manage(new Gtk::ProgressBar()); + table->attach(*Gtk::manage(progress),0,row, 2, 1); + progress->pack_start(* progress_bar, Gtk::PACK_EXPAND_WIDGET); + progress->set_margin_top(5); + + ++row; + + Gtk::Separator* separator_search = new Gtk::Separator(); + separator_search->set_margin_top(2); + separator_search->set_margin_bottom(3); + table->attach(*Gtk::manage(separator_search),0,row,2,1); + + ++row; + /********************* Icon View **************************/ SymbolColumns* columns = getColumns(); - iconView = new Gtk::IconView(static_cast >(store)); - //iconView->set_text_column( columns->symbol_id ); - iconView->set_tooltip_column( 1 ); - iconView->set_pixbuf_column( columns->symbol_image ); + icon_view = new Gtk::IconView(static_cast >(store)); + //icon_view->set_text_column( columns->symbol_id ); + icon_view->set_tooltip_column( 1 ); + icon_view->set_pixbuf_column( columns->symbol_image ); // Giving the iconview a small minimum size will help users understand // What the dialog does. - iconView->set_size_request( 100, 200 ); + icon_view->set_size_request( 100, 200 ); std::vector< Gtk::TargetEntry > targets; targets.push_back(Gtk::TargetEntry( "application/x-inkscape-paste")); - iconView->enable_model_drag_source (targets, Gdk::BUTTON1_MASK, Gdk::ACTION_COPY); - iconView->signal_drag_data_get().connect( + icon_view->enable_model_drag_source (targets, Gdk::BUTTON1_MASK, Gdk::ACTION_COPY); + icon_view->signal_drag_data_get().connect( sigc::mem_fun(*this, &SymbolsDialog::iconDragDataGet)); sigc::connection connIconChanged; - connIconChanged = iconView->signal_selection_changed().connect( + connIconChanged = icon_view->signal_selection_changed().connect( sigc::mem_fun(*this, &SymbolsDialog::iconChanged)); instanceConns.push_back(connIconChanged); scroller = new Gtk::ScrolledWindow(); scroller->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS); - scroller->add(*Gtk::manage(iconView)); + scroller->add(*Gtk::manage(icon_view)); scroller->set_hexpand(); scroller->set_vexpand(); table->attach(*Gtk::manage(scroller),0,row,2,1); @@ -169,35 +213,30 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : scroller->set_hexpand(); table->attach(*Gtk::manage(tools),0,row,2,1); - auto addSymbolImage = Gtk::manage(new Gtk::Image()); - addSymbolImage->set_from_icon_name("symbol-add", Gtk::ICON_SIZE_SMALL_TOOLBAR); + auto add_symbol_image = Gtk::manage(new Gtk::Image()); + add_symbol_image->set_from_icon_name("symbol-add", Gtk::ICON_SIZE_SMALL_TOOLBAR); - addSymbol = Gtk::manage(new Gtk::Button()); - addSymbol->add(*addSymbolImage); - addSymbol->set_tooltip_text(_("Add Symbol from the current document.")); - addSymbol->set_relief( Gtk::RELIEF_NONE ); - addSymbol->set_focus_on_click( false ); - addSymbol->signal_activate().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); - tools->pack_start(* addSymbol, Gtk::PACK_SHRINK); + add_symbol = Gtk::manage(new Gtk::Button()); + add_symbol->add(*add_symbol_image); + add_symbol->set_tooltip_text(_("Add Symbol from the current document.")); + add_symbol->set_relief( Gtk::RELIEF_NONE ); + add_symbol->set_focus_on_click( false ); + add_symbol->signal_activate().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); + tools->pack_start(* add_symbol, Gtk::PACK_SHRINK); - auto removeSymbolImage = Gtk::manage(new Gtk::Image()); - removeSymbolImage->set_from_icon_name("symbol-remove", Gtk::ICON_SIZE_SMALL_TOOLBAR); + auto remove_symbolImage = Gtk::manage(new Gtk::Image()); + remove_symbolImage->set_from_icon_name("symbol-remove", Gtk::ICON_SIZE_SMALL_TOOLBAR); - removeSymbol = Gtk::manage(new Gtk::Button()); - removeSymbol->add(*removeSymbolImage); - removeSymbol->set_tooltip_text(_("Remove Symbol from the current document.")); - removeSymbol->set_relief( Gtk::RELIEF_NONE ); - removeSymbol->set_focus_on_click( false ); - removeSymbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::revertSymbol)); - tools->pack_start(* removeSymbol, Gtk::PACK_SHRINK); + remove_symbol = Gtk::manage(new Gtk::Button()); + remove_symbol->add(*remove_symbolImage); + remove_symbol->set_tooltip_text(_("Remove Symbol from the current document.")); + remove_symbol->set_relief( Gtk::RELIEF_NONE ); + remove_symbol->set_focus_on_click( false ); + remove_symbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::revertSymbol)); + tools->pack_start(* remove_symbol, Gtk::PACK_SHRINK); Gtk::Label* spacer = Gtk::manage(new Gtk::Label("")); tools->pack_start(* Gtk::manage(spacer)); - search = Gtk::manage(new Gtk::SearchEntry()); // Search - search->set_tooltip_text(_("Return to start search. Use * to get all symbols (slow).")); - tools->pack_start(* search, Gtk::PACK_SHRINK); - - search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::prepare_find_symbols)); // Pack size (controls display area) pack_size = 2; // Default 32px @@ -225,87 +264,79 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : tools->pack_start(* button, Gtk::PACK_SHRINK); // Toggle scale to fit on/off - auto fitSymbolImage = Gtk::manage(new Gtk::Image()); - fitSymbolImage->set_from_icon_name("symbol-fit", Gtk::ICON_SIZE_SMALL_TOOLBAR); - - fitSymbol = Gtk::manage(new Gtk::ToggleButton()); - fitSymbol->add(*fitSymbolImage); - fitSymbol->set_tooltip_text(_("Toggle 'fit' symbols in icon space.")); - fitSymbol->set_relief( Gtk::RELIEF_NONE ); - fitSymbol->set_focus_on_click( false ); - fitSymbol->set_active( true ); - fitSymbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::rebuild)); - tools->pack_start(* fitSymbol, Gtk::PACK_SHRINK); + auto fit_symbolImage = Gtk::manage(new Gtk::Image()); + fit_symbolImage->set_from_icon_name("symbol-fit", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + fit_symbol = Gtk::manage(new Gtk::ToggleButton()); + fit_symbol->add(*fit_symbolImage); + fit_symbol->set_tooltip_text(_("Toggle 'fit' symbols in icon space.")); + fit_symbol->set_relief( Gtk::RELIEF_NONE ); + fit_symbol->set_focus_on_click( false ); + fit_symbol->set_active( true ); + fit_symbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::rebuild)); + tools->pack_start(* fit_symbol, Gtk::PACK_SHRINK); // Render size (scales symbols within display area) scale_factor = 0; // Default 1:1 * pack_size/pack_size default - auto zoomOutImage = Gtk::manage(new Gtk::Image()); - zoomOutImage->set_from_icon_name("symbol-smaller", Gtk::ICON_SIZE_SMALL_TOOLBAR); - - zoomOut = Gtk::manage(new Gtk::Button()); - zoomOut->add(*zoomOutImage); - zoomOut->set_tooltip_text(_("Make symbols smaller by zooming out.")); - zoomOut->set_relief( Gtk::RELIEF_NONE ); - zoomOut->set_focus_on_click( false ); - zoomOut->set_sensitive( false ); - zoomOut->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::zoomout)); - tools->pack_start(* zoomOut, Gtk::PACK_SHRINK); - - auto zoomInImage = Gtk::manage(new Gtk::Image()); - zoomInImage->set_from_icon_name("symbol-bigger", Gtk::ICON_SIZE_SMALL_TOOLBAR); - - zoomIn = Gtk::manage(new Gtk::Button()); - zoomIn->add(*zoomInImage); - zoomIn->set_tooltip_text(_("Make symbols bigger by zooming in.")); - zoomIn->set_relief( Gtk::RELIEF_NONE ); - zoomIn->set_focus_on_click( false ); - zoomIn->set_sensitive( false ); - zoomIn->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::zoomin)); - tools->pack_start(* zoomIn, Gtk::PACK_SHRINK); - - ++row; + auto zoom_outImage = Gtk::manage(new Gtk::Image()); + zoom_outImage->set_from_icon_name("symbol-smaller", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + zoom_out = Gtk::manage(new Gtk::Button()); + zoom_out->add(*zoom_outImage); + zoom_out->set_tooltip_text(_("Make symbols smaller by zooming out.")); + zoom_out->set_relief( Gtk::RELIEF_NONE ); + zoom_out->set_focus_on_click( false ); + zoom_out->set_sensitive( false ); + zoom_out->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::zoomout)); + tools->pack_start(* zoom_out, Gtk::PACK_SHRINK); + + auto zoom_inImage = Gtk::manage(new Gtk::Image()); + zoom_inImage->set_from_icon_name("symbol-bigger", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + zoom_in = Gtk::manage(new Gtk::Button()); + zoom_in->add(*zoom_inImage); + zoom_in->set_tooltip_text(_("Make symbols bigger by zooming in.")); + zoom_in->set_relief( Gtk::RELIEF_NONE ); + zoom_in->set_focus_on_click( false ); + zoom_in->set_sensitive( false ); + zoom_in->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::zoomin)); + tools->pack_start(* zoom_in, Gtk::PACK_SHRINK); - /******************** Progress *******************************/ - progress = new Gtk::HBox(); - progressbar = Gtk::manage(new Gtk::ProgressBar()); - table->attach(*Gtk::manage(progress),0,row, 2, 1); - progress->pack_start(* progressbar, Gtk::PACK_EXPAND_WIDGET); - progress->set_margin_top(5); ++row; /**********************************************************/ sensitive = true; processed = false; search_str = ""; - currentDesktop = SP_ACTIVE_DESKTOP; - currentDocument = currentDesktop->getDocument(); + current_desktop = SP_ACTIVE_DESKTOP; + current_document = current_desktop->getDocument(); - previewDocument = symbols_preview_doc(); /* Template to render symbols in */ - previewDocument->ensureUpToDate(); /* Necessary? */ + preview_document = symbolsPreviewDoc(); /* Template to render symbols in */ + preview_document->ensureUpToDate(); /* Necessary? */ key = SPItem::display_key_new(1); - renderDrawing.setRoot(previewDocument->getRoot()->invoke_show(renderDrawing, key, SP_ITEM_SHOW_DISPLAY )); + renderDrawing.setRoot(preview_document->getRoot()->invoke_show(renderDrawing, key, SP_ITEM_SHOW_DISPLAY )); // This might need to be a global variable so setTargetDesktop can modify it - SPDefs *defs = currentDocument->getDefs(); + SPDefs *defs = current_document->getDefs(); sigc::connection defsModifiedConn = defs->connectModified(sigc::mem_fun(*this, &SymbolsDialog::defsModified)); instanceConns.push_back(defsModifiedConn); - sigc::connection selectionChangedConn = currentDesktop->selection->connectChanged( + sigc::connection selectionChangedConn = current_desktop->selection->connectChanged( sigc::mem_fun(*this, &SymbolsDialog::selectionChanged)); instanceConns.push_back(selectionChangedConn); - sigc::connection documentReplacedConn = currentDesktop->connectDocumentReplaced( + sigc::connection documentReplacedConn = current_desktop->connectDocumentReplaced( sigc::mem_fun(*this, &SymbolsDialog::documentReplaced)); instanceConns.push_back(documentReplacedConn); - get_symbols(); - add_symbols( currentDocument ); /* Defaults to current document */ + getSymbols(); + addSymbols( current_document ); /* Defaults to current document */ sigc::connection desktopChangeConn = - deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); + desk_track.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); instanceConns.push_back( desktopChangeConn ); - Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::parse_documents) ); - deskTrack.connect(GTK_WIDGET(gobj())); + Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::parseDocuments) ); + desk_track.connect(GTK_WIDGET(gobj())); } SymbolsDialog::~SymbolsDialog() @@ -314,7 +345,7 @@ SymbolsDialog::~SymbolsDialog() it->disconnect(); } instanceConns.clear(); - deskTrack.disconnect(); + desk_track.disconnect(); } SymbolsDialog& SymbolsDialog::getInstance() @@ -356,12 +387,12 @@ void SymbolsDialog::rebuild() { return; } - if( fitSymbol->get_active() ) { - zoomIn->set_sensitive( false ); - zoomOut->set_sensitive( false ); + if( fit_symbol->get_active() ) { + zoom_in->set_sensitive( false ); + zoom_out->set_sensitive( false ); } else { - zoomIn->set_sensitive( true); - zoomOut->set_sensitive( true ); + zoom_in->set_sensitive( true); + zoom_out->set_sensitive( true ); } store->clear(); @@ -369,35 +400,35 @@ void SymbolsDialog::rebuild() { if( !symbol_document ) { // Symbol must be from Current Document (this method of // checking should be language independent). - symbol_document = currentDocument; - addSymbol->set_sensitive( true ); - removeSymbol->set_sensitive( true ); + symbol_document = current_document; + add_symbol->set_sensitive( true ); + remove_symbol->set_sensitive( true ); } else { - addSymbol->set_sensitive( false ); - removeSymbol->set_sensitive( false ); + add_symbol->set_sensitive( false ); + remove_symbol->set_sensitive( false ); } - if (symbolSet->get_active_text() == "Search") { - find_symbols(); + if (symbol_set->get_active_text() == _("Global Search")) { + findSymbols(); } else { - add_symbols( symbol_document ); + findSymbolsInDoc(symbol_document, last_symbol_set); } } void SymbolsDialog::insertSymbol() { Inkscape::Verb *verb = Inkscape::Verb::get( SP_VERB_EDIT_SYMBOL ); - SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->currentDesktop) ); + SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->current_desktop) ); sp_action_perform (action, NULL); } void SymbolsDialog::revertSymbol() { Inkscape::Verb *verb = Inkscape::Verb::get( SP_VERB_EDIT_UNSYMBOL ); - SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->currentDesktop ) ); + SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->current_desktop ) ); sp_action_perform (action, NULL); } void SymbolsDialog::iconDragDataGet(const Glib::RefPtr& /*context*/, Gtk::SelectionData& data, guint /*info*/, guint /*time*/) { - auto iconArray = iconView->get_selected_items(); + auto iconArray = icon_view->get_selected_items(); if( iconArray.empty() ) { //std::cout << " iconArray empty: huh? " << std::endl; @@ -414,7 +445,7 @@ void SymbolsDialog::iconDragDataGet(const Glib::RefPtr& /*cont void SymbolsDialog::defsModified(SPObject * /*object*/, guint /*flags*/) { - if ( !symbolSets[symbolSet->get_active_text()] ) { + if ( !symbol_sets[symbol_set->get_active_text()] ) { rebuild(); } } @@ -425,14 +456,14 @@ void SymbolsDialog::selectionChanged(Inkscape::Selection *selection) { SPObject* symbol = symbol_document->getObjectById(symbol_id); if(symbol && !selection->includes(symbol)) { - iconView->unselect_all(); + icon_view->unselect_all(); } } void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) { - currentDesktop = desktop; - currentDocument = document; + current_desktop = desktop; + current_document = document; rebuild(); } @@ -440,18 +471,17 @@ SPDocument* SymbolsDialog::selectedSymbols(bool ignorecurrent) { /* OK, we know symbol name... now we need to copy it to clipboard, bon chance! */ Glib::ustring doc_title = selectedSymbolDocTitle(); if (doc_title.empty()) { - doc_title = symbolSet->get_active_text(); + doc_title = symbol_set->get_active_text(); } - SPDocument* symbol_document = symbolSets[doc_title]; + SPDocument* symbol_document = symbol_sets[doc_title]; if( !symbol_document ) { - doc_title = get_symbols(doc_title); - symbol_document = symbolSets[doc_title]; + symbol_document = getSymbols(doc_title).second; // Symbol must be from Current Document (this method of checking should be language independent). if( !symbol_document ) { if (ignorecurrent) { return NULL; } - return currentDocument; + return current_document; } } return symbol_document; @@ -459,7 +489,7 @@ SPDocument* SymbolsDialog::selectedSymbols(bool ignorecurrent) { Glib::ustring SymbolsDialog::selectedSymbolId() { - auto iconArray = iconView->get_selected_items(); + auto iconArray = icon_view->get_selected_items(); if( !iconArray.empty() ) { Gtk::TreeModel::Path const & path = *iconArray.begin(); @@ -471,7 +501,7 @@ Glib::ustring SymbolsDialog::selectedSymbolId() { Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { - auto iconArray = iconView->get_selected_items(); + auto iconArray = icon_view->get_selected_items(); if( !iconArray.empty() ) { Gtk::TreeModel::Path const & path = *iconArray.begin(); @@ -493,15 +523,15 @@ void SymbolsDialog::iconChanged() { gchar const* style = symbol->getAttribute("inkscape:symbol-style"); if( !style ) { // If no default style in , look in documents. - if( symbol_document == currentDocument ) { - style = style_from_use( symbol_id.c_str(), currentDocument ); + if( symbol_document == current_document ) { + style = styleFromUse( symbol_id.c_str(), current_document ); } else { style = symbol_document->getReprRoot()->attribute("style"); } } ClipboardManager *cm = ClipboardManager::get(); - cm->copySymbol(symbol->getRepr(), style, symbol_document == currentDocument); + cm->copySymbol(symbol->getRepr(), style, symbol_document == current_document); } } @@ -624,7 +654,7 @@ SPDocument* read_vss(Glib::ustring filename, Glib::ustring name ) { #endif /* Hunts preference directories for symbol files */ -void SymbolsDialog::get_symbols() { +void SymbolsDialog::getSymbols() { using namespace Inkscape::IO::Resource; Glib::ustring title; @@ -638,8 +668,8 @@ void SymbolsDialog::get_symbols() { if(title.empty()) { title = _("Unnamed Symbols"); } - symbolSets[title]= NULL; - symbolSet->append(title); + symbol_sets[title]= NULL; + symbol_set->append(title); ++number_docs; } #ifdef WITH_LIBVISIO @@ -650,8 +680,8 @@ void SymbolsDialog::get_symbols() { if(title.empty()) { title = _("Unnamed Symbols"); } - symbolSets[title]= NULL; - symbolSet->append(title); + symbol_sets[title]= NULL; + symbol_set->append(title); ++number_docs; } #endif @@ -659,8 +689,9 @@ void SymbolsDialog::get_symbols() { } /* Hunts preference directories for symbol files */ -Glib::ustring SymbolsDialog::get_symbols(Glib::ustring title) { - +std::pair +SymbolsDialog::getSymbols(Glib::ustring title) +{ using namespace Inkscape::IO::Resource; SPDocument* symbol_doc = NULL; Glib::ustring new_title; @@ -695,21 +726,21 @@ Glib::ustring SymbolsDialog::get_symbols(Glib::ustring title) { } #endif if(symbol_doc) { - symbolSets.erase(title); - symbolSets[new_title]= symbol_doc; + symbol_sets.erase(title); + symbol_sets[new_title]= symbol_doc; sensitive = false; - symbolSet->remove_text(i); - symbolSet->insert (i, new_title); - symbolSet->set_active(i); - symbolSet->set_active_text(new_title); + symbol_set->remove_text(i); + symbol_set->insert (i, new_title); + symbol_set->set_active(i); + symbol_set->set_active_text(new_title); sensitive = true; break; } } - return new_title; + return std::make_pair(new_title, symbol_doc); } -void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vector &l) +void SymbolsDialog::symbolsInDocRecursive (SPObject *r, std::vector &l) { if(!r) return; @@ -723,19 +754,19 @@ void SymbolsDialog::symbols_in_doc_recursive (SPObject *r, std::vectorchildren) { - symbols_in_doc_recursive( &child, l ); + symbolsInDocRecursive( &child, l ); } } -std::vector SymbolsDialog::symbols_in_doc( SPDocument* symbol_document) +std::vector SymbolsDialog::symbolsInDoc( SPDocument* symbol_document) { std::vector l; - symbols_in_doc_recursive (symbol_document->getRoot(), l ); + symbolsInDocRecursive (symbol_document->getRoot(), l ); return l; } -void SymbolsDialog::use_in_doc_recursive (SPObject *r, std::vector &l) +void SymbolsDialog::useInDoc (SPObject *r, std::vector &l) { if ( dynamic_cast(r) ) { @@ -743,22 +774,22 @@ void SymbolsDialog::use_in_doc_recursive (SPObject *r, std::vector &l) } for (auto& child: r->children) { - use_in_doc_recursive( &child, l ); + useInDoc( &child, l ); } } -std::vector SymbolsDialog::use_in_doc( SPDocument* useDocument) { +std::vector SymbolsDialog::useInDoc( SPDocument* useDocument) { std::vector l; - use_in_doc_recursive (useDocument->getRoot(), l); + useInDoc (useDocument->getRoot(), l); return l; } // Returns style from first element found that references id. // This is a last ditch effort to find a style. -gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* document) { +gchar const* SymbolsDialog::styleFromUse( gchar const* id, SPDocument* document) { gchar const* style = 0; - std::vector l = use_in_doc( document ); + std::vector l = useInDoc( document ); for( auto use:l ) { if ( use ) { gchar const *href = use->getRepr()->attribute("xlink:href"); @@ -776,107 +807,157 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen return style; } -void SymbolsDialog::add_symbols( SPDocument* symbol_document ) { - std::vector l = symbols_in_doc( symbol_document ); +void SymbolsDialog::addSymbols( SPDocument* symbol_document ) { + std::vector l = symbolsInDoc( symbol_document ); Glib::ustring doc_title = ""; if (symbol_document->getRoot()->title()) { doc_title = symbol_document->getRoot()->title(); } for(auto symbol:l) { if (symbol) { - add_symbol( symbol, doc_title); + addSymbol( symbol, doc_title); } } } -void SymbolsDialog::prepare_find_symbols(GdkEventKey* evt) { +void SymbolsDialog::clearSearch() +{ + search_str = search->get_text(); + if(search_str.empty()) { + store->clear(); + findSymbolsInDoc(symbol_sets[last_symbol_set], last_symbol_set); + symbol_set->set_active_text(last_symbol_set); + } +} + +void SymbolsDialog::prepareFindSymbols(GdkEventKey* evt) +{ search_str = search->get_text().lowercase(); - if (evt->keyval != GDK_KEY_Return || search_str.empty()) { + if (evt->keyval != GDK_KEY_Return) { return; } - progressbar->set_fraction(0.0); + progress_bar->set_fraction(0.0); search->set_text(_("Searching...")); search->set_sensitive(false); - if(processed) { - find_symbols(); + global->set_sensitive(false); + if(!global->get_active()) { + bool icons_found = false; + Glib::ustring doc_title = symbol_set->get_active_text(); + if (!doc_title.empty()) { + SPDocument* symbol_document = symbol_sets[doc_title]; + if(symbol_document) { + store->clear(); + icons_found = findSymbolsInDoc(symbol_document, doc_title); + } + } + if (!icons_found) { + for(auto const &symbol_document_map : symbol_sets) { + SPDocument* symbol_document = symbol_document_map.second; + Glib::ustring doc_title = symbol_document_map.first; + //Cover the two cases if search document is procesed or not (title based or filename based) + if (doc_title.lowercase() == "search") { + if(!symbol_document) { + symbol_document = getSymbols(symbol_document_map.first).second; + } + addSymbols(symbol_document); + break; + } + } + } + search->set_text(search_str); + search->set_sensitive(true); + global->set_sensitive(true); + dynamic_cast(progress_bar)->set_visible(false); + } else if(processed) { + findSymbols(); } else { - dynamic_cast(progressbar)->set_visible(true); + dynamic_cast(progress_bar)->set_visible(true); } } -bool SymbolsDialog::parse_documents(){ - if (search->get_text() != _("Searching...")) { - dynamic_cast(progressbar)->set_visible(false); +bool SymbolsDialog::parseDocuments(){ + if (search->get_text() != _("Searching...") || !global->get_active()) { + dynamic_cast(progress_bar)->set_visible(false); return true; } size_t counter = 0; - for(auto const &symbol_document_map : symbolSets) { + for(auto const &symbol_document_map : symbol_sets) { ++counter; SPDocument* symbol_document = symbol_document_map.second; if (symbol_document) { continue; } - get_symbols(symbol_document_map.first); - progressbar->set_fraction(((100.0/number_docs) * counter)/100.0); + getSymbols(symbol_document_map.first); + progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); return true; } - find_symbols(); + findSymbols(); processed = true; - progressbar->set_fraction(1.0); + progress_bar->set_fraction(1.0); return false; } -void SymbolsDialog::find_symbols() { +bool SymbolsDialog::findSymbolsInDoc(SPDocument* symbol_document, Glib::ustring doc_title) { + bool icons_found = false; + std::vector l = symbolsInDoc(symbol_document); + last_symbol_set = doc_title; + for(auto symbol:l) { + gchar const *symbol_title_char = symbol->title(); + gchar const *symbol_desc_char = symbol->description(); + if (symbol_title_char) { + bool found = false; + Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); + auto pos = symbol_title.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + if (!found && symbol_desc_char) { + Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); + auto pos = symbol_desc.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + } + if (symbol && (search_str.empty() || found)) { + addSymbol( symbol, doc_title); + icons_found = true; + } + } + } + return icons_found; +} + +void SymbolsDialog::findSymbols() { bool icons_found = false; SPDocument* searchdoc; - size_t counter = 0; store->clear(); - for(auto const &symbol_document_map : symbolSets) { - ++counter; + for(auto const &symbol_document_map : symbol_sets) { SPDocument* symbol_document = symbol_document_map.second; if (!symbol_document) { - return; + continue; } Glib::ustring doc_title = symbol_document_map.first; if (doc_title == "Search") { searchdoc = symbol_document; continue; } - std::vector l = symbols_in_doc(symbol_document); - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - gchar const *symbol_desc_char = symbol->description(); - if (symbol_title_char) { - bool found = false; - Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); - auto pos = symbol_title.rfind(search_str); - if (pos != std::string::npos) { - found = true; - } - if (!found && symbol_desc_char) { - Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); - auto pos = symbol_desc.rfind(search_str); - if (pos != std::string::npos) { - found = true; - } - } - if (symbol && (search_str == "*" || found)) { - add_symbol( symbol, doc_title); - icons_found = true; - } - } + if(findSymbolsInDoc(symbol_document, doc_title) && !icons_found) { + icons_found = true; } } if (!icons_found) { - add_symbols(searchdoc); + addSymbols(searchdoc); + } + if (global->get_active()) { + symbol_set->set_active_text(_("Global Search")); } - symbolSet->set_active_text(_("Search")); search->set_text(search_str); search->set_sensitive(true); - dynamic_cast(progressbar)->set_visible(false); + global->set_sensitive(true); + dynamic_cast(progress_bar)->set_visible(false); } -void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { +void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { SymbolColumns* columns = getColumns(); @@ -887,11 +968,11 @@ void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { } Glib::ustring symbol_title = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); if (doc_title.empty()) { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" [") +_("Current Document") + Glib::ustring("]")).c_str()))); + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" (") +_("Current Document") + Glib::ustring(")")).c_str()))); } else { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" [") + doc_title + Glib::ustring("]")).c_str()))); + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" (") + doc_title + Glib::ustring(")")).c_str()))); } - Glib::RefPtr pixbuf = draw_symbol( symbol ); + Glib::RefPtr pixbuf = drawSymbol( symbol ); if( pixbuf ) { Gtk::ListStore::iterator row = store->append(); @@ -914,16 +995,16 @@ void SymbolsDialog::add_symbol( SPObject* symbol, Glib::ustring doc_title) { * the temporary document is rendered. */ Glib::RefPtr -SymbolsDialog::draw_symbol(SPObject *symbol) +SymbolsDialog::drawSymbol(SPObject *symbol) { // Create a copy repr of the symbol with id="the_symbol" - Inkscape::XML::Document *xml_doc = previewDocument->getReprDoc(); + Inkscape::XML::Document *xml_doc = preview_document->getReprDoc(); Inkscape::XML::Node *repr = symbol->getRepr()->duplicate(xml_doc); repr->setAttribute("id", "the_symbol"); - // Replace old "the_symbol" in previewDocument by new. - Inkscape::XML::Node *root = previewDocument->getReprRoot(); - SPObject *symbol_old = previewDocument->getObjectById("the_symbol"); + // Replace old "the_symbol" in preview_document by new. + Inkscape::XML::Node *root = preview_document->getReprRoot(); + SPObject *symbol_old = preview_document->getObjectById("the_symbol"); if (symbol_old) { symbol_old->deleteObject(false); } @@ -932,9 +1013,9 @@ SymbolsDialog::draw_symbol(SPObject *symbol) gchar const* style = repr->attribute("inkscape:symbol-style"); if( !style ) { // If no default style in , look in documents. - if( symbol->document == currentDocument ) { + if( symbol->document == current_document ) { gchar const *id = symbol->getRepr()->attribute("id"); - style = style_from_use( id, symbol->document ); + style = styleFromUse( id, symbol->document ); } else { style = symbol->document->getReprRoot()->attribute("style"); } @@ -951,19 +1032,19 @@ SymbolsDialog::draw_symbol(SPObject *symbol) //defsrepr->appendChild(repr); Inkscape::GC::release(repr); - // Uncomment this to get the previewDocument documents saved (useful for debugging) + // Uncomment this to get the preview_document documents saved (useful for debugging) // FILE *fp = fopen (g_strconcat(id, ".svg", NULL), "w"); - // sp_repr_save_stream(previewDocument->getReprDoc(), fp); + // sp_repr_save_stream(preview_document->getReprDoc(), fp); // fclose (fp); - // Make sure previewDocument is up-to-date. - previewDocument->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - previewDocument->ensureUpToDate(); + // Make sure preview_document is up-to-date. + preview_document->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + preview_document->ensureUpToDate(); - // Make sure we have symbol in previewDocument - SPObject *object_temp = previewDocument->getObjectById( "the_use" ); - previewDocument->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - previewDocument->ensureUpToDate(); + // Make sure we have symbol in preview_document + SPObject *object_temp = preview_document->getObjectById( "the_use" ); + preview_document->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + preview_document->ensureUpToDate(); SPItem *item = dynamic_cast(object_temp); g_assert(item != NULL); @@ -987,7 +1068,7 @@ SymbolsDialog::draw_symbol(SPObject *symbol) if( width == 0.0 ) width = 1.0; if( height == 0.0 ) height = 1.0; - if( fitSymbol->get_active() ) + if( fit_symbol->get_active() ) scale = psize / std::max(width, height); else scale = pow( 2.0, scale_factor/2.0 ) * psize / 32.0; @@ -1003,7 +1084,7 @@ SymbolsDialog::draw_symbol(SPObject *symbol) * Symbols are by default not rendered so a element is * provided. */ -SPDocument* SymbolsDialog::symbols_preview_doc() +SPDocument* SymbolsDialog::symbolsPreviewDoc() { // BUG: must be inside gchar const *buffer = @@ -1021,9 +1102,9 @@ SPDocument* SymbolsDialog::symbols_preview_doc() void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) { - if (this->currentDesktop != desktop) { - this->currentDesktop = desktop; - if( !symbolSets[symbolSet->get_active_text()] ) { + if (this->current_desktop != desktop) { + this->current_desktop = desktop; + if( !symbol_sets[symbol_set->get_active_text()] ) { // Symbol set is from Current document, update rebuild(); } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 23a81c68c..54a42ec71 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -6,6 +6,7 @@ * * Copyright (C) 2012 Tavmjong Bah * 2013 Martin Owens + * 2017 Jabiertxo Arraiza * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -81,29 +82,31 @@ private: void iconChanged(); void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); - void get_symbols(); - Glib::ustring get_symbols(Glib::ustring title); - void add_symbols( SPDocument* symbol_document ); - void add_symbol( SPObject* symbol, Glib::ustring doc_title); - SPDocument* symbols_preview_doc(); - - void symbols_in_doc_recursive(SPObject *r, std::vector &l); - std::vector symbols_in_doc( SPDocument* document); - void use_in_doc_recursive(SPObject *r, std::vector &l); - std::vector use_in_doc( SPDocument* document); - void prepare_find_symbols(GdkEventKey* evt); - void find_symbols(); - bool parse_documents(); - gchar const* style_from_use( gchar const* id, SPDocument* document); - - Glib::RefPtr draw_symbol(SPObject *symbol); + void getSymbols(); + std::pair getSymbols(Glib::ustring title); + void addSymbols( SPDocument* symbol_document ); + void addSymbol( SPObject* symbol, Glib::ustring doc_title); + SPDocument* symbolsPreviewDoc(); + + void symbolsInDocRecursive(SPObject *r, std::vector &l); + std::vector symbolsInDoc( SPDocument* document); + void useInDoc(SPObject *r, std::vector &l); + std::vector useInDoc( SPDocument* document); + void prepareFindSymbols(GdkEventKey* evt); + void findSymbols(); + void clearSearch(); + bool findSymbolsInDoc(SPDocument* document, Glib::ustring doc_title); + bool parseDocuments(); + gchar const* styleFromUse( gchar const* id, SPDocument* document); + + Glib::RefPtr drawSymbol(SPObject *symbol); /* Keep track of all symbol template documents */ - std::map symbolSets; + std::map symbol_sets; // Index into sizes which is selected int pack_size; - + // Scale factor int scale_factor; @@ -112,27 +115,28 @@ private: bool processed; size_t number_docs; - + Glib::ustring last_symbol_set; Glib::RefPtr store; - Gtk::ComboBoxText* symbolSet; - Gtk::ProgressBar* progressbar; + Gtk::ComboBoxText* symbol_set; + Gtk::ProgressBar* progress_bar; Gtk::HBox* progress; Gtk::SearchEntry* search; Glib::ustring search_str; - Gtk::IconView* iconView; - Gtk::Button* addSymbol; - Gtk::Button* removeSymbol; - Gtk::Button* zoomIn; - Gtk::Button* zoomOut; + Gtk::IconView* icon_view; + Gtk::Button* add_symbol; + Gtk::Button* remove_symbol; + Gtk::Button* zoom_in; + Gtk::Button* zoom_out; Gtk::Grid* table; + Gtk::Switch * global; Gtk::ScrolledWindow *scroller; - Gtk::ToggleButton* fitSymbol; + Gtk::ToggleButton* fit_symbol; void setTargetDesktop(SPDesktop *desktop); - SPDesktop* currentDesktop; - DesktopTracker deskTrack; - SPDocument* currentDocument; - SPDocument* previewDocument; /* Document to render single symbol */ + SPDesktop* current_desktop; + DesktopTracker desk_track; + SPDocument* current_document; + SPDocument* preview_document; /* Document to render single symbol */ /* For rendering the template drawing */ unsigned key; -- cgit v1.2.3 From 9ff0e67294c5bf435c76fe74ec39c13adeb10d86 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 22 Oct 2017 19:17:34 +0200 Subject: Added some improvements discused in MR --- share/symbols/search.svg | 62 ----------- src/ui/dialog/symbols.cpp | 267 ++++++++++++++++++++++------------------------ src/ui/dialog/symbols.h | 24 ++--- 3 files changed, 141 insertions(+), 212 deletions(-) delete mode 100644 share/symbols/search.svg diff --git a/share/symbols/search.svg b/share/symbols/search.svg deleted file mode 100644 index 5ef63f31c..000000000 --- a/share/symbols/search.svg +++ /dev/null @@ -1,62 +0,0 @@ - - - Search - - - - image/svg+xml - - Suru Icon Not Found - 2015-10-05 - - - Sam Hewitt - - - - - Creative Commons Attribution-ShareAlike - - - English - - https://github.com/snwh/suru-icons - Ubuntu icons - - - - - - clear-search - - - - - - - - - - - - diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 56af2256b..6c7fa6bef 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -111,7 +111,9 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /******************** Table *************************/ table = new Gtk::Grid(); - + table->set_margin_left(3); + table->set_margin_right(3); + table->set_margin_top(4); // panel is a cloked Gtk::VBox _getContents()->pack_start(*Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); guint row = 0; @@ -121,6 +123,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : table->attach(*Gtk::manage(labelSet),0,row,1,1); symbol_set = new Gtk::ComboBoxText(); // Fill in later symbol_set->append(_("Current Document")); + symbol_set->append(_("Search all sets")); symbol_set->set_active_text(_("Current Document")); symbol_set->set_hexpand(); table->attach(*Gtk::manage(symbol_set),1,row,1,1); @@ -130,49 +133,29 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; - Gtk::Separator* separator_sets = new Gtk::Separator(); - separator_sets->set_margin_top(3); - separator_sets->set_margin_bottom(3); - table->attach(*Gtk::manage(separator_sets),0,row,2,1); - - ++row; - /******************** Search *************************/ - - Gtk::Label* label_global = new Gtk::Label(_("Global Search: ")); - table->attach(*Gtk::manage(label_global),0,row,1,1); - Gtk::HBox * global_container = new Gtk::HBox(); - global = new Gtk::Switch(); - global->set_state(false); - global_container->pack_start(* global, Gtk::PACK_SHRINK); - Gtk::Separator* separator_global = new Gtk::Separator(Gtk::ORIENTATION_VERTICAL); - separator_global->set_margin_right(3); - separator_global->set_margin_left(3); - global_container->pack_start(* separator_global, Gtk::PACK_SHRINK); - search = Gtk::manage(new Gtk::SearchEntry()); // Search - search->set_tooltip_text(_("Return to start search.")); - search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::prepareFindSymbols)); - search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); - global_container->pack_start(* search, Gtk::PACK_EXPAND_WIDGET); - table->attach(*Gtk::manage(global_container),1,row,1,1); - - ++row; - /******************** Progress *******************************/ progress = new Gtk::HBox(); progress_bar = Gtk::manage(new Gtk::ProgressBar()); table->attach(*Gtk::manage(progress),0,row, 2, 1); progress->pack_start(* progress_bar, Gtk::PACK_EXPAND_WIDGET); - progress->set_margin_top(5); + progress->set_margin_top(8); + progress->set_margin_bottom(8); ++row; - Gtk::Separator* separator_search = new Gtk::Separator(); - separator_search->set_margin_top(2); - separator_search->set_margin_bottom(3); - table->attach(*Gtk::manage(separator_search),0,row,2,1); + /******************** Search *************************/ + - ++row; + search = Gtk::manage(new Gtk::SearchEntry()); // Search + search->set_tooltip_text(_("Return to start search.")); + search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::beforeAddSymbols)); + search->set_margin_left(10); + search->set_margin_right(10); + search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); + table->attach(*Gtk::manage(search),0,row,2,1); + ++row; + /********************* Icon View **************************/ SymbolColumns* columns = getColumns(); @@ -329,13 +312,12 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : sigc::connection documentReplacedConn = current_desktop->connectDocumentReplaced( sigc::mem_fun(*this, &SymbolsDialog::documentReplaced)); instanceConns.push_back(documentReplacedConn); - getSymbols(); - addSymbols( current_document ); /* Defaults to current document */ + getSymbolsFilename(); + addSymbolsInDoc(current_document); /* Defaults to current document */ sigc::connection desktopChangeConn = desk_track.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); instanceConns.push_back( desktopChangeConn ); - Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::parseDocuments) ); desk_track.connect(GTK_WIDGET(gobj())); } @@ -407,10 +389,14 @@ void SymbolsDialog::rebuild() { add_symbol->set_sensitive( false ); remove_symbol->set_sensitive( false ); } - if (symbol_set->get_active_text() == _("Global Search")) { - findSymbols(); + if (symbol_set->get_active_text() == _("Search all sets")) { + store->clear(); + if (search_str != "" && processed) { + addSymbols(); + } } else { - findSymbolsInDoc(symbol_document, last_symbol_set); + search->set_text(""); + addSymbolsInDoc(symbol_document); } } @@ -475,7 +461,7 @@ SPDocument* SymbolsDialog::selectedSymbols(bool ignorecurrent) { } SPDocument* symbol_document = symbol_sets[doc_title]; if( !symbol_document ) { - symbol_document = getSymbols(doc_title).second; + symbol_document = getSymbolsSet(doc_title).second; // Symbol must be from Current Document (this method of checking should be language independent). if( !symbol_document ) { if (ignorecurrent) { @@ -511,6 +497,18 @@ Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { return Glib::ustring(""); } +Glib::ustring SymbolsDialog::documentTitle(SPDocument* symbol_doc) { + Glib::ustring title = ""; + if (symbol_doc) { + SPRoot * root = symbol_doc->getRoot(); + if (root->title()) { + title = Glib::ustring(root->title()); + } + return title; + } + return title; +} + void SymbolsDialog::iconChanged() { Glib::ustring symbol_id = selectedSymbolId(); @@ -654,7 +652,7 @@ SPDocument* read_vss(Glib::ustring filename, Glib::ustring name ) { #endif /* Hunts preference directories for symbol files */ -void SymbolsDialog::getSymbols() { +void SymbolsDialog::getSymbolsFilename() { using namespace Inkscape::IO::Resource; Glib::ustring title; @@ -690,52 +688,57 @@ void SymbolsDialog::getSymbols() { /* Hunts preference directories for symbol files */ std::pair -SymbolsDialog::getSymbols(Glib::ustring title) +SymbolsDialog::getSymbolsSet(Glib::ustring title) { + if (symbol_sets[title]) { + return std::make_pair(title, symbol_sets[title]); + } using namespace Inkscape::IO::Resource; SPDocument* symbol_doc = NULL; Glib::ustring new_title; size_t i = 0; for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) { - std::size_t found = filename.find_last_of("/\\"); - Glib::ustring filename_short = filename.substr(found+1); - if(filename_short == title + ".svg") { - symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); - if(symbol_doc) { - new_title = symbol_doc->getRoot()->title(); - if(new_title.empty()) { - new_title = _("Unnamed Symbols"); - } - } - } - if(Glib::str_has_suffix(filename, ".svg")) { - i++; - } + std::size_t pos = filename.find_last_of("/\\"); + if (pos != std::string::npos) { + Glib::ustring filename_short = filename.substr(pos+1); + if(filename_short == title + ".svg") { + symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); + if(symbol_doc) { + new_title = symbol_doc->getRoot()->title(); + if(new_title.empty()) { + new_title = _("Unnamed Symbols"); + } + } + } + if(Glib::str_has_suffix(filename, ".svg")) { + i++; + } #ifdef WITH_LIBVISIO - if(filename_short == title + ".vss") { - symbol_doc = read_vss(filename, title); - if(symbol_doc) { - new_title = symbol_doc->getRoot()->title(); - if(new_title.empty()) { - new_title = _("Unnamed Symbols"); - } - } - } - if(Glib::str_has_suffix(filename, ".vss")) { - i++; - } + if(filename_short == title + ".vss") { + symbol_doc = read_vss(filename, title); + if(symbol_doc) { + new_title = symbol_doc->getRoot()->title(); + if(new_title.empty()) { + new_title = _("Unnamed Symbols"); + } + } + } + if(Glib::str_has_suffix(filename, ".vss")) { + i++; + } #endif - if(symbol_doc) { - symbol_sets.erase(title); - symbol_sets[new_title]= symbol_doc; - sensitive = false; - symbol_set->remove_text(i); - symbol_set->insert (i, new_title); - symbol_set->set_active(i); - symbol_set->set_active_text(new_title); - sensitive = true; - break; - } + if(symbol_doc) { + symbol_sets.erase(title); + symbol_sets[new_title]= symbol_doc; + sensitive = false; + symbol_set->remove_text(i+1); + symbol_set->insert (i+1, new_title); + symbol_set->set_active(i+1); + symbol_set->set_active_text(new_title); + sensitive = true; + break; + } + } } return std::make_pair(new_title, symbol_doc); } @@ -807,30 +810,19 @@ gchar const* SymbolsDialog::styleFromUse( gchar const* id, SPDocument* document) return style; } -void SymbolsDialog::addSymbols( SPDocument* symbol_document ) { - std::vector l = symbolsInDoc( symbol_document ); - Glib::ustring doc_title = ""; - if (symbol_document->getRoot()->title()) { - doc_title = symbol_document->getRoot()->title(); - } - for(auto symbol:l) { - if (symbol) { - addSymbol( symbol, doc_title); - } - } -} - void SymbolsDialog::clearSearch() { - search_str = search->get_text(); - if(search_str.empty()) { + if(search->get_text().empty()) { + search_str = ""; store->clear(); - findSymbolsInDoc(symbol_sets[last_symbol_set], last_symbol_set); - symbol_set->set_active_text(last_symbol_set); + Glib::ustring current = symbol_set->get_active_text(); + if (current != _("Search all sets")) { + addSymbolsInDoc(symbol_sets[current]); + } } } -void SymbolsDialog::prepareFindSymbols(GdkEventKey* evt) +void SymbolsDialog::beforeAddSymbols(GdkEventKey* evt) { search_str = search->get_text().lowercase(); if (evt->keyval != GDK_KEY_Return) { @@ -839,45 +831,33 @@ void SymbolsDialog::prepareFindSymbols(GdkEventKey* evt) progress_bar->set_fraction(0.0); search->set_text(_("Searching...")); search->set_sensitive(false); - global->set_sensitive(false); - if(!global->get_active()) { + Glib::ustring current = symbol_set->get_active_text(); + if (current != _("Search all sets")) { bool icons_found = false; Glib::ustring doc_title = symbol_set->get_active_text(); if (!doc_title.empty()) { SPDocument* symbol_document = symbol_sets[doc_title]; if(symbol_document) { store->clear(); - icons_found = findSymbolsInDoc(symbol_document, doc_title); + icons_found = addSymbolsInDoc(symbol_document); } } if (!icons_found) { - for(auto const &symbol_document_map : symbol_sets) { - SPDocument* symbol_document = symbol_document_map.second; - Glib::ustring doc_title = symbol_document_map.first; - //Cover the two cases if search document is procesed or not (title based or filename based) - if (doc_title.lowercase() == "search") { - if(!symbol_document) { - symbol_document = getSymbols(symbol_document_map.first).second; - } - addSymbols(symbol_document); - break; - } - } + //show overlay } search->set_text(search_str); search->set_sensitive(true); - global->set_sensitive(true); - dynamic_cast(progress_bar)->set_visible(false); } else if(processed) { - findSymbols(); + Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::callbackGetSymbols) ); + addSymbols(); } else { - dynamic_cast(progress_bar)->set_visible(true); + Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::callbackGetSymbolsSets) ); } } -bool SymbolsDialog::parseDocuments(){ - if (search->get_text() != _("Searching...") || !global->get_active()) { - dynamic_cast(progress_bar)->set_visible(false); +bool SymbolsDialog::callbackGetSymbolsSets(){ + Glib::ustring current = symbol_set->get_active_text(); + if (search->get_text() != _("Searching...") || current != _("Search all sets")) { return true; } size_t counter = 0; @@ -887,20 +867,40 @@ bool SymbolsDialog::parseDocuments(){ if (symbol_document) { continue; } - getSymbols(symbol_document_map.first); + symbol_document = getSymbolsSet(symbol_document_map.first).second; + symbol_set->set_active_text(_("Search all sets")); + if (!symbol_document) { + continue; + } progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); return true; } - findSymbols(); + addSymbols(); processed = true; progress_bar->set_fraction(1.0); return false; } -bool SymbolsDialog::findSymbolsInDoc(SPDocument* symbol_document, Glib::ustring doc_title) { +bool SymbolsDialog::callbackGetSymbols() +{ + if (loading && processed) { + progress_bar->pulse(); + return true; + } + return false; +} + +bool SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { bool icons_found = false; + if (!symbol_document) { + return false; //Search all + } + Glib::ustring doc_title = documentTitle(symbol_document); + if (doc_title.empty()) { + return false; + } std::vector l = symbolsInDoc(symbol_document); - last_symbol_set = doc_title; + loading = false; for(auto symbol:l) { gchar const *symbol_title_char = symbol->title(); gchar const *symbol_desc_char = symbol->description(); @@ -923,38 +923,29 @@ bool SymbolsDialog::findSymbolsInDoc(SPDocument* symbol_document, Glib::ustring icons_found = true; } } + } + loading = false; return icons_found; } -void SymbolsDialog::findSymbols() { +void SymbolsDialog::addSymbols() { bool icons_found = false; - SPDocument* searchdoc; store->clear(); for(auto const &symbol_document_map : symbol_sets) { SPDocument* symbol_document = symbol_document_map.second; if (!symbol_document) { continue; } - Glib::ustring doc_title = symbol_document_map.first; - if (doc_title == "Search") { - searchdoc = symbol_document; - continue; - } - if(findSymbolsInDoc(symbol_document, doc_title) && !icons_found) { + if(addSymbolsInDoc(symbol_document) && !icons_found) { icons_found = true; } } if (!icons_found) { - addSymbols(searchdoc); - } - if (global->get_active()) { - symbol_set->set_active_text(_("Global Search")); + //Show overlay } search->set_text(search_str); search->set_sensitive(true); - global->set_sensitive(true); - dynamic_cast(progress_bar)->set_visible(false); } void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 54a42ec71..bc6c127a7 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -81,22 +81,22 @@ private: Glib::ustring selectedSymbolDocTitle(); void iconChanged(); void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); - - void getSymbols(); - std::pair getSymbols(Glib::ustring title); - void addSymbols( SPDocument* symbol_document ); + void getSymbolsFilename(); + Glib::ustring documentTitle(SPDocument* doc); + std::pair getSymbolsSet(Glib::ustring title); void addSymbol( SPObject* symbol, Glib::ustring doc_title); SPDocument* symbolsPreviewDoc(); - void symbolsInDocRecursive(SPObject *r, std::vector &l); std::vector symbolsInDoc( SPDocument* document); void useInDoc(SPObject *r, std::vector &l); std::vector useInDoc( SPDocument* document); - void prepareFindSymbols(GdkEventKey* evt); - void findSymbols(); + void beforeAddSymbols(GdkEventKey* evt); + void addSymbols(); + bool addSymbolsInDoc(SPDocument* document); void clearSearch(); - bool findSymbolsInDoc(SPDocument* document, Glib::ustring doc_title); - bool parseDocuments(); + bool callbackGetSymbolsSets(); + bool callbackGetSymbols(); + gchar const* styleFromUse( gchar const* id, SPDocument* document); Glib::RefPtr drawSymbol(SPObject *symbol); @@ -112,23 +112,23 @@ private: bool sensitive; + bool loading; + bool processed; size_t number_docs; - Glib::ustring last_symbol_set; Glib::RefPtr store; + Glib::ustring search_str; Gtk::ComboBoxText* symbol_set; Gtk::ProgressBar* progress_bar; Gtk::HBox* progress; Gtk::SearchEntry* search; - Glib::ustring search_str; Gtk::IconView* icon_view; Gtk::Button* add_symbol; Gtk::Button* remove_symbol; Gtk::Button* zoom_in; Gtk::Button* zoom_out; Gtk::Grid* table; - Gtk::Switch * global; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; -- cgit v1.2.3 From d26f81a4c3c918fa2af5cb454ec569376a7c0b51 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 25 Oct 2017 01:12:45 +0200 Subject: Add progressbar to all actions --- src/ui/dialog/symbols.cpp | 278 +++++++++++++++++++++++++++++----------------- src/ui/dialog/symbols.h | 24 ++-- 2 files changed, 185 insertions(+), 117 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 6c7fa6bef..bb544e4c9 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -115,15 +115,15 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : table->set_margin_right(3); table->set_margin_top(4); // panel is a cloked Gtk::VBox - _getContents()->pack_start(*Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); + _getContents()->pack_start(* Gtk::manage(table), Gtk::PACK_EXPAND_WIDGET); guint row = 0; /******************** Symbol Sets *************************/ - Gtk::Label* labelSet = new Gtk::Label(_("Symbol set: ")); - table->attach(*Gtk::manage(labelSet),0,row,1,1); + Gtk::Label* label_set = new Gtk::Label(_("Symbol set: ")); + table->attach(*Gtk::manage(label_set),0,row,1,1); symbol_set = new Gtk::ComboBoxText(); // Fill in later symbol_set->append(_("Current Document")); - symbol_set->append(_("Search all sets")); + symbol_set->append(_("All symbols sets")); symbol_set->set_active_text(_("Current Document")); symbol_set->set_hexpand(); table->attach(*Gtk::manage(symbol_set),1,row,1,1); @@ -133,13 +133,13 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; - /******************** Progress *******************************/ - progress = new Gtk::HBox(); - progress_bar = Gtk::manage(new Gtk::ProgressBar()); - table->attach(*Gtk::manage(progress),0,row, 2, 1); - progress->pack_start(* progress_bar, Gtk::PACK_EXPAND_WIDGET); - progress->set_margin_top(8); - progress->set_margin_bottom(8); + /******************** Separator *************************/ + + + Gtk::Separator* separator = Gtk::manage(new Gtk::Separator()); // Search + separator->set_margin_top(10); + separator->set_margin_bottom(10); + table->attach(*Gtk::manage(separator),0,row,2,1); ++row; @@ -185,7 +185,24 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : scroller->add(*Gtk::manage(icon_view)); scroller->set_hexpand(); scroller->set_vexpand(); - table->attach(*Gtk::manage(scroller),0,row,2,1); + overlay = new Gtk::Overlay(); + overlay->set_hexpand(); + overlay->set_vexpand(); + overlay->add(* scroller); + table->attach(*Gtk::manage(overlay),0,row,2,1); + + ++row; + + /******************** Progress *******************************/ + progress = new Gtk::HBox(); + progress_bar = Gtk::manage(new Gtk::ProgressBar()); + table->attach(*Gtk::manage(progress),0,row, 2, 1); + progress->pack_start(* progress_bar, Gtk::PACK_EXPAND_WIDGET); + progress->set_margin_top(15); + progress->set_margin_bottom(15); + progress->set_margin_left(20); + progress->set_margin_right(20); + ++row; /******************** Tools *******************************/ @@ -289,7 +306,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /**********************************************************/ sensitive = true; - processed = false; search_str = ""; current_desktop = SP_ACTIVE_DESKTOP; current_document = current_desktop->getDocument(); @@ -313,6 +329,10 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : sigc::mem_fun(*this, &SymbolsDialog::documentReplaced)); instanceConns.push_back(documentReplacedConn); getSymbolsFilename(); + icons_found = false; + + Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::callbackSymbols)); + addSymbolsInDoc(current_document); /* Defaults to current document */ sigc::connection desktopChangeConn = @@ -389,13 +409,14 @@ void SymbolsDialog::rebuild() { add_symbol->set_sensitive( false ); remove_symbol->set_sensitive( false ); } - if (symbol_set->get_active_text() == _("Search all sets")) { + if (search->get_text() != _("Searching...")) { + search_str = ""; + search->set_text(""); + } + icons_found = false; + if (symbol_set->get_active_text() == _("All symbols sets")) { store->clear(); - if (search_str != "" && processed) { - addSymbols(); - } } else { - search->set_text(""); addSymbolsInDoc(symbol_document); } } @@ -816,8 +837,13 @@ void SymbolsDialog::clearSearch() search_str = ""; store->clear(); Glib::ustring current = symbol_set->get_active_text(); - if (current != _("Search all sets")) { - addSymbolsInDoc(symbol_sets[current]); + if (current != _("All symbols sets")) { + icons_found = false; + SPDocument* symbol_document = symbol_sets[current]; + if (current == _("Current Document")) { + symbol_document = current_document; + } + addSymbolsInDoc(symbol_document); } } } @@ -832,120 +858,134 @@ void SymbolsDialog::beforeAddSymbols(GdkEventKey* evt) search->set_text(_("Searching...")); search->set_sensitive(false); Glib::ustring current = symbol_set->get_active_text(); - if (current != _("Search all sets")) { - bool icons_found = false; + if (current != _("All symbols sets")) { Glib::ustring doc_title = symbol_set->get_active_text(); if (!doc_title.empty()) { SPDocument* symbol_document = symbol_sets[doc_title]; - if(symbol_document) { - store->clear(); - icons_found = addSymbolsInDoc(symbol_document); + if (current == _("Current Document")) { + symbol_document = current_document; } + store->clear(); + icons_found = false; + addSymbolsInDoc(symbol_document); } - if (!icons_found) { - //show overlay - } - search->set_text(search_str); - search->set_sensitive(true); - } else if(processed) { - Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::callbackGetSymbols) ); + } else if(all_docs_processed) { addSymbols(); - } else { - Glib::signal_idle().connect( sigc::mem_fun(*this, &SymbolsDialog::callbackGetSymbolsSets) ); } } -bool SymbolsDialog::callbackGetSymbolsSets(){ +bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); - if (search->get_text() != _("Searching...") || current != _("Search all sets")) { - return true; - } - size_t counter = 0; - for(auto const &symbol_document_map : symbol_sets) { - ++counter; - SPDocument* symbol_document = symbol_document_map.second; - if (symbol_document) { - continue; + if (l.size()) { + for (auto symbol:l) { + counter_symbols ++; + gchar const *symbol_title_char = symbol->title(); + gchar const *symbol_desc_char = symbol->description(); + if (symbol_title_char) { + bool found = false; + Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); + auto pos = symbol_title.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + if (!found && symbol_desc_char) { + Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); + auto pos = symbol_desc.rfind(search_str); + if (pos != std::string::npos) { + found = true; + } + } + if (symbol && (search_str.empty() || found)) { + addSymbol( symbol, doc_title); + icons_found = true; + } + } + progress_bar->set_fraction(((100.0/number_symbols) * counter_symbols)/100.0); + l.erase(l.begin()); + //to get more items and best performance + int modulus = number_symbols > 200 ? 50 : (number_symbols/4); + if (modulus && counter_symbols % modulus == 0 && !l.empty()) { + return true; + } } - symbol_document = getSymbolsSet(symbol_document_map.first).second; - symbol_set->set_active_text(_("Search all sets")); - if (!symbol_document) { - continue; + if (!icons_found && !search_str.empty()) { + Gtk::Image* no_results_icon = new Gtk::Image(getSearchPixbuf()); + no_results_icon->set_halign(Gtk::ALIGN_CENTER ); + no_results_icon->set_valign(Gtk::ALIGN_CENTER ); + Gtk::Label* no_results = new Gtk::Label(); + no_results->set_halign(Gtk::ALIGN_CENTER ); + no_results->set_valign(Gtk::ALIGN_CENTER ); + no_results->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + Gtk::Label* different = new Gtk::Label(); + different->set_halign(Gtk::ALIGN_CENTER ); + different->set_valign(Gtk::ALIGN_CENTER ); + different->set_markup(Glib::ustring("") + Glib::ustring(_("Try a different search")) + Glib::ustring("")); + overlay->add_overlay(* no_results_icon); + overlay->add_overlay(* no_results); + overlay->add_overlay(* different); } - progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); + search->set_text(search_str); + search->set_sensitive(true); return true; - } - addSymbols(); - processed = true; - progress_bar->set_fraction(1.0); - return false; -} - -bool SymbolsDialog::callbackGetSymbols() -{ - if (loading && processed) { - progress_bar->pulse(); + } else if (current == _("All symbols sets") && + search->get_text() == _("Searching...") ) { + size_t counter = 0; + for(auto const &symbol_document_map : symbol_sets) { + ++counter; + SPDocument* symbol_document = symbol_document_map.second; + if (symbol_document) { + continue; + } + symbol_document = getSymbolsSet(symbol_document_map.first).second; + symbol_set->set_active_text(_("All symbols sets")); + if (!symbol_document) { + continue; + } + progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); + return true; + } + progress_bar->set_fraction(1.0); + all_docs_processed = true; + addSymbols(); return true; } - return false; + return true; } -bool SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { - bool icons_found = false; +void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { if (!symbol_document) { - return false; //Search all + return; //Search all } - Glib::ustring doc_title = documentTitle(symbol_document); + doc_title = documentTitle(symbol_document); if (doc_title.empty()) { - return false; - } - std::vector l = symbolsInDoc(symbol_document); - loading = false; - for(auto symbol:l) { - gchar const *symbol_title_char = symbol->title(); - gchar const *symbol_desc_char = symbol->description(); - if (symbol_title_char) { - bool found = false; - Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); - auto pos = symbol_title.rfind(search_str); - if (pos != std::string::npos) { - found = true; - } - if (!found && symbol_desc_char) { - Glib::ustring symbol_desc = Glib::ustring(symbol_desc_char).lowercase(); - auto pos = symbol_desc.rfind(search_str); - if (pos != std::string::npos) { - found = true; - } - } - if (symbol && (search_str.empty() || found)) { - addSymbol( symbol, doc_title); - icons_found = true; - } - } - + doc_title = _("Untitled document"); ; } - loading = false; - return icons_found; + progress_bar->set_fraction(0.0); + counter_symbols = 0; + std::vector container_symbols_tmp = symbolsInDoc(symbol_document); + number_symbols = container_symbols_tmp.size(); + l = container_symbols_tmp; + container_symbols_tmp.clear(); } void SymbolsDialog::addSymbols() { - bool icons_found = false; store->clear(); + icons_found = false; + std::vector container_symbols; for(auto const &symbol_document_map : symbol_sets) { SPDocument* symbol_document = symbol_document_map.second; if (!symbol_document) { continue; } - if(addSymbolsInDoc(symbol_document) && !icons_found) { - icons_found = true; - } - } - if (!icons_found) { - //Show overlay + std::vector container_symbols_tmp = symbolsInDoc(symbol_document); + container_symbols.insert(container_symbols.end(), container_symbols_tmp.begin(), container_symbols_tmp.end()); + container_symbols_tmp.clear(); } - search->set_text(search_str); - search->set_sensitive(true); + counter_symbols = 0; + progress_bar->set_fraction(0.0); + number_symbols = container_symbols.size(); + l = container_symbols; + container_symbols.clear(); } void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { @@ -1091,6 +1131,38 @@ SPDocument* SymbolsDialog::symbolsPreviewDoc() return SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); } +/* + * Return search symbol pixbuf + */ +Glib::RefPtr +SymbolsDialog::getSearchPixbuf() +{ + // BUG: must be inside + gchar const *buffer = +"" +" " +" " +" Search Taiga Icon" +" " +" " +" " +""; + + SPDocument* doc = SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); + std::vector l = symbolsInDoc(doc); + int prev_scale_factor = scale_factor; + scale_factor = 10; + Glib::RefPtr pb = drawSymbol(l[0]); + scale_factor = prev_scale_factor; + return pb; +} + void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) { if (this->current_desktop != desktop) { diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index bc6c127a7..586ea2116 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -92,31 +92,26 @@ private: std::vector useInDoc( SPDocument* document); void beforeAddSymbols(GdkEventKey* evt); void addSymbols(); - bool addSymbolsInDoc(SPDocument* document); + void addSymbolsInDoc(SPDocument* document); void clearSearch(); - bool callbackGetSymbolsSets(); - bool callbackGetSymbols(); - + bool callbackSymbols(); gchar const* styleFromUse( gchar const* id, SPDocument* document); - + Glib::ustring doc_title; Glib::RefPtr drawSymbol(SPObject *symbol); - + Glib::RefPtr getSearchPixbuf(); /* Keep track of all symbol template documents */ std::map symbol_sets; - + std::vector l; // Index into sizes which is selected int pack_size; - // Scale factor int scale_factor; - bool sensitive; - - bool loading; - - bool processed; - + bool all_docs_processed; size_t number_docs; + size_t number_symbols; + size_t counter_symbols; + bool icons_found; Glib::RefPtr store; Glib::ustring search_str; Gtk::ComboBoxText* symbol_set; @@ -131,6 +126,7 @@ private: Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; + Gtk::Overlay* overlay; void setTargetDesktop(SPDesktop *desktop); SPDesktop* current_desktop; -- cgit v1.2.3 From 465a6f1db66db8101b22ee14d9a528a836f01e77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 28 Oct 2017 01:00:20 +0200 Subject: Fix simbols dialog expand, Fix add symbols to document on global search --- src/ui/dialog/symbols.cpp | 163 ++++++++++++++++++++++++++-------------------- src/ui/dialog/symbols.h | 14 ++-- 2 files changed, 103 insertions(+), 74 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index bb544e4c9..9b4d2ae12 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -148,7 +148,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search = Gtk::manage(new Gtk::SearchEntry()); // Search search->set_tooltip_text(_("Return to start search.")); - search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::beforeAddSymbols)); + search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::beforeSearch)); search->set_margin_left(10); search->set_margin_right(10); search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); @@ -206,8 +206,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; /******************** Tools *******************************/ - Gtk::Button* button; - Gtk::HBox* tools = new Gtk::HBox(); + tools = new Gtk::HBox(); //tools->set_layout( Gtk::BUTTONBOX_END ); scroller->set_hexpand(); @@ -244,24 +243,24 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : auto packMoreImage = Gtk::manage(new Gtk::Image()); packMoreImage->set_from_icon_name("pack-more", Gtk::ICON_SIZE_SMALL_TOOLBAR); - button = Gtk::manage(new Gtk::Button()); - button->add(*packMoreImage); - button->set_tooltip_text(_("Display more icons in row.")); - button->set_relief( Gtk::RELIEF_NONE ); - button->set_focus_on_click( false ); - button->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::packmore)); - tools->pack_start(* button, Gtk::PACK_SHRINK); + more = Gtk::manage(new Gtk::Button()); + more->add(*packMoreImage); + more->set_tooltip_text(_("Display more icons in row.")); + more->set_relief( Gtk::RELIEF_NONE ); + more->set_focus_on_click( false ); + more->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::packmore)); + tools->pack_start(* more, Gtk::PACK_SHRINK); auto packLessImage = Gtk::manage(new Gtk::Image()); packLessImage->set_from_icon_name("pack-less", Gtk::ICON_SIZE_SMALL_TOOLBAR); - button = Gtk::manage(new Gtk::Button()); - button->add(*packLessImage); - button->set_tooltip_text(_("Display fewer icons in row.")); - button->set_relief( Gtk::RELIEF_NONE ); - button->set_focus_on_click( false ); - button->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::packless)); - tools->pack_start(* button, Gtk::PACK_SHRINK); + fewer = Gtk::manage(new Gtk::Button()); + fewer->add(*packLessImage); + fewer->set_tooltip_text(_("Display fewer icons in row.")); + fewer->set_relief( Gtk::RELIEF_NONE ); + fewer->set_focus_on_click( false ); + fewer->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::packless)); + tools->pack_start(* fewer, Gtk::PACK_SHRINK); // Toggle scale to fit on/off auto fit_symbolImage = Gtk::manage(new Gtk::Image()); @@ -396,7 +395,6 @@ void SymbolsDialog::rebuild() { zoom_in->set_sensitive( true); zoom_out->set_sensitive( true ); } - store->clear(); SPDocument* symbol_document = selectedSymbols(true); if( !symbol_document ) { @@ -409,14 +407,15 @@ void SymbolsDialog::rebuild() { add_symbol->set_sensitive( false ); remove_symbol->set_sensitive( false ); } - if (search->get_text() != _("Searching...")) { + if (search->get_text() != _("Searching...") && + search->get_text() != _("Loading documents...") && + search->get_text() != _("Documents done, searchig inside...") ) + { search_str = ""; search->set_text(""); } icons_found = false; - if (symbol_set->get_active_text() == _("All symbols sets")) { - store->clear(); - } else { + if (symbol_set->get_active_text() != _("All symbols sets")) { addSymbolsInDoc(symbol_document); } } @@ -523,7 +522,7 @@ Glib::ustring SymbolsDialog::documentTitle(SPDocument* symbol_doc) { if (symbol_doc) { SPRoot * root = symbol_doc->getRoot(); if (root->title()) { - title = Glib::ustring(root->title()); + title = ellipsize(Glib::ustring(root->title())); } return title; } @@ -725,7 +724,7 @@ SymbolsDialog::getSymbolsSet(Glib::ustring title) if(filename_short == title + ".svg") { symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); if(symbol_doc) { - new_title = symbol_doc->getRoot()->title(); + new_title = ellipsize(symbol_doc->getRoot()->title()); if(new_title.empty()) { new_title = _("Unnamed Symbols"); } @@ -738,7 +737,7 @@ SymbolsDialog::getSymbolsSet(Glib::ustring title) if(filename_short == title + ".vss") { symbol_doc = read_vss(filename, title); if(symbol_doc) { - new_title = symbol_doc->getRoot()->title(); + new_title = ellipsize(symbol_doc->getRoot()->title()); if(new_title.empty()) { new_title = _("Unnamed Symbols"); } @@ -764,7 +763,7 @@ SymbolsDialog::getSymbolsSet(Glib::ustring title) return std::make_pair(new_title, symbol_doc); } -void SymbolsDialog::symbolsInDocRecursive (SPObject *r, std::vector &l) +void SymbolsDialog::symbolsInDocRecursive (SPObject *r, std::vector > &l, Glib::ustring doc_title) { if(!r) return; @@ -774,19 +773,20 @@ void SymbolsDialog::symbolsInDocRecursive (SPObject *r, std::vector & } if ( dynamic_cast(r) ) { - l.push_back(dynamic_cast(r)); + l.push_back(std::make_pair(doc_title,dynamic_cast(r))); } for (auto& child: r->children) { - symbolsInDocRecursive( &child, l ); + symbolsInDocRecursive(&child, l, doc_title); } } -std::vector SymbolsDialog::symbolsInDoc( SPDocument* symbol_document) +std::vector > +SymbolsDialog::symbolsInDoc( SPDocument* symbol_document, Glib::ustring doc_title) { - std::vector l; - symbolsInDocRecursive (symbol_document->getRoot(), l ); + std::vector > l; + symbolsInDocRecursive (symbol_document->getRoot(), l , doc_title); return l; } @@ -833,7 +833,7 @@ gchar const* SymbolsDialog::styleFromUse( gchar const* id, SPDocument* document) void SymbolsDialog::clearSearch() { - if(search->get_text().empty()) { + if(search->get_text().empty() && sensitive) { search_str = ""; store->clear(); Glib::ustring current = symbol_set->get_active_text(); @@ -848,17 +848,24 @@ void SymbolsDialog::clearSearch() } } -void SymbolsDialog::beforeAddSymbols(GdkEventKey* evt) +void SymbolsDialog::enableWidgets(bool enable) +{ + symbol_set->set_sensitive(enable); + search->set_sensitive(enable); + tools ->set_sensitive(enable); +} + +void SymbolsDialog::beforeSearch(GdkEventKey* evt) { search_str = search->get_text().lowercase(); if (evt->keyval != GDK_KEY_Return) { return; } progress_bar->set_fraction(0.0); - search->set_text(_("Searching...")); - search->set_sensitive(false); + enableWidgets(false); Glib::ustring current = symbol_set->get_active_text(); if (current != _("All symbols sets")) { + search->set_text(_("Searching...")); Glib::ustring doc_title = symbol_set->get_active_text(); if (!doc_title.empty()) { SPDocument* symbol_document = symbol_sets[doc_title]; @@ -869,15 +876,40 @@ void SymbolsDialog::beforeAddSymbols(GdkEventKey* evt) icons_found = false; addSymbolsInDoc(symbol_document); } - } else if(all_docs_processed) { - addSymbols(); + } else { + search->set_text(_("Loading documents...")); } } bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); - if (l.size()) { - for (auto symbol:l) { + if (current == _("All symbols sets") && + search->get_text() == _("Loading documents...") ) + { + size_t counter = 0; + for(auto const &symbol_document_map : symbol_sets) { + ++counter; + SPDocument* symbol_document = symbol_document_map.second; + if (symbol_document) { + continue; + } + symbol_document = getSymbolsSet(symbol_document_map.first).second; + symbol_set->set_active_text(_("All symbols sets")); + if (!symbol_document) { + continue; + } + progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); + return true; + } + progress_bar->set_fraction(1.0); + all_docs_processed = true; + addSymbols(); + search->set_text("Documents done, searchig inside..."); + return true; + } else if (l.size()) { + for (auto symbol_data = l.begin(); symbol_data != l.end();) { + Glib::ustring doc_title = symbol_data->first; + SPSymbol * symbol = symbol_data->second; counter_symbols ++; gchar const *symbol_title_char = symbol->title(); gchar const *symbol_desc_char = symbol->description(); @@ -901,7 +933,7 @@ bool SymbolsDialog::callbackSymbols(){ } } progress_bar->set_fraction(((100.0/number_symbols) * counter_symbols)/100.0); - l.erase(l.begin()); + symbol_data = l.erase(l.begin()); //to get more items and best performance int modulus = number_symbols > 200 ? 50 : (number_symbols/4); if (modulus && counter_symbols % modulus == 0 && !l.empty()) { @@ -924,45 +956,34 @@ bool SymbolsDialog::callbackSymbols(){ overlay->add_overlay(* no_results); overlay->add_overlay(* different); } + bool prev_sensitive = sensitive; + sensitive = false; search->set_text(search_str); - search->set_sensitive(true); - return true; - } else if (current == _("All symbols sets") && - search->get_text() == _("Searching...") ) { - size_t counter = 0; - for(auto const &symbol_document_map : symbol_sets) { - ++counter; - SPDocument* symbol_document = symbol_document_map.second; - if (symbol_document) { - continue; - } - symbol_document = getSymbolsSet(symbol_document_map.first).second; - symbol_set->set_active_text(_("All symbols sets")); - if (!symbol_document) { - continue; - } - progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); - return true; - } - progress_bar->set_fraction(1.0); - all_docs_processed = true; - addSymbols(); + sensitive = prev_sensitive; + enableWidgets(true); return true; } return true; } +Glib::ustring SymbolsDialog::ellipsize(Glib::ustring data, size_t limit) { + if (data.length() > limit) { + return data.substr(0,limit-3) + "..."; + } + return data; +} + void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { if (!symbol_document) { return; //Search all } - doc_title = documentTitle(symbol_document); + Glib::ustring doc_title = documentTitle(symbol_document); if (doc_title.empty()) { doc_title = _("Untitled document"); ; } progress_bar->set_fraction(0.0); counter_symbols = 0; - std::vector container_symbols_tmp = symbolsInDoc(symbol_document); + std::vector > container_symbols_tmp = symbolsInDoc(symbol_document, doc_title); number_symbols = container_symbols_tmp.size(); l = container_symbols_tmp; container_symbols_tmp.clear(); @@ -971,14 +992,18 @@ void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { void SymbolsDialog::addSymbols() { store->clear(); icons_found = false; - std::vector container_symbols; + std::vector > container_symbols; for(auto const &symbol_document_map : symbol_sets) { SPDocument* symbol_document = symbol_document_map.second; if (!symbol_document) { continue; } - std::vector container_symbols_tmp = symbolsInDoc(symbol_document); - container_symbols.insert(container_symbols.end(), container_symbols_tmp.begin(), container_symbols_tmp.end()); + Glib::ustring doc_title = documentTitle(symbol_document); + if (doc_title.empty()) { + doc_title = _("Untitled document"); ; + } + std::vector > container_symbols_tmp = symbolsInDoc(symbol_document, doc_title); + container_symbols.insert(container_symbols.end(), std::make_move_iterator(container_symbols_tmp.begin()), std::make_move_iterator(container_symbols_tmp.end())); container_symbols_tmp.clear(); } counter_symbols = 0; @@ -1155,10 +1180,10 @@ SymbolsDialog::getSearchPixbuf() ""; SPDocument* doc = SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); - std::vector l = symbolsInDoc(doc); + std::vector > l = symbolsInDoc(doc, "Search Taiga Icon"); int prev_scale_factor = scale_factor; scale_factor = 10; - Glib::RefPtr pb = drawSymbol(l[0]); + Glib::RefPtr pb = drawSymbol(l[0].second); scale_factor = prev_scale_factor; return pb; } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 586ea2116..d252b7c71 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -86,22 +86,23 @@ private: std::pair getSymbolsSet(Glib::ustring title); void addSymbol( SPObject* symbol, Glib::ustring doc_title); SPDocument* symbolsPreviewDoc(); - void symbolsInDocRecursive(SPObject *r, std::vector &l); - std::vector symbolsInDoc( SPDocument* document); + void symbolsInDocRecursive (SPObject *r, std::vector > &l, Glib::ustring doc_title); + std::vector > symbolsInDoc( SPDocument* document, Glib::ustring doc_title); void useInDoc(SPObject *r, std::vector &l); std::vector useInDoc( SPDocument* document); - void beforeAddSymbols(GdkEventKey* evt); + void beforeSearch(GdkEventKey* evt); void addSymbols(); void addSymbolsInDoc(SPDocument* document); void clearSearch(); bool callbackSymbols(); + void enableWidgets(bool enable); + Glib::ustring ellipsize(Glib::ustring data, size_t limit = 40); gchar const* styleFromUse( gchar const* id, SPDocument* document); - Glib::ustring doc_title; Glib::RefPtr drawSymbol(SPObject *symbol); Glib::RefPtr getSearchPixbuf(); /* Keep track of all symbol template documents */ std::map symbol_sets; - std::vector l; + std::vector > l; // Index into sizes which is selected int pack_size; // Scale factor @@ -123,6 +124,9 @@ private: Gtk::Button* remove_symbol; Gtk::Button* zoom_in; Gtk::Button* zoom_out; + Gtk::Button* more; + Gtk::Button* fewer; + Gtk::HBox* tools; Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; -- cgit v1.2.3 From c9e7774bafe671e2b5c09c70f9f83a6eec8cb1a7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 28 Oct 2017 03:01:52 +0200 Subject: Remove CMake blank line --- CMakeLists.txt | 1 - src/ui/dialog/symbols.cpp | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65c5fa83f..4732766c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ include(CMakeScripts/ConfigPaths.cmake) # ----------------------------------------------------------------------------- # CMake Configuration # ----------------------------------------------------------------------------- - list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeScripts/Modules") # avoid having empty buildtype diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 9b4d2ae12..e1b013c10 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -220,7 +220,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : add_symbol->set_tooltip_text(_("Add Symbol from the current document.")); add_symbol->set_relief( Gtk::RELIEF_NONE ); add_symbol->set_focus_on_click( false ); - add_symbol->signal_activate().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); + add_symbol->signal_clicked().connect(sigc::mem_fun(*this, &SymbolsDialog::insertSymbol)); tools->pack_start(* add_symbol, Gtk::PACK_SHRINK); auto remove_symbolImage = Gtk::manage(new Gtk::Image()); @@ -421,14 +421,15 @@ void SymbolsDialog::rebuild() { } void SymbolsDialog::insertSymbol() { + std::cout << "fgasgggggggggggggg" << std::endl; Inkscape::Verb *verb = Inkscape::Verb::get( SP_VERB_EDIT_SYMBOL ); - SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->current_desktop) ); + SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) current_desktop) ); sp_action_perform (action, NULL); } void SymbolsDialog::revertSymbol() { Inkscape::Verb *verb = Inkscape::Verb::get( SP_VERB_EDIT_UNSYMBOL ); - SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) this->current_desktop ) ); + SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) current_desktop ) ); sp_action_perform (action, NULL); } -- cgit v1.2.3 From c55b8b44d0b477069231a62507d5cbd968a34935 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 28 Oct 2017 19:19:36 +0200 Subject: Bug fixes previous to overlay implementation --- src/selection-chemistry.cpp | 16 ++-- src/ui/dialog/symbols.cpp | 190 ++++++++++++++++++++++---------------------- src/ui/dialog/symbols.h | 5 +- 3 files changed, 111 insertions(+), 100 deletions(-) diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 0bd611163..b8a769d1c 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3096,7 +3096,6 @@ void ObjectSet::toSymbol() SPDocument *doc = document(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - // Check if something is selected. if (isEmpty()) { if (desktop()) @@ -3154,8 +3153,11 @@ void ObjectSet::toSymbol() // For a single group, copy relevant attributes. if( single_group ) { - symbol_repr->setAttribute("style", the_group->getAttribute("style")); + symbol_repr->setAttribute("title", the_group->getAttribute("title")); + if (!the_group->getAttribute("title")) { + symbol_repr->setAttribute("title", _("Symbol without title")); + } symbol_repr->setAttribute("class", the_group->getAttribute("class")); Glib::ustring id = the_group->getAttribute("id"); the_group->setAttribute("id", id + "_transform"); @@ -3214,7 +3216,6 @@ void ObjectSet::unSymbol() { SPDocument *doc = document(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - // Check if something is selected. if (isEmpty()) { if(desktop()) @@ -3236,8 +3237,12 @@ void ObjectSet::unSymbol() // Create new and insert in current layer Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); - symbol->parent->getRepr()->appendChild(group); - + //TODO: Better handle if no desktop, currently go to defs without it + if(desktop()) { + desktop()->currentLayer()->getRepr()->appendChild(group); + } else { + symbol->parent->getRepr()->appendChild(group); + } // Move all children of symbol to group std::vector children = symbol->childList(false); @@ -3265,6 +3270,7 @@ void ObjectSet::unSymbol() // Copy relevant attributes group->setAttribute("style", symbol->getAttribute("style")); group->setAttribute("class", symbol->getAttribute("class")); + group->setAttribute("title", symbol->getAttribute("title")); group->setAttribute("inkscape:transform-center-x", symbol->getAttribute("inkscape:transform-center-x")); group->setAttribute("inkscape:transform-center-y", diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index e1b013c10..e0aa4cb23 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -148,9 +148,11 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search = Gtk::manage(new Gtk::SearchEntry()); // Search search->set_tooltip_text(_("Return to start search.")); - search->signal_key_press_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::beforeSearch)); + search->signal_key_press_event().connect_notify( sigc::mem_fun(*this, &SymbolsDialog::beforeSearch)); + search->signal_key_release_event().connect_notify(sigc::mem_fun(*this, &SymbolsDialog::unsensitive)); search->set_margin_left(10); search->set_margin_right(10); + search->set_margin_bottom(6); search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); table->attach(*Gtk::manage(search),0,row,2,1); @@ -396,32 +398,22 @@ void SymbolsDialog::rebuild() { zoom_out->set_sensitive( true ); } store->clear(); - SPDocument* symbol_document = selectedSymbols(true); - if( !symbol_document ) { - // Symbol must be from Current Document (this method of - // checking should be language independent). - symbol_document = current_document; - add_symbol->set_sensitive( true ); - remove_symbol->set_sensitive( true ); - } else { - add_symbol->set_sensitive( false ); - remove_symbol->set_sensitive( false ); - } + SPDocument* symbol_document = selectedSymbols(); + icons_found = false; + //We are not in search all docs if (search->get_text() != _("Searching...") && - search->get_text() != _("Loading documents...") && - search->get_text() != _("Documents done, searchig inside...") ) + search->get_text() != _("Loading documents...") && + search->get_text() != _("Documents done, searchig inside...") ) { search_str = ""; search->set_text(""); } - icons_found = false; - if (symbol_set->get_active_text() != _("All symbols sets")) { + if (symbol_document) { addSymbolsInDoc(symbol_document); } } void SymbolsDialog::insertSymbol() { - std::cout << "fgasgggggggggggggg" << std::endl; Inkscape::Verb *verb = Inkscape::Verb::get( SP_VERB_EDIT_SYMBOL ); SPAction *action = verb->get_action(Inkscape::ActionContext( (Inkscape::UI::View::View *) current_desktop) ); sp_action_perform (action, NULL); @@ -443,7 +435,6 @@ void SymbolsDialog::iconDragDataGet(const Glib::RefPtr& /*cont Gtk::TreeModel::Path const & path = *iconArray.begin(); Gtk::ListStore::iterator row = store->get_iter(path); Glib::ustring symbol_id = (*row)[getColumns()->symbol_id]; - GdkAtom dataAtom = gdk_atom_intern( "application/x-inkscape-paste", FALSE ); gtk_selection_data_set( data.gobj(), dataAtom, 9, (guchar*)symbol_id.c_str(), symbol_id.length() ); } @@ -452,18 +443,24 @@ void SymbolsDialog::iconDragDataGet(const Glib::RefPtr& /*cont void SymbolsDialog::defsModified(SPObject * /*object*/, guint /*flags*/) { - if ( !symbol_sets[symbol_set->get_active_text()] ) { + Glib::ustring doc_title = symbol_set->get_active_text(); + if (doc_title != _("All symbols sets") && !symbol_sets[symbol_set->get_active_text()] ) { rebuild(); } } void SymbolsDialog::selectionChanged(Inkscape::Selection *selection) { Glib::ustring symbol_id = selectedSymbolId(); - SPDocument* symbol_document = selectedSymbols(); - SPObject* symbol = symbol_document->getObjectById(symbol_id); - - if(symbol && !selection->includes(symbol)) { - icon_view->unselect_all(); + SPDocument* symbol_document = symbol_sets[selectedSymbolTitle()]; + if (!symbol_document) { + //we are in global search so get the original symbol document by title + symbol_document = selectedSymbols(); + } + if (symbol_document) { + SPObject* symbol = symbol_document->getObjectById(symbol_id); + if(symbol && !selection->includes(symbol)) { + icon_view->unselect_all(); + } } } @@ -474,21 +471,25 @@ void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) rebuild(); } -SPDocument* SymbolsDialog::selectedSymbols(bool ignorecurrent) { +SPDocument* SymbolsDialog::selectedSymbols() { /* OK, we know symbol name... now we need to copy it to clipboard, bon chance! */ - Glib::ustring doc_title = selectedSymbolDocTitle(); - if (doc_title.empty()) { - doc_title = symbol_set->get_active_text(); + Glib::ustring doc_title = symbol_set->get_active_text(); + if (doc_title == _("All symbols sets")) { + return NULL; } SPDocument* symbol_document = symbol_sets[doc_title]; if( !symbol_document ) { symbol_document = getSymbolsSet(doc_title).second; // Symbol must be from Current Document (this method of checking should be language independent). if( !symbol_document ) { - if (ignorecurrent) { - return NULL; - } - return current_document; + // Symbol must be from Current Document (this method of + // checking should be language independent). + symbol_document = current_document; + add_symbol->set_sensitive( true ); + remove_symbol->set_sensitive( true ); + } else { + add_symbol->set_sensitive( false ); + remove_symbol->set_sensitive( false ); } } return symbol_document; @@ -506,7 +507,7 @@ Glib::ustring SymbolsDialog::selectedSymbolId() { return Glib::ustring(""); } -Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { +Glib::ustring SymbolsDialog::selectedSymbolTitle() { auto iconArray = icon_view->get_selected_items(); @@ -519,13 +520,17 @@ Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { } Glib::ustring SymbolsDialog::documentTitle(SPDocument* symbol_doc) { - Glib::ustring title = ""; + Glib::ustring title = _("Untitled document"); if (symbol_doc) { SPRoot * root = symbol_doc->getRoot(); if (root->title()) { title = ellipsize(Glib::ustring(root->title())); + return title; } - return title; + } + Glib::ustring current = symbol_set->get_active_text(); + if (current == _("Current Document")) { + return current; } return title; } @@ -534,23 +539,33 @@ void SymbolsDialog::iconChanged() { Glib::ustring symbol_id = selectedSymbolId(); SPDocument* symbol_document = selectedSymbols(); - SPObject* symbol = symbol_document->getObjectById(symbol_id); - - if( symbol ) { - // Find style for use in - // First look for default style stored in - gchar const* style = symbol->getAttribute("inkscape:symbol-style"); - if( !style ) { - // If no default style in , look in documents. + if (!symbol_document) { + //we are in global search so get the original symbol document by title + symbol_document = symbol_sets[selectedSymbolTitle()]; + } + if (symbol_document) { + SPObject* symbol = symbol_document->getObjectById(symbol_id); + + if( symbol ) { if( symbol_document == current_document ) { - style = styleFromUse( symbol_id.c_str(), current_document ); - } else { - style = symbol_document->getReprRoot()->attribute("style"); + // Select the symbol on the canvas so it can be manipulated + current_desktop->selection->set( symbol, false ); + } + // Find style for use in + // First look for default style stored in + gchar const* style = symbol->getAttribute("inkscape:symbol-style"); + if( !style ) { + // If no default style in , look in documents. + if( symbol_document == current_document ) { + style = styleFromUse( symbol_id.c_str(), current_document ); + } else { + style = symbol_document->getReprRoot()->attribute("style"); + } } - } - ClipboardManager *cm = ClipboardManager::get(); - cm->copySymbol(symbol->getRepr(), style, symbol_document == current_document); + ClipboardManager *cm = ClipboardManager::get(); + cm->copySymbol(symbol->getRepr(), style, symbol_document == current_document); + } } } @@ -725,10 +740,7 @@ SymbolsDialog::getSymbolsSet(Glib::ustring title) if(filename_short == title + ".svg") { symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE); if(symbol_doc) { - new_title = ellipsize(symbol_doc->getRoot()->title()); - if(new_title.empty()) { - new_title = _("Unnamed Symbols"); - } + new_title = documentTitle(symbol_doc); } } if(Glib::str_has_suffix(filename, ".svg")) { @@ -738,10 +750,7 @@ SymbolsDialog::getSymbolsSet(Glib::ustring title) if(filename_short == title + ".vss") { symbol_doc = read_vss(filename, title); if(symbol_doc) { - new_title = ellipsize(symbol_doc->getRoot()->title()); - if(new_title.empty()) { - new_title = _("Unnamed Symbols"); - } + new_title = documentTitle(symbol_doc); } } if(Glib::str_has_suffix(filename, ".vss")) { @@ -835,16 +844,16 @@ gchar const* SymbolsDialog::styleFromUse( gchar const* id, SPDocument* document) void SymbolsDialog::clearSearch() { if(search->get_text().empty() && sensitive) { + enableWidgets(false); search_str = ""; store->clear(); - Glib::ustring current = symbol_set->get_active_text(); - if (current != _("All symbols sets")) { + SPDocument* symbol_document = selectedSymbols(); + if (symbol_document) { + //We are not in search all docs icons_found = false; - SPDocument* symbol_document = symbol_sets[current]; - if (current == _("Current Document")) { - symbol_document = current_document; - } addSymbolsInDoc(symbol_document); + } else { + enableWidgets(true); } } } @@ -858,30 +867,30 @@ void SymbolsDialog::enableWidgets(bool enable) void SymbolsDialog::beforeSearch(GdkEventKey* evt) { + sensitive = false; search_str = search->get_text().lowercase(); if (evt->keyval != GDK_KEY_Return) { return; } progress_bar->set_fraction(0.0); enableWidgets(false); - Glib::ustring current = symbol_set->get_active_text(); - if (current != _("All symbols sets")) { + SPDocument* symbol_document = selectedSymbols(); + if (symbol_document) { + //We are not in search all docs search->set_text(_("Searching...")); - Glib::ustring doc_title = symbol_set->get_active_text(); - if (!doc_title.empty()) { - SPDocument* symbol_document = symbol_sets[doc_title]; - if (current == _("Current Document")) { - symbol_document = current_document; - } - store->clear(); - icons_found = false; - addSymbolsInDoc(symbol_document); - } + store->clear(); + icons_found = false; + addSymbolsInDoc(symbol_document); } else { search->set_text(_("Loading documents...")); } } +void SymbolsDialog::unsensitive(GdkEventKey* evt) +{ + sensitive = true; +} + bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); if (current == _("All symbols sets") && @@ -914,8 +923,8 @@ bool SymbolsDialog::callbackSymbols(){ counter_symbols ++; gchar const *symbol_title_char = symbol->title(); gchar const *symbol_desc_char = symbol->description(); + bool found = false; if (symbol_title_char) { - bool found = false; Glib::ustring symbol_title = Glib::ustring(symbol_title_char).lowercase(); auto pos = symbol_title.rfind(search_str); if (pos != std::string::npos) { @@ -928,11 +937,12 @@ bool SymbolsDialog::callbackSymbols(){ found = true; } } - if (symbol && (search_str.empty() || found)) { - addSymbol( symbol, doc_title); - icons_found = true; - } } + if (symbol && (search_str.empty() || found || (search_str.empty() && !symbol_title_char))) { + addSymbol( symbol, doc_title); + icons_found = true; + } + progress_bar->set_fraction(((100.0/number_symbols) * counter_symbols)/100.0); symbol_data = l.erase(l.begin()); //to get more items and best performance @@ -957,10 +967,9 @@ bool SymbolsDialog::callbackSymbols(){ overlay->add_overlay(* no_results); overlay->add_overlay(* different); } - bool prev_sensitive = sensitive; sensitive = false; search->set_text(search_str); - sensitive = prev_sensitive; + sensitive = true; enableWidgets(true); return true; } @@ -975,13 +984,11 @@ Glib::ustring SymbolsDialog::ellipsize(Glib::ustring data, size_t limit) { } void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { + if (!symbol_document) { return; //Search all } Glib::ustring doc_title = documentTitle(symbol_document); - if (doc_title.empty()) { - doc_title = _("Untitled document"); ; - } progress_bar->set_fraction(0.0); counter_symbols = 0; std::vector > container_symbols_tmp = symbolsInDoc(symbol_document, doc_title); @@ -1000,9 +1007,6 @@ void SymbolsDialog::addSymbols() { continue; } Glib::ustring doc_title = documentTitle(symbol_document); - if (doc_title.empty()) { - doc_title = _("Untitled document"); ; - } std::vector > container_symbols_tmp = symbolsInDoc(symbol_document, doc_title); container_symbols.insert(container_symbols.end(), std::make_move_iterator(container_symbols_tmp.begin()), std::make_move_iterator(container_symbols_tmp.end())); container_symbols_tmp.clear(); @@ -1025,10 +1029,9 @@ void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { } Glib::ustring symbol_title = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); if (doc_title.empty()) { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" (") +_("Current Document") + Glib::ustring(")")).c_str()))); - } else { - symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" (") + doc_title + Glib::ustring(")")).c_str()))); + doc_title = _("Current Document"); } + symbol_title = symbol_title + Glib::Markup::escape_text(Glib::ustring(g_dpgettext2(NULL, "Symbol", (Glib::ustring(" (") + doc_title + Glib::ustring(")")).c_str()))); Glib::RefPtr pixbuf = drawSymbol( symbol ); if( pixbuf ) { @@ -1125,8 +1128,9 @@ SymbolsDialog::drawSymbol(SPObject *symbol) if( width == 0.0 ) width = 1.0; if( height == 0.0 ) height = 1.0; - if( fit_symbol->get_active() ) - scale = psize / std::max(width, height); + if( fit_symbol->get_active() ) { + scale = psize / ceil(std::max(width, height)); + } else scale = pow( 2.0, scale_factor/2.0 ) * psize / 32.0; diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index d252b7c71..a77a265b5 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -76,9 +76,9 @@ private: void defsModified(SPObject *object, guint flags); void selectionChanged(Inkscape::Selection *selection); void documentReplaced(SPDesktop *desktop, SPDocument *document); - SPDocument* selectedSymbols(bool ignorecurrent = false); + SPDocument* selectedSymbols(); Glib::ustring selectedSymbolId(); - Glib::ustring selectedSymbolDocTitle(); + Glib::ustring selectedSymbolTitle(); void iconChanged(); void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void getSymbolsFilename(); @@ -91,6 +91,7 @@ private: void useInDoc(SPObject *r, std::vector &l); std::vector useInDoc( SPDocument* document); void beforeSearch(GdkEventKey* evt); + void unsensitive(GdkEventKey* evt); void addSymbols(); void addSymbolsInDoc(SPDocument* document); void clearSearch(); -- cgit v1.2.3 From 625c4435399d3b80902b9cdbd2be3071ca527f77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 29 Oct 2017 11:18:24 +0100 Subject: Add overlay widgets --- src/ui/dialog/symbols.cpp | 197 +++++++++++++++++++++++++++++++++++++--------- src/ui/dialog/symbols.h | 12 ++- 2 files changed, 167 insertions(+), 42 deletions(-) diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index e0aa4cb23..ec1345257 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -108,7 +108,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : preview_document(0), instanceConns() { - /******************** Table *************************/ table = new Gtk::Grid(); table->set_margin_left(3); @@ -155,9 +154,10 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : search->set_margin_bottom(6); search->signal_search_changed().connect(sigc::mem_fun(*this, &SymbolsDialog::clearSearch)); table->attach(*Gtk::manage(search),0,row,2,1); + search_str = ""; ++row; - + /********************* Icon View **************************/ SymbolColumns* columns = getColumns(); @@ -192,7 +192,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : overlay->set_vexpand(); overlay->add(* scroller); table->attach(*Gtk::manage(overlay),0,row,2,1); - + ++row; /******************** Progress *******************************/ @@ -305,20 +305,47 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : ++row; - /**********************************************************/ sensitive = true; - search_str = ""; + current_desktop = SP_ACTIVE_DESKTOP; current_document = current_desktop->getDocument(); - preview_document = symbolsPreviewDoc(); /* Template to render symbols in */ preview_document->ensureUpToDate(); /* Necessary? */ - key = SPItem::display_key_new(1); renderDrawing.setRoot(preview_document->getRoot()->invoke_show(renderDrawing, key, SP_ITEM_SHOW_DISPLAY )); // This might need to be a global variable so setTargetDesktop can modify it SPDefs *defs = current_document->getDefs(); + + /*************************Overlays******************************/ + //Loading + overlay_opacity = new Gtk::Image(getStockPixbuf("overlay", 1000)); + overlay_opacity->set_halign(Gtk::ALIGN_START ); + overlay_opacity->set_valign(Gtk::ALIGN_START ); + //No results + noresults_icon = getStockPixbuf("noresults", 90); + search_icon = getStockPixbuf("search", 90); + overlay_icon = new Gtk::Image(noresults_icon); + overlay_icon->set_halign(Gtk::ALIGN_CENTER ); + overlay_icon->set_valign(Gtk::ALIGN_START ); + overlay_icon->set_margin_top(45); + overlay_title = new Gtk::Label(); + overlay_title->set_halign(Gtk::ALIGN_CENTER ); + overlay_title->set_valign(Gtk::ALIGN_START ); + overlay_title->set_justify(Gtk::JUSTIFY_CENTER); + overlay_title->set_margin_top(155); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc = new Gtk::Label(); + overlay_desc->set_halign(Gtk::ALIGN_CENTER ); + overlay_desc->set_valign(Gtk::ALIGN_START ); + overlay_desc->set_margin_top(180); + overlay_desc->set_justify(Gtk::JUSTIFY_CENTER); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("Try a another search or select other set")) + Glib::ustring("")); + overlay->add_overlay(* overlay_opacity); + overlay->add_overlay(* overlay_icon); + overlay->add_overlay(* overlay_title); + overlay->add_overlay(* overlay_desc); + sigc::connection defsModifiedConn = defs->connectModified(sigc::mem_fun(*this, &SymbolsDialog::defsModified)); instanceConns.push_back(defsModifiedConn); @@ -796,7 +823,9 @@ SymbolsDialog::symbolsInDoc( SPDocument* symbol_document, Glib::ustring doc_titl { std::vector > l; - symbolsInDocRecursive (symbol_document->getRoot(), l , doc_title); + if (symbol_document) { + symbolsInDocRecursive (symbol_document->getRoot(), l , doc_title); + } return l; } @@ -893,9 +922,42 @@ void SymbolsDialog::unsensitive(GdkEventKey* evt) bool SymbolsDialog::callbackSymbols(){ Glib::ustring current = symbol_set->get_active_text(); + if (current == _("All symbols sets") && + search->get_text() != _("Loading documents...")) + { + if (!all_docs_processed) { + overlay_opacity->show(); + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Search over all symbols sets")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + } + } + if (current == _("Current Document") && !icons_found) { + if (!all_docs_processed) { + overlay_icon->set(noresults_icon); + overlay_opacity->show(); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No icons in current document")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You can fill me if you want\nUse add and remove buttons.\nOr drag symbols from other sets")) + Glib::ustring("")); + } + } if (current == _("All symbols sets") && search->get_text() == _("Loading documents...") ) { + overlay_opacity->show(); + if (!all_docs_processed) { + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Processing all symbols sets")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + overlay_icon->show(); + overlay_title->show(); + overlay_icon->set(search_icon); + overlay_desc->show(); + } size_t counter = 0; for(auto const &symbol_document_map : symbol_sets) { ++counter; @@ -911,12 +973,16 @@ bool SymbolsDialog::callbackSymbols(){ progress_bar->set_fraction(((100.0/number_docs) * counter)/100.0); return true; } + overlay_icon->hide(); + overlay_title->hide(); + overlay_desc->hide(); progress_bar->set_fraction(1.0); all_docs_processed = true; addSymbols(); search->set_text("Documents done, searchig inside..."); return true; } else if (l.size()) { + overlay_opacity->show(); for (auto symbol_data = l.begin(); symbol_data != l.end();) { Glib::ustring doc_title = symbol_data->first; SPSymbol * symbol = symbol_data->second; @@ -952,20 +1018,17 @@ bool SymbolsDialog::callbackSymbols(){ } } if (!icons_found && !search_str.empty()) { - Gtk::Image* no_results_icon = new Gtk::Image(getSearchPixbuf()); - no_results_icon->set_halign(Gtk::ALIGN_CENTER ); - no_results_icon->set_valign(Gtk::ALIGN_CENTER ); - Gtk::Label* no_results = new Gtk::Label(); - no_results->set_halign(Gtk::ALIGN_CENTER ); - no_results->set_valign(Gtk::ALIGN_CENTER ); - no_results->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); - Gtk::Label* different = new Gtk::Label(); - different->set_halign(Gtk::ALIGN_CENTER ); - different->set_valign(Gtk::ALIGN_CENTER ); - different->set_markup(Glib::ustring("") + Glib::ustring(_("Try a different search")) + Glib::ustring("")); - overlay->add_overlay(* no_results_icon); - overlay->add_overlay(* no_results); - overlay->add_overlay(* different); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("Try a another search or select other set")) + Glib::ustring("")); + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + } else { + overlay_opacity->hide(); + overlay_icon->hide(); + overlay_title->hide(); + overlay_desc->hide(); } sensitive = false; search->set_text(search_str); @@ -995,6 +1058,16 @@ void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { number_symbols = container_symbols_tmp.size(); l = container_symbols_tmp; container_symbols_tmp.clear(); + if (!number_symbols) { + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + sensitive = false; + search->set_text(search_str); + sensitive = true; + enableWidgets(true); + } } void SymbolsDialog::addSymbols() { @@ -1016,6 +1089,16 @@ void SymbolsDialog::addSymbols() { number_symbols = container_symbols.size(); l = container_symbols; container_symbols.clear(); + if (!number_symbols) { + overlay_icon->set(noresults_icon); + overlay_icon->show(); + overlay_title->show(); + overlay_desc->show(); + sensitive = false; + search->set_text(search_str); + sensitive = true; + enableWidgets(true); + } } void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { @@ -1055,7 +1138,7 @@ void SymbolsDialog::addSymbol( SPObject* symbol, Glib::ustring doc_title) { * the temporary document is rendered. */ Glib::RefPtr -SymbolsDialog::drawSymbol(SPObject *symbol) +SymbolsDialog::drawSymbol(SPObject *symbol, unsigned force_psize) { // Create a copy repr of the symbol with id="the_symbol" Inkscape::XML::Document *xml_doc = preview_document->getReprDoc(); @@ -1128,12 +1211,16 @@ SymbolsDialog::drawSymbol(SPObject *symbol) if( width == 0.0 ) width = 1.0; if( height == 0.0 ) height = 1.0; - if( fit_symbol->get_active() ) { - scale = psize / ceil(std::max(width, height)); - } + if( fit_symbol->get_active() ) + scale = psize / ceil(std::max(width, height)); else scale = pow( 2.0, scale_factor/2.0 ) * psize / 32.0; + if (force_psize > 0) { + psize = force_psize; + scale = psize / ceil(std::max(width, height)); + } + pixbuf = Glib::wrap(render_pixbuf(renderDrawing, scale, *dbox, psize)); } @@ -1165,32 +1252,64 @@ SPDocument* SymbolsDialog::symbolsPreviewDoc() * Return search symbol pixbuf */ Glib::RefPtr -SymbolsDialog::getSearchPixbuf() +SymbolsDialog::getStockPixbuf(gchar const * symbol_title, unsigned psize) { - // BUG: must be inside gchar const *buffer = "" +" Inkscape " " " " " +" id=\"search\">" " Search Taiga Icon" +" id=\"search_title\">Search" +" From Taiga Icon Set" " " +" style=\"fill:#dddddd;stroke:none\"" +" d=\"m 296.87191,139.51013 c -42.96864,0 -77.93812,28.58932 -77.93812,63.7203 0,35.13101 34.96894,63.72102 77.93812,63.72102 18.73068,0 35.93889,-5.43504 49.39552,-14.4736 l 50.71196,41.46091 8.86813,-7.2504 -50.55612,-41.33356 c 12.13855,-11.23867 19.51775,-25.99037 19.51775,-42.12437 0,-35.13098 -34.96854,-63.7203 -77.93724,-63.7203 z m 0,10.25413 c 36.19119,0 65.3962,23.87692 65.3962,53.46617 0,29.58969 -29.20519,53.46706 -65.3962,53.46706 -36.19149,0 -65.39616,-23.87737 -65.39616,-53.46706 0,-29.58939 29.20467,-53.46685 65.39616,-53.46685 z\"" +" id=\"search_shape_1\" />" +" " +" " +" Overlay" +" Overlay Square" +" " +" " +" " +" No Results" +" No results" +" " " " " " ""; SPDocument* doc = SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); - std::vector > l = symbolsInDoc(doc, "Search Taiga Icon"); - int prev_scale_factor = scale_factor; - scale_factor = 10; - Glib::RefPtr pb = drawSymbol(l[0].second); - scale_factor = prev_scale_factor; - return pb; + std::vector > symbols_data = symbolsInDoc(doc, "Search Taiga Icon"); + Glib::RefPtr pixbuf(NULL); + for(auto data:symbols_data) { + Glib::ustring doc_title = data.first; + SPSymbol * symbol = data.second; + if (!strcmp(symbol->getId(),symbol_title)) { + pixbuf = drawSymbol(symbol, psize); + return pixbuf; + } + } + //Fallback if errors + return pixbuf; } void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index a77a265b5..3a007aba8 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -99,12 +99,14 @@ private: void enableWidgets(bool enable); Glib::ustring ellipsize(Glib::ustring data, size_t limit = 40); gchar const* styleFromUse( gchar const* id, SPDocument* document); - Glib::RefPtr drawSymbol(SPObject *symbol); - Glib::RefPtr getSearchPixbuf(); + Glib::RefPtr drawSymbol(SPObject *symbol, unsigned force_psize = 0); + Glib::RefPtr getStockPixbuf(gchar const * symbol_title, unsigned psize); /* Keep track of all symbol template documents */ std::map symbol_sets; std::vector > l; // Index into sizes which is selected + Glib::RefPtr noresults_icon; + Glib::RefPtr search_icon; int pack_size; // Scale factor int scale_factor; @@ -128,10 +130,14 @@ private: Gtk::Button* more; Gtk::Button* fewer; Gtk::HBox* tools; + Gtk::Overlay* overlay; + Gtk::Image* overlay_icon; + Gtk::Image* overlay_opacity; + Gtk::Label* overlay_title; + Gtk::Label* overlay_desc; Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; - Gtk::Overlay* overlay; void setTargetDesktop(SPDesktop *desktop); SPDesktop* current_desktop; -- cgit v1.2.3 From 0af8e9ec59bd4bde68da4b74cba74ff986344176 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 29 Oct 2017 22:19:49 +0100 Subject: Add search and no results from stock icons. Improve text. Thanks Maren for the inputs --- share/icons/none.svg | 32 ++++++++++++++ share/icons/searching.svg | 76 ++++++++++++++++++++++++++++++++ src/ui/dialog/symbols.cpp | 109 +++++++++++++++++++++------------------------- src/ui/dialog/symbols.h | 5 ++- 4 files changed, 160 insertions(+), 62 deletions(-) create mode 100644 share/icons/none.svg create mode 100644 share/icons/searching.svg diff --git a/share/icons/none.svg b/share/icons/none.svg new file mode 100644 index 000000000..719498dc3 --- /dev/null +++ b/share/icons/none.svg @@ -0,0 +1,32 @@ + + + + + + + + + diff --git a/share/icons/searching.svg b/share/icons/searching.svg new file mode 100644 index 000000000..0bc5b57bc --- /dev/null +++ b/share/icons/searching.svg @@ -0,0 +1,76 @@ + + + + + + image/svg+xml + + Taiga + 24-10-2016 + + + Taiga + + + + + CC + + + + + Taiga + + + http://taiga.io + http://taiga.io + + + + + + + + + + + + + + + + + + diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index ec1345257..082993158 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -319,12 +319,14 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : /*************************Overlays******************************/ //Loading - overlay_opacity = new Gtk::Image(getStockPixbuf("overlay", 1000)); + overlay_opacity = new Gtk::Image(); + overlay_opacity->set(getOverlay(overlay_opacity, "overlay", 1000)); overlay_opacity->set_halign(Gtk::ALIGN_START ); overlay_opacity->set_valign(Gtk::ALIGN_START ); //No results - noresults_icon = getStockPixbuf("noresults", 90); - search_icon = getStockPixbuf("search", 90); + iconsize = Gtk::IconSize().register_new(Glib::ustring("ICON_SIZE_DIALOG_EXTRA"), 110, 110); + overlay_icon = new Gtk::Image(); + overlay_icon->set_from_icon_name("none", iconsize); overlay_icon = new Gtk::Image(noresults_icon); overlay_icon->set_halign(Gtk::ALIGN_CENTER ); overlay_icon->set_valign(Gtk::ALIGN_START ); @@ -478,15 +480,18 @@ void SymbolsDialog::defsModified(SPObject * /*object*/, guint /*flags*/) void SymbolsDialog::selectionChanged(Inkscape::Selection *selection) { Glib::ustring symbol_id = selectedSymbolId(); - SPDocument* symbol_document = symbol_sets[selectedSymbolTitle()]; - if (!symbol_document) { - //we are in global search so get the original symbol document by title - symbol_document = selectedSymbols(); - } - if (symbol_document) { - SPObject* symbol = symbol_document->getObjectById(symbol_id); - if(symbol && !selection->includes(symbol)) { - icon_view->unselect_all(); + Glib::ustring doc_title = selectedSymbolDocTitle(); + if (!doc_title.empty()) { + SPDocument* symbol_document = symbol_sets[doc_title]; + if (!symbol_document) { + //we are in global search so get the original symbol document by title + symbol_document = selectedSymbols(); + } + if (symbol_document) { + SPObject* symbol = symbol_document->getObjectById(symbol_id); + if(symbol && !selection->includes(symbol)) { + icon_view->unselect_all(); + } } } } @@ -534,7 +539,7 @@ Glib::ustring SymbolsDialog::selectedSymbolId() { return Glib::ustring(""); } -Glib::ustring SymbolsDialog::selectedSymbolTitle() { +Glib::ustring SymbolsDialog::selectedSymbolDocTitle() { auto iconArray = icon_view->get_selected_items(); @@ -568,7 +573,10 @@ void SymbolsDialog::iconChanged() { SPDocument* symbol_document = selectedSymbols(); if (!symbol_document) { //we are in global search so get the original symbol document by title - symbol_document = symbol_sets[selectedSymbolTitle()]; + Glib::ustring doc_title = selectedSymbolDocTitle(); + if (!doc_title.empty()) { + symbol_document = symbol_sets[doc_title]; + } } if (symbol_document) { SPObject* symbol = symbol_document->getObjectById(symbol_id); @@ -927,23 +935,23 @@ bool SymbolsDialog::callbackSymbols(){ { if (!all_docs_processed) { overlay_opacity->show(); - overlay_icon->set(noresults_icon); + overlay_icon->set_from_icon_name("none", iconsize); overlay_icon->show(); overlay_title->show(); overlay_desc->show(); - overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Search over all symbols sets")) + Glib::ustring("")); - overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Searching in all symbol sets ...")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("When run for the first time, search will be slow.\nPlease wait ...")) + Glib::ustring("")); } } if (current == _("Current Document") && !icons_found) { if (!all_docs_processed) { - overlay_icon->set(noresults_icon); + overlay_icon->set_from_icon_name("none", iconsize); overlay_opacity->show(); overlay_icon->show(); overlay_title->show(); overlay_desc->show(); - overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No icons in current document")) + Glib::ustring("")); - overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You can fill me if you want\nUse add and remove buttons.\nOr drag symbols from other sets")) + Glib::ustring("")); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); } } if (current == _("All symbols sets") && @@ -951,11 +959,11 @@ bool SymbolsDialog::callbackSymbols(){ { overlay_opacity->show(); if (!all_docs_processed) { - overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Processing all symbols sets")) + Glib::ustring("")); - overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("This process is slow first time.\nFuture searches dont need this process.\nKeep waiting!")) + Glib::ustring("")); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("Loading all symbol sets ...")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("When run for the first time, search will be slow.\nPlease wait ...")) + Glib::ustring("")); overlay_icon->show(); overlay_title->show(); - overlay_icon->set(search_icon); + overlay_icon->set_from_icon_name("searching", iconsize); overlay_desc->show(); } size_t counter = 0; @@ -983,6 +991,9 @@ bool SymbolsDialog::callbackSymbols(){ return true; } else if (l.size()) { overlay_opacity->show(); + overlay_icon->hide(); + overlay_title->hide(); + overlay_desc->hide(); for (auto symbol_data = l.begin(); symbol_data != l.end();) { Glib::ustring doc_title = symbol_data->first; SPSymbol * symbol = symbol_data->second; @@ -1019,16 +1030,13 @@ bool SymbolsDialog::callbackSymbols(){ } if (!icons_found && !search_str.empty()) { overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); - overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("Try a another search or select other set")) + Glib::ustring("")); - overlay_icon->set(noresults_icon); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); + overlay_icon->set_from_icon_name("none", iconsize); overlay_icon->show(); overlay_title->show(); overlay_desc->show(); } else { overlay_opacity->hide(); - overlay_icon->hide(); - overlay_title->hide(); - overlay_desc->hide(); } sensitive = false; search->set_text(search_str); @@ -1059,8 +1067,10 @@ void SymbolsDialog::addSymbolsInDoc(SPDocument* symbol_document) { l = container_symbols_tmp; container_symbols_tmp.clear(); if (!number_symbols) { - overlay_icon->set(noresults_icon); + overlay_icon->set_from_icon_name("none", iconsize); overlay_icon->show(); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); overlay_title->show(); overlay_desc->show(); sensitive = false; @@ -1090,7 +1100,9 @@ void SymbolsDialog::addSymbols() { l = container_symbols; container_symbols.clear(); if (!number_symbols) { - overlay_icon->set(noresults_icon); + overlay_icon->set_from_icon_name("none", iconsize); + overlay_title->set_markup(Glib::ustring("") + Glib::ustring(_("No results found")) + Glib::ustring("")); + overlay_desc->set_markup(Glib::ustring("") + Glib::ustring(_("You could try a different search term,\nor switch to a different symbol set.")) + Glib::ustring("")); overlay_icon->show(); overlay_title->show(); overlay_desc->show(); @@ -1249,12 +1261,12 @@ SPDocument* SymbolsDialog::symbolsPreviewDoc() } /* - * Return search symbol pixbuf + * Update image widgets */ -Glib::RefPtr -SymbolsDialog::getStockPixbuf(gchar const * symbol_title, unsigned psize) +Glib::RefPtr +SymbolsDialog::getOverlay(Gtk::Image* image, gchar const * icon_title, unsigned psize) { - gchar const *buffer = +gchar const *buffer = "Inkscape " " " " " -" Search" -" From Taiga Icon Set" -" " -" " -" " " Overlay" " Overlay Square" " " " " -" " -" No Results" -" No results" -" " -" " " " ""; SPDocument* doc = SPDocument::createNewDocFromMem( buffer, strlen(buffer), FALSE ); - std::vector > symbols_data = symbolsInDoc(doc, "Search Taiga Icon"); + std::vector > symbols_data = symbolsInDoc(doc, "Overlay Doc"); Glib::RefPtr pixbuf(NULL); for(auto data:symbols_data) { Glib::ustring doc_title = data.first; SPSymbol * symbol = data.second; - if (!strcmp(symbol->getId(),symbol_title)) { + if (!strcmp(symbol->getId(), icon_title)) { pixbuf = drawSymbol(symbol, psize); return pixbuf; } } - //Fallback if errors return pixbuf; } diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 3a007aba8..1bddc5b2c 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -78,7 +78,7 @@ private: void documentReplaced(SPDesktop *desktop, SPDocument *document); SPDocument* selectedSymbols(); Glib::ustring selectedSymbolId(); - Glib::ustring selectedSymbolTitle(); + Glib::ustring selectedSymbolDocTitle(); void iconChanged(); void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void getSymbolsFilename(); @@ -100,7 +100,7 @@ private: Glib::ustring ellipsize(Glib::ustring data, size_t limit = 40); gchar const* styleFromUse( gchar const* id, SPDocument* document); Glib::RefPtr drawSymbol(SPObject *symbol, unsigned force_psize = 0); - Glib::RefPtr getStockPixbuf(gchar const * symbol_title, unsigned psize); + Glib::RefPtr getOverlay(Gtk::Image* image, gchar const * icon_title, unsigned psize); /* Keep track of all symbol template documents */ std::map symbol_sets; std::vector > l; @@ -138,6 +138,7 @@ private: Gtk::Grid* table; Gtk::ScrolledWindow *scroller; Gtk::ToggleButton* fit_symbol; + Gtk::IconSize iconsize; void setTargetDesktop(SPDesktop *desktop); SPDesktop* current_desktop; -- cgit v1.2.3