[BACK]Return to window-customize.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/window-customize.c between version 1.3 and 1.4

version 1.3, 2020/05/16 16:35:13 version 1.4, 2020/06/16 08:18:34
Line 76 
Line 76 
         WINDOW_CUSTOMIZE_PANE          WINDOW_CUSTOMIZE_PANE
 };  };
   
   enum window_customize_change {
           WINDOW_CUSTOMIZE_UNSET,
           WINDOW_CUSTOMIZE_RESET,
   };
   
 struct window_customize_itemdata {  struct window_customize_itemdata {
         struct window_customize_modedata        *data;          struct window_customize_modedata        *data;
         enum window_customize_scope              scope;          enum window_customize_scope              scope;
Line 101 
Line 106 
         u_int                                     item_size;          u_int                                     item_size;
   
         struct cmd_find_state                     fs;          struct cmd_find_state                     fs;
           enum window_customize_change              change;
 };  };
   
 static uint64_t  static uint64_t
Line 380 
Line 386 
         enum window_customize_scope       scope;          enum window_customize_scope       scope;
   
         top = mode_tree_add(data->data, NULL, NULL, tag, title, NULL, 0);          top = mode_tree_add(data->data, NULL, NULL, tag, title, NULL, 0);
           mode_tree_no_tag(top);
   
         /*          /*
          * We get the options from the first tree, but build it using the           * We get the options from the first tree, but build it using the
Line 452 
Line 459 
   
         xasprintf(&title, "Key Table - %s", kt->name);          xasprintf(&title, "Key Table - %s", kt->name);
         top = mode_tree_add(data->data, NULL, NULL, tag, title, NULL, 0);          top = mode_tree_add(data->data, NULL, NULL, tag, title, NULL, 0);
           mode_tree_no_tag(top);
         free(title);          free(title);
   
         ft = format_create_from_state(NULL, NULL, fs);          ft = format_create_from_state(NULL, NULL, fs);
Line 476 
Line 484 
                 item->scope = WINDOW_CUSTOMIZE_KEY;                  item->scope = WINDOW_CUSTOMIZE_KEY;
                 item->table = xstrdup(kt->name);                  item->table = xstrdup(kt->name);
                 item->key = bd->key;                  item->key = bd->key;
                   item->name = xstrdup(key_string_lookup_key(item->key, 0));
                   item->idx = -1;
   
                 expanded = format_expand(ft, data->format);                  expanded = format_expand(ft, data->format);
                 child = mode_tree_add(data->data, top, item, (uint64_t)bd,                  child = mode_tree_add(data->data, top, item, (uint64_t)bd,
Line 488 
Line 498 
                 mti = mode_tree_add(data->data, child, item,                  mti = mode_tree_add(data->data, child, item,
                     tag|(bd->key << 3)|(0 << 1)|1, "Command", text, -1);                      tag|(bd->key << 3)|(0 << 1)|1, "Command", text, -1);
                 mode_tree_draw_as_parent(mti);                  mode_tree_draw_as_parent(mti);
                   mode_tree_no_tag(mti);
                 free(text);                  free(text);
   
                 if (bd->note != NULL)                  if (bd->note != NULL)
Line 497 
Line 508 
                 mti = mode_tree_add(data->data, child, item,                  mti = mode_tree_add(data->data, child, item,
                     tag|(bd->key << 3)|(1 << 1)|1, "Note", text, -1);                      tag|(bd->key << 3)|(1 << 1)|1, "Note", text, -1);
                 mode_tree_draw_as_parent(mti);                  mode_tree_draw_as_parent(mti);
                   mode_tree_no_tag(mti);
                 free(text);                  free(text);
   
                 if (bd->flags & KEY_BINDING_REPEAT)                  if (bd->flags & KEY_BINDING_REPEAT)
Line 506 
Line 518 
                 mti = mode_tree_add(data->data, child, item,                  mti = mode_tree_add(data->data, child, item,
                     tag|(bd->key << 3)|(2 << 1)|1, "Repeat", flag, -1);                      tag|(bd->key << 3)|(2 << 1)|1, "Repeat", flag, -1);
                 mode_tree_draw_as_parent(mti);                  mode_tree_draw_as_parent(mti);
                   mode_tree_no_tag(mti);
   
                 bd = key_bindings_next(kt, bd);                  bd = key_bindings_next(kt, bd);
         }          }
Line 1125 
Line 1138 
 window_customize_unset_option(struct window_customize_modedata *data,  window_customize_unset_option(struct window_customize_modedata *data,
     struct window_customize_itemdata *item)      struct window_customize_itemdata *item)
 {  {
         struct options_entry                    *o;          struct options_entry    *o;
         const struct options_table_entry        *oe;  
   
         if (item == NULL || !window_customize_check_item(data, item, NULL))          if (item == NULL || !window_customize_check_item(data, item, NULL))
                 return;                  return;
Line 1134 
Line 1146 
         o = options_get(item->oo, item->name);          o = options_get(item->oo, item->name);
         if (o == NULL)          if (o == NULL)
                 return;                  return;
         if (item->idx != -1) {          if (item->idx != -1 && item == mode_tree_get_current(data->data))
                 if (item == mode_tree_get_current(data->data))                  mode_tree_up(data->data, 0);
                         mode_tree_up(data->data, 0);          options_remove_or_default(o, item->idx, NULL);
                 options_array_set(o, item->idx, NULL, 0, NULL);  }
   
   static void
   window_customize_reset_option(struct window_customize_modedata *data,
       struct window_customize_itemdata *item)
   {
           struct options          *oo;
           struct options_entry    *o;
   
           if (item == NULL || !window_customize_check_item(data, item, NULL))
                 return;                  return;
           if (item->idx != -1)
                   return;
   
           oo = item->oo;
           while (oo != NULL) {
                   o = options_get_only(item->oo, item->name);
                   if (o != NULL)
                           options_remove_or_default(o, -1, NULL);
                   oo = options_get_parent(oo);
         }          }
         oe = options_table_entry(o);  
         if (oe != NULL &&  
             options_owner(o) != global_options &&  
             options_owner(o) != global_s_options &&  
             options_owner(o) != global_w_options)  
                 options_remove(o);  
         else  
                 options_default(options_owner(o), oe);  
 }  }
   
 static int  static int
Line 1286 
Line 1308 
 }  }
   
 static void  static void
 window_customize_unset_each(void *modedata, void *itemdata,  window_customize_reset_key(struct window_customize_modedata *data,
       struct window_customize_itemdata *item)
   {
           struct key_table        *kt;
           struct key_binding      *dd, *bd;
   
           if (item == NULL || !window_customize_get_key(item, &kt, &bd))
                   return;
   
           dd = key_bindings_get_default(kt, bd->key);
           if (dd != NULL && bd->cmdlist == dd->cmdlist)
                   return;
           if (dd == NULL && item == mode_tree_get_current(data->data)) {
                   mode_tree_collapse_current(data->data);
                   mode_tree_up(data->data, 0);
           }
           key_bindings_reset(kt->name, bd->key);
   }
   
   static void
   window_customize_change_each(void *modedata, void *itemdata,
     __unused struct client *c, __unused key_code key)      __unused struct client *c, __unused key_code key)
 {  {
           struct window_customize_modedata        *data = modedata;
         struct window_customize_itemdata        *item = itemdata;          struct window_customize_itemdata        *item = itemdata;
   
         if (item->scope == WINDOW_CUSTOMIZE_KEY)          switch (data->change) {
                 window_customize_unset_key(modedata, item);          case WINDOW_CUSTOMIZE_UNSET:
         else {                  if (item->scope == WINDOW_CUSTOMIZE_KEY)
                 window_customize_unset_option(modedata, item);                          window_customize_unset_key(data, item);
                 options_push_changes(item->name);                  else
                           window_customize_unset_option(data, item);
                   break;
           case WINDOW_CUSTOMIZE_RESET:
                   if (item->scope == WINDOW_CUSTOMIZE_KEY)
                           window_customize_reset_key(data, item);
                   else
                           window_customize_reset_option(data, item);
                   break;
         }          }
           if (item->scope != WINDOW_CUSTOMIZE_KEY)
                   options_push_changes(item->name);
 }  }
   
 static int  static int
 window_customize_unset_current_callback(__unused struct client *c,  window_customize_change_current_callback(__unused struct client *c,
     void *modedata, const char *s, __unused int done)      void *modedata, const char *s, __unused int done)
 {  {
         struct window_customize_modedata        *data = modedata;          struct window_customize_modedata        *data = modedata;
Line 1312 
Line 1365 
                 return (0);                  return (0);
   
         item = mode_tree_get_current(data->data);          item = mode_tree_get_current(data->data);
         if (item->scope == WINDOW_CUSTOMIZE_KEY)          switch (data->change) {
                 window_customize_unset_key(data, item);          case WINDOW_CUSTOMIZE_UNSET:
         else {                  if (item->scope == WINDOW_CUSTOMIZE_KEY)
                 window_customize_unset_option(data, item);                          window_customize_unset_key(data, item);
                 options_push_changes(item->name);                  else
                           window_customize_unset_option(data, item);
                   break;
           case WINDOW_CUSTOMIZE_RESET:
                   if (item->scope == WINDOW_CUSTOMIZE_KEY)
                           window_customize_reset_key(data, item);
                   else
                           window_customize_reset_option(data, item);
                   break;
         }          }
           if (item->scope != WINDOW_CUSTOMIZE_KEY)
                   options_push_changes(item->name);
         mode_tree_build(data->data);          mode_tree_build(data->data);
         mode_tree_draw(data->data);          mode_tree_draw(data->data);
         data->wp->flags |= PANE_REDRAW;          data->wp->flags |= PANE_REDRAW;
Line 1326 
Line 1389 
 }  }
   
 static int  static int
 window_customize_unset_tagged_callback(struct client *c, void *modedata,  window_customize_change_tagged_callback(struct client *c, void *modedata,
     const char *s, __unused int done)      const char *s, __unused int done)
 {  {
         struct window_customize_modedata        *data = modedata;          struct window_customize_modedata        *data = modedata;
Line 1336 
Line 1399 
         if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')          if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
                 return (0);                  return (0);
   
         mode_tree_each_tagged(data->data, window_customize_unset_each, c,          mode_tree_each_tagged(data->data, window_customize_change_each, c,
             KEYC_NONE, 0);              KEYC_NONE, 0);
         mode_tree_build(data->data);          mode_tree_build(data->data);
         mode_tree_draw(data->data);          mode_tree_draw(data->data);
Line 1353 
Line 1416 
         struct window_pane                      *wp = wme->wp;          struct window_pane                      *wp = wme->wp;
         struct window_customize_modedata        *data = wme->data;          struct window_customize_modedata        *data = wme->data;
         struct window_customize_itemdata        *item, *new_item;          struct window_customize_itemdata        *item, *new_item;
         int                                      finished;          int                                      finished, idx;
         char                                    *prompt;          char                                    *prompt;
         u_int                                    tagged;          u_int                                    tagged;
   
Line 1390 
Line 1453 
                 options_push_changes(item->name);                  options_push_changes(item->name);
                 mode_tree_build(data->data);                  mode_tree_build(data->data);
                 break;                  break;
           case 'd':
                   if (item == NULL || item->idx != -1)
                           break;
                   xasprintf(&prompt, "Reset %s to default? ", item->name);
                   data->references++;
                   data->change = WINDOW_CUSTOMIZE_RESET;
                   status_prompt_set(c, NULL, prompt, "",
                       window_customize_change_current_callback,
                       window_customize_free_callback, data,
                       PROMPT_SINGLE|PROMPT_NOFORMAT);
                   free(prompt);
                   break;
           case 'D':
                   tagged = mode_tree_count_tagged(data->data);
                   if (tagged == 0)
                           break;
                   xasprintf(&prompt, "Reset %u tagged to default? ", tagged);
                   data->references++;
                   data->change = WINDOW_CUSTOMIZE_RESET;
                   status_prompt_set(c, NULL, prompt, "",
                       window_customize_change_tagged_callback,
                       window_customize_free_callback, data,
                       PROMPT_SINGLE|PROMPT_NOFORMAT);
                   free(prompt);
                   break;
         case 'u':          case 'u':
                 if (item == NULL)                  if (item == NULL)
                         break;                          break;
                 if (item->scope == WINDOW_CUSTOMIZE_KEY) {                  idx = item->idx;
                         xasprintf(&prompt, "Unbind key %s? ",                  if (idx != -1)
                             key_string_lookup_key(item->key, 0));                          xasprintf(&prompt, "Unset %s[%d]? ", item->name, idx);
                 } else                  else
                         xasprintf(&prompt, "Unset option %s? ", item->name);                          xasprintf(&prompt, "Unset %s? ", item->name);
                 data->references++;                  data->references++;
                   data->change = WINDOW_CUSTOMIZE_UNSET;
                 status_prompt_set(c, NULL, prompt, "",                  status_prompt_set(c, NULL, prompt, "",
                     window_customize_unset_current_callback,                      window_customize_change_current_callback,
                     window_customize_free_callback, data,                      window_customize_free_callback, data,
                     PROMPT_SINGLE|PROMPT_NOFORMAT);                      PROMPT_SINGLE|PROMPT_NOFORMAT);
                 free(prompt);                  free(prompt);
Line 1409 
Line 1498 
                 tagged = mode_tree_count_tagged(data->data);                  tagged = mode_tree_count_tagged(data->data);
                 if (tagged == 0)                  if (tagged == 0)
                         break;                          break;
                 xasprintf(&prompt, "Unset or unbind %u tagged? ", tagged);                  xasprintf(&prompt, "Unset %u tagged? ", tagged);
                 data->references++;                  data->references++;
                   data->change = WINDOW_CUSTOMIZE_UNSET;
                 status_prompt_set(c, NULL, prompt, "",                  status_prompt_set(c, NULL, prompt, "",
                     window_customize_unset_tagged_callback,                      window_customize_change_tagged_callback,
                     window_customize_free_callback, data,                      window_customize_free_callback, data,
                     PROMPT_SINGLE|PROMPT_NOFORMAT);                      PROMPT_SINGLE|PROMPT_NOFORMAT);
                 free(prompt);                  free(prompt);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4