home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _f6553294e873267d6c3fd1db42a3a591 < prev    next >
Encoding:
Text File  |  2004-06-01  |  12.0 KB  |  430 lines

  1. # Gedi master advanced text editor.
  2.  
  3. use Tk::TextEdit;
  4.  
  5. use vars qw/$TOP/;
  6.  
  7. my $TOP;
  8. my $text_frame;
  9. my $counter_frame;
  10. my $textwindow;
  11. my $current_line_label;
  12. my $total_line_label;
  13. my $current_column_label;
  14. my $insert_overstrike_mode_label;
  15. my $about_pop_up_reference;
  16. my $menu;
  17. my $help_menu;
  18.  
  19. sub about_pop_up
  20. {
  21.     my $name = ref($about_pop_up_reference);
  22.     if (defined($about_pop_up_reference))
  23.         {
  24.         $about_pop_up_reference->raise;
  25.         $about_pop_up_reference->focus;
  26.         }
  27.     else
  28.         {
  29.         my $pop = $TOP->Toplevel();
  30.         $pop->title("About");
  31.  
  32.         $pop->Label(-text=>"Gedi (Gregs EDItor)")->pack();
  33.         $pop->Label(-text=>"Ver. 1.0")->pack();
  34.         $pop->Label(-text=>"Copyright 1999")->pack();
  35.         $pop->Label(-text=>"Greg London")->pack();
  36.         $pop->Label(-text=>"All Rights Reserved.")->pack();
  37.         $pop->Label(-text=>"This program is free software.")->pack();
  38.         $pop->Label(-text=>"You can redistribute it and/or")->pack();
  39.         $pop->Label(-text=>"modify it under the same terms")->pack();
  40.         $pop->Label(-text=>"as Perl itself.")->pack();
  41.         $pop->Label(-text=>"Special Thanks to")->pack();
  42.         $pop->Label(-text=>"Nick Ing-Simmons.")->pack();
  43.  
  44.         my $button_ok = $pop->Button(-text=>'OK',
  45.             -command => sub {$pop->destroy();
  46.             $about_pop_up_reference = undef;
  47.             } )
  48.             ->pack();
  49.         $pop->resizable('no','no');
  50.         $about_pop_up_reference = $pop;
  51.         }
  52. }
  53.  
  54.  
  55. sub update_indicators
  56. {
  57.     my ($line,$column)= split(/\./,$textwindow->index('insert'));
  58.     $current_line_label->configure (-text=> "line: $line");
  59.     $current_column_label->configure (-text=> "column: $column");
  60.  
  61.     my ($last_line,$last_col) = split(/\./,$textwindow->index('end'));
  62.     $total_line_label->configure (-text=> "total lines: $last_line");
  63.  
  64.     my $mode = $textwindow->OverstrikeMode;
  65.     my $overstrke_insert='Insert Mode';
  66.     if ($mode)
  67.         {$overstrke_insert='Overstrike Mode';}
  68.     $insert_overstrike_mode_label->configure
  69.         (-text=> "$overstrke_insert");
  70.  
  71.     my $filename = $textwindow->FileName;
  72.     $filename = 'NoName' unless(defined($filename));
  73.     my $edit_flag='';
  74.     if($textwindow->numberChanges)
  75.          {$edit_flag='edited';}
  76.     $TOP->configure(-title => "Gedi  $edit_flag $filename");
  77.     $textwindow->idletasks;
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. sub Gedi {
  87.     my($demo) = @_;
  88.     $TOP = $MW->WidgetDemo(
  89.         -name             => $demo,
  90.         -text             => 'Gedi master advanced text editor ',
  91.     -geometry_manager => 'grid',
  92.         -title            => 'GEDI Text Editor',
  93.         -iconname         => 'GEDI',
  94.     );
  95.  
  96. $TOP->withdraw;
  97.  
  98. $text_frame = $TOP->Frame->pack
  99.     (-anchor=>'nw', -expand=>'yes', -fill => 'both'); # autosizing
  100. $counter_frame = $TOP->Frame->pack(-anchor=>'nw');
  101.  
  102. $textwindow = $text_frame->Scrolled(
  103.     'TextEdit',
  104.     exportselection => 'true',  # 'sel' tag is associated with selections
  105.     # initial height, if it isnt 1, then autosizing fails
  106.     # once window shrinks below height
  107.     # and the line counters go off the screen.
  108.     # seems to be a problem with the Tk::pack command;
  109. #    height => 40,
  110.     -background => 'white',
  111.     -wrap=> 'none',
  112.     -setgrid => 'true', # use this for autosizing
  113.     -scrollbars =>'se')
  114.     -> pack(-expand => 'yes' , -fill => 'both');    # autosizing
  115.  
  116. $TOP->protocol('WM_DELETE_WINDOW'=>
  117.  sub{$textwindow->ConfirmExit;}
  118.  );
  119.  
  120. $SIG{INT} = sub {$textwindow->ConfirmExit;};
  121.  
  122. $current_line_label = $counter_frame
  123.     -> Label(-text=>'line: 1')
  124.     -> grid(-row=>1,-column=>1, -sticky=>'nw' );
  125.  
  126. $total_line_label = $counter_frame
  127.     -> Label(-text=>'total lines: 1')
  128.     -> grid(-row=>2,-column=>1, -sticky=>'nw' );
  129.  
  130. $current_column_label = $counter_frame
  131.     -> Label(-text=>'column: 0')
  132.     -> grid(-row=>3,-column=>1, -sticky=>'nw' );
  133.  
  134. $insert_overstrike_mode_label = $counter_frame
  135.     -> Label(-text=>' ')
  136.     -> grid(-row=>5,-column=>1, -sticky=>'nw' );
  137.  
  138. $textwindow->SetGUICallbacks (
  139.  [
  140.   \&update_indicators,
  141.   sub{$textwindow->HighlightAllPairsBracketingCursor}
  142.  ]
  143. );
  144.  
  145. $menu = $textwindow->menu;
  146.  
  147. $TOP->configure(-menu => $menu);
  148.  
  149. $help_menu = $menu->cascade(-label=>'~Help', -tearoff => 0, -menuitems => [
  150.          [Command => 'A~bout', -command => \&about_pop_up]
  151.          ]);
  152.  
  153.  
  154. #$TOP->minsize(30,1);
  155. #$TOP->geometry("80x24");
  156.  
  157. while(<DATA>)
  158.     {$textwindow->insert('insert',$_);}
  159. $textwindow->ResetUndo;
  160.  
  161. $textwindow->CallNextGUICallback;
  162.  
  163. # adjust height
  164. $TOP->update;
  165. my $menuheight = ($TOP->wrapper)[1];
  166. my $TOPheight = 30 + $TOP->reqheight + $menuheight;
  167. if ($TOP->screenheight < $TOPheight) {
  168.     $textwindow->GeometryRequest($textwindow->reqwidth, $textwindow->reqheight - ($TOPheight - $TOP->screenheight));
  169. }
  170. $TOP->deiconify;
  171.  
  172. }
  173.  
  174.  
  175. __DATA__
  176.  
  177. Tk800.015 contains many modifications to the
  178. text based modules, as well as new text modules
  179. and an application that uses them all.
  180. Text.pm, TextUndo.pm, TextEdit.pm, and gedi
  181. have all been updated since the release prior
  182. to Tk800.015.
  183.  
  184. This demo contains a rundown of all the features
  185. of the text modules, and
  186.  
  187. What is available in the text modules?
  188. ================================================
  189.  
  190. Text.pm
  191. ========
  192.  
  193. Text.pm is the base text editing module.
  194. Beyond the core functionality of typing text,
  195. Text.pm has built in menu support for basic
  196. editing features such as Find/Replace text,
  197. Copy/Cut/Paste, Goto Line Number, and What
  198. Line Number queries.
  199.  
  200. These functions are available simply by right
  201. clicking the mouse over the text area. Doing
  202. so will cause a pop-up menu to appear which will
  203. contain cascading menus to give access to all of
  204. these new functions.
  205.  
  206. Many of these functions will create their own
  207. pop-up windows. Find/Replace will create a pop-up
  208. window which contains an entry for text to
  209. find, an entry for replace text, a number of
  210. radio buttons to control options such as
  211. case sensitivity, and several command buttons to
  212. perform functions such as Find, Find All,
  213. Replace, Replace All.
  214.  
  215. All of these features have corresponding methods
  216. built into the Text widget. This allows the basic
  217. functions to be built into the widget, and also
  218. allows added features to be built on the lower
  219. level methods as needed. No one should have to
  220. reinvent the wheel when it comes to text editing
  221. features.
  222.  
  223. Insert and Overstrike modes are also supported
  224. in the Text.pm module. Pressing the <Insert>
  225. key will toggle modes back and forth.
  226.  
  227. Column based copy/cut/paste features are also
  228. available in the Text.pm module. They are bound
  229. to the following keys:
  230.  
  231. <F1> clipboardColumnCopy
  232. <F2> clipboardColumnCut
  233. <F3> clipboardColumnPaste
  234.  
  235. Currently, column based operations are beta versions.
  236. They compensate for tabs, but they will not behave
  237. properly unless the text is all the same font, and
  238. is the same width per character.
  239.  
  240. Hopefully some future version of Text.pm will correct
  241. for this deficiency.
  242.  
  243. Column paste should work with overstrike mode.
  244.  
  245.  
  246. TextUndo.pm
  247. =============
  248.  
  249. TextUndo.pm is the second level module, being
  250. derived from the Text.pm module. As it's name
  251. implies, TextUndo supports "UNDO" capability.
  252. It now also supports "REDO" capability.
  253.  
  254. Undo/redo works on user typed commands and
  255. also programmatically, so that any application
  256. that causes text to be inserted or deleted
  257. can be undone/redone, whether it was directly
  258. typed by the user or indirectly through another
  259. method.
  260.  
  261. The undo/redo functions support tags, so that
  262. if you delete text with tags, undo will re-insert
  263. the text and re-tag it as well. This will eventually
  264. allow the text modules to support more sophisticated
  265. word processing type features. Such functionality
  266. should be available in a future release of the
  267. text modules.
  268.  
  269. The TextUndo.pm module also has several added
  270. features to support file based operations.
  271. File based methods include ->Save, ->Load, and
  272. ->Include. All methods take a filename as a
  273. parameter. These methods will create a progress
  274. widget to indicate the progress of the operation.
  275.  
  276. The other feature of the TextUndo.pm module
  277. is the ConfirmDiscard method. This method checks to
  278. see if the text has been modified since it was
  279. last saved. If it has been modified, and the
  280. it will create a pop-up menu asking the user
  281. if they want to save the text to a file before
  282. exiting. This method can easily be tied into
  283. the exit routines, and signal handlers, to provide
  284. a consistent "save before exit?" feel.
  285.  
  286. TextEdit.pm
  287. =============
  288.  
  289. The TextEdit.pm is a new module in prototype version
  290. which adds further features to the text modules.
  291. TextEdit is based off of the TextUndo module,
  292. and so has all of the features of TextUndo and
  293. Text.
  294.  
  295. Features of the TextEdit.pm module include
  296. parenthesis matching. The module looks at the
  297. current cursor position and then tries to find
  298. the parenthesis that bracket the cursor.
  299. Character pairs that are searched for are:
  300. () {} [] "" ''
  301.  
  302. It also checks the position of the pairs to
  303. try to highlight bad positions. The module
  304. assumes that if the pairs are not on the same
  305. line or not on the same column, then there
  306. might be a missing parenthesis somewhere.
  307. Characters that appear to not align are
  308. highlighted in red.
  309.  
  310. (quotations must start and end on the same line)
  311.  
  312.  
  313. PARENTHISIS MATCHING DEMO:
  314. move the cursor to the x between the quotes
  315. on the line below:
  316.  
  317.  
  318. {
  319.         (  )
  320.     (    {      }
  321.         [
  322.     '    ">> x <<"    '
  323.     []    ]
  324.     )
  325.  
  326. }
  327.  
  328. PARENTHESIS MISMATCHING DEMO:
  329. move the cursor to the x between the quotes
  330. on the line below:
  331.  
  332.  
  333. {
  334.         (  )
  335.      ( <<RED possible error        {      }
  336.         [
  337.     '    ">> x <<"    '
  338.     []    ]
  339.     ) <<RED possible error
  340.  
  341. }
  342.  
  343.  
  344.  
  345. Another feature of the TextEdit module is support
  346. for application level indicators which reflect
  347. the status of certain internals.  The line and
  348. column position of the cursor, the total length
  349. of the file, whether the widget is in insert or
  350. overstrike mode.  Anytime anything occurs that could
  351. affect these values, a user supplied callback
  352. is invoked. This callback is supplied by the
  353. application so that the application can update
  354. whatever indicators it uses, however it implements
  355. them.
  356.  
  357. One other feature of the TextEdit.pm module is
  358. block level text indention and block level text
  359. commenting. If a block of text is selected,
  360. that text can be indented or unindented wiht
  361. a single keystroke. It can also be commented
  362. out or uncommented as well. The keystroke bindings
  363. that support this are:
  364.  
  365. <F5> IndentSelectedLines
  366. <F6> UnindentSelectedLines
  367.  
  368. <F7> CommentSelectedLines
  369. <F8> UncommentSelectedLines
  370.  
  371. These bindings only operate on the currently
  372. selected text. The indent string and the comment
  373. string can be programmed to be anything, but
  374. defaults to "\t" (tab) for indent and "#" for
  375. comments.
  376.  
  377. (currently the widget hash is used to store these values.
  378. $w->{'INDENT_STRING'} and $w->{'LINE_COMMENT_STRING'}
  379. At some point in the future, this will be changed to
  380. use configure options to set these values.
  381. any application that changes these values should do
  382. so in such a way that when the TextEdit module changes,
  383. the application can be easily changed to handle this)
  384.  
  385.  
  386.  
  387. gedi application
  388. =====================
  389. gedi is short for Greg's EDItor.
  390. The "g" is soft, pronounced like a "j".
  391.  
  392. The gedi application uses all of the features of
  393. the text modules, Text, TextUndo, and TextEdit.
  394. It supplies TextEdit with a callback to update
  395. the indicator displays. This information includes
  396. the current cursor position, insert/overstrike
  397. mode, length of the file, filename, and whether
  398. the file has been edited or not.
  399.  
  400. The bottom of this display contains
  401. line number
  402. column number
  403. total lines
  404. insert/overstrike mode.
  405.  
  406. The title bar contains
  407. filename
  408. and if the file has been edited, the word "edited".
  409.  
  410. Where gedi is installed depends on your system,
  411. but it is part of the tarkit for Tk800.015 and above.
  412.  
  413. gedi was created to be put a perl editor in with the
  414. perl tar kit.
  415.  
  416. NOTE: THIS IS NOT THE ACTUAL GEDI APPLICATION, BUT
  417. A DEMO SET UP TO BE SIMILAR IN NATURE TO THE GEDI
  418. APPLICATION. THE ACTUAL GEDI APPLICATION IS PART OF
  419. THE TK800.015 TARKIT. WHERE IT IS LOCATED ON YOUR
  420. SYSTEM WILL VARY DEPENDING ON YOUR SYSTEM. ONCE
  421. YOU LOCATE THE GEDI APPLICATION, PUT IT IN YOUR
  422. EXECUTABLE PATH, AND YOU WILL BE ABLE TO USE IT AS
  423. A TEXT EDITOR.
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.