I'm trying to create a program using gtkmm3 and the Application::set_menubar method. I can create the menu, but when I run the program, all of the items in the menus are greyed out. I have scoured both the glibmm and glib libraries looking for ways to enable (and later disable/hide) menu items, and I cannot find any function or method to do it. How do I fix this?
I'm compiling with:
g++ -std=c++0x -o program program.cpp `pkg-config --cflags --libs gtkmm-3.0`
Code code is as follows:
// vim:set ai et shiftwidth=4 softtabstop=4 :
#include <gtkmm.h>
#include <glibmm.h>
#include <giomm/menulinkiter.h>
class ApplicationMain{
private:
Glib::RefPtr<Gtk::Application> app;
Glib::RefPtr<Gio::Menu> mnuMenu;
/// Builds menu and puts menu actions into the application's action map
void createMenu();
/// Recursive method that iterates over the supplied MenuModel and
/// extracts actions into the application's action map
void extractMenuActions(const Glib::RefPtr<Gio::MenuModel> &model);
public:
ApplicationMain(int argc, char **argv);
~ApplicationMain();
int run();
};
using namespace std;
/// Container for menu xml data
struct MenuStringContainer{
static const char *string;
};
/// Builds menu and puts menu actions into the application's action map
void ApplicationMain::createMenu(){
// Build menu from xml data
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_string(MenuStringContainer::string);
mnuMenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(builder->get_object("menubar"));
// Extract actions from menu model and add them to our action map
extractMenuActions(Glib::RefPtr<Gio::MenuModel>::cast_static(mnuMenu));
}
void ApplicationMain::extractMenuActions(const Glib::RefPtr<Gio::MenuModel> &model){
// Get the number of items in this menu model
gint count = g_menu_model_get_n_items(model->gobj());
// Iterate over the items in this model
for(gint i = 0; i < count; i++){
// Iterate over and recurse into the links in this menu model item
auto iter = model->iterate_item_links(i);
while(iter->next()){
extractMenuActions(iter->get_value());
}
try{
// Get the action for this item. Throws std::bad_cast if the cast can't be made
Glib::Variant<Glib::ustring> act = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(
model->get_item_attribute(i, Gio::MENU_ATTRIBUTE_ACTION, Glib::Variant<Glib::ustring>::variant_type())
);
// If this action is valid, get the action name and add it to the action map
if(act.gobj() != nullptr){
Glib::ustring actName = act.get();
app->add_action(Gio::SimpleAction::create(actName));
}
} catch(std::bad_cast &){
}
}
}
ApplicationMain::ApplicationMain(int argc, char **argv){
app = Gtk::Application::create(argc, argv, "com.angellistaliuu.jaguar.Chummer5");
chdir(Gio::File::create_for_commandline_arg(argv[0])->get_basename().c_str());
}
ApplicationMain::~ApplicationMain(){
}
int ApplicationMain::run(){
if(app->register_application()){
createMenu();
app->set_menubar(mnuMenu);
{
Gtk::ApplicationWindow *frm = new Gtk::ApplicationWindow();
// Allow pointer to be unreferenced when this scope ends
Glib::RefPtr<Gtk::ApplicationWindow> frmPtr(frm);
app->run(*frm);
}
} else {
app->activate();
}
}
int main(int argc, char **argv){
ApplicationMain appMain(argc, argv);
return appMain.run();
}
// XML data for application menu
const char *MenuStringContainer::string = R"rawstring(
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="menubar">
<submenu>
<attribute name="label">_File</attribute>
<section>
<item>
<attribute name="label">_New Character</attribute>
<attribute name="action">file.newchar</attribute>
</item>
<item>
<attribute name="label">New _Critter</attribute>
<attribute name="action">file.newcrit</attribute>
</item>
<item>
<attribute name="label">_Open</attribute>
<attribute name="action">file.open</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">_Print</attribute>
<attribute name="action">file.print</attribute>
</item>
<item>
<attribute name="label">Print _Multiple</attribute>
<attribute name="action">file.printmultiple</attribute>
</item>
<item>
<attribute name="label">Print Setup</attribute>
<attribute name="action">file.printsetup</attribute>
</item>
</section>
<section id="mru">
<item>
<attribute name="label">[StickyMRU0]</attribute>
<attribute name="action">file.smru0</attribute>
</item>
<item>
<attribute name="label">[StickyMRU1]</attribute>
<attribute name="action">file.smru1</attribute>
</item>
<item>
<attribute name="label">[StickyMRU2]</attribute>
<attribute name="action">file.smru2</attribute>
</item>
<item>
<attribute name="label">[StickyMRU3]</attribute>
<attribute name="action">file.smru3</attribute>
</item>
<item>
<attribute name="label">[StickyMRU4]</attribute>
<attribute name="action">file.smru4</attribute>
</item>
<item>
<attribute name="label">[StickyMRU5]</attribute>
<attribute name="action">file.smru5</attribute>
</item>
<item>
<attribute name="label">[StickyMRU6]</attribute>
<attribute name="action">file.smru6</attribute>
</item>
<item>
<attribute name="label">[StickyMRU7]</attribute>
<attribute name="action">file.smru7</attribute>
</item>
<item>
<attribute name="label">[StickyMRU8]</attribute>
<attribute name="action">file.smru8</attribute>
</item>
<item>
<attribute name="label">[StickyMRU9]</attribute>
<attribute name="action">file.smru9</attribute>
</item>
<item>
<attribute name="label">[MRU0]</attribute>
<attribute name="action">file.mru0</attribute>
</item>
<item>
<attribute name="label">[MRU1]</attribute>
<attribute name="action">file.mru1</attribute>
</item>
<item>
<attribute name="label">[MRU2]</attribute>
<attribute name="action">file.mru2</attribute>
</item>
<item>
<attribute name="label">[MRU3]</attribute>
<attribute name="action">file.mru3</attribute>
</item>
<item>
<attribute name="label">[MRU4]</attribute>
<attribute name="action">file.mru4</attribute>
</item>
<item>
<attribute name="label">[MRU5]</attribute>
<attribute name="action">file.mru5</attribute>
</item>
<item>
<attribute name="label">[MRU6]</attribute>
<attribute name="action">file.mru6</attribute>
</item>
<item>
<attribute name="label">[MRU7]</attribute>
<attribute name="action">file.mru7</attribute>
</item>
<item>
<attribute name="label">[MRU8]</attribute>
<attribute name="action">file.mru8</attribute>
</item>
<item>
<attribute name="label">[MRU9]</attribute>
<attribute name="action">file.mru9</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">E_xit</attribute>
<attribute name="action">file.exit</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label">_Tools</attribute>
<section>
<item>
<attribute name="label">_Dice Roller</attribute>
<attribute name="action">tools.roller</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">_Options</attribute>
<attribute name="action">tools.options</attribute>
</item>
<item>
<attribute name="label">Check for Updates</attribute>
<attribute name="action">tools.updates</attribute>
</item>
<item>
<attribute name="label">Omae</attribute>
<attribute name="action">tools.omae</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label">_Windows</attribute>
<section>
<item>
<attribute name="label">_New Window</attribute>
<attribute name="action">windows.new</attribute>
</item>
<item>
<attribute name="label">C_lose All</attribute>
<attribute name="action">windows.closeall</attribute>
</item>
</section>
<section id="windowlist">
</section>
</submenu>
<submenu>
<attribute name="label">_Help</attribute>
<section>
<section>
<item>
<attribute name="label">Chummer Wiki</attribute>
<attribute name="action">help.chummerwiki</attribute>
</item>
</section>
<item>
<attribute name="label">_Revision History</attribute>
<attribute name="action">help.revisionhistory</attribute>
</item>
<item>
<attribute name="label">_Dumpshock Thread</attribute>
<attribute name="action">help.dumpshockthread</attribute>
</item>
<item>
<attribute name="label">_About...</attribute>
<attribute name="action">help.about</attribute>
</item>
</section>
</submenu>
</menu>
</interface>
)rawstring"; //"(
You are calling register_application() manually, rather than letting GtkApplication/GApplication do that for you. You probably did that to avoid this warning, which I think is the main clue, because the gtkmm examples never need to do that:
(a.out:24959): Gtk-CRITICAL **: gtk_application_set_menubar: assertion 'g_application_get_is_registered (G_APPLICATION (application))' failed
I have reduced your test case down to a simpler test case with no class definition and no use of GtkBuilder, and now I guess the problem is probably that you are adding these actions, or the menu, too early, though I'm not sure exactly what is not yet set up properly. I can post that test case here, if you like.
For instance, this example works, but notice that it adds the menu and its actions in the derived Gtk::Application's on_startup():
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/application/app_and_win_menus/exampleapplication.cc#n32
Deriving a Gtk::Application is the more correct structure anyway, allowing the app to do the right thing at the right time. GtkApplication is a rather awkward and unforgiving API, in my opinion, so I wouldn't stray from the path.
Incidentally, it's also rather confusing to define an ApplicationMain class that doesn't derive from Gtk::Application. And you should avoid using RefPtr<> with a widget (Gtk::ApplicationWindow) class. You should never need to do any referencing or unreferencing of widgets in your application code.
Related
I am trying to develop a hierarchical structure from a flat file thus i need to establish parent child relationship in the desired output. Could you please suggest a method in XSLT 2.0.
Please find below the input XML which contains LEVEL and IDENTIFY tags on the basis of which i was trying to build the parent child relationship.
All the IDENTIFY tags with 'IB' should be in a separate tag like LOCATION and all the IDENTIFY tags with 'ER' should be in a separate tag like ADDRESS in output.
Input XML:
<Path>
<item>
<LEVEL>1</LEVEL>
<RANK>340</RANK>
<TYPE>T</TYPE>
<DESC>Sheet</DESC>
<NAME>I</NAME>
<IDENTIFY>IB</IDENTIFY>
</item>
<item>
<LEVEL>2</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC> Handler</DESC>
<NAME>D</NAME>
<IDENTIFY></IDENTIFY>
</item>
<item>
<LEVEL>2</LEVEL>
<RANK>341</RANK>
<TYPE>M</TYPE>
<DESC>handler </DESC>
<NAME>I</NAME>
<IDENTIFY>IB</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC>pdf</DESC>
<NAME>D</NAME>
<IDENTIFY></IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>330</RANK>
<TYPE>M</TYPE>
<DESC>SERVO </DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>331</RANK>
<TYPE>M</TYPE>
<DESC>SENSOR</DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>2</LEVEL>
<RANK>342</RANK>
<TYPE>M</TYPE>
<DESC>xyz</DESC>
<NAME>I</NAME>
<IDENTIFY>IB</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>335</RANK>
<TYPE>M</TYPE>
<DESC>FILTER</DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>2</LEVEL>
<RANK>343</RANK>
<TYPE>M</TYPE>
<DESC>safety </DESC>
<NAME>I</NAME>
<IDENTIFY>IB</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC>doc</DESC>
<NAME>D</NAME>
<IDENTIFY></IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>337</RANK>
<TYPE>M</TYPE>
<DESC>ROD </DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>338</RANK>
<TYPE>M</TYPE>
<DESC>CYL</DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>3</LEVEL>
<RANK>339</RANK>
<TYPE>M</TYPE>
<DESC>COMPRESSION </DESC>
<NAME>L</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
<item>
<LEVEL>2</LEVEL>
<RANK>345</RANK>
<TYPE>M</TYPE>
<DESC>Nylon</DESC>
<NAME>I</NAME>
<IDENTIFY>ER</IDENTIFY>
</item>
</Path>
Desired Output:
<LOCATION>
<LEVEL>1</LEVEL>
<RANK>340</RANK>
<TYPE>T</TYPE>
<DESC>Sheet</DESC>
<NAME>I</NAME>
</LOCATION>
<LOCATION>
<LEVEL>2</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC> Handler</DESC>
<NAME>D</NAME>
</LOCATION>
<LOCATION>
<LEVEL>2</LEVEL>
<RANK>341</RANK>
<TYPE>M</TYPE>
<DESC> handler </DESC>
<NAME>I</NAME>
</LOCATION>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC>pdf</DESC>
<NAME>D</NAME>
</ADDRESS>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>330</RANK>
<TYPE>M</TYPE>
<DESC>pqr</DESC>
<NAME>L</NAME>
</ADDRESS>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>331</RANK>
<TYPE>M</TYPE>
<DESC>SENSOR</DESC>
<NAME>L</NAME>
</ADDRESS>
<LOCATION>
<LEVEL>2</LEVEL>
<RANK>342</RANK>
<TYPE>M</TYPE>
<DESC>xyz</DESC>
<NAME>I</NAME>
</LOCATION>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>335</RANK>
<TYPE>M</TYPE>
<DESC>TER</DESC>
<NAME>L</NAME>
</ADDRESS>
<LOCATION>
<LEVEL>2</LEVEL>
<RANK>343</RANK>
<TYPE>M</TYPE>
<DESC>SAFE</DESC>
<NAME>I</NAME>
</LOCATION>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK/>
<TYPE>M</TYPE>
<DESC>doc</DESC>
<NAME>D</NAME>
</ADDRESS>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>337</RANK>
<TYPE>M</TYPE>
<DESC>RST/DESC>
<NAME>L</NAME>
</ADDRESS>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>338</RANK>
<TYPE>M</TYPE>
<DESC>CYL</DESC>
<NAME>L</NAME>
</ADDRESS>
<ADDRESS>
<LEVEL>3</LEVEL>
<RANK>339</RANK>
<TYPE>M</TYPE>
<DESC>COMP</DESC>
<NAME>L</NAME>
</ADDRESS>
<LOCATION>
<LEVEL>2</LEVEL>
<RANK>345</RANK>
<TYPE>M</TYPE>
<DESC>Nyl</DESC>
<NAME>I</NAME>
</LOCATION>
i use word list updater 2.7 for windows to filetr this type of list:
<username>vasile_2200</username>
<user_password>2550e911cb740fbfc8b08482bc6b80a5</user_password>
</item>
- <item>
<username>spitalfetesti</username>
<user_password>e28e9b2242e579f40bc78d08628c7297</user_password>
</item>
- <item>
<username>spital_bailesti</username>
<user_password>62a12df86a9bf85fc77fe495783f79fd</user_password>
</item>
filter only hashes
62a12df86a9bf85fc77fe495783f79fd
I'm converting SQL to FetchXml for migrating existing reports in Dynamics CRM 2013 to Dynamics CRM 2015 online. There is an optionset and ran into this issue that
The attribute type "Virtual" is not supported. Remove attribute "s_expensetypename" from the query, and try again.
The problem is: How to get optionset label and value in link-entity using Fetch Xml CRM 2015 Online.
Here's my Fetch XML:
<fetch mapping="logical" version="1.0">
<entity name="new_timereport">
<attribute name="new_timereportid" alias="InvoiceID" />
<attribute name="new_name" alias="Invoice Number" />
<attribute name="new_projectid" alias="ProjectID" />
<attribute name="new_projectidname" alias="Project Name" />
<attribute name="new_customeridname" alias="Customer Name" />
<filter>
<condition attribute="new_timereportid" operator="eq" value="#SubreportParam" />
</filter>
<link-entity name="new_expenses" from="new_expenseid" to="new_timereportid" alias="Y" link-type="outer">
<attribute name="s_expensetype" alias="Expense Type Key" />
<attribute name="s_expensetypename" alias="Expense Type" />
<attribute name="ownerid" alias="ConsultantID" />
<attribute name="owneridname" alias="Consultant" />
<attribute name="new_date" />
<attribute name="new_amount" alias="Amount" />
<attribute name="new_vat" alias="VAT" />
<attribute name="new_total" alias="Total Amount" />
<attribute name="new_name" alias="Description" />
</link-entity>
</entity>
</fetch>
Any ideas on how to deal with this?
Many thanks,
Just remove s_expensetypename field from FetchXml query and leave s_expensetype. In datasource as result you will get 2 fields instead on 1 - s_expensetype will contain label of your optionset and sexpensetypeValue will contain optionsetcode.
Suppose I have some XML like this:
<section name="SampleSection">
<item name="ScoredItem1">
<attributes>
<scored data_type="boolean" value="true"/>
</attributes>
</item>
<item name="UnscoredItem1">
<attributes>
<scored data_type="boolean" value="false"/>
</attributes>
</item>
<item key="(3272fbb5:22)" name="ScoredItem2">
<attributes>
<scored data_type="boolean" value="true"/>
</attributes>
</item>
</section>
Now, I know, using XSLT, I can count the items that have a scored attribute like this:
<xsl:variable name="scoredItems" select="item/attributes/scored"/>
<xsl:value-of select="count($scoredItems)"/>
This will give me a value of 3, of course.
Suppose I only want to count those items for which scored is true. How do I do that using XSLT? (This should return a value of 2 for this example.
Do it like this:
<xsl:variable name="scoredItems"
select=
"item/attributes/scored[#value='true']"/>
Input XML
<?xml version="1.0" encoding="UTF-8" ?>
<Z_RFC_SP_POTEXT_OUT >
<ZMPO_TXT>
<item>
<LIFNR>0009002008</LIFNR>
<ZPOTEXT1>BSE-TSE Statement document is accpeted by sup3#spp2.com on 2010-04-12</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009002008</LIFNR>
<ZPOTEXT1>Ist Part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009002008</LIFNR>
<ZPOTEXT1>2nd Part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000013</LIFNR>
<ZPOTEXT1>vComments for Obj 1hkshkshdiswyidswyidyswidysiysiysskhskchskhckchk</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000017</LIFNR>
<ZPOTEXT1>vComments for Obj 1hkshkshdiswyidswyidyswidysiysiysskhskchskhckchk</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000017</LIFNR>
<ZPOTEXT1>1st part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000017</LIFNR>
<ZPOTEXT1>2nd part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000022</LIFNR>
<ZPOTEXT1>INCLUDE ZPTP_TERMS_AND_CONDITIONS_2003 OBJECT TEXT ID ST</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000026</LIFNR>
<ZPOTEXT1>INCLUDE ZPTP_TERMS_AND_CONDITIONS_2003 OBJECT TEXT ID ST</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
</ZMPO_TXT>
</Z_RFC_SP_POTEXT_OUT>
I am looking for the output
<?xml version="1.0" encoding="UTF-8" ?>
<Z_RFC_SP_POTEXT_OUT >
<ZMPO_TXT>
<item>
<LIFNR>0009002008</LIFNR>
<ZPOTEXT1>BSE-TSE Statement document is accpeted by sup3#spp2.com on 2010-04-12 Ist Part 2nd Part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000013</LIFNR>
<ZPOTEXT1>vComments for Obj 1hkshkshdiswyidswyidyswidysiysiysskhskchskhckchk</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000017</LIFNR>
<ZPOTEXT1>vComments for Obj 1hkshkshdiswyidswyidyswidysiysiysskhskchskhckchk 1st part 2nd part</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000022</LIFNR>
<ZPOTEXT1>INCLUDE ZPTP_TERMS_AND_CONDITIONS_2003 OBJECT TEXT ID ST</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
<item>
<LIFNR>0009000026</LIFNR>
<ZPOTEXT1>INCLUDE ZPTP_TERMS_AND_CONDITIONS_2003 OBJECT TEXT ID ST</ZPOTEXT1>
<ZPOTEXT2 />
<FLAG />
</item>
</ZMPO_TXT>
</Z_RFC_SP_POTEXT_OUT>
How to do that using xslt?
looks like a Munchian Sort can help you further. if you group the items by <LIFNR>, you should be able to drop all text in a single node.