mainwindow.cc 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* $Id$
 *
 * Copyright (c) 2002  Daniel Elstner  <daniel.elstner@gmx.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License VERSION 2 as
 * published by the Free Software Foundation.  You are not allowed to
 * use any other version of the license; unless you got the explicit
 * permission from the author to do so.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
daniel_e's avatar
daniel_e committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

#include "mainwindow.h"
#include "filelist.h"
#include "pcreshell.h"
#include "stringutils.h"

#include <iostream>
#include <memory>
#include <gtkmm.h>

#include <config.h>


namespace
{

const char regexxer_icon_path[] = "pixmaps" G_DIR_SEPARATOR_S "regexxer.png";

typedef Glib::RefPtr<Regexxer::FileBuffer> FileBufferPtr;


class ImageButton : public Gtk::Button
{
public:
  explicit ImageButton(const Gtk::StockID& stock_id);
  virtual ~ImageButton();
};

class CustomButton : public Gtk::Button
{
public:
  CustomButton(const Gtk::StockID& stock_id, const Glib::ustring& label, bool mnemonic = false);
  virtual ~CustomButton();
};


ImageButton::ImageButton(const Gtk::StockID& stock_id)
{
  Gtk::Image *const image = new Gtk::Image(stock_id, Gtk::ICON_SIZE_BUTTON);
  add(*Gtk::manage(image));
  image->show();
}

ImageButton::~ImageButton()
{}


CustomButton::CustomButton(const Gtk::StockID& stock_id, const Glib::ustring& label, bool mnemonic)
{
  using namespace Gtk;

  Alignment *const alignment = new Alignment(0.5, 0.5, 0.0, 0.0);
  add(*manage(alignment));

  HBox *const hbox = new HBox(false, 3);
  alignment->add(*manage(hbox));

  hbox->pack_start(*manage(new Image(stock_id, ICON_SIZE_BUTTON)), PACK_SHRINK);
  hbox->pack_start(*manage(new Label(label, mnemonic)),            PACK_SHRINK);

  show_all_children();
}

CustomButton::~CustomButton()
{}


void dummy_handler()
{
  std::cout << "foo!\n";
}

} // anonymous namespace


