Commit 9fdeba17 authored by Daniel Elstner's avatar Daniel Elstner
Browse files

Operate directly in filename encoding since all callers need to convert

* src/stringutils.{cc,h} (expand_pathname): Operate directly in
filename encoding since all callers need to convert one way or
the other anyway.  Change type of parameter and return value to
std::string accordingly.
(shorten_pathname): ditto.

* src/mainwindow.cc (MainWindow::MainWindow): Reverse order of
the calls to filename_to_utf8_fallback() and shorten_pathname().
(MainWindow::on_select_folder): ditto
(MainWindow::on_find_files): ditto.

* src/mainwindow.{cc,h} (MainWindow::set_title_filename): Change
parameter type to std::string and call filename_to_utf8_fallback().
Also remove the default argument from the declaration, and get rid
of the logic that handles the empty string.
(MainWindow::MainWindow): Call window_->set_title() directly in
order to set the default title, instead of passing an empty string
to set_title_filename().
(MainWindow::on_filetree_switch_buffer): ditto.
parent 5052d823
2004-05-28 Daniel Elstner <daniel.elstner@gmx.net>
* src/stringutils.{cc,h} (expand_pathname): Operate directly in
filename encoding since all callers need to convert one way or
the other anyway. Change type of parameter and return value to
std::string accordingly.
(shorten_pathname): ditto.
* src/mainwindow.cc (MainWindow::MainWindow): Reverse order of
the calls to filename_to_utf8_fallback() and shorten_pathname().
(MainWindow::on_select_folder): ditto
(MainWindow::on_find_files): ditto.
* src/mainwindow.{cc,h} (MainWindow::set_title_filename): Change
parameter type to std::string and call filename_to_utf8_fallback().
Also remove the default argument from the declaration, and get rid
of the logic that handles the empty string.
(MainWindow::MainWindow): Call window_->set_title() directly in
order to set the default title, instead of passing an empty string
to set_title_filename().
(MainWindow::on_filetree_switch_buffer): ditto.
2004-05-27 Daniel Elstner <daniel.elstner@gmx.net>
* src/stringutils.cc (filename_to_utf8_fallback): On failure,
......
......@@ -145,10 +145,10 @@ MainWindow::MainWindow()
load_xml();
textview_->set_buffer(FileBuffer::create());
set_title_filename();
window_->set_title(PACKAGE_NAME);
entry_folder_->set_text(Util::shorten_pathname(
Util::filename_to_utf8_fallback(Glib::get_current_dir())));
entry_folder_->set_text(
Util::filename_to_utf8_fallback(Util::shorten_pathname(Glib::get_current_dir())));
connect_signals();
......@@ -325,15 +325,15 @@ void MainWindow::on_select_folder()
chooser.add_button(Stock::OK, RESPONSE_OK);
chooser.set_default_response(RESPONSE_OK);
chooser.set_modal(true);
chooser.set_local_only(true);
chooser.set_current_folder(Glib::filename_from_utf8(
Util::expand_pathname(entry_folder_->get_text())));
chooser.set_current_folder(Util::expand_pathname(
Glib::filename_from_utf8(entry_folder_->get_text())));
if (chooser.run() == RESPONSE_OK)
{
const Glib::ustring dirname = Util::filename_to_utf8_fallback(chooser.get_filename());
entry_folder_->set_text(Util::shorten_pathname(dirname));
const std::string dirname = Util::shorten_pathname(chooser.get_filename());
entry_folder_->set_text(Util::filename_to_utf8_fallback(dirname));
}
}
......@@ -350,7 +350,7 @@ void MainWindow::on_find_files()
undo_stack_clear();
std::string folder = Glib::filename_from_utf8(Util::expand_pathname(entry_folder_->get_text()));
std::string folder = Util::expand_pathname(Glib::filename_from_utf8(entry_folder_->get_text()));
if (folder.empty())
folder = Glib::get_current_dir();
......@@ -477,7 +477,7 @@ void MainWindow::on_filetree_switch_buffer(FileInfoPtr fileinfo, int file_index)
connect(sigc::mem_fun(*this, &MainWindow::update_preview)));
}
set_title_filename(Util::filename_to_utf8_fallback(fileinfo->fullname));
set_title_filename(fileinfo->fullname);
controller_.replace_file.set_enabled(buffer->get_match_count() > 0);
controller_.save_file.set_enabled(buffer->get_modified());
......@@ -492,7 +492,7 @@ void MainWindow::on_filetree_switch_buffer(FileInfoPtr fileinfo, int file_index)
textview_->set_editable(false);
textview_->set_cursor_visible(false);
set_title_filename();
window_->set_title(PACKAGE_NAME);
controller_.replace_file.set_enabled(false);
controller_.save_file.set_enabled(false);
......@@ -692,18 +692,13 @@ void MainWindow::update_preview()
}
}
void MainWindow::set_title_filename(const Glib::ustring& filename)
void MainWindow::set_title_filename(const std::string& filename)
{
Glib::ustring title;
if (!filename.empty())
{
title = Glib::path_get_basename(filename);
title += " (";
title += Util::shorten_pathname(Glib::path_get_dirname(filename));
title += ") \342\200\223 "; // U+2013 EN DASH
}
Glib::ustring title = Util::filename_to_utf8_fallback(Glib::path_get_basename(filename));
title += " (";
title += Util::filename_to_utf8_fallback(Util::shorten_pathname(Glib::path_get_dirname(filename)));
title += ") \342\200\223 "; // U+2013 EN DASH
title += PACKAGE_NAME;
window_->set_title(title);
......
......@@ -134,7 +134,7 @@ private:
void on_entry_pattern_changed();
void update_preview();
void set_title_filename(const Glib::ustring& filename = Glib::ustring());
void set_title_filename(const std::string& filename);
void busy_action_enter();
void busy_action_leave();
......
......@@ -647,33 +647,30 @@ Glib::ustring Util::int_to_string(int number)
return Glib::locale_to_utf8(output.str());
}
Glib::ustring Util::shorten_pathname(const Glib::ustring& path)
std::string Util::shorten_pathname(const std::string& path)
{
const Glib::ustring homedir = Util::filename_to_utf8_fallback(Glib::get_home_dir());
const Glib::ustring::size_type len = homedir.bytes();
const std::string homedir = Glib::get_home_dir();
const std::string::size_type len = homedir.length();
if (path.bytes() >= len
&& (path.bytes() == len || path.raw()[len] == G_DIR_SEPARATOR)
&& path.raw().compare(0, len, homedir.raw()) == 0)
if (path.length() >= len
&& (path.length() == len || path[len] == G_DIR_SEPARATOR)
&& path.compare(0, len, homedir) == 0)
{
std::string result (1, '~');
result.append(path.raw(), len, std::string::npos);
result.append(path, len, std::string::npos);
return result;
}
return path;
}
Glib::ustring Util::expand_pathname(const Glib::ustring& path)
std::string Util::expand_pathname(const std::string& path)
{
const std::string::const_iterator pend = path.end().base();
std::string::const_iterator pbegin = path.begin().base();
if (pbegin != pend && *pbegin == '~'
&& (++pbegin == pend || *pbegin == G_DIR_SEPARATOR))
if (path.length() > 0 && path[0] == '~'
&& (path.length() == 1 || path[1] == G_DIR_SEPARATOR))
{
Glib::ustring result = Util::filename_to_utf8_fallback(Glib::get_home_dir());
result.append(path, 1, Glib::ustring::npos);
std::string result = Glib::get_home_dir();
result.append(path, 1, std::string::npos);
return result;
}
......
......@@ -47,8 +47,8 @@ Glib::ustring filename_to_utf8_fallback(const std::string& filename);
Glib::ustring convert_to_ascii(const std::string& str);
Glib::ustring int_to_string(int number);
Glib::ustring shorten_pathname(const Glib::ustring& path);
Glib::ustring expand_pathname(const Glib::ustring& path);
std::string shorten_pathname(const std::string& path);
std::string expand_pathname(const std::string& path);
Glib::ustring color_to_string(const Gdk::Color& color);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment