]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/commands.cpp
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / radiant / commands.cpp
index 9c1b7682246febb16f70c082faba1da1b418dbd2..4276805658975a1da8eb03c6961e067dfb0b3a18 100644 (file)
 #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;
 
@@ -219,6 +226,11 @@ void accelerator_edit_button_clicked( ui::Button btn, gpointer dialogptr ){
        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::from(model);
 
@@ -232,6 +244,14 @@ void accelerator_edit_button_clicked( ui::Button btn, gpointer dialogptr ){
        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;
 
@@ -408,7 +428,9 @@ void DoCommandListDlg(){
                        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);
@@ -427,31 +449,19 @@ void DoCommandListDlg(){
 
                        {
                                // 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 );
                        }
@@ -487,11 +497,21 @@ public:
 
 #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() ) {
@@ -515,6 +535,8 @@ public:
                } visitor( file );
                GlobalShortcuts_foreach( visitor );
        }
+       
+       DeleteOldCommandMap();
 }
 
 const char* stringrange_find( const char* first, const char* last, char c ){
@@ -558,9 +580,9 @@ std::size_t count() const {
 }
 };
 
-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 ) {