#include "gtkutil/messagebox.h"
#include "gtkmisc.h"
+#define NETRADIANT_CUSTOM_FULLY_MERGED 0
+#if NETRADIANT_CUSTOM_FULLY_MERGED
+// For deleting old shortcuts.ini file
+#include "preferences.h"
+#include "unistd.h"
+#endif // NETRADIANT_CUSTOM_FULLY_MERGED
+
typedef std::pair<Accelerator, int> ShortcutValue; // accelerator, isRegistered
typedef std::map<CopiedString, ShortcutValue> Shortcuts;
struct command_list_dialog_t : public ModalDialog
{
command_list_dialog_t()
- : m_close_button( *this, eIDCANCEL ), m_list( NULL ), m_command_iter(), m_model( NULL ), m_waiting_for_key( false ){
+ : m_close_button( *this, eIDCANCEL ), m_list( ui::null ), m_command_iter(), m_model( ui::null ), m_waiting_for_key( false ){
}
ModalDialogButton m_close_button;
if ( !gtk_tree_selection_get_selected( sel, &model, &iter ) ) {
return;
}
+ if ( dialog.m_waiting_for_key ) {
+ // unhighlight highlit
+ dialog.m_waiting_for_key = false;
+ gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 );
+ }
dialog.m_command_iter = iter;
- dialog.m_model = ui::TreeModel(model);
+ dialog.m_model = ui::TreeModel::from(model);
// 2. disallow changing the row
//gtk_widget_set_sensitive(dialog.m_list, false);
dialog.m_waiting_for_key = true;
}
+gboolean accelerator_tree_butt_press( GtkWidget* widget, GdkEventButton* event, gpointer dialogptr ){
+ if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 ) {
+ accelerator_edit_button_clicked( ui::Button( ui::null ), dialogptr );
+ return TRUE;
+ }
+ return FALSE;
+}
+
bool accelerator_window_key_press( ui::Window widget, GdkEventKey *event, gpointer dialogptr ){
command_list_dialog_t &dialog = *(command_list_dialog_t *) dialogptr;
StringOutputStream msg;
msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n"
<< "Do you want to unassign " << name << " first?";
- auto r = widget.window().alert( msg.c_str(), "Key already used", ui::alert_type::YESNOCANCEL );
+ auto r = ui::alert( widget.window(), msg.c_str(), "Key already used", ui::alert_type::YESNOCANCEL );
if ( r == ui::alert_response::YES ) {
// clear the ACTUAL accelerator too!
disconnect_accelerator( name );
hbox.pack_start( scr, TRUE, TRUE, 0 );
{
- ui::ListStore store = ui::ListStore(gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT ));
+ auto store = ui::ListStore::from(gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT ));
- auto view = ui::TreeView(ui::TreeModel(store));
+ auto view = ui::TreeView(ui::TreeModel::from(store._handle));
dialog.m_list = view;
- gtk_tree_view_set_enable_search(view, false ); // annoying
+ //gtk_tree_view_set_enable_search( GTK_TREE_VIEW( view ), false ); // annoying
+
+ g_signal_connect( G_OBJECT( view ), "button_press_event", G_CALLBACK( accelerator_tree_butt_press ), &dialog );
{
auto renderer = ui::CellRendererText(ui::New);
{
// Initialize dialog
- StringOutputStream path( 256 );
- path << SettingsPath_get() << "commandlist.txt";
- globalOutputStream() << "Writing the command list to " << path.c_str() << "\n";
class BuildCommandList : public CommandVisitor
{
- TextFileOutputStream m_commandList;
ui::ListStore m_store;
public:
- BuildCommandList( const char* filename, ui::ListStore store ) : m_commandList( filename ), m_store( store ){
+ BuildCommandList( ui::ListStore store ) : m_store( store ){
}
void visit( const char* name, Accelerator& accelerator ){
StringOutputStream modifiers;
modifiers << accelerator;
m_store.append(0, name, 1, modifiers.c_str(), 2, false, 3, 800);
-
- if ( !m_commandList.failed() ) {
- int l = strlen( name );
- m_commandList << name;
- while ( l++ < 25 )
- m_commandList << ' ';
- m_commandList << modifiers.c_str() << '\n';
- }
}
- } visitor( path.c_str(), store );
+ } visitor( store );
GlobalShortcuts_foreach( visitor );
}
#include "profile/profile.h"
-const char* const COMMANDS_VERSION = "1.0-gtk-accelnames";
+const char* const COMMANDS_VERSION = "1.1-gtk-accelnames";
+
+void DeleteOldCommandMap(){
+#if NETRADIANT_CUSTOM_FULLY_MERGED
+// To enable when NetRadiant and NetRadiant-custom are fully merged together.
+ StringOutputStream path( 256 );
+ path << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << '/';
+ path << "shortcuts.ini";
+ unlink( path.c_str() );
+#endif
+}
-void SaveCommandMap( const char* path ){
+void SaveCommandMap(){
StringOutputStream strINI( 256 );
- strINI << path << "shortcuts.ini";
+ strINI << SettingsPath_get() << "shortcuts.ini";
TextFileOutputStream file( strINI.c_str() );
if ( !file.failed() ) {
} visitor( file );
GlobalShortcuts_foreach( visitor );
}
+
+ DeleteOldCommandMap();
}
const char* stringrange_find( const char* first, const char* last, char c ){
}
};
-void LoadCommandMap( const char* path ){
+void LoadCommandMap(){
StringOutputStream strINI( 256 );
- strINI << path << "shortcuts.ini";
+ strINI << SettingsPath_get() << "shortcuts.ini";
FILE* f = fopen( strINI.c_str(), "r" );
if ( f != 0 ) {