viewermanager.h
Go to the documentation of this file.00001 #ifndef viewermanager_h_included
00002 #define viewermanager_h_included
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00053
00054
00055 #include <cxxtls/viewer.h>
00056 #include <utility>
00057 #include <cxxtls/sequence_map.h>
00058 #include <cxxtls/file.h>
00059 #include <cxxtls/mru.h>
00060
00061 namespace cxxtls
00062 {
00063
00064 class ViewerSelector;
00065 class appChooser;
00066 class EtagsDB;
00067 namespace CppTagDB { class Info; }
00068
00069 class ProgramOptions;
00070
00071 class ViewerManager
00072
00153
00154 {
00155 public:
00156
00157 static int normal_att;
00158 static int active_title_att;
00159 static int inactive_title_att;
00160 static int active_mark_att;
00161 static int inactive_mark_att;
00162 static int bottom_att;
00163 static int highlighted_att;
00164
00165 static std::list<std::string> key_bindings_doc;
00166
00167
00168
00169 friend class ViewerSelector;
00170 friend class appChooser;
00171
00172
00173 typedef CursorWindow::viewport viewport;
00174
00175
00176
00177 typedef CursorWindow::input_event input_event;
00178 typedef std::auto_ptr<viewport> vp_handle;
00179 typedef CursorWindow::row_col row_col;
00180 typedef std::pair<Viewer*,std::string> vpentry;
00181 typedef viewport::repaint_handler repaint_handler;
00182
00183 typedef Viewer* (*application)(ViewerManager*vm, std::string &fullname);
00207
00208 typedef std::pair<application,std::string> appentry;
00211
00212
00213 CursorWindow* window() { return &cw_; }
00214
00215 struct FileLocation
00217 {
00218 std::string filename_;
00219 int lineNumber_;
00220
00221 FileLocation(std::string const &file, int line)
00222 : filename_(file)
00223 , lineNumber_(line)
00224 {
00225 }
00226
00227 FileLocation()
00228 : lineNumber_(0)
00229 {
00230 }
00231
00232
00233 };
00234
00235 typedef std::list<FileLocation> FileLocations;
00236
00237
00238
00239 private:
00240
00241 std::string tool_dir_;
00242
00243 CursorWindow cw_;
00244
00245 std::vector<viewport*> viewports_;
00246
00247
00248
00249
00250 std::vector<vpentry> viewers_;
00251
00252
00253
00254
00255
00256
00257
00258 MRU<std::string> order_;
00259
00260 size_t active_viewport_;
00265
00266 void setup_key_bindings();
00267
00268 void dispatch_event(input_event const &e);
00270
00271 void handle_master_command(int cmd);
00272
00273 std::auto_ptr<Viewer> vs_;
00274
00275 std::vector<appentry> apps_;
00276
00277 size_t override_active_viewport_;
00278
00279
00280 typedef std::pair<application, std::string> opener_map_entry;
00281
00282 std::list<opener_map_entry> openers_;
00283
00284
00285 std::list<opener_map_entry> editors_;
00286
00287
00288
00289 application dir_opener_;
00290
00291 std::string exit_dir_;
00292
00293
00294 void recordExitDir() const;
00295
00296
00297 FileLocations fileLocations_;
00298
00299 public:
00300
00301 void findMatchingViewers(FileName namePattern, std::list<std::pair<Viewer*, FileName> > &viewers);
00311
00312
00313 ViewerManager();
00314 ~ViewerManager();
00315
00316
00317 FileName find_file_in_standard_locations(FileName const &fragment, FileName const &directory);
00340
00341 bool popFileLocation(FileLocation &output)
00342 {
00343 if(fileLocations_.empty())
00344 return false;
00345
00346 output = fileLocations_.front();
00347 fileLocations_.pop_front();
00348
00349 return true;
00350 }
00351
00352 template<class Container>
00353 void setFileLocations(Container const &c)
00354 {
00355 typename Container::const_iterator first = c.begin(), last = c.end();
00356
00357 fileLocations_.clear();
00358
00359 while(first != last)
00360 {
00361 fileLocations_.push_back(*first++);
00362
00363 }
00364 }
00365
00366 void add_app(application a, std::string const &s)
00368 {
00369 apps_.push_back(appentry(a,s));
00370 }
00371
00372 void vsplit(Viewer*, std::string fullname);
00377
00378 void hsplit(Viewer*, std::string fullname);
00383
00384 void add(Viewer*, std::string fullname);
00391
00392 bool activate(Viewer* v);
00398
00399 bool is_visible(Viewer* v);
00403
00404 void unify();
00405
00406
00407
00408 void vs();
00409
00410
00411
00412 void open();
00413
00414
00415
00416 void close();
00417
00418
00419 void exit();
00420
00421 void run();
00422
00423 enum master_commands
00424 {
00425
00426 vertical_split,
00427 horizontal_split,
00428 unsplit,
00429 next,
00430 selector,
00431 die,
00432 die_and_jump,
00433
00434
00435 new_application,
00436 new_viewer,
00437 new_editor,
00438 display_help,
00439 interactive_shell,
00440 last_command
00441 };
00442
00443 typedef Sequence_Map<int,int> master_key_map;
00447
00448 master_key_map master_keys_;
00453
00454 Viewer* active_viewer()
00455 {
00456 size_t viewport_no = active_viewport_;
00457
00458 if(override_active_viewport_ < viewports_.size())
00459 viewport_no = override_active_viewport_;
00460
00461 if(viewports_.size())
00462 return static_cast<Viewer*>( viewports_[viewport_no]->get_repaint_handler() );
00463
00464 return 0;
00465 }
00466
00467 viewport* active_viewport()
00471 {
00472 size_t viewport_no = active_viewport_;
00473
00474 if(override_active_viewport_ < viewports_.size())
00475 viewport_no = override_active_viewport_;
00476
00477 return viewports_[viewport_no];
00478 }
00479
00480
00481 Viewer* find_viewer(std::string const& viewername);
00486
00487 Viewer* most_recent_viewer();
00495
00496 std::string find_viewer_name(Viewer *vp);
00498
00499 size_t find_viewport_index(std::string const &viewername);
00500
00501
00502
00503
00504
00505
00506
00507
00508 void help();
00512
00513 void help_helper( std::list<std::string> & help_text);
00519
00520 Viewer* open(std::string const &fullname);
00541
00542 Viewer* edit(std::string const &fullname);
00552
00553 void set_directory_app(application);
00557
00558 void add_viewer_app(application, std::string filename_extension);
00566
00567 void add_editor_app(application, std::string filename_extension);
00570
00571 Viewer::paste_buffer_type paste_buffer_;
00574
00575 void popup_new_viewer(bool edit=false);
00583
00584 void splitscreen_new_editor(bool horizontal=false);
00592
00593 std::string active_directory() const;
00600
00601 void handle_die_request();
00606
00607 std::string executable_version_;
00613
00614 std::string executable_name_;
00619
00620 static std::string default_etags_path(std::string &pathlist, char const *file="TAGS");
00625
00626 EtagsDB* default_etags_db();
00631
00632 CppTagDB::Info* default_cpptags_db();
00637
00638
00639 int find_files(std::string operand, std::list<std::string> *result);
00680
00681 };
00682 }
00683 #endif