Code

code style, indent with tabs
[ncmpc.git] / src / screen_keydef.c
index 809561b80bea1709478bff0706bacdaf759c9504..a8f32d3dab17317b1f2fbe28298bfc39ce7fb54f 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "config.h"
 
-#ifdef  ENABLE_KEYDEF_SCREEN
+#ifndef  DISABLE_KEYDEF_SCREEN
 #include "ncmpc.h"
 #include "mpdclient.h"
 #include "options.h"
@@ -89,7 +89,7 @@ save_keys(void)
     {
       screen_status_printf(_("Error: Unable to create direcory ~/.ncmpc - %s"),
                           strerror(errno));
-      beep();
+      screen_bell();
       return -1;
     }
 
@@ -98,11 +98,11 @@ save_keys(void)
   if( (f=fopen(filename,"w")) == NULL )
     {
       screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
-      beep();
+      screen_bell();
       g_free(filename);
       return -1;
     }
-  if( write_key_bindings(f) )
+  if( write_key_bindings(f, KEYDEF_WRITE_HEADER) )
     screen_status_printf(_("Error: %s - %s"), filename, strerror(errno));
   else
     screen_status_printf(_("Wrote %s"), filename);
@@ -137,21 +137,24 @@ delete_key(int cmd_index, int key_index)
   while( i<MAX_COMMAND_KEYS && cmds[cmd_index].keys[i] )
     cmds[cmd_index].keys[key_index++] = cmds[cmd_index].keys[i++];
   cmds[cmd_index].keys[key_index] = 0;
-
+  cmds[cmd_index].flags |= COMMAND_KEY_MODIFIED;
   check_subcmd_length();
   lw->clear = 1;
   lw->repaint = 1;
+  /* update key conflict flags */
+  check_key_bindings(cmds, NULL, 0);
 }
 
 static void
 assign_new_key(WINDOW *w, int cmd_index, int key_index)
 {
   int key;
-  char buf[BUFSIZE];
+  char *buf;
   command_t cmd;
 
-  snprintf(buf, BUFSIZE, _("Enter new key for %s: "), cmds[cmd_index].name);
+  buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name);
   key = screen_getch(w, buf);
+  g_free(buf);
   if( key==KEY_RESIZE )
     screen_resize();
   if( key==ERR )
@@ -165,52 +168,53 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index)
       screen_status_printf(_("Error: key %s is already used for %s"), 
                           key2str(key),
                           get_key_command_name(cmd));
-      beep();
+      screen_bell();
       return;
     }
   cmds[cmd_index].keys[key_index] = key;
+  cmds[cmd_index].flags |= COMMAND_KEY_MODIFIED;
+  
   screen_status_printf(_("Assigned %s to %s"), 
                       key2str(key),cmds[cmd_index].name);
   check_subcmd_length();
   lw->repaint = 1;
+  /* update key conflict flags */
+  check_key_bindings(cmds, NULL, 0);
 }
 
 static char *
 list_callback(int index, int *highlight, void *data)
 {
-  static char buf[BUFSIZE];
+       static char buf[BUFSIZE];
+
+       *highlight = 0;
+       if (subcmd < 0) {
+               if (index < command_list_length) {
+                       if (cmds[index].flags & COMMAND_KEY_CONFLICT)
+                               *highlight = 1;
+                       return cmds[index].name;
+               } else if (index == LIST_ITEM_APPLY())
+                       return LIST_ITEM_APPLY_LABEL;
+               else if (index == LIST_ITEM_SAVE())
+                       return LIST_ITEM_SAVE_LABEL;
+       } else {
+               if (index == 0)
+                       return "[..]";
+               index--;
+               if (index < MAX_COMMAND_KEYS && cmds[subcmd].keys[index] > 0) {
+                       g_snprintf(buf,
+                                  BUFSIZE, "%d. %-20s   (%d) ",
+                                  index + 1,
+                                  key2str(cmds[subcmd].keys[index]),
+                                  cmds[subcmd].keys[index]);
+                       return buf;
+               } else if (index == subcmd_addpos) {
+                       g_snprintf(buf, BUFSIZE, _("%d. Add new key "), index + 1);
+                       return buf;
+               }
+       }
 
-  if( subcmd <0 )
-    {
-      if( index<command_list_length )
-       return cmds[index].name;
-      else if( index==LIST_ITEM_APPLY() )
-       return LIST_ITEM_APPLY_LABEL;
-      else if( index==LIST_ITEM_SAVE() )
-       return LIST_ITEM_SAVE_LABEL;
-    }
-  else
-  {
-    if( index== 0 )
-      return "[..]";
-    index--;
-    if( index<MAX_COMMAND_KEYS && cmds[subcmd].keys[index]>0 )
-      {
-       snprintf(buf, 
-                BUFSIZE, "%d. %-20s   (%d) ", 
-                index+1, 
-                key2str(cmds[subcmd].keys[index]),
-                cmds[subcmd].keys[index]);
-       return buf;
-      } 
-    else if ( index==subcmd_addpos )
-      {
-       snprintf(buf, BUFSIZE, _("%d. Add new key "), index+1 );
-       return buf;
-      }
-  }
-  
-  return NULL;
+       return NULL;
 }
 
 static void 
