Ejemplo n.º 1
0
void Shortcuts_foreach(Shortcuts& shortcuts, CommandVisitor& visitor)
{
  for(Shortcuts::iterator i = shortcuts.begin(); i != shortcuts.end(); ++i)
  {
    visitor.visit((*i).first.c_str(), (*i).second.first);
  }
}
Ejemplo n.º 2
0
void GlobalShortcuts_reportUnregistered(){
	for ( Shortcuts::iterator i = g_shortcuts.begin(); i != g_shortcuts.end(); ++i )
	{
		if ( ( *i ).second.first.key != 0 && !( *i ).second.second ) {
			globalOutputStream() << "shortcut not registered: " << ( *i ).first.c_str() << "\n";
		}
	}
}
Ejemplo n.º 3
0
void GlobalShortcuts_register(const char* name)
{
  Shortcuts::iterator i = g_shortcuts.find(name);
  if(i != g_shortcuts.end())
  {
    (*i).second.second = true;
  }
}
Ejemplo n.º 4
0
void ResourceConverterDialog::build_checkbutton_button(GtkWidget * &image_ok, GtkWidget * &label_ok, GtkWidget * &checkbutton, const gchar * checkbutton_text, GCallback checkbutton_handler, GtkWidget * &button, const gchar * button_text, GCallback button_handler, Shortcuts & shortcuts, GtkWidget * &label)
{
    GtkWidget *hseparator = gtk_hseparator_new();
    gtk_widget_show(hseparator);
    gtk_table_attach(GTK_TABLE(table1), hseparator, 0, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
    table_attachment_offset++;

    image_ok = gtk_image_new_from_icon_name("gtk-apply", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image_ok);
    gtk_table_attach(GTK_TABLE(table1), image_ok, 0, 1, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

    label_ok = gtk_label_new("Done");
    gtk_widget_show(label_ok);
    gtk_table_attach(GTK_TABLE(table1), label_ok, 1, 2, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment(GTK_MISC(label_ok), 0, 0.5);

    checkbutton = gtk_check_button_new_with_mnemonic(checkbutton_text);
    gtk_widget_show(checkbutton);
    gtk_table_attach(GTK_TABLE(table1), checkbutton, 2, 3, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);

    shortcuts.button(checkbutton);

    button = gtk_button_new();
    gtk_widget_show(button);
    gtk_table_attach(GTK_TABLE(table1), button, 3, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
    table_attachment_offset++;

    GtkWidget *alignment2 = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_widget_show(alignment2);
    gtk_container_add(GTK_CONTAINER(button), alignment2);

    GtkWidget *hbox2 = gtk_hbox_new(FALSE, 2);
    gtk_widget_show(hbox2);
    gtk_container_add(GTK_CONTAINER(alignment2), hbox2);

    GtkWidget *image2 = gtk_image_new_from_stock("gtk-index", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image2);
    gtk_box_pack_start(GTK_BOX(hbox2), image2, FALSE, FALSE, 0);

    GtkWidget *label2 = gtk_label_new_with_mnemonic(button_text);
    gtk_widget_show(label2);
    gtk_box_pack_start(GTK_BOX(hbox2), label2, FALSE, FALSE, 0);

    shortcuts.label(label2);

    label = gtk_label_new("");
    gtk_widget_show(label);
    gtk_table_attach(GTK_TABLE(table1), label, 0, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
    table_attachment_offset++;

    g_signal_connect((gpointer) checkbutton, "toggled", checkbutton_handler, gpointer(this));
    g_signal_connect((gpointer) button, "clicked", button_handler, gpointer(this));
}
Ejemplo n.º 5
0
void RootMenu::setShortcuts(const Shortcuts &shortcuts) {
	for (auto it = shortcuts.cbegin(); it != shortcuts.cend(); ++it) {
		auto id = it.key();
		if (id.startsWith("menu/"))
			id = id.mid(5);
		auto found = m_actions.constFind(id);
		if (found != m_actions.cend())
			found.value().action->setShortcuts(it.value());
		else
			_Warn("Cannot set shortcuts for '%%'", id);
	}
#ifdef Q_OS_MAC
	a(_L("exit"))->setShortcut(QKeySequence());
#endif
}
Ejemplo n.º 6
0
void connect_accelerator( const char *name ){
	Shortcuts::iterator i = g_shortcuts.find( name );
	if ( i != g_shortcuts.end() ) {
		switch ( ( *i ).second.second )
		{
		case 1:
			// command
			command_connect_accelerator( name );
			break;
		case 2:
			// toggle
			toggle_add_accelerator( name );
			break;
		}
	}
}
Ejemplo n.º 7
0
void accelerator_clear_button_clicked( GtkButton *btn, gpointer dialogptr ){
	command_list_dialog_t &dialog = *(command_list_dialog_t *) dialogptr;

	if ( dialog.m_waiting_for_key ) {
		// just unhighlight, user wanted to cancel
		dialog.m_waiting_for_key = false;
		gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 );
		gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true );
		dialog.m_model = NULL;
		return;
	}

	GtkTreeSelection *sel = gtk_tree_view_get_selection( dialog.m_list );
	GtkTreeModel *model;
	GtkTreeIter iter;
	if ( !gtk_tree_selection_get_selected( sel, &model, &iter ) ) {
		return;
	}

	GValue val;
	memset( &val, 0, sizeof( val ) );
	gtk_tree_model_get_value( GTK_TREE_MODEL( model ), &iter, 0, &val );
	const char *commandName = g_value_get_string( &val );;

	// clear the ACTUAL accelerator too!
	disconnect_accelerator( commandName );

	Shortcuts::iterator thisShortcutIterator = g_shortcuts.find( commandName );
	if ( thisShortcutIterator == g_shortcuts.end() ) {
		return;
	}
	thisShortcutIterator->second.first = accelerator_null();

	gtk_list_store_set( GTK_LIST_STORE( model ), &iter, 1, "", -1 );

	g_value_unset( &val );
}
Ejemplo n.º 8
0
const Accelerator& GlobalShortcuts_insert( const char* name, const Accelerator& accelerator ){
	return ( *g_shortcuts.insert( Shortcuts::value_type( name, ShortcutValue( accelerator, false ) ) ).first ).second.first;
}
Ejemplo n.º 9
0
gboolean accelerator_window_key_press( GtkWidget *widget, GdkEventKey *event, gpointer dialogptr ){
	command_list_dialog_t &dialog = *(command_list_dialog_t *) dialogptr;

	if ( !dialog.m_waiting_for_key ) {
		return false;
	}

#if 0
	if ( event->is_modifier ) {
		return false;
	}
#else
	switch ( event->keyval )
	{
	case GDK_Shift_L:
	case GDK_Shift_R:
	case GDK_Control_L:
	case GDK_Control_R:
	case GDK_Caps_Lock:
	case GDK_Shift_Lock:
	case GDK_Meta_L:
	case GDK_Meta_R:
	case GDK_Alt_L:
	case GDK_Alt_R:
	case GDK_Super_L:
	case GDK_Super_R:
	case GDK_Hyper_L:
	case GDK_Hyper_R:
		return false;
	}
#endif

	dialog.m_waiting_for_key = false;

	// 7. find the name of the accelerator
	GValue val;
	memset( &val, 0, sizeof( val ) );
	gtk_tree_model_get_value( GTK_TREE_MODEL( dialog.m_model ), &dialog.m_command_iter, 0, &val );
	const char *commandName = g_value_get_string( &val );;
	Shortcuts::iterator thisShortcutIterator = g_shortcuts.find( commandName );
	if ( thisShortcutIterator == g_shortcuts.end() ) {
		gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 );
		gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true );
		return true;
	}

	// 8. build an Accelerator
	Accelerator newAccel( event->keyval, (GdkModifierType) event->state );

	// 8. verify the key is still free, show a dialog to ask what to do if not
	class VerifyAcceleratorNotTaken : public CommandVisitor
	{
	const char *commandName;
	const Accelerator &newAccel;
	GtkWidget *widget;
	GtkTreeModel *model;
public:
	bool allow;
	VerifyAcceleratorNotTaken( const char *name, const Accelerator &accelerator, GtkWidget *w, GtkTreeModel *m ) : commandName( name ), newAccel( accelerator ), widget( w ), model( m ), allow( true ){
	}
	void visit( const char* name, Accelerator& accelerator ){
		if ( !strcmp( name, commandName ) ) {
			return;
		}
		if ( !allow ) {
			return;
		}
		if ( accelerator.key == 0 ) {
			return;
		}
		if ( accelerator == newAccel ) {
			StringOutputStream msg;
			msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n"
				<< "Do you want to unassign " << name << " first?";
			EMessageBoxReturn r = gtk_MessageBox( widget, msg.c_str(), "Key already used", eMB_YESNOCANCEL );
			if ( r == eIDYES ) {
				// clear the ACTUAL accelerator too!
				disconnect_accelerator( name );
				// delete the modifier
				accelerator = accelerator_null();
				// empty the cell of the key binds dialog
				GtkTreeIter i;
				if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL( model ), &i ) ) {
					for (;; )
					{
						GValue val;
						memset( &val, 0, sizeof( val ) );
						gtk_tree_model_get_value( GTK_TREE_MODEL( model ), &i, 0, &val );
						const char *thisName = g_value_get_string( &val );;
						if ( !strcmp( thisName, name ) ) {
							gtk_list_store_set( GTK_LIST_STORE( model ), &i, 1, "", -1 );
						}
						g_value_unset( &val );
						if ( !gtk_tree_model_iter_next( GTK_TREE_MODEL( model ), &i ) ) {
							break;
						}
					}
				}
			}
			else if ( r == eIDCANCEL ) {
				// aborted
				allow = false;
			}
		}
	}
	} verify_visitor( commandName, newAccel, widget, dialog.m_model );
	GlobalShortcuts_foreach( verify_visitor );

	gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 );
	gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true );

	if ( verify_visitor.allow ) {
		// clear the ACTUAL accelerator first
		disconnect_accelerator( commandName );

		thisShortcutIterator->second.first = newAccel;

		// write into the cell
		StringOutputStream modifiers;
		modifiers << newAccel;
		gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 1, modifiers.c_str(), -1 );

		// set the ACTUAL accelerator too!
		connect_accelerator( commandName );
	}

	g_value_unset( &val );

	dialog.m_model = NULL;

	return true;
}
Ejemplo n.º 10
0
// Entry, combo, entry.
void ResourceConverterDialog::build_entry_combo_entry(GtkWidget * &image_ok, GtkWidget * &label_ok, GtkWidget * &label, GtkWidget * &label_entry_1, GtkWidget * &entry_1, GtkWidget * &label_combo, GtkWidget * &combo, GtkWidget * &label_entry_2, GtkWidget * &entry_2, GCallback entry_handler, Shortcuts & shortcuts)
{
    GtkWidget *hseparator;
    hseparator = gtk_hseparator_new();
    gtk_widget_show(hseparator);
    gtk_table_attach(GTK_TABLE(table1), hseparator, 0, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

    table_attachment_offset++;

    image_ok = gtk_image_new_from_icon_name("gtk-apply", GTK_ICON_SIZE_BUTTON);
    gtk_widget_show(image_ok);
    gtk_table_attach(GTK_TABLE(table1), image_ok, 0, 1, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

    label_ok = gtk_label_new(_("Done"));
    gtk_widget_show(label_ok);
    gtk_table_attach(GTK_TABLE(table1), label_ok, 1, 2, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment(GTK_MISC(label_ok), 0, 0.5);

    label = gtk_label_new("");
    gtk_widget_show(label);
    gtk_table_attach(GTK_TABLE(table1), label, 2, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

    table_attachment_offset++;

    GtkWidget *hbox;
    hbox = gtk_hbox_new(FALSE, 5);
    gtk_widget_show(hbox);
    gtk_table_attach(GTK_TABLE(table1), hbox, 0, 4, table_attachment_offset, table_attachment_offset + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);

    table_attachment_offset++;

    label_entry_1 = gtk_label_new("");
    gtk_widget_show(label_entry_1);
    gtk_box_pack_start(GTK_BOX(hbox), label_entry_1, FALSE, FALSE, 0);

    entry_1 = gtk_entry_new();
    gtk_widget_show(entry_1);
    gtk_box_pack_start(GTK_BOX(hbox), entry_1, TRUE, TRUE, 0);

    shortcuts.label(label_entry_1);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label_entry_1), entry_1);

    label_combo = gtk_label_new("");
    gtk_widget_show(label_combo);
    gtk_box_pack_start(GTK_BOX(hbox), label_combo, FALSE, FALSE, 0);

    combo = gtk_combo_box_new_text();
    gtk_widget_show(combo);
    gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0);

    shortcuts.label(label_combo);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label_combo), combo);

    label_entry_2 = gtk_label_new("");
    gtk_widget_show(label_entry_2);
    gtk_box_pack_start(GTK_BOX(hbox), label_entry_2, FALSE, FALSE, 0);

    entry_2 = gtk_entry_new();
    gtk_widget_show(entry_2);
    gtk_box_pack_start(GTK_BOX(hbox), entry_2, TRUE, TRUE, 0);

    shortcuts.label(label_entry_2);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label_entry_2), entry_2);

    g_signal_connect((gpointer) entry_1, "changed", entry_handler, gpointer(this));
    g_signal_connect((gpointer) entry_2, "changed", entry_handler, gpointer(this));
}
Ejemplo n.º 11
0
void SettingsDialog::editShortcuts()
{
    Shortcuts *dialog = new Shortcuts(this);
    dialog->exec();
	delete dialog;
}