Changeset c162fd6
- Timestamp:
- Sep 27, 2011, 5:24:40 PM (13 years ago)
- Parents:
- eba02ec (diff), c8ef50b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
rf271129 rc8ef50b 2796 2796 owl_history_store(hist, owl_editwin_get_text(e), false); 2797 2797 2798 /* Take a reference to the editwin, so that it survives the pop 2799 * context. TODO: We should perhaps refcount or otherwise protect 2800 * the context so that, even if a command pops a context, the 2801 * context itself will last until the command returns. */ 2802 owl_editwin_ref(e); 2798 2803 owl_global_pop_context(&g); 2804 2805 owl_editwin_do_callback(e, false); 2806 owl_editwin_unref(e); 2799 2807 } 2800 2808 … … 2856 2864 owl_global_pop_context(&g); 2857 2865 2858 owl_editwin_do_callback(e );2866 owl_editwin_do_callback(e, true); 2859 2867 owl_editwin_unref(e); 2860 2868 } -
editwin.c
rf271129 rc8ef50b 33 33 oe_excursion *excursions; 34 34 35 void (*callback)(struct _owl_editwin *);35 void (*callback)(struct _owl_editwin *e, bool success); 36 36 void (*destroy_cbdata)(void *); 37 37 void *cbdata; … … 220 220 } 221 221 222 void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin *))222 void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin *, bool)) 223 223 { 224 224 e->callback = cb; 225 225 } 226 226 227 void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin *)227 void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin *, bool) 228 228 { 229 229 return e->callback; … … 248 248 } 249 249 250 void owl_editwin_do_callback(owl_editwin *e) { 251 void (*cb)(owl_editwin*); 252 cb=owl_editwin_get_callback(e); 253 if(!cb) { 250 void owl_editwin_do_callback(owl_editwin *e, bool success) 251 { 252 void (*cb)(owl_editwin *, bool); 253 cb = owl_editwin_get_callback(e); 254 if (!cb) { 254 255 owl_function_error("Internal error: No editwin callback!"); 255 256 } else { 256 /* owl_function_error("text: |%s|", owl_editwin_get_text(e)); */ 257 cb(e); 257 cb(e, success); 258 258 } 259 259 } -
functions.c
r6646fdb rc8ef50b 272 272 } 273 273 274 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))274 owl_editwin *owl_function_start_edit_win(const char *line) 275 275 { 276 276 owl_editwin *e; … … 286 286 g_free(s); 287 287 288 owl_editwin_set_cbdata(e, data, cleanup);289 owl_editwin_set_callback(e, callback);290 288 ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti", 291 289 owl_global_deactivate_editcontext, &g); 292 290 owl_global_push_context_obj(&g, ctx); 293 291 return e; 294 292 } 295 293 … … 309 307 void owl_function_zwrite_setup(owl_zwrite *z) 310 308 { 309 owl_editwin *e; 311 310 /* send a ping if necessary */ 312 311 if (owl_global_is_txping(&g)) { … … 316 315 317 316 owl_function_write_setup("zephyr"); 318 owl_function_start_edit_win(z->zwriteline,319 &owl_callback_zwrite,320 z, (void(*)(void*))owl_zwrite_delete);317 e = owl_function_start_edit_win(z->zwriteline); 318 owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete); 319 owl_editwin_set_callback(e, &owl_callback_zwrite); 321 320 } 322 321 323 322 void owl_function_aimwrite_setup(const char *to) 324 323 { 324 owl_editwin *e; 325 325 /* TODO: We probably actually want an owl_aimwrite object like 326 326 * owl_zwrite. */ 327 327 char *line = g_strdup_printf("aimwrite %s", to); 328 328 owl_function_write_setup("message"); 329 owl_function_start_edit_win(line, 330 &owl_callback_aimwrite, 331 g_strdup(to), 332 g_free); 329 e = owl_function_start_edit_win(line); 330 owl_editwin_set_cbdata(e, g_strdup(to), g_free); 331 owl_editwin_set_callback(e, &owl_callback_aimwrite); 333 332 g_free(line); 334 333 } … … 336 335 void owl_function_loopwrite_setup(void) 337 336 { 337 owl_editwin *e; 338 338 owl_function_write_setup("message"); 339 owl_function_start_edit_win("loopwrite", 340 &owl_callback_loopwrite, 341 NULL, NULL); 342 } 343 344 void owl_callback_zwrite(owl_editwin *e) { 339 e = owl_function_start_edit_win("loopwrite"); 340 owl_editwin_set_callback(e, &owl_callback_loopwrite); 341 } 342 343 void owl_callback_zwrite(owl_editwin *e, bool success) 344 { 345 if (!success) return; 345 346 owl_zwrite *z = owl_editwin_get_cbdata(e); 346 347 owl_function_zwrite(z, owl_editwin_get_text(e)); … … 437 438 } 438 439 439 void owl_callback_aimwrite(owl_editwin *e) { 440 void owl_callback_aimwrite(owl_editwin *e, bool success) 441 { 442 if (!success) return; 440 443 char *to = owl_editwin_get_cbdata(e); 441 444 owl_function_aimwrite(to, owl_editwin_get_text(e), true); … … 501 504 } 502 505 503 void owl_callback_loopwrite(owl_editwin *e) { 506 void owl_callback_loopwrite(owl_editwin *e, bool success) 507 { 508 if (!success) return; 504 509 owl_function_loopwrite(owl_editwin_get_text(e)); 505 510 } … … 912 917 } 913 918 914 void owl_callback_aimlogin(owl_editwin *e) { 919 void owl_callback_aimlogin(owl_editwin *e, bool success) 920 { 921 if (!success) return; 915 922 char *user = owl_editwin_get_cbdata(e); 916 923 owl_function_aimlogin(user, … … 1934 1941 } 1935 1942 1936 void owl_callback_command(owl_editwin *e) 1937 { 1943 void owl_callback_command(owl_editwin *e, bool success) 1944 { 1945 if (!success) return; 1938 1946 char *rv; 1939 1947 const char *line = owl_editwin_get_text(e); … … 1946 1954 } 1947 1955 1948 voidowl_function_start_command(const char *line)1956 owl_editwin *owl_function_start_command(const char *line) 1949 1957 { 1950 1958 owl_editwin *tw; … … 1961 1969 owl_global_push_context_obj(&g, ctx); 1962 1970 owl_editwin_set_callback(tw, owl_callback_command); 1963 } 1964 1965 CALLER_OWN owl_editwin *owl_function_start_question(const char *line) 1971 return tw; 1972 } 1973 1974 owl_editwin *owl_function_start_question(const char *line) 1966 1975 { 1967 1976 owl_editwin *tw; … … 1978 1987 } 1979 1988 1980 CALLER_OWNowl_editwin *owl_function_start_password(const char *line)1989 owl_editwin *owl_function_start_password(const char *line) 1981 1990 { 1982 1991 owl_editwin *tw; -
perl/lib/BarnOwl.pm
ra130fc5 rc8ef50b 9 9 zephyr_stylestrip zephyr_smartstrip_user zephyr_getsubs 10 10 queue_message admin_message 11 start_edit 11 12 start_question start_password start_edit_win 12 13 get_data_dir get_config_dir popless_text popless_ztext … … 105 106 Enqueue a message in the BarnOwl message list, logging it and 106 107 processing it appropriately. C<MESSAGE> should be an instance of 107 BarnOwl::Message or a subclass. Returns the queued message. This 108 is useful for, e.g., deleting a message from the message list. 108 BarnOwl::Message or a subclass. 109 109 110 110 =head2 admin_message HEADER BODY … … 112 112 Display a BarnOwl B<Admin> message, with the given header and body. 113 113 114 =head2 start_edit %ARGS 115 116 Displays a prompt on the screen and lets the user enter text, 117 and calls a callback when the editwin is closed. 118 119 C<%ARGS> must contain the following keys: 120 121 =over 4 122 123 =item prompt 124 125 The line to display on the screen 126 127 =item type 128 129 One of: 130 131 =over 4 132 133 =item edit_win 134 135 Displays the prompt on a line of its own and opens the edit_win. 136 137 =item question 138 139 Displays prompt on the screen and lets the user enter a line of 140 text. 141 142 =item password 143 144 Like question, but echoes the user's input as C<*>s when they 145 input. 146 147 =back 148 149 =item callback 150 151 A Perl subroutine that is called when the user closes the edit_win. 152 C<CALLBACK> gets called with two parameters: the text the user entered, 153 and a C<SUCCESS> boolean parameter which is false if the user canceled 154 the edit_win and true otherwise. 155 156 =back 157 114 158 =head2 start_question PROMPT CALLBACK 115 159 116 Displays C<PROMPT> on the screen and lets the user enter a line of117 text, and calls C<CALLBACK>, which must be a perl subroutine118 reference, with the text the user entered119 120 160 =head2 start_password PROMPT CALLBACK 121 161 122 Like C<start_question>, but echoes the user's input as C<*>s when they123 input.124 125 162 =head2 start_edit_win PROMPT CALLBACK 126 163 127 Like C<start_question>, but displays C<PROMPT> on a line of its own 128 and opens the editwin. If the user cancels the edit win, C<CALLBACK> 129 is not invoked. 164 Roughly equivalent to C<start_edit> called with the appropriate parameters. 165 C<CALLBACK> is only called on success. 166 167 These are deprecated wrappers around L<BarnOwl::start_edit>, and should not 168 be uesd in new code. 169 170 =cut 171 172 sub start_edit { 173 my %args = (@_); 174 BarnOwl::Internal::start_edit($args{type}, $args{prompt}, $args{callback}); 175 } 176 177 sub start_question { 178 my ($prompt, $callback) = @_; 179 BarnOwl::start_edit(type => 'question', prompt => $prompt, callback => sub { 180 my ($text, $success) = @_; 181 $callback->($text) if $success; 182 }); 183 } 184 185 sub start_password { 186 my ($prompt, $callback) = @_; 187 BarnOwl::start_edit(type => 'password', prompt => $prompt, callback => sub { 188 my ($text, $success) = @_; 189 $callback->($text) if $success; 190 }); 191 } 192 193 sub start_edit_win { 194 my ($prompt, $callback) = @_; 195 BarnOwl::start_edit(type => 'edit_win', prompt => $prompt, callback => sub { 196 my ($text, $success) = @_; 197 $callback->($text) if $success; 198 }); 199 } 130 200 131 201 =head2 get_data_dir -
perlconfig.c
rb9517cf rc8ef50b 520 520 } 521 521 522 void owl_perlconfig_edit_callback(owl_editwin *e )522 void owl_perlconfig_edit_callback(owl_editwin *e, bool success) 523 523 { 524 524 SV *cb = owl_editwin_get_cbdata(e); … … 537 537 PUSHMARK(SP); 538 538 XPUSHs(sv_2mortal(text)); 539 XPUSHs(sv_2mortal(newSViv(success))); 539 540 PUTBACK; 540 541 -
perlglue.xs
rf271129 r8ad3964 167 167 } 168 168 169 void170 start_question(line, callback)171 const char *line172 SV *callback173 PREINIT:174 owl_editwin *e;175 CODE:176 {177 if(!SV_IS_CODEREF(callback))178 croak("Callback must be a subref");179 180 e = owl_function_start_question(line);181 182 owl_editwin_set_cbdata(e,183 newSVsv(callback),184 owl_perlconfig_dec_refcnt);185 owl_editwin_set_callback(e, owl_perlconfig_edit_callback);186 }187 188 void189 start_password(line, callback)190 const char *line191 SV *callback192 PREINIT:193 owl_editwin *e;194 CODE:195 {196 if(!SV_IS_CODEREF(callback))197 croak("Callback must be a subref");198 199 e = owl_function_start_password(line);200 201 owl_editwin_set_cbdata(e,202 newSVsv(callback),203 owl_perlconfig_dec_refcnt);204 owl_editwin_set_callback(e, owl_perlconfig_edit_callback);205 }206 207 void208 start_edit_win(line, callback)209 const char *line210 SV *callback211 CODE:212 {213 if(!SV_IS_CODEREF(callback))214 croak("Callback must be a subref");215 216 owl_function_start_edit_win(line,217 owl_perlconfig_edit_callback,218 newSVsv(callback),219 owl_perlconfig_dec_refcnt);220 }221 222 169 223 170 const char * … … 496 443 ival); 497 444 445 void 446 start_edit(edit_type, line, callback) 447 const char *edit_type 448 const char *line 449 SV *callback 450 PREINIT: 451 owl_editwin *e; 452 CODE: 453 { 454 if (!SV_IS_CODEREF(callback)) 455 croak("Callback must be a subref"); 456 457 if (!strcmp(edit_type, "question")) 458 e = owl_function_start_question(line); 459 else if (!strcmp(edit_type, "password")) 460 e = owl_function_start_password(line); 461 else if (!strcmp(edit_type, "edit_win")) 462 e = owl_function_start_edit_win(line); 463 else 464 croak("edit_type must be one of 'password', 'question', 'edit_win', not '%s'", edit_type); 465 466 owl_editwin_set_cbdata(e, newSVsv(callback), owl_perlconfig_dec_refcnt); 467 owl_editwin_set_callback(e, owl_perlconfig_edit_callback); 468 } 469 498 470 MODULE = BarnOwl PACKAGE = BarnOwl::Editwin 499 471 -
viewwin.c
rf271129 rc8ef50b 158 158 } owl_viewwin_search_data; 159 159 160 static void owl_viewwin_callback_search(owl_editwin *e) 161 { 160 static void owl_viewwin_callback_search(owl_editwin *e, bool success) 161 { 162 if (!success) return; 162 163 int consider_current = false; 163 164 const char *line = owl_editwin_get_text(e); -
window.c
rf271129 reba02ec 441 441 } 442 442 443 static bool _owl_window_is_subtree_dirty(owl_window *w) 444 { 445 owl_window *child; 446 447 if (w->dirty) 448 return true; 449 for (child = w->child; 450 child != NULL; 451 child = child->next) { 452 if (child->dirty_subtree) 453 return true; 454 } 455 return false; 456 } 457 443 458 static void _owl_window_redraw_subtree(owl_window *w) 444 459 { 445 460 FuncOneArg ptr = (FuncOneArg)_owl_window_redraw_subtree; 461 446 462 if (!w->dirty_subtree) 447 463 return; 464 448 465 _owl_window_redraw(w); 449 466 owl_window_children_foreach(w, first_arg_only, &ptr); 450 w->dirty_subtree = 0; 467 468 /* Clear the dirty_subtree bit, unless a child doesn't have it 469 * cleared because we dirtied a window in redraw. Dirtying a 470 * non-descendant window during a redraw handler is 471 * discouraged. Redraw will not break, but it is undefined whether 472 * the dirty is delayed to the next event loop iteration. */ 473 if (_owl_window_is_subtree_dirty(w)) { 474 owl_function_debugmsg("subtree still dirty after one iteration!"); 475 } else { 476 w->dirty_subtree = 0; 477 } 451 478 } 452 479
Note: See TracChangeset
for help on using the changeset viewer.