Ticket #1490: mc-4.7.0-pre1.dlgswitch.patch
File mc-4.7.0-pre1.dlgswitch.patch, 31.4 KB (added by angel_il, 15 years ago) |
---|
-
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/config.h.in mc-4.7.0-pre1/config.h.in
old new 130 130 /* Define to 1 if you have the <dlfcn.h> header file. */ 131 131 #undef HAVE_DLFCN_H 132 132 133 /* Define to enable dialog switcher */ 134 #undef HAVE_DLGSWITCH 135 133 136 /* Define to 1 if you have the <dustat.h> header file. */ 134 137 #undef HAVE_DUSTAT_H 135 138 -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/configure mc-4.7.0-pre1/configure
old new 789 789 ac_subst_vars='LTLIBOBJS 790 790 CONS_SAVER_FALSE 791 791 CONS_SAVER_TRUE 792 DLGSWITCH_FALSE 793 DLGSWITCH_TRUE 792 794 CHARSET_FALSE 793 795 CHARSET_TRUE 794 796 ENABLE_MCSERVER_FALSE … … 1097 1099 with_edit 1098 1100 enable_background 1099 1101 enable_charset 1102 enable_dlgswitch 1100 1103 ' 1101 1104 ac_precious_vars='build_alias 1102 1105 host_alias … … 1788 1791 --enable-mcserver Support mc-specific networking file system server [no] 1789 1792 --enable-background Support for background file operations [yes] 1790 1793 --enable-charset Support for charset selection and conversion [no] 1794 --enable-dlgswitch Enable dialog switcher [yes] 1791 1795 1792 1796 Optional Packages: 1793 1797 --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] … … 40789 40793 40790 40794 fi 40791 40795 40796 40797 # Check whether --enable-dlgswitch was given. 40798 if test "${enable_dlgswitch+set}" = set; then 40799 enableval=$enable_dlgswitch; 40800 fi 40801 40802 dlgswitch_msg="no" 40803 if test x$enable_dlgswitch != xno; then 40804 40805 cat >>confdefs.h <<\_ACEOF 40806 #define HAVE_DLGSWITCH 1 40807 _ACEOF 40808 40809 have_dlgswitch=yes 40810 dlgswitch_msg="yes" 40811 { $as_echo "$as_me:$LINENO: enabling dialog switcher" >&5 40812 $as_echo "$as_me: enabling dialog switcher" >&6;} 40813 fi 40814 40792 40815 if test -z "$ac_env_CFLAGS_set"; then 40793 40816 if test -n "$GCC"; then 40794 40817 CFLAGS="$CFLAGS -Wall" … … 40868 40891 CHARSET_FALSE= 40869 40892 fi 40870 40893 40894 if test -n "$have_dlgswitch"; then 40895 DLGSWITCH_TRUE= 40896 DLGSWITCH_FALSE='#' 40897 else 40898 DLGSWITCH_TRUE='#' 40899 DLGSWITCH_FALSE= 40900 fi 40901 40871 40902 if test -n "$cons_saver"; then 40872 40903 CONS_SAVER_TRUE= 40873 40904 CONS_SAVER_FALSE='#' … … 41327 41358 Usually this means the macro was only invoked conditionally." >&2;} 41328 41359 { (exit 1); exit 1; }; } 41329 41360 fi 41361 if test -z "${DLGSWITCH_TRUE}" && test -z "${DLGSWITCH_FALSE}"; then 41362 { { $as_echo "$as_me:$LINENO: error: conditional \"DLGSWITCH\" was never defined. 41363 Usually this means the macro was only invoked conditionally." >&5 41364 $as_echo "$as_me: error: conditional \"DLGSWITCH\" was never defined. 41365 Usually this means the macro was only invoked conditionally." >&2;} 41366 { (exit 1); exit 1; }; } 41367 fi 41330 41368 if test -z "${CONS_SAVER_TRUE}" && test -z "${CONS_SAVER_FALSE}"; then 41331 41369 { { $as_echo "$as_me:$LINENO: error: conditional \"CONS_SAVER\" was never defined. 41332 41370 Usually this means the macro was only invoked conditionally." >&5 … … 43959 43997 With subshell support: ${subshell} 43960 43998 Internal editor: ${edit_msg} 43961 43999 Support for charset: ${charset_msg} 44000 Dialog switcher: ${dlgswitch_msg} 43962 44001 Search type: ${SEARCH_TYPE} 43963 44002 " -
configure.ac
diff -Naur mc-4.7.0-pre1~/configure.ac mc-4.7.0-pre1/configure.ac
old new 509 509 AC_DEFINE(USE_INCLUDED_REGEX, 1, [Use the regex included here]) 510 510 fi 511 511 512 513 dnl 514 dnl Dialog switcher support. 515 dnl 516 AC_ARG_ENABLE([dlgswitch], 517 [ --enable-dlgswitch Enable dialog switcher [[yes]]]) 518 dlgswitch_msg="no" 519 if test x$enable_dlgswitch != xno; then 520 AC_DEFINE(HAVE_DLGSWITCH, 1, [Define to enable dialog switcher]) 521 have_dlgswitch=yes 522 dlgswitch_msg="yes" 523 AC_MSG_NOTICE([enabling dialog switcher]) 524 fi 525 512 526 dnl If default CFLAGS is used with gcc, add -Wall 513 527 if test -z "$ac_env_CFLAGS_set"; then 514 528 if test -n "$GCC"; then … … 539 553 AM_CONDITIONAL(USE_SAMBA_FS, [test -n "$use_smbfs"]) 540 554 AM_CONDITIONAL(ENABLE_MCSERVER, [test x"$enable_mcserver" = "xyes"]) 541 555 AM_CONDITIONAL(CHARSET, [test -n "$have_charset"]) 556 AM_CONDITIONAL(DLGSWITCH, [test -n "$have_dlgswitch"]) 542 557 AM_CONDITIONAL(CONS_SAVER, [test -n "$cons_saver"]) 543 558 544 559 AC_CONFIG_FILES([ … … 629 644 With subshell support: ${subshell} 630 645 Internal editor: ${edit_msg} 631 646 Support for charset: ${charset_msg} 647 Dialog switcher: ${dlgswitch_msg} 632 648 Search type: ${SEARCH_TYPE} 633 649 " -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/edit/edit.h mc-4.7.0-pre1/edit/edit.h
old new 73 73 74 74 int edit_file (const char *_file, int line); 75 75 76 #ifdef HAVE_DLGSWITCH 77 void edit_finish_editor(void *edit_dlg, WEdit *wedit, void *edit_menubar); 78 void edit_run_editor(void *edit_dlg, WEdit *wedit, void *edit_menubar); 79 int edit_file_modified (WEdit *wedit); 80 #endif 81 76 82 const char *edit_get_file_name (const WEdit *edit); 77 83 int edit_get_curs_col (const WEdit *edit); 78 84 const char *edit_get_syntax_type (const WEdit *edit); -
edit/editcmd.c
diff -Naur mc-4.7.0-pre1~/edit/editcmd.c mc-4.7.0-pre1/edit/editcmd.c
old new 67 67 #include "../edit/editcmd_dialogs.h" 68 68 #include "../edit/etags.h" 69 69 70 #ifdef HAVE_DLGSWITCH 71 #include "../src/dlgswitch.h" 72 #endif 73 70 74 /* globals: */ 71 75 72 76 /* search and replace: */ … … 512 516 } 513 517 514 518 edit_set_filename (edit, exp); 519 #ifdef HAVE_DLGSWITCH 520 dlgswitch_update_path(edit->dir, edit->filename); 521 #endif 515 522 g_free (exp); 516 523 edit->modified = 0; 517 524 edit->delete_file = 0; … … 1654 1661 { 1655 1662 if (!edit->modified) 1656 1663 return 1; 1664 #ifdef HAVE_DLGSWITCH 1665 if (edit->widget.parent->soft_exit) { 1666 return 1; 1667 } 1668 #endif 1657 1669 1658 1670 switch (edit_query_dialog3 1659 1671 (_("Quit"), _(" File was modified, Save with exit? "), -
edit/editmenu.c
diff -Naur mc-4.7.0-pre1~/edit/editmenu.c mc-4.7.0-pre1/edit/editmenu.c
old new 547 547 548 548 static Menu *EditMenuBar [N_menus]; 549 549 550 #ifdef HAVE_DLGSWITCH 551 /* Hacks */ 552 static int menu_ref_count = 0; 553 #endif 554 550 555 static void 551 556 edit_init_menu_normal (void) 552 557 { 558 #ifdef HAVE_DLGSWITCH 559 ++menu_ref_count; 560 if (menu_ref_count > 1) return; 561 #endif 553 562 EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu), 554 563 "[Internal File Editor]"); 555 564 EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu), … … 565 574 static void 566 575 edit_init_menu_emacs (void) 567 576 { 577 #ifdef HAVE_DLGSWITCH 578 ++menu_ref_count; 579 if (menu_ref_count > 1) return; 580 #endif 568 581 EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs), 569 582 "[Internal File Editor]"); 570 583 EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs), … … 602 615 edit_done_menu (struct WMenu *wmenu) 603 616 { 604 617 int i; 618 #ifdef HAVE_DLGSWITCH 619 --menu_ref_count; 620 if (menu_ref_count > 0) return; 621 #endif 605 622 for (i = 0; i < N_menus; i++) 606 623 destroy_menu (wmenu->menu[i]); 607 624 } -
edit/editwidget.c
diff -Naur mc-4.7.0-pre1~/edit/editwidget.c mc-4.7.0-pre1/edit/editwidget.c
old new 49 49 #include "../src/menu.h" /* menubar_new() */ 50 50 #include "../src/key.h" /* is_idle() */ 51 51 52 #ifdef HAVE_DLGSWITCH 53 #include "../src/dlgswitch.h" 54 #endif 55 52 56 WEdit *wedit; 53 57 struct WMenu *edit_menubar; 54 58 … … 169 173 } 170 174 } 171 175 176 #ifdef HAVE_DLGSWITCH 177 int 178 edit_file_modified (WEdit *wedit) 179 { 180 return wedit->modified; 181 } 182 183 void 184 edit_finish_editor(void *edit_dlg, WEdit *wedit, void *edit_menubar) 185 { 186 edit_done_menu (edit_menubar); /* editmenu.c */ 187 destroy_dlg (edit_dlg); 188 dlgswitch_remove_current(); 189 } 190 191 void 192 edit_run_editor(void *_edit_dlg, WEdit *_wedit, void *_edit_menubar) 193 { 194 Dlg_head *edit_dlg = _edit_dlg; 195 wedit = _wedit; 196 edit_menubar = _edit_menubar; 197 198 run_dlg (edit_dlg); 199 if (!edit_dlg->soft_exit) { 200 edit_finish_editor(_edit_dlg, _wedit, _edit_menubar); 201 } 202 } 203 #endif 204 172 205 int 173 206 edit_file (const char *_file, int line) 174 207 { … … 205 238 add_widget (edit_dlg, wedit); 206 239 add_widget (edit_dlg, edit_menubar); 207 240 241 #ifdef HAVE_DLGSWITCH 242 dlgswitch_add(edit_dlg, DLG_TYPE_EDIT, _file, wedit, edit_menubar); 243 edit_run_editor(edit_dlg, wedit, edit_menubar); 244 #else 208 245 run_dlg (edit_dlg); 209 246 210 247 edit_done_menu (edit_menubar); /* editmenu.c */ 211 248 212 249 destroy_dlg (edit_dlg); 250 #endif 213 251 214 252 return 1; 215 253 } -
src/Makefile.am
diff -Naur mc-4.7.0-pre1~/src/Makefile.am mc-4.7.0-pre1/src/Makefile.am
old new 49 49 chmod.c chmod.h chown.c chown.h cmd.c cmd.h color.c color.h \ 50 50 command.c command.h complete.c cons.handler.c \ 51 51 cons.saver.h dialog.c dialog.h dir.c dir.h \ 52 dlgswitch.c dlgswitch.h \ 52 53 execute.c execute.h ext.c ext.h file.c filegui.c \ 53 54 filegui.h file.h filenot.c fileopctx.c fileopctx.h find.c \ 54 55 find.h findme.c findme.h fs.h \ -
src/Makefile.in
diff -Naur mc-4.7.0-pre1~/src/Makefile.in mc-4.7.0-pre1/src/Makefile.in
old new 105 105 am__mc_SOURCES_DIST = achown.c achown.h background.c background.h \ 106 106 boxes.c boxes.h chmod.c chmod.h chown.c chown.h cmd.c cmd.h \ 107 107 color.c color.h command.c command.h complete.c cons.handler.c \ 108 cons.saver.h dialog.c dialog.h dir.c dir.h execute.c execute.h \108 cons.saver.h dialog.c dialog.h dir.c dir.h dlgswitch.c dlgswitch.h execute.c execute.h \ 109 109 ext.c ext.h file.c filegui.c filegui.h file.h filenot.c \ 110 110 fileopctx.c fileopctx.h find.c find.h findme.c findme.h fs.h \ 111 111 glibcompat.c glibcompat.h global.h help.c help.h hotlist.c \ … … 126 126 am__objects_1 = achown.$(OBJEXT) background.$(OBJEXT) boxes.$(OBJEXT) \ 127 127 chmod.$(OBJEXT) chown.$(OBJEXT) cmd.$(OBJEXT) color.$(OBJEXT) \ 128 128 command.$(OBJEXT) complete.$(OBJEXT) cons.handler.$(OBJEXT) \ 129 dialog.$(OBJEXT) dir.$(OBJEXT) execute.$(OBJEXT) ext.$(OBJEXT) \129 dialog.$(OBJEXT) dir.$(OBJEXT) dlgswitch.$(OBJEXT) execute.$(OBJEXT) ext.$(OBJEXT) \ 130 130 file.$(OBJEXT) filegui.$(OBJEXT) filenot.$(OBJEXT) \ 131 131 fileopctx.$(OBJEXT) find.$(OBJEXT) findme.$(OBJEXT) \ 132 132 glibcompat.$(OBJEXT) help.$(OBJEXT) hotlist.$(OBJEXT) \ … … 404 404 chmod.c chmod.h chown.c chown.h cmd.c cmd.h color.c color.h \ 405 405 command.c command.h complete.c cons.handler.c \ 406 406 cons.saver.h dialog.c dialog.h dir.c dir.h \ 407 dlgswitch.c dlgswitch.h \ 407 408 execute.c execute.h ext.c ext.h file.c filegui.c \ 408 409 filegui.h file.h filenot.c fileopctx.c fileopctx.h find.c \ 409 410 find.h findme.c findme.h fs.h \ … … 568 569 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cons.saver.Po@am__quote@ 569 570 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dialog.Po@am__quote@ 570 571 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dir.Po@am__quote@ 572 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlgswitch.Po@am__quote@ 571 573 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ecs-test.Po@am__quote@ 572 574 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ecs.Po@am__quote@ 573 575 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/execute.Po@am__quote@ -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/cmd.c mc-4.7.0-pre1/src/cmd.c
old new 85 85 # include "../edit/edit.h" 86 86 #endif 87 87 88 #ifdef HAVE_DLGSWITCH 89 #include "dlgswitch.h" 90 #endif 91 88 92 /* If set and you don't have subshell support,then C-o will give you a shell */ 89 93 int output_starts_shell = 0; 90 94 … … 110 114 static const char *viewer = NULL; 111 115 int move_dir = 0; 112 116 117 #ifdef HAVE_DLGSWITCH 118 if (plain_view || internal) { 119 if (dlgswitch_reuse(DLG_TYPE_VIEW, NULL, filename) == 0) { 120 return 0; 121 } 122 } 123 #endif 113 124 114 125 if (plain_view) { 115 126 int changed_hex_mode = 0; … … 135 146 default_nroff_flag = 1; 136 147 if (changed_magic_flag && !altered_magic_flag) 137 148 default_magic_flag = 1; 149 #ifdef HAVE_DLGSWITCH 150 dlgswitch_process_pending(); 151 #endif 138 152 repaint_screen (); 139 153 return move_dir; 140 154 } … … 149 163 150 164 if (regex_command (filename, view_entry, &move_dir) == 0) { 151 165 mc_internal_viewer (NULL, filename, &move_dir, start_line); 166 #ifdef HAVE_DLGSWITCH 167 dlgswitch_process_pending(); 168 #endif 152 169 repaint_screen (); 153 170 } 154 171 } else { … … 288 305 mc_internal_viewer (command, "", NULL, 0); 289 306 290 307 g_free (command); 308 #ifdef HAVE_DLGSWITCH 309 dlgswitch_process_pending(); 310 #endif 291 311 } 292 312 293 313 void do_edit_at_line (const char *what, int start_line) … … 296 316 297 317 #ifdef USE_INTERNAL_EDIT 298 318 if (use_internal_edit){ 319 #ifdef HAVE_DLGSWITCH 320 if (dlgswitch_reuse(DLG_TYPE_EDIT, NULL, what) == 0) { 321 return; 322 } 323 #endif 299 324 edit_file (what, start_line); 300 325 update_panels (UP_OPTIMIZE, UP_KEEPSEL); 326 #ifdef HAVE_DLGSWITCH 327 dlgswitch_process_pending(); 328 #endif 301 329 repaint_screen (); 302 330 return; 303 331 } -
src/dialog.c
diff -Naur mc-4.7.0-pre1~/src/dialog.c mc-4.7.0-pre1/src/dialog.c
old new 41 41 #include "strutil.h" 42 42 #include "setup.h" /* mouse_close_dialog */ 43 43 44 #ifdef HAVE_DLGSWITCH 45 #include "dlgswitch.h" 46 #endif 47 44 48 #define waddc(w,y1,x1,c) move (w->y+y1, w->x+x1); addch (c) 45 49 46 50 /* Primitive way to check if the the current dialog is our dialog */ … … 661 665 /* first can dlg_callback handle the key */ 662 666 handled = (*h->callback) (h, DLG_KEY, d_key); 663 667 668 #ifdef HAVE_DLGSWITCH 669 if (!handled) { 670 switch (d_key) { 671 case ALT ('`'): 672 dlgswitch_select(); 673 return; 674 case ALT ('.'): 675 dlgswitch_goto_next(); 676 return; 677 case ALT (','): 678 dlgswitch_goto_prev(); 679 return; 680 } 681 } 682 #endif 683 664 684 /* next try the hotkey */ 665 685 if (!handled) 666 686 handled = dlg_try_hotkey (h, d_key); … … 728 748 /* Init the process */ 729 749 void init_dlg (Dlg_head *h) 730 750 { 751 #ifdef HAVE_DLGSWITCH 752 if (h->winch_pending) { 753 h->winch_pending = 0; 754 (*h->callback) (h, DLG_RESIZE, 0); 755 } 756 #endif 757 731 758 /* Initialize dialog manager and widgets */ 732 759 (*h->callback) (h, DLG_INIT, 0); 733 760 dlg_broadcast_msg (h, WIDGET_INIT, 0); -
src/dialog.h
diff -Naur mc-4.7.0-pre1~/src/dialog.h mc-4.7.0-pre1/src/dialog.h
old new 115 115 dlg_cb_fn callback; 116 116 struct Dlg_head *parent; /* Parent dialog */ 117 117 118 #ifdef HAVE_DLGSWITCH 119 /* Hacks */ 120 int soft_exit; 121 int winch_pending; 122 #endif 118 123 } Dlg_head; 119 124 120 125 -
src/dlgswitch.c
diff -Naur mc-4.7.0-pre1~/src/dlgswitch.c mc-4.7.0-pre1/src/dlgswitch.c
old new 1 /* 2 * Copyright (c) 2009 Daniel Borca All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * 18 * Original idea and code: Oleg "Olegarch" Konovalov <olegarch@linuxinside.com> 19 */ 20 21 22 #include <config.h> 23 #include <stdlib.h> 24 #include "global.h" 25 #include "dialog.h" 26 #include "panel.h" 27 #include "wtools.h" 28 #include "main.h" 29 #include "view.h" 30 #include "../edit/edit.h" 31 #include "dlgswitch.h" 32 33 34 #ifdef HAVE_DLGSWITCH 35 36 #define LOG(format, ...) /*fprintf (stderr, format, ## __VA_ARGS__)*/ 37 38 39 struct DLG_NODE { 40 struct DLG_NODE *next; 41 char *name; 42 DLG_TYPE type; 43 Dlg_head *dlg; 44 union { 45 struct { 46 WView *wview; 47 int *move_dir_p; 48 } view_data; 49 struct { 50 WEdit *wedit; 51 void *edit_menubar; 52 } edit_data; 53 } u; 54 }; 55 56 57 static struct DLG_NODE *mc_dialogs = NULL; /* List of (background) dialogs: filemanagers, editors, viewers */ 58 static struct DLG_NODE *mc_cur_dlg = NULL; /* Currently active dialog */ 59 static struct DLG_NODE *mc_manager = NULL; /* File manager dialog - there can be only one */ 60 static int dlgswitch_pending = 0; /* Is there any dialogs that we have to run after returning to the manager from another dialog */ 61 62 63 static unsigned char 64 get_hotkey (int n) 65 { 66 return (n <= 9) ? '0' + n : 'a' + n - 10; 67 } 68 69 70 int 71 dlgswitch_remove_current (void) 72 { 73 struct DLG_NODE *e, *p; 74 75 if (mc_cur_dlg == NULL) { 76 mc_cur_dlg = mc_manager; 77 return 1; 78 } 79 80 for (p = NULL, e = mc_dialogs; e != NULL; p = e, e = e->next) { 81 if (e == mc_cur_dlg) { 82 if (p != NULL) { 83 p->next = e->next; 84 } else { 85 mc_dialogs = e->next; 86 } 87 free(e->name); 88 free(e); 89 if (e == mc_manager) { 90 mc_manager = NULL; 91 } 92 mc_cur_dlg = mc_manager; 93 return 0; 94 } 95 } 96 97 return -1; 98 } 99 100 101 int 102 dlgswitch_add (Dlg_head *h, DLG_TYPE type, const char *name, ...) 103 { 104 struct DLG_NODE *e; 105 106 if (mc_manager != NULL && type == DLG_TYPE_MC) { 107 LOG("BUG: %s: mc_manager=%p\n", __FUNCTION__, mc_manager); 108 return -1; /* XXX bug: cannot have two managers */ 109 } 110 if (mc_manager == NULL && type != DLG_TYPE_MC) { 111 goto err; 112 } 113 114 e = malloc(sizeof(struct DLG_NODE)); 115 if (e) { 116 switch (type) { 117 case DLG_TYPE_VIEW: 118 e->name = concat_dir_and_file(current_panel->cwd, name); 119 if (e->name != NULL) { 120 va_list ap; 121 va_start(ap, name); 122 e->u.view_data.wview = va_arg(ap, WView *); 123 e->u.view_data.move_dir_p = va_arg(ap, int *); 124 va_end(ap); 125 } 126 break; 127 case DLG_TYPE_EDIT: 128 e->name = name ? concat_dir_and_file(current_panel->cwd, name) : strdup("<new>"); 129 if (e->name != NULL) { 130 va_list ap; 131 va_start(ap, name); 132 e->u.edit_data.wedit = va_arg(ap, WEdit *); 133 e->u.edit_data.edit_menubar = va_arg(ap, void *); 134 va_end(ap); 135 } 136 break; 137 case DLG_TYPE_MC: 138 e->name = strdup(name); 139 if (e->name != NULL) { 140 mc_manager = e; 141 } 142 break; 143 default: 144 e->name = NULL; 145 } 146 if (e->name == NULL) { 147 free(e); 148 goto err; 149 } 150 e->dlg = h; 151 e->type = type; 152 e->next = mc_dialogs; 153 mc_dialogs = e; 154 mc_cur_dlg = e; 155 return 0; 156 } 157 158 err: 159 mc_cur_dlg = NULL; 160 return -1; 161 } 162 163 164 int 165 dlgswitch_update_path (const char *dir, const char *file) 166 { 167 char *p; 168 169 if (mc_cur_dlg == NULL) { 170 return -1; 171 } 172 173 if (file == NULL) { 174 return -1; 175 } 176 177 if (dir == NULL) { 178 dir = current_panel->cwd; 179 } 180 181 p = concat_dir_and_file(dir, file); 182 if (p == NULL) { 183 return -1; 184 } 185 186 free(mc_cur_dlg->name); 187 mc_cur_dlg->name = p; 188 189 return 0; 190 } 191 192 193 static int 194 dlgswitch_get_title_len(struct DLG_NODE *e) 195 { 196 int len; 197 switch (e->type) { 198 case DLG_TYPE_VIEW: 199 len = strlen(" View: ") + strlen(e->name); 200 break; 201 case DLG_TYPE_EDIT: 202 len = strlen(" Edit: ") + strlen(e->name); 203 if (edit_file_modified(e->u.edit_data.wedit)) { 204 len += strlen(" (*)"); 205 } 206 break; 207 case DLG_TYPE_MC: 208 len = strlen(" ") + strlen(e->name); 209 break; 210 default: 211 len = 0; 212 } 213 return len; 214 } 215 216 217 static char * 218 dlgswitch_get_title(struct DLG_NODE *e) 219 { 220 char *name; 221 switch (e->type) { 222 case DLG_TYPE_VIEW: 223 name = malloc(strlen(" View: ") + strlen(e->name) + 1); 224 if (name != NULL) { 225 strcpy(name, " View: "); 226 strcat(name, e->name); 227 } 228 break; 229 case DLG_TYPE_EDIT: 230 name = malloc(strlen(" Edit: ") + strlen(e->name) + 1 + strlen(" (*)")); 231 if (name != NULL) { 232 strcpy(name, " Edit: "); 233 strcat(name, e->name); 234 if (edit_file_modified(e->u.edit_data.wedit)) { 235 strcat(name, " (*)"); 236 } 237 } 238 break; 239 case DLG_TYPE_MC: 240 name = malloc(strlen(" ") + strlen(e->name) + 1); 241 if (name != NULL) { 242 strcpy(name, " "); 243 strcat(name, e->name); 244 } 245 break; 246 default: 247 name = NULL; 248 } 249 if (name != NULL && e == mc_cur_dlg) { 250 name[0] = '>'; 251 } 252 return name; 253 } 254 255 256 void 257 dlgswitch_process_pending(void) 258 { 259 while (dlgswitch_pending) { 260 dlgswitch_pending = 0; 261 262 mc_cur_dlg->dlg->soft_exit = 0; 263 264 switch (mc_cur_dlg->type) { 265 case DLG_TYPE_VIEW: 266 view_run_viewer(mc_cur_dlg->dlg, mc_cur_dlg->u.view_data.wview, NULL); /* XXX move_dir_p may not be valid anymore */ 267 break; 268 case DLG_TYPE_EDIT: 269 edit_run_editor(mc_cur_dlg->dlg, mc_cur_dlg->u.edit_data.wedit, mc_cur_dlg->u.edit_data.edit_menubar); 270 update_panels (UP_OPTIMIZE, UP_KEEPSEL); /* XXX a bit heavy-handed */ 271 break; 272 case DLG_TYPE_MC: 273 /* XXX DLG_TYPE_MC can't be pending */ 274 default: 275 break; 276 } 277 } 278 279 do_refresh(); 280 } 281 282 283 static void 284 dlgswitch_goto(struct DLG_NODE *e) 285 { 286 if (mc_cur_dlg != e) { 287 struct DLG_NODE *old_dlg = mc_cur_dlg; 288 mc_cur_dlg = e; 289 if (old_dlg->type != DLG_TYPE_MC) { 290 old_dlg->dlg->running = 0; 291 old_dlg->dlg->soft_exit = 1; 292 if (e->type != DLG_TYPE_MC) { 293 dlgswitch_pending = 1; 294 } else { 295 do_refresh(); 296 } 297 } else { 298 dlgswitch_pending = 1; 299 dlgswitch_process_pending(); 300 } 301 } 302 } 303 304 305 void 306 dlgswitch_select (void) 307 { 308 struct DLG_NODE *e; 309 int rows, cols; 310 int i; 311 312 int rv; 313 Listbox *listbox; 314 315 if (midnight_shutdown || mc_cur_dlg == NULL) { 316 return; 317 } 318 319 if (mc_dialogs == NULL) { 320 return; 321 } 322 323 rows = 0; 324 cols = 0; 325 for (e = mc_dialogs; e != NULL; e = e->next) { 326 int len = dlgswitch_get_title_len(e); 327 if (cols < len) { 328 cols = len; 329 } 330 rows++; 331 } 332 333 listbox = create_listbox_window(cols + 2, rows, _(" Dialogs "), "[Dialog selector]"); 334 if (listbox == NULL) { 335 return; 336 } 337 for (i = 0, e = mc_dialogs; e != NULL; e = e->next, i++) { 338 char *text = dlgswitch_get_title(e); 339 LISTBOX_APPEND_TEXT(listbox, get_hotkey(i), text, NULL); 340 free(text); 341 } 342 rv = run_listbox(listbox); 343 if (rv != -1) { 344 for (i = 0, e = mc_dialogs; e != NULL; e = e->next, i++) { 345 if (i == rv) { 346 dlgswitch_goto(e); 347 break; 348 } 349 } 350 } 351 } 352 353 354 void 355 dlgswitch_goto_next (void) 356 { 357 struct DLG_NODE *e; 358 359 if (midnight_shutdown || mc_cur_dlg == NULL) { 360 return; 361 } 362 363 for (e = mc_dialogs; e != NULL; e = e->next) { 364 if (e == mc_cur_dlg) { 365 e = e->next; 366 if (!e) { 367 e = mc_dialogs; 368 } 369 dlgswitch_goto(e); 370 break; 371 } 372 } 373 } 374 375 376 void 377 dlgswitch_goto_prev (void) 378 { 379 struct DLG_NODE *e, *p; 380 381 if (midnight_shutdown || mc_cur_dlg == NULL) { 382 return; 383 } 384 385 for (p = NULL, e = mc_dialogs; e != NULL; p = e, e = e->next) { 386 if (e == mc_cur_dlg) { 387 if (!p) { 388 for (p = mc_dialogs; p->next != NULL; p = p->next) { 389 } 390 } 391 dlgswitch_goto(p); 392 break; 393 } 394 } 395 } 396 397 398 int 399 dlgswitch_reuse (DLG_TYPE type, const char *dir, const char *file) 400 { 401 struct DLG_NODE *e; 402 403 if (midnight_shutdown || mc_cur_dlg != mc_manager) { 404 LOG("BUG: %s: midnight_shutdown=%d, mc_cur_dlg=%p, mc_manager=%p\n", __FUNCTION__, midnight_shutdown, mc_cur_dlg, mc_manager); 405 return -1; /* XXX bug? */ 406 } 407 408 if ((type == DLG_TYPE_VIEW || type == DLG_TYPE_EDIT) && file != NULL) { 409 char *filename; 410 if (dir == NULL) { 411 dir = current_panel->cwd; 412 } 413 filename = concat_dir_and_file(dir, file); 414 if (filename == NULL) { 415 return -1; 416 } 417 for (e = mc_dialogs; e != NULL; e = e->next) { 418 if (type == e->type && !strcmp(filename, e->name)) { 419 free(filename); 420 dlgswitch_goto(e); 421 return 0; 422 } 423 } 424 free(filename); 425 } 426 427 return -1; 428 } 429 430 431 void 432 dlgswitch_before_exit (void) 433 { 434 struct DLG_NODE *e = mc_dialogs; 435 436 while (e != NULL) { 437 mc_cur_dlg = e; 438 e = mc_cur_dlg->next; 439 switch (mc_cur_dlg->type) { 440 case DLG_TYPE_VIEW: 441 view_finish_viewer(mc_cur_dlg->dlg, mc_cur_dlg->u.view_data.wview, NULL); /* XXX move_dir_p may not be valid anymore */ 442 break; 443 case DLG_TYPE_EDIT: 444 if (edit_file_modified(mc_cur_dlg->u.edit_data.wedit)) { 445 dlgswitch_pending = 1; 446 dlgswitch_process_pending(); 447 break; 448 } 449 edit_finish_editor(mc_cur_dlg->dlg, mc_cur_dlg->u.edit_data.wedit, mc_cur_dlg->u.edit_data.edit_menubar); 450 break; 451 case DLG_TYPE_MC: 452 default: 453 break; 454 } 455 } 456 457 dlgswitch_remove_current(); 458 } 459 460 461 void 462 dlgswitch_got_winch (void) 463 { 464 struct DLG_NODE *e; 465 for (e = mc_dialogs; e != NULL; e = e->next) { 466 if (e != mc_cur_dlg && e != mc_manager) { 467 e->dlg->winch_pending = 1; 468 } 469 } 470 } 471 #endif -
src/dlgswitch.h
diff -Naur mc-4.7.0-pre1~/src/dlgswitch.h mc-4.7.0-pre1/src/dlgswitch.h
old new 1 #ifndef DLGSWITCH_H_included 2 #define DLGSWITCH_H_included 3 4 typedef enum { 5 DLG_TYPE_VIEW, 6 DLG_TYPE_EDIT, 7 DLG_TYPE_MC 8 } DLG_TYPE; 9 10 int dlgswitch_remove_current (void); 11 int dlgswitch_add (Dlg_head *h, DLG_TYPE type, const char *name, ...); 12 int dlgswitch_update_path (const char *dir, const char *file); 13 void dlgswitch_process_pending(void); 14 void dlgswitch_select (void); 15 void dlgswitch_goto_next (void); 16 void dlgswitch_goto_prev (void); 17 int dlgswitch_reuse (DLG_TYPE type, const char *dir, const char *file); 18 void dlgswitch_before_exit (void); 19 void dlgswitch_got_winch (void); 20 21 #endif -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/ext.c mc-4.7.0-pre1/src/ext.c
old new 45 45 #include "layout.h" 46 46 #include "../src/search/search.h" 47 47 48 #ifdef HAVE_DLGSWITCH 49 #include "dlgswitch.h" 50 #endif 51 48 52 /* If set, we execute the file command to check the file type */ 49 53 int use_file_to_check_type = 1; 50 54 … … 254 258 default_hex_mode = def_hex_mode; 255 259 if (changed_nroff_flag && !altered_nroff_flag) 256 260 default_nroff_flag = def_nroff_flag; 261 #ifdef HAVE_DLGSWITCH 262 dlgswitch_process_pending(); 263 #endif 257 264 repaint_screen (); 258 265 } else if (is_cd) { 259 266 char *q; -
src/layout.c
diff -Naur mc-4.7.0-pre1~/src/layout.c mc-4.7.0-pre1/src/layout.c
old new 73 73 74 74 #include "setup.h" /* For save_setup() */ 75 75 76 #ifdef HAVE_DLGSWITCH 77 #include "dlgswitch.h" 78 #endif 79 76 80 /* Controls the display of the rotating dash on the verbose mode */ 77 81 int nice_rotating_dash = 1; 78 82 … … 798 802 799 803 /* Inform currently running dialog */ 800 804 (*current_dlg->callback) (current_dlg, DLG_RESIZE, 0); 805 #ifdef HAVE_DLGSWITCH 806 dlgswitch_got_winch(); 807 #endif 801 808 802 809 #ifdef RESIZABLE_MENUBAR 803 810 menubar_arrange (the_menubar); -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/main.c mc-4.7.0-pre1/src/main.c
old new 97 97 98 98 #include "popt.h" 99 99 100 #ifdef HAVE_DLGSWITCH 101 #include "dlgswitch.h" 102 #endif 103 100 104 /* When the modes are active, left_panel, right_panel and tree_panel */ 101 105 /* Point to a proper data structure. You should check with the functions */ 102 106 /* get_current_type and get_other_type the types of the panels before using */ … … 928 932 #ifdef WITH_BACKGROUND 929 933 {' ', N_("&Background jobs C-x j"), NULL_HOTKEY, jobs_cmd}, 930 934 #endif 935 #ifdef HAVE_DLGSWITCH 936 {' ', N_("Dialog &list M-`"), NULL_HOTKEY, dlgswitch_select}, 937 {' ', N_("Dialog &next M-."), NULL_HOTKEY, dlgswitch_goto_next}, 938 {' ', N_("Dialog pre&v M-,"), NULL_HOTKEY, dlgswitch_goto_prev}, 939 #endif 931 940 {' ', "", NULL_HOTKEY, 0}, 932 941 #ifdef USE_EXT2FSLIB 933 942 {' ', N_("&Undelete files (ext2fs only)"), NULL_HOTKEY, undelete_cmd}, … … 1866 1875 /* Check if we were invoked as an editor or file viewer */ 1867 1876 if (!mc_maybe_editor_or_viewer ()) { 1868 1877 setup_mc (); 1878 #ifdef HAVE_DLGSWITCH 1879 dlgswitch_add(midnight_dlg, DLG_TYPE_MC, _("Midnight Commander")); 1880 #endif 1869 1881 setup_panels_and_run_mc (); 1870 1882 1871 1883 /* Program end */ 1872 1884 midnight_shutdown = 1; 1885 #ifdef HAVE_DLGSWITCH 1886 dlgswitch_before_exit(); 1887 #endif 1873 1888 1874 1889 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */ 1875 1890 if (last_wd_file && vfs_current_is_local ()) { -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/user.c mc-4.7.0-pre1/src/user.c
old new 50 50 #include "wtools.h" 51 51 #include "view.h" /* for default_* externs */ 52 52 53 #ifdef HAVE_DLGSWITCH 54 #include "dlgswitch.h" 55 #endif 56 53 57 #define MAX_ENTRIES 16 54 58 #define MAX_ENTRY_LEN 60 55 59 … … 695 699 if (run_view) { 696 700 run_view = 0; 697 701 mc_internal_viewer (file_name, NULL, &run_view, 0); 702 #ifdef HAVE_DLGSWITCH 703 dlgswitch_process_pending(); 704 #endif 698 705 } else { 699 706 /* execute the command indirectly to allow execution even 700 707 * on no-exec filesystems. */ -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/view.c mc-4.7.0-pre1/src/view.c
old new 71 71 #include "strutil.h" 72 72 #include "../src/search/search.h" 73 73 74 #ifdef HAVE_DLGSWITCH 75 #include "dlgswitch.h" 76 #endif 77 74 78 /* Block size for reading files in parts */ 75 79 #define VIEW_PAGE_SIZE ((size_t) 8192) 76 80 … … 3808 3812 /* {{{ External interface }}} */ 3809 3813 3810 3814 /* Real view only */ 3815 3816 #ifdef HAVE_DLGSWITCH 3817 void 3818 view_finish_viewer (Dlg_head *view_dlg, WView *wview, int *move_dir_p) 3819 { 3820 if (move_dir_p) 3821 *move_dir_p = wview->move_dir; 3822 destroy_dlg (view_dlg); 3823 dlgswitch_remove_current(); 3824 } 3825 3826 void 3827 view_run_viewer (Dlg_head *view_dlg, WView *wview, int *move_dir_p) 3828 { 3829 run_dlg (view_dlg); 3830 if (!view_dlg->soft_exit) { 3831 view_finish_viewer(view_dlg, wview, move_dir_p); 3832 } 3833 } 3834 #endif 3835 3811 3836 int 3812 3837 mc_internal_viewer (const char *command, const char *file, 3813 3838 int *move_dir_p, int start_line) … … 3829 3854 add_widget (view_dlg, bar); 3830 3855 add_widget (view_dlg, wview); 3831 3856 3857 #ifdef HAVE_DLGSWITCH 3858 if (move_dir_p) 3859 *move_dir_p = 0; 3860 succeeded = view_load (wview, command, file, start_line); 3861 if (succeeded) { 3862 dlgswitch_add(view_dlg, DLG_TYPE_VIEW, file, wview, move_dir_p); 3863 view_run_viewer(view_dlg, wview, move_dir_p); 3864 } else { 3865 destroy_dlg (view_dlg); 3866 } 3867 #else 3832 3868 succeeded = view_load (wview, command, file, start_line); 3833 3869 if (succeeded) { 3834 3870 run_dlg (view_dlg); … … 3839 3875 *move_dir_p = 0; 3840 3876 } 3841 3877 destroy_dlg (view_dlg); 3878 #endif 3842 3879 3843 3880 return succeeded; 3844 3881 } -
mc-4.7.0-pre1
diff -Naur mc-4.7.0-pre1~/src/view.h mc-4.7.0-pre1/src/view.h
old new 38 38 extern int altered_nroff_flag; 39 39 extern int mcview_remember_file_position; 40 40 41 #ifdef HAVE_DLGSWITCH 42 void view_run_viewer (Dlg_head *view_dlg, WView *wview, int *move_dir_p); 43 void view_finish_viewer (Dlg_head *view_dlg, WView *wview, int *move_dir_p); 44 #endif 45 41 46 #endif