NAME
Padre::Wx::Main - The main window for the Padre IDE
DESCRIPTION
Padre::Wx::Main
implements Padre's main window. It is the window containing the menus, the notebook with all opened tabs, the various sub- windows (outline, subs, output, errors, etc).
It inherits from Wx::Frame
, so check wx documentation to see all the available methods that can be applied to it besides the added ones (see below).
PUBLIC API
Constructor
There's only one constructor for this class.
new
my $main = Padre::Wx::Main->new($ide);
Create and return a new Padre main window. One should pass a Padre
object as argument, to get a reference to the Padre application.
Accessors
The following methods access the object attributes. They are both getters and setters, depending on whether you provide them with an argument. Use them wisely.
Accessors to GUI elements:
title
config
aui
menu
notebook
left
right
functions
outline
directory
bottom
output
syntax
errorlist
Accessors to operating data:
cwd
no_refresh
Accessors that may not belong to this class:
ack
find
my $find = $main->find;
Returns the find dialog, creating a new one if needed.
fast_find
my $find = $main->fast_find;
Return current quick find dialog. Create a new one if needed.
replace
my $replace = $main->replace;
Return current replace dialog. Create a new one if needed.
Public Methods
load_files
$main->load_files;
Load any default files: session from command-line, explicit list on command- line, or last session if user has this setup, a new file, or nothing.
freezer
my $locker = $main->freezer;
Create and return an automatic Freeze object that Thaw's on destruction.
Single Instance Server
Padre embeds a small network server to handle single instance. Here are the methods that allow to control this embedded server.
single_instance_start
$main->single_instance_start;
Start the embedded server. Create it if it doesn't exist. Return true on success, die otherwise.
single_instance_stop
$main->single_instance_stop;
Stop & destroy the embedded server if it was running. Return true on success.
single_instance_running
my $is_running = $main->single_instance_running;
Return true if the embedded server is currently running.
single_instance_connect
$main->single_instance_connect;
Callback called when a client is connecting to embedded server. This is the case when user starts a new Padre, and preference "open all documents in single Padre instance" is checked.
single_instance_command
$main->single_instance_command( $line );
Callback called when a client has issued a command $line
while connected on embedded server. Current supported commands are open $file
and focus
.
Window Methods
Those methods allow to query properties about the main window.
window_width
my $width = $main->window_width;
Return the main window width.
window_height
my $width = $main->window_height;
Return the main window height.
window_left
my $left = $main->window_left;
Return the main window position from the left of the screen.
window_top
my $top = $main->window_top;
Return the main window position from the top of the screen.
Refresh Methods
Those methods refresh parts of Padre main window. The term refresh
and the following methods are reserved for fast, blocking, real-time updates to the GUI, implying rapid changes.
refresh
$main->refresh;
Force refresh of all elements of Padre main window. (see below for individual refresh methods)
refresh_syntaxcheck
$main->refresh_syntaxcheck;
Do a refresh of document syntax checking. This is a "rapid" change, since actual syntax check is happening in the background.
refresh_menu
$main->refresh_menu;
Force a refresh of all menus. It can enable / disable menu entries depending on current document or Padre internal state.
refresh_menubar
$main->refresh_menubar;
Force a refresh of Padre's menubar.
refresh_toolbar
$main->refresh_toolbar;
Force a refresh of Padre's toolbar.
refresh_status
$main->refresh_status;
Force a refresh of Padre's status bar.
refresh_cursorpos
$main->refresh_cursorpos;
Force a refresh of the position of the cursor on Padre's status bar.
refresh_functions
$main->refresh_functions;
Force a refresh of the function list on the right.
Interface Rebuilding Methods
Those methods reconfigure Padre's main window in case of drastic changes (locale, etc.)
change_style
$main->change_style( $style, $private );
Apply $style
to Padre main window. $private
is a boolean true if the style is located in user's private Padre directory.
change_locale
$main->change_locale( $locale );
Change Padre's locale to $locale
. This will update the GUI to reflect the new locale.
relocale
$main->relocale;
The term and method relocale
is reserved for functionality intended to run when the application wishes to change locale (and wishes to do so without restarting).
Note at this point, that the new locale has already been fixed, and this method is usually called by change_locale()
.
reconfig
$main->reconfig( $config );
The term and method "reconfig" is reserved for functionality intended to run when Padre's underlying configuration is updated by an external actor at run-time. The primary use cases for this method are when the user configuration file is synced from a remote network location.
Note: This method is highly experimental and subject to change.
rebuild_toolbar
$main->rebuild_toolbar;
Destroy and rebuild the toolbar. This method is useful because the toolbar is not really flexible, and most of the time it's better to recreate it from scratch.
Tools and Dialogs
Those methods deal with the various panels that Padre provides, and allow to show or hide them.
show_functions
$main->show_functions( $visible );
Show the functions panel on the right if $visible
is true. Hide it otherwise. If $visible
is not provided, the method defaults to show the panel.
show_outline
$main->show_outline( $visible );
Show the outline panel on the right if $visible
is true. Hide it otherwise. If $visible
is not provided, the method defaults to show the panel.
show_directory
$main->show_directory( $visible );
Show the directory panel on the right if $visible
is true. Hide it otherwise. If $visible
is not provided, the method defaults to show the panel.
show_output
$main->show_output( $visible );
Show the output panel at the bottom if $visible
is true. Hide it otherwise. If $visible
is not provided, the method defaults to show the panel.
show_syntax
$main->show_syntax( $visible );
Show the syntax panel at the bottom if $visible
is true. Hide it otherwise. If $visible
is not provided, the method defaults to show the panel.
Introspection
The following methods allow to poke into Padre's internals.
current
my $current = $main->current;
Creates a Padre::Current object for the main window, giving you quick and cacheing access to the current various whatevers.
See Padre::Current for more information.
pageids
my @ids = $main->pageids;
Return a list of all current tab ids (integers) within the notebook.
pages
my @pages = $main->pages;
Return a list of all notebook tabs. Those are the real objects, not the ids (see pageids()
above).
editors
my @editors = $main->editors;
Return a list of all current editors. Those are the real objects, not the ids (see pageids()
above).
Note: for now, this has the same meaning as pages()
(see above), but this will change once we get project tabs or something else.
documents
my @document = $main->documents;
Return a list of all current docunments, in the specific order they are open in the notepad.
Process Execution
The following methods run an external command, for example to evaluate current document.
on_run_command
$main->on_run_command;
Prompt the user for a command to run, then run it with run_command()
(see below).
Note: it probably needs to be combined with run_command()
itself.
on_run_tdd_tests
$main->on_run_tdd_tests;
Callback method, to build and then call on_run_tests
on_run_tests
$main->on_run_tests;
Callback method, to run the project tests and harness them.
on_run_this_test
$main->on_run_this_test;
Callback method, to run the currently open test through prove.
run_command
$main->run_command( $command );
Run $command
and display the result in the output panel.
run_document
$main->run_document( $debug )
Run current document. If $debug
is true, document will be run with diagnostics and various debug options.
Note: this should really be somewhere else, but can stay here for now.
debug_perl
$main->debug_perl;
Run current document under perl debugger. An error is reported if current is not a Perl document.
Session Support
Those methods deal with Padre sessions. A session is a set of files / tabs opened, with the position within the files saved, as well as the document that has the focus.
capture_session
my @session = $main->capture_session;
Capture list of opened files, with information. Return a list of Padre::DB::SessionFile
objects.
open_session
$main->open_session( $session );
Try to close all files, then open all files referenced in the given $session
(a Padre::DB::Session
object). No return value.
save_session
$main->save_session( $session, @session );
Try to save @session
files (Padre::DB::SessionFile
objects, such as what is returned by capture_session()
- see above) to database, associated to $session
. Note that $session
should already exist.
User Interaction
Various methods to help send information to user.
message
$main->message( $msg, $title );
Open a dialog box with $msg
as main text and $title
(title defaults to Message
). There's only one OK button. No return value.
info
$main->info( $msg );
Print a message on the status bar or within a dialog box depending on the users preferences setting. The dialog has only a OK button and there is no return value.
error
$main->error( $msg );
Open an error dialog box with $msg
as main text. There's only one OK button. No return value.
prompt
my $value = $main->prompt( $title, $subtitle, $key );
Prompt user with a dialog box about the value that $key
should have. Return this value, or undef if user clicked cancel
.
Search and Replace
These methods provide the highest level abstraction for entry into the various search and replace functions and dialogs.
However, they still represent abstract logic and should NOT be tied directly to keystroke or menu events.
search_next
# Next match for a new search
$main->search_next( $search );
# Next match on current search (or show Find dialog if none)
$main->search_next;
Find the next match for the current search, or spawn the Find dialog.
If no files are open, silently do nothing (don't even remember the new search)
search_previous
# Previous match for a new search
$main->search_previous( $search );
# Previous match on current search (or show Find dialog if none)
$main->search_previous;
Find the previous match for the current search, or spawn the Find dialog.
If no files are open, do nothing.
replace_next
# Next replace for a new search
$main->replace_next( $search );
# Next replace on current search (or show Find dialog if none)
$main->replace_next;
Replace the next match for the current search, or spawn the Replace dialog.
If no files are open, do nothing.
replace_all
# Replace all for a new search
$main->replace_all( $search );
# Replace all for the current search (or show Replace dialog if none)
$main->replace_all;
Replace all matches for the current search, or spawn the Replace dialog.
If no files are open, do nothing.
General Events
Those methods are the various callbacks registered in the menus or whatever widgets Padre has.
on_brace_matching
$main->on_brace_matching;
Jump to brace matching current the one at current position.
on_comment_block
$main->on_comment_block;
Performs one of the following depending the given operation
Uncomment or comment selected lines, depending on their current state.
Comment out selected lines unilateraly.
Uncomment selected lines unilateraly.
on_autocompletion
$main->on_autocompletion;
Try to autocomplete current word being typed, depending on document type.
on_goto
$main->on_goto;
Prompt user for a line, and jump to this line in current document.
on_close_window
$main->on_close_window( $event );
Callback when window is about to be closed. This is our last chance to veto the $event
close, eg when some files are not yet saved.
If close is confirmed, save config to disk. Also, capture current session to be able to restore it next time if user set Padre to open last session on startup. Clean up all Task Manager's tasks.
setup_editors
$main->setup_editors( @files );
Setup (new) tabs for @files
, and update the GUI. If @files
is undef, open an empty document.
on_new
$main->on_new;
Create a new empty tab. No return value.
setup_editor
$main->setup_editor( $file );
Setup a new tab / buffer and open $file
, then update the GUI. Recycle current buffer if there's only one empty tab currently opened. If $file
is already opened, focus on the tab displaying it. Finally, if $file
does not exist, create an empty file before opening it.
create_tab
my $tab = $main->create_tab;
Create a new tab in the notebook, and return its id (an integer).
on_open_selection
$main->on_open_selection;
Try to open current selection in a new tab. Different combinations are tried in order: as full path, as path relative to cwd (where the editor was started), as path to relative to where the current file is, if we are in a perl file or perl environment also try if the thing might be a name of a module and try to open it locally or from @INC.
No return value.
on_open_all_recent_files
$main->on_open_all_recent_files;
Try to open all recent files within Padre. No return value.
on_filter_tool
$main->on_filter_tool;
Prompt user for a command to filter the selection/document.
on_open_url
$main->on_open_url;
Prompt user for URL to open and open it as a new tab.
Should be merged with ->on_open or at least a browsing function should be added.
on_open
$main->on_open;
Prompt user for file(s) to open, and open them as new tabs. No return value.
reload_all
my $success = $main->reload_all();
Reload all open files from disk.
reload_file
$main->reload_file;
Try to reload a file from disk. Display an error if something went wrong.
Returns 1 on success and 0 in case of and error.
on_reload_file
$main->on_reload_file;
Try to reload current file from disk. Display an error if something went wrong. No return value.
on_reload_all
$main->on_reload_all;
Reload all currently opened files from disk. No return value.
on_save_as
my $was_saved = $main->on_save_as;
Prompt user for a new filename to save current document, and save it. Returns true if saved, false if cancelled.
on_save
my $success = $main->on_save;
Try to save current document. Prompt user for a filename if document was new (see on_save_as()
above). Return true if document has been saved, false otherwise.
on_save_all
my $success = $main->on_save_all;
Try to save all opened documents. Return true if all documents were saved, false otherwise.
_save_buffer
my $success = $main->_save_buffer( $id );
Try to save buffer in tab $id
. This is the method used underneath by all on_save_*()
methods. It will check if document has been updated out of Padre before saving, and report an error if something went wrong. Return true if buffer was saved, false otherwise.
on_close
$main->on_close( $event );
Handler when there is a close $event
. Veto it if it's from the aui notebook, since wx will try to close the tab no matter what. Otherwise, close current tab. No return value.
close
my $success = $main->close( $id );
Request to close document in tab $id
, or current one if no $id
provided. Return true if closed, false otherwise.
close_all
my $success = $main->close_all( $skip );
Try to close all documents. If $skip
is specified (an integer), don't close the tab with this id. Return true upon success, false otherwise.
close_where
# Close all files in current project
my $project = Padre::Current->document->project_dir;
my $success = $main->close_where( sub {
$_[0]->project_dir eq $project
} );
The close_where
method is a programatically enhanceable mass-close tool. It takes a subroutine as a parameter and calls that subroutine for each currently open document, passing the document as the first parameter.
Any documents that return true will be closed.
on_nth_path
$main->on_nth_pane( $id );
Put focus on tab $id
in the notebook. Return true upon success, false otherwise.
on_next_pane
$main->on_next_pane;
Put focus on tab next to current document. Currently, only left to right order is supported, but later on it can be extended to follow a last seen order.
No return value.
on_prev_pane
$main->on_prev_pane;
Put focus on tab previous to current document. Currently, only right to left order is supported, but later on it can be extended to follow a reverse last seen order.
No return value.
on_diff
$main->on_diff;
Run Text::Diff
between current document and its last saved content on disk. This allow to see what has changed before saving. Display the differences in the output pane.
on_join_lines
$main->on_join_lines;
Join current line with next one (a-la vi with Ctrl+J). No return value.
Preferences and toggle methods
Those methods allow to change Padre's preferences.
zoom
$main->zoom( $factor );
Apply zoom $factor
to Padre's documents. Factor can be either positive or negative.
open_regex_editor
$main->open_regex_editor;
Open Padre's regex editor. No return value.
on_preferences
$main->on_preferences;
Open Padre's preferences dialog. No return value.
on_toggle_line_numbers
$main->on_toggle_line_numbers;
Toggle visibility of line numbers on the left of the document. No return value.
on_toggle_code_folding
$main->on_toggle_code_folding;
De/activate code folding. No return value.
on_toggle_currentline
$main->on_toggle_currentline;
Toggle overlining of current line. No return value.
on_toggle_right_margin
$main->on_toggle_right_margin;
Toggle display of right margin. No return value.
on_toggle_syntax_check
$main->on_toggle_syntax_check;
Toggle visibility of syntax panel. No return value.
on_toggle_errorlist
$main->on_toggle_errorlist;
Toggle visibility of error-list panel. No return value.
on_toggle_indentation_guide
$main->on_toggle_indentation_guide;
Toggle visibility of indentation guide. No return value.
on_toggle_eol
$main->on_toggle_eol;
Toggle visibility of end of line cariage returns. No return value.
on_toggle_whitespaces
$main->on_toggle_whitespaces;
Show/hide spaces and tabs (with dots and arrows respectively). No return value.
on_word_wrap
$main->on_word_wrap;
Toggle word wrapping for current document. No return value.
on_toggle_toolbar
$main->on_toggle_toolbar;
Toggle toolbar visibility. No return value.
on_toggle_statusbar
$main->on_toggle_statusbar;
Toggle statusbar visibility. No return value.
on_toggle_lockinterface
$main->on_toggle_lockinterface;
Toggle possibility for user to change Padre's external aspect. No return value.
on_insert_from_file
$main->on_insert_from_file;
Prompt user for a file to be inserted at current position in current document. No return value.
convert_to
$main->convert_to( $eol_style );
Convert document to $eol_style
line endings (can be one of WIN
, UNIX
, or MAC
). No return value.
find_editor_of_file
my $editor = $main->find_editor_of_file( $file );
Return the editor (a Padre::Wx::Editor
object) containing the wanted $file
, or undef if file is not opened currently.
find_id_of_editor
my $id = $main->find_id_of_editor( $editor );
Given $editor
, return the tab id holding it, or undef if it was not found.
Note: can this really work? What happens when we split a window?
run_in_padre
$main->run_in_padre;
Eval current document within Padre. It means it can access all of Padre's internals, and wreck havoc. Display an error message if the eval went wrong, dump the result in the output panel otherwise.
No return value.
STC related methods
Those methods are needed to have a smooth STC experience.
on_stc_style_needed
$main->on_stc_style_needed( $event );
Handler of EVT_STC_STYLENEEDED $event
. Used to work around some edge cases in scintilla. No return value.
on_stc_update_ui
$main->on_stc_update_ui;
Handler called on every movement of the cursor. No return value.
on_stc_change
$main->on_stc_change;
Handler of the EVT_STC_CHANGE event. Doesn't do anythin. No return value.
on_stc_char_needed
$main->on_stc_char_added;
This handler is called when a character is added. No return value. See http://www.yellowbrain.com/stc/events.html#EVT_STC_CHARADDED
TODO: maybe we need to check this more carefully.
on_stc_dwell_start
$main->on_stc_dwell_start( $event );
Handler of the DWELLSTART $event
. This event is sent when the mouse has not moved in a given amount of time. Doesn't do anything by now. No return value.
on_aui_pane_close
$main->on_aui_pane_close( $event );
Handler called upon EVT_AUI_PANE_CLOSE $event
. Doesn't do anything by now.
on_doc_stats
$main->on_doc_stats;
Compute various stats about current document, and display them in a message. No return value.
on_tab_and_space
$main->on_tab_and_space( $style );
Convert current document from spaces to tabs (or vice-versa) depending on $style
(can be either of Space_to_Tab
or Tab_to_Space
). Prompts the user for how many spaces are to be used to replace tabs (whatever the replacement direction). No return value.
on_delete_ending_space
$main->on_delete_ending_space;
Trim all ending spaces in current selection, or document if no text is selected. No return value.
on_delete_leading_space
$main->on_delete_leading_space;
Trim all leading spaces in current selection. No return value.
timer_check_overwrite
$main->timer_check_overwrite;
Called every n seconds to check if file has been overwritten outside of Padre. If that's the case, prompts the user whether s/he wants to reload the document. No return value.
on_last_visited_pane
$main->on_last_visited_pane;
Put focus on tab visited before the current one. No return value.
on_new_from_template
$main->on_new_from_template( $extension );
Create a new document according to template for $extension
type of file. No return value.
Auxiliary Methods
Various methods that did not fit exactly in above categories...
install_cpan
$main->install_cpan( $module );
Install $module
from CPAN.
Note: this method may not belong here...
setup_bindings
$main->setup_bindings;
Setup the various bindings needed to handle output pane correctly.
Note: I'm not sure those are really needed...
key_up
$main->key_up( $event );
Callback for when a key up $event
happens in Padre. This handles the various ctrl+key combinations used within Padre.
new_document_from_string
$main->new_document_from_string( $string, $mimetype );
Create a new document in Padre with the string value.
Pass in an optional mime type to have Padre colorize the text correctly.
Note: this method may not belong here...
COPYRIGHT & LICENSE
Copyright 2008-2009 The Padre development team as listed in Padre.pm.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.