namespace Regexxer
{

MainWindow::MainWindow()
:
  entry_folder_         (0),
  entry_pattern_        (0),
  button_recursive_     (0),
  button_hidden_        (0),
  entry_regex_          (0),
  entry_substitution_   (0),
  button_multiple_      (0),
  button_caseless_      (0),
  filelist_             (0),
  textview_             (0),
  entry_preview_        (0),
  button_prev_file_     (0),
  button_prev_          (0),
  button_next_          (0),
  button_next_file_     (0),
  button_replace_       (0),
  button_replace_file_  (0),
  button_replace_all_   (0)
{
  using namespace Gtk;

  try
  {
    const std::string filename = Glib::build_filename(REGEXXER_DATADIR, regexxer_icon_path);
    set_icon(Gdk::Pixbuf::create_from_file(filename));
  }
  catch(const Glib::Error& e)
  {
    std::cerr << e.what() << std::endl;
  }

  set_title_filename();
  set_default_size(600, 400);

  Box *const vbox_main = new VBox();
  add(*manage(vbox_main));

  vbox_main->pack_start(*manage(create_toolbar()), PACK_SHRINK);

  Box *const vbox_interior = new VBox();
  vbox_main->pack_start(*manage(vbox_interior), PACK_EXPAND_WIDGET);
  vbox_interior->set_border_width(2);

  Box *const hbox_bottom = new HBox(false, 1);
  vbox_main->pack_start(*manage(hbox_bottom), PACK_SHRINK);
  hbox_bottom->pack_start(*manage(new ProgressBar()), PACK_SHRINK);
  hbox_bottom->pack_start(*manage(new Statusbar()), PACK_EXPAND_WIDGET);

  Paned *const paned = new HPaned();
  vbox_interior->pack_start(*manage(paned), PACK_EXPAND_WIDGET);
  vbox_interior->pack_start(*manage(create_buttonbox()), PACK_SHRINK);

  paned->pack1(*manage(create_left_pane()),  EXPAND);
  paned->pack2(*manage(create_right_pane()), EXPAND);

  show_all_children();

  entry_folder_->set_text(Util::shorten_pathname(Glib::filename_to_utf8(Glib::get_current_dir())));
  entry_pattern_->set_text("*");
  button_recursive_->set_active(true);

  signal_hide().connect_notify(SigC::slot(*filelist_, &FileList::stop_find_files));

163 164 165 166 167
  filelist_->signal_match_count_changed.connect(
      SigC::slot(*this, &MainWindow::on_filelist_match_count_changed));

  filelist_->signal_switch_buffer.connect(
      SigC::slot(*this, &MainWindow::on_filelist_switch_buffer));
daniel_e's avatar
daniel_e committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
}

MainWindow::~MainWindow()
{}

Gtk::Widget* MainWindow::create_toolbar()
{
  using namespace Gtk;
  using namespace Gtk::Toolbar_Helpers;

  std::auto_ptr<Toolbar> toolbar (new Toolbar());
  ToolList& tools = toolbar->tools();

  tools.push_back(StockElem(Stock::SAVE, &dummy_handler));
  tools.push_back(Space());
  tools.push_back(StockElem(Stock::UNDO, &dummy_handler));
  tools.push_back(Space());
  tools.push_back(StockElem(Stock::PREFERENCES, &dummy_handler));
  tools.push_back(Space());
  tools.push_back(StockElem(Stock::QUIT, SigC::slot(*this, &Widget::hide)));

  toolbar->set_toolbar_style(TOOLBAR_BOTH_HORIZ);

  return toolbar.release();
}

Gtk::Widget* MainWindow::create_buttonbox()
{
  using namespace Gtk;
  using SigC::bind;
  using SigC::slot;

  std::auto_ptr<Box> buttonbox (new HBox(false, 10));
  buttonbox->set_border_width(2);

  Box *const box_action = new HBox(true, 5);
  buttonbox->pack_end(*manage(box_action), PACK_SHRINK);

  Box *const box_move = new HBox(true, 5);
  buttonbox->pack_end(*manage(box_move), PACK_SHRINK);

  button_prev_file_ = new ImageButton(Stock::GOTO_FIRST);
  box_move->pack_start(*manage(button_prev_file_));

  button_prev_ = new ImageButton(Stock::GO_BACK);
  box_move->pack_start(*manage(button_prev_));

  button_next_ = new ImageButton(Stock::GO_FORWARD);
  box_move->pack_start(*manage(button_next_));

  button_next_file_ = new ImageButton(Stock::GOTO_LAST);
  box_move->pack_start(*manage(button_next_file_));

  button_replace_ = new CustomButton(Stock::CONVERT, "_Replace", true);
  box_action->pack_start(*manage(button_replace_));

  button_replace_file_ = new CustomButton(Stock::CONVERT, "_This file", true);
  box_action->pack_start(*manage(button_replace_file_));

  button_replace_all_ = new CustomButton(Stock::CONVERT, "_All files", true);
  box_action->pack_start(*manage(button_replace_all_));

  button_prev_file_   ->set_sensitive(false);
  button_prev_        ->set_sensitive(false);
  button_next_        ->set_sensitive(false);
  button_next_file_   ->set_sensitive(false);
  button_replace_     ->set_sensitive(false);
  button_replace_file_->set_sensitive(false);
  button_replace_all_ ->set_sensitive(false);

  button_prev_file_   ->signal_clicked().connect(bind(slot(*this, &MainWindow::on_go_next_file), false));
  button_prev_        ->signal_clicked().connect(bind(slot(*this, &MainWindow::on_go_next),      false));
  button_next_        ->signal_clicked().connect(bind(slot(*this, &MainWindow::on_go_next),      true));
  button_next_file_   ->signal_clicked().connect(bind(slot(*this, &MainWindow::on_go_next_file), true));
  button_replace_     ->signal_clicked().connect(slot(*this, &MainWindow::on_replace));
  button_replace_file_->signal_clicked().connect(slot(*this, &MainWindow::on_replace_file));
  button_replace_all_ ->signal_clicked().connect(slot(*this, &MainWindow::on_replace_all));

  return buttonbox.release();
}

Gtk::Widget* MainWindow::create_left_pane()
{
  using namespace Gtk;

  std::auto_ptr<VBox> vbox (new VBox(false, 3));
  vbox->set_border_width(1);

  Table *const table = new Table(3, 2, false);
  vbox->pack_start(*manage(table), PACK_SHRINK);
  table->set_border_width(1);
  table->set_spacings(2);

  Button *const button_folder = new CustomButton(Stock::OPEN, "_Folder:", true);
  table->attach(*manage(button_folder), 0, 1, 0, 1, FILL, AttachOptions(0));
  button_folder->signal_clicked().connect(SigC::slot(*this, &MainWindow::on_select_folder));

  table->attach(*manage(new Label("Pattern:", 0.0, 0.5)), 0, 1, 1, 2, FILL, AttachOptions(0));
  table->attach(*manage(entry_folder_  = new Entry()), 1, 2, 0, 1, EXPAND|FILL, AttachOptions(0));
  table->attach(*manage(entry_pattern_ = new Entry()), 1, 2, 1, 2, EXPAND|FILL, AttachOptions(0));

  HBox *const hbox = new HBox(false, 5);
  table->attach(*manage(hbox), 0, 2, 2, 3, EXPAND|FILL, AttachOptions(0));

  button_recursive_ = new CheckButton("recursive");
  hbox->pack_start(*manage(button_recursive_), PACK_SHRINK);

  button_hidden_ = new CheckButton("hidden");
  hbox->pack_start(*manage(button_hidden_), PACK_SHRINK);

  Button *const button_find = new Button(Stock::FIND);
  hbox->pack_end(*manage(button_find), PACK_SHRINK);
  button_find->signal_clicked().connect(SigC::slot(*this, &MainWindow::on_find_files));

  Frame *const frame = new Frame();
  vbox->pack_start(*manage(frame), PACK_EXPAND_WIDGET);

  ScrolledWindow *const scrollwin = new ScrolledWindow();
  frame->add(*manage(scrollwin));

  filelist_ = new FileList();
  scrollwin->add(*manage(filelist_));
  scrollwin->set_policy(POLICY_AUTOMATIC, POLICY_ALWAYS);

  tooltips_.set_tip(*entry_folder_,     "The directory to be searched.");
  tooltips_.set_tip(*entry_pattern_,    "A filename pattern as used by the shell. "
                                        "Character classes [ab] and csh style "
                                        "brace expressions {a,b} are supported.");
  tooltips_.set_tip(*button_recursive_, "recurse into subdirectories");
  tooltips_.set_tip(*button_hidden_,    "also find hidden files");

  return vbox.release();
}

Gtk::Widget* MainWindow::create_right_pane()
{
  using namespace Gtk;

  std::auto_ptr<VBox> vbox (new VBox(false, 3));
  vbox->set_border_width(1);

  Table *const table = new Table(2, 3, false);
  vbox->pack_start(*manage(table), PACK_SHRINK);
  table->set_border_width(1);
  table->set_spacings(2);

  table->attach(*manage(new Label("Search:",  0.0, 0.5)), 0, 1, 0, 1, FILL, AttachOptions(0));
  table->attach(*manage(new Label("Replace:", 0.0, 0.5)), 0, 1, 1, 2, FILL, AttachOptions(0));
  table->attach(*manage(entry_regex_        = new Entry()),  1, 2, 0, 1, EXPAND|FILL, AttachOptions(0));
  table->attach(*manage(entry_substitution_ = new Entry()),  1, 2, 1, 2, EXPAND|FILL, AttachOptions(0));

  entry_substitution_->signal_changed().connect(SigC::slot(*this, &MainWindow::update_preview));

  HBox *const hbox_options = new HBox(false, 5);
  table->attach(*manage(hbox_options), 2, 3, 0, 1, FILL, AttachOptions(0));
  hbox_options->pack_start(*manage(button_multiple_ = new CheckButton("/g")), PACK_SHRINK);
  hbox_options->pack_start(*manage(button_caseless_ = new CheckButton("/i")), PACK_SHRINK);

  Button *const button_find = new Button(Stock::FIND);
  table->attach(*manage(button_find), 2, 3, 1, 2, FILL, AttachOptions(0));
  button_find->signal_clicked().connect(SigC::slot(*this, &MainWindow::on_exec_search));

  Frame *const frame = new Frame();
  vbox->pack_start(*manage(frame), PACK_EXPAND_WIDGET);

  VBox *const vbox_textview = new VBox(false, 3);
  frame->add(*manage(vbox_textview));

  ScrolledWindow *const scrollwin = new ScrolledWindow();
  vbox_textview->pack_start(*manage(scrollwin), PACK_EXPAND_WIDGET);

  textview_ = new TextView();
  scrollwin->add(*manage(textview_));

  entry_preview_ = new Entry();
  vbox_textview->pack_start(*manage(entry_preview_), PACK_SHRINK);
  entry_preview_->set_has_frame(false);
  entry_preview_->set_editable(false);
  entry_preview_->unset_flags(CAN_FOCUS);

  const Pango::FontDescription fixed_font ("fixed");
  textview_     ->modify_font(fixed_font);
  entry_preview_->modify_font(fixed_font);

  tooltips_.set_tip(*entry_regex_,        "A regular expression in Perl syntax.");
  tooltips_.set_tip(*entry_substitution_, "The new string to substitute. As in Perl, you can "
                                          "refer to parts of the match using $1, $2, etc. "
                                          "or even $+, $&, $` and $'. The operators "
                                          "\\l, \\u, \\L, \\U and \\E are supported as well.");
  tooltips_.set_tip(*button_multiple_,    "find all possible matches in a line");
  tooltips_.set_tip(*button_caseless_,    "do case insensitive matching");

  return vbox.release();
}

void MainWindow::on_select_folder()
{
  using namespace Glib;

  Gtk::FileSelection filesel ("Select a folder");
  filesel.set_transient_for(*this);
  filesel.hide_fileop_buttons();

  std::string filename = filename_from_utf8(Util::expand_pathname(entry_folder_->get_text()));

  if(!filename.empty())
  {
    if(*filename.rbegin() != G_DIR_SEPARATOR)
      filename += G_DIR_SEPARATOR;

    filesel.set_filename(filename);
  }

  if(filesel.run() == Gtk::RESPONSE_OK)
  {
    filename = filesel.get_filename();
    entry_folder_->set_text(Util::shorten_pathname(filename_to_utf8(path_get_dirname(filename))));

    if(!filename.empty() && *filename.rbegin() != G_DIR_SEPARATOR)
      entry_pattern_->set_text(filename_to_utf8(path_get_basename(filename)));
  }
}

void MainWindow::on_find_files()
{
  filelist_->find_files(
      Util::expand_pathname(entry_folder_->get_text()),
      entry_pattern_->get_text(),
      button_recursive_->get_active(),
      button_hidden_->get_active());
}

void MainWindow::on_exec_search()
{
  button_prev_file_->set_sensitive(false);
  button_prev_     ->set_sensitive(false);
  button_next_     ->set_sensitive(false);
  button_next_file_->set_sensitive(false);

  try
  {
409
    Pcre::Pattern pattern (
daniel_e's avatar
daniel_e committed
410
        entry_regex_->get_text(),
411 412 413
        button_caseless_->get_active() ? Pcre::CASELESS : Pcre::CompileOptions(0));

    filelist_->find_matches(pattern, button_multiple_->get_active());
daniel_e's avatar
daniel_e committed
414 415 416 417 418 419 420
  }
  catch(const Pcre::Error& e)
  {
    std::cerr << e.what() << std::endl;
    return;
  }

421
  if(filelist_->get_match_count() > 0)
daniel_e's avatar
daniel_e committed
422 423 424 425 426 427
  {
    filelist_->select_first_file();
    on_go_next(true);
  }
}

428 429 430 431 432
void MainWindow::on_filelist_match_count_changed(long match_count)
{
  button_replace_all_->set_sensitive(match_count > 0);
}

daniel_e's avatar
daniel_e committed
433 434 435 436 437 438 439 440 441
void MainWindow::on_filelist_switch_buffer(FileInfoPtr fileinfo, BoundState bound)
{
  const FileBufferPtr old_buffer = FileBufferPtr::cast_dynamic(textview_->get_buffer());

  if(fileinfo && fileinfo->buffer == old_buffer)
    return;

  if(old_buffer)
  {
442
    conn_match_count_changed_.disconnect();
daniel_e's avatar
daniel_e committed
443 444 445 446 447 448 449 450 451 452 453
    conn_bound_state_changed_.disconnect();
    conn_preview_changed_.disconnect();

    old_buffer->forget_current_match();
  }

  button_prev_file_->set_sensitive((bound & BOUND_FIRST) == 0);
  button_next_file_->set_sensitive((bound & BOUND_LAST)  == 0);

  if(fileinfo && fileinfo->buffer)
  {
454 455 456
    const FileBufferPtr buffer = fileinfo->buffer;

    textview_->set_buffer(buffer);
daniel_e's avatar
daniel_e committed
457 458
    set_title_filename(Glib::filename_to_utf8(fileinfo->fullname));

459 460 461 462 463
    conn_match_count_changed_ = buffer->signal_match_count_changed.
        connect(SigC::slot(*this, &MainWindow::on_buffer_match_count_changed));

    conn_bound_state_changed_ = buffer->signal_bound_state_changed.
        connect(SigC::slot(*this, &MainWindow::on_buffer_bound_state_changed));
daniel_e's avatar
daniel_e committed
464

465
    conn_preview_changed_ = buffer->signal_preview_line_changed.
daniel_e's avatar
daniel_e committed
466 467
        connect(SigC::slot(*this, &MainWindow::update_preview));

468 469
    on_buffer_match_count_changed(buffer->get_match_count());
    on_buffer_bound_state_changed(buffer->get_bound_state());
daniel_e's avatar
daniel_e committed
470 471 472 473 474 475
  }
  else
  {
    textview_->set_buffer(FileBuffer::create());
    set_title_filename();

476 477
    on_buffer_match_count_changed(0);
    on_buffer_bound_state_changed(BOUND_FIRST | BOUND_LAST);
daniel_e's avatar
daniel_e committed
478 479 480 481 482
  }

  update_preview();
}

483 484 485 486 487 488
void MainWindow::on_buffer_match_count_changed(int match_count)
{
  button_replace_file_->set_sensitive(match_count > 0);
}

void MainWindow::on_buffer_bound_state_changed(BoundState bound)
daniel_e's avatar
daniel_e committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
{
  button_prev_->set_sensitive((bound & BOUND_FIRST) == 0 || button_prev_file_->sensitive());
  button_next_->set_sensitive((bound & BOUND_LAST)  == 0 || button_next_file_->sensitive());
}

void MainWindow::on_go_next_file(bool move_forward)
{
  filelist_->select_next_file(move_forward);
  on_go_next(move_forward);
}

void MainWindow::on_go_next(bool move_forward)
{
  if(const FileBufferPtr buffer = FileBufferPtr::cast_dynamic(textview_->get_buffer()))
  {
    if(const Glib::RefPtr<Gtk::TextMark> mark = buffer->get_next_match(move_forward))
    {
      textview_->scroll_to_mark(mark, 0.2);
      return;
    }
  }

  if(filelist_->select_next_file(move_forward))
  {
    on_go_next(move_forward); // recursive call
  }
}

void MainWindow::on_replace()
{
  if(const FileBufferPtr buffer = FileBufferPtr::cast_dynamic(textview_->get_buffer()))
  {
    buffer->replace_current_match(entry_substitution_->get_text());
522
    on_go_next(true);
daniel_e's avatar
daniel_e committed
523 524 525 526 527
  }
}

void MainWindow::on_replace_file()
{
528 529 530 531
  if(const FileBufferPtr buffer = FileBufferPtr::cast_dynamic(textview_->get_buffer()))
  {
    buffer->replace_all_matches(entry_substitution_->get_text());
  }
daniel_e's avatar
daniel_e committed
532 533 534 535
}

void MainWindow::on_replace_all()
{
536
  filelist_->replace_all_matches(entry_substitution_->get_text());
daniel_e's avatar
daniel_e committed
537

538 539 540 541
  button_prev_file_->set_sensitive(false);
  button_prev_     ->set_sensitive(false);
  button_next_     ->set_sensitive(false);
  button_next_file_->set_sensitive(false);
daniel_e's avatar
daniel_e committed
542 543 544 545 546 547 548 549 550 551
}

void MainWindow::update_preview()
{
  if(const FileBufferPtr buffer = FileBufferPtr::cast_dynamic(textview_->get_buffer()))
  {
    Glib::ustring preview;
    const int pos = buffer->get_line_preview(entry_substitution_->get_text(), preview);
    entry_preview_->set_text(preview);

552
    button_replace_->set_sensitive(pos >= 0);
daniel_e's avatar
daniel_e committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

    // Beware, strange code ahead!
    //
    // The goal is to scroll the preview entry so that it shows the entire
    // replaced text if possible.  In order to do that we first move the cursor
    // to 0, forcing scrolling to the left boundary.  Then we set the cursor to
    // the end of the replaced text, thus forcing the entry widget to scroll
    // again.  The replacement should then be entirely visible provided that it
    // fits into the entry.
    //
    // The problem is that Gtk::Entry doesn't update its scroll position
    // immediately but in an idle handler, thus any calls to set_position()
    // but the last one have no effect at all.
    //
    // To workaround that, we install an idle handler that's executed just
    // after the entry updated its scroll position, but before redrawing is
    // done.

    entry_preview_->set_position(0);

    if(pos > 0)
    {
      using SigC::slot;
      using SigC::bind;
      using SigC::bind_return;

      Glib::signal_idle().connect(
          bind_return(bind(slot(*entry_preview_, &Gtk::Editable::set_position), pos), false),
          Glib::PRIORITY_HIGH_IDLE + 17); // between scroll update (+ 15) and redraw (+ 20)
    }
  }
}

void MainWindow::set_title_filename(const Glib::ustring& filename)
{
  Glib::ustring title;

  if(!filename.empty())
  {
    title  = Glib::path_get_basename(filename);
    title += " (";
    title += Util::shorten_pathname(Glib::path_get_dirname(filename));
    title += ") - ";
  }

  title += PACKAGE_NAME;

  set_title(title);
}

} // namespace Regexxer