@@ -277,7 +281,7 @@ keydef_title(char *str, size_t size)
   if( subcmd<0 )
     return _("Edit key bindings");
   
-  snprintf(str, size, _("Edit keys for %s"), cmds[subcmd].name);
+  g_snprintf(str, size, _("Edit keys for %s"), cmds[subcmd].name);
   return str;
 }
 
@@ -300,66 +304,61 @@ keydef_update(screen_t *screen, mpdclient_t *c)
     }
 }
 
-static int 
+static int
 keydef_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
 {
-  int length = LIST_LENGTH();
-
-  if( subcmd>=0 )
-    length = subcmd_length;
-
-  switch(cmd)
-    {
-    case CMD_PLAY:
-      if( subcmd<0 )
-       {
-         if( lw->selected == LIST_ITEM_APPLY() )
-           apply_keys();
-         else if( lw->selected == LIST_ITEM_SAVE() )
-           {
-             apply_keys();
-             save_keys();
-           }
-         else
-           {
-             subcmd = lw->selected;
-             lw->selected=0;
-             check_subcmd_length();
-           }
-       }
-      else
-       {
-         if( lw->selected == 0 ) /* up */
-           {
-             lw->selected = subcmd;
-             subcmd = -1;
-           }
-         else
-           assign_new_key(screen->status_window.w, 
-                          subcmd,
-                          lw->selected-STATIC_SUB_ITEMS);
+       int length = LIST_LENGTH();
+
+       if (subcmd >= 0)
+               length = subcmd_length;
+
+       switch(cmd) {
+       case CMD_PLAY:
+               if( subcmd<0 ) {
+                       if( lw->selected == LIST_ITEM_APPLY() )
+                               apply_keys();
+                       else if( lw->selected == LIST_ITEM_SAVE() ) {
+                               apply_keys();
+                               save_keys();
+                       } else {
+                               subcmd = lw->selected;
+                               lw->selected=0;
+                               check_subcmd_length();
+                       }
+               } else {
+                       if (lw->selected == 0) { /* up */
+                               lw->selected = subcmd;
+                               subcmd = -1;
+                       } else
+                               assign_new_key(screen->status_window.w,
+                                              subcmd,
+                                              lw->selected-STATIC_SUB_ITEMS);
+               }
+               lw->repaint = 1;
+               lw->clear = 1;
+               return 1;
+       case CMD_DELETE:
+               if (subcmd >= 0 && lw->selected - STATIC_SUB_ITEMS >= 0)
+                       delete_key(subcmd, lw->selected - STATIC_SUB_ITEMS);
+               return 1;
+               break;
+       case CMD_SAVE_PLAYLIST:
+               apply_keys();
+               save_keys();
+               break;
+       case CMD_LIST_FIND:
+       case CMD_LIST_RFIND:
+       case CMD_LIST_FIND_NEXT:
+       case CMD_LIST_RFIND_NEXT:
+               return screen_find(screen,
+                                  lw,  length,
+                                  cmd, list_callback, NULL);
+
+       default:
+               break;
        }
-      lw->repaint = 1;
-      lw->clear = 1;
-      return 1;
-    case CMD_DELETE:
-      if( subcmd>=0 && lw->selected-STATIC_SUB_ITEMS>=0 )
-       delete_key(subcmd, lw->selected-STATIC_SUB_ITEMS);
-      return 1;
-      break;
-    case CMD_LIST_FIND:
-    case CMD_LIST_RFIND:
-    case CMD_LIST_FIND_NEXT:
-    case CMD_LIST_RFIND_NEXT:
-      return screen_find(screen, c, 
-                        lw,  length,
-                        cmd, list_callback);
-
-    default:
-      break;
-    }
 
-  return list_window_cmd(lw, length, cmd);
+       return list_window_cmd(lw, length, cmd);
 }
 
 static list_window_t *