[nemiver] Simplify file searching API and worfklow
- From: Dodji Seketeli <dodji src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver] Simplify file searching API and worfklow
- Date: Wed, 8 Sep 2010 14:04:15 +0000 (UTC)
commit 968d5265c3b9a661921e288c72812598bccb8a5c
Author: Dodji Seketeli <dodji redhat com>
Date: Wed Sep 8 15:50:52 2010 +0200
Simplify file searching API and worfklow
* src/common/nmv-env.[h,cc] (find_file_absolute_or_relative): Remove
this ugly API.
* src/common/nmv-asm-utils.h (FindFileAndReadLine): Simplify this
API.
(class ReadLine): Likewise.
(find_file): Make this API look less like Belzebuth.
* nmv-ui-utils.[h,cc] (find_file_or_ask_user): Rename the awful
find_absolute_path_or_ask_user into this and make its API more
maintainable. Make it use env::find_file instead of the now
[luckily] defunct find_file_absolute_or_relative. Update comment.
(find_file_and_read_line): Use find_file_or_ask_user instead of
the defunct find_absolute_path_or_ask_user.
* nmv-source-editor.h (add_asm, load_asm): Simplify the APIs and
implementation of these as they need to be less weird now that the
underlying file searching API looks more reasonable.
* src/persp/dbgperspective/nmv-dbg-perspective.cc
():
(DBGPerspective::load_asm): New helper fn.
(DBGPerspective::Priv::find_file): Renamed
DBGPerspective::find_absolute_path into this and move if from
DBGPerspective to DBGPerspective::Priv.
(DBGPerspective::Priv::find_file_or_ask_user): Renamed
DBGPerspective::find_absolute_path_or_ask_user into this and move
it here.
(DBGPerspective::Priv::is_asm_title): Moved
DBGPerspective::is_asm_title to here.
(DBGPerspective::Priv::build_find_file_search_path)
(DBGPerspective::Priv::is_persistent_file): New functions.
(DBGPerspective::get_current_source_editor)
(DBGPerspective::get_or_append_source_editor_from_path)
(DBGPerspective::switch_to_source_code): Use
DBGPerspective::Priv::find_file_or_ask_user.
(DBGPerspective::do_unmonitor_file): Use
DBGPerspective::Priv::is_asm_title.
(DBGPerspective::open_asm, DBGPerspective::switch_to_asm): Use
DBGPerspective::load_asm.
src/common/nmv-asm-utils.h | 31 ++---
src/common/nmv-env.cc | 97 +++-----------
src/common/nmv-env.h | 14 +--
src/persp/dbgperspective/nmv-dbg-perspective.cc | 163 ++++++++++++++---------
src/uicommon/nmv-source-editor.cc | 15 +--
src/uicommon/nmv-source-editor.h | 8 +-
src/uicommon/nmv-ui-utils.cc | 54 +++-----
src/uicommon/nmv-ui-utils.h | 20 +--
8 files changed, 170 insertions(+), 232 deletions(-)
---
diff --git a/src/common/nmv-asm-utils.h b/src/common/nmv-asm-utils.h
index 08454a5..d0e2dcf 100644
--- a/src/common/nmv-asm-utils.h
+++ b/src/common/nmv-asm-utils.h
@@ -92,13 +92,10 @@ operator<< (Stream &a_out, const Asm &a_asm)
void log_asm_insns (const std::list<common::Asm> &a_asm);
typedef bool (* FindFileAndReadLine) (const UString &a_file_path,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const std::list<UString> &a_where_to_look,
list<UString> &a_sess_dirs,
- const list<UString> &a_glob_dirs,
map<UString, bool> &a_ignore_paths,
- bool a_ignore_if_not_found,
- int a_line_number,
+ int a_line_number,
std::string &a_line);
class ReadLine
{
@@ -107,23 +104,20 @@ class ReadLine
ReadLine (const ReadLine &);
protected:
- const UString &m_prog_path;
- const UString &m_cwd;
+ const std::list<UString> &m_where_to_look;
list<UString> &m_session_dirs;
- const list<UString> &m_global_dirs;
map<UString, bool> &m_ignore_paths;
FindFileAndReadLine read_line;
public:
- ReadLine (const UString &prog_path,
- const UString &cwd,
- list<UString> &session_dirs,
- const list<UString> &global_dirs,
- map<UString, bool> &ignore_paths,
+ ReadLine (const std::list<UString> &where_to_look,
+ list<UString> &session_dirs,
+ map<UString, bool> &ignore_paths,
FindFileAndReadLine read_line_func) :
- m_prog_path (prog_path), m_cwd (cwd), m_session_dirs (session_dirs),
- m_global_dirs (global_dirs), m_ignore_paths (ignore_paths),
- read_line (read_line_func)
+ m_where_to_look (where_to_look),
+ m_session_dirs (session_dirs),
+ m_ignore_paths (ignore_paths),
+ read_line (read_line_func)
{
}
@@ -131,9 +125,8 @@ class ReadLine
int a_line_number,
std::string &a_line)
{
- return read_line (a_file_path, m_prog_path, m_cwd, m_session_dirs,
- m_global_dirs, m_ignore_paths, true, a_line_number,
- a_line);
+ return read_line (a_file_path, m_where_to_look, m_session_dirs,
+ m_ignore_paths, a_line_number, a_line);
}
};
diff --git a/src/common/nmv-env.cc b/src/common/nmv-env.cc
index d635162..6e3571a 100644
--- a/src/common/nmv-env.cc
+++ b/src/common/nmv-env.cc
@@ -377,100 +377,45 @@ build_path_to_executable (const UString &a_exe_name,
return true;
}
+/// Find a file name, by looking in a given set of directories
+/// \param a_file_name the file name to look for.
+/// \param a_where_to_look the list of directories where to look for
+/// \param a_absolute_file_path the absolute path of the file name
+/// found. This parameter is set iff the function return true.
+/// \return true upon successful completion, false otherwise.
bool
find_file (const UString &a_file_name,
- const UString &a_prog_path,
- const UString &a_cwd,
- const list<UString> &a_session_dirs,
- const list<UString> &a_global_dirs,
- UString &a_file_path)
+ const list<UString> &a_where_to_look,
+ UString &a_absolute_file_path)
{
- string file_name = Glib::filename_from_utf8 (a_file_name),
- path,
- candidate;
+ string file_name = Glib::filename_from_utf8 (a_file_name);
+ string path, candidate;
+
+ if (a_file_name.empty ())
+ return false;
// first check if this is an absolute path
if (Glib::path_is_absolute (file_name)) {
if (Glib::file_test (file_name, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = Glib::filename_to_utf8 (file_name);
+ a_absolute_file_path = Glib::filename_to_utf8 (file_name);
return true;
}
}
- // then look in the working directory
- candidate = Glib::build_filename (a_cwd, file_name);
- if (Glib::file_test (candidate, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = Glib::filename_to_utf8 (candidate);
- return true;
- }
- // then look in the directory of the binary
- candidate =
- Glib::build_filename (Glib::path_get_dirname (a_prog_path),
- file_name);
- if (Glib::file_test (candidate, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = Glib::filename_to_utf8 (candidate);
- return true;
- }
- // then look in the session-specific search paths
- list<UString>::const_iterator session_iter;
- for (session_iter = a_session_dirs.begin ();
- session_iter != a_session_dirs.end ();
- ++session_iter) {
- path = Glib::filename_from_utf8 (*session_iter);
- candidate = Glib::build_filename (path, file_name);
- if (Glib::file_test (candidate, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = Glib::filename_to_utf8 (candidate);
- return true;
- }
- }
- // if not found, then look in the global search paths
- list<UString>::const_iterator global_iter;
- for (global_iter = a_global_dirs.begin ();
- global_iter != a_global_dirs.end ();
- ++global_iter) {
- path = Glib::filename_from_utf8 (*global_iter);
+
+ // Otherwise, lookup the file in the directories we where given
+ for (list<UString>::const_iterator i = a_where_to_look.begin ();
+ i != a_where_to_look.end ();
+ ++i) {
+ path = Glib::filename_from_utf8 (*i);
candidate = Glib::build_filename (path, file_name);
if (Glib::file_test (candidate, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = Glib::filename_to_utf8 (candidate);
+ a_absolute_file_path = Glib::filename_to_utf8 (candidate);
return true;
}
}
return false;
}
-bool
-find_file_absolute_or_relative (const UString &a_file_name,
- const UString &a_prog_path,
- const UString &a_cwd,
- const list<UString> &a_session_dirs,
- const list<UString> &a_global_dirs,
- UString &a_file_path)
-{
- // First, assume it's a full path name already.
- if (Glib::file_test (a_file_name, Glib::FILE_TEST_IS_REGULAR)) {
- a_file_path = a_file_name;
- return true;
- }
-
- // If that didn't work, look for a file of that name in the search
- // directories.
- if (find_file (a_file_name, a_prog_path, a_cwd,
- a_session_dirs, a_global_dirs,
- a_file_path)) {
- return true;
- }
-
- // Then look for a file of that basename in the search directories.
- std::string basename =
- Glib::path_get_basename (Glib::filename_from_utf8 (a_file_name));
- if (basename != a_file_name
- && find_file (basename, a_prog_path, a_cwd,
- a_session_dirs, a_global_dirs,
- a_file_path)) {
- return true;
- }
- return false;
-}
-
/// Given a file path P and a line number N , reads the line N from P
/// and return it iff the function returns true. This is useful
/// e.g. when forging a mixed source/assembly source view, and we want
diff --git a/src/common/nmv-env.h b/src/common/nmv-env.h
index 8b5e1b0..5e63543 100644
--- a/src/common/nmv-env.h
+++ b/src/common/nmv-env.h
@@ -84,18 +84,8 @@ NEMIVER_API bool build_path_to_executable (const UString &a_exe_name,
UString &a_exe_path);
NEMIVER_API bool find_file (const UString &a_file_name,
- const UString &a_prog_path,
- const UString &a_cwd,
- const list<UString> &a_session_dirs,
- const list<UString> &a_global_dirs,
- UString &a_file_path);
-
-NEMIVER_API bool find_file_absolute_or_relative (const UString &a_file_name,
- const UString &a_prog_path,
- const UString &a_cwd,
- const list<UString> &a_sess_dirs,
- const list<UString> &a_glob_dirs,
- UString &a_file_path);
+ const list<UString> &a_where_to_look,
+ UString &a_aboslute_file_path);
NEMIVER_API bool read_file_line (const UString &a_file_path,
int a_line_number,
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 9e03d3b..3d1f376 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -531,9 +531,9 @@ public:
const char* get_asm_title ();
- bool is_asm_title (const UString &);
-
- bool read_file_line (const UString&, int, string&);
+ bool load_asm (const common::DisassembleInfo &a_info,
+ const std::list<common::Asm> &a_asm,
+ Glib::RefPtr<SourceBuffer> &a_buf);
SourceEditor* open_asm (const common::DisassembleInfo &a_info,
const std::list<common::Asm> &a_asm,
@@ -665,11 +665,6 @@ public:
void update_src_dependant_bp_actions_sensitiveness ();
- bool find_absolute_path (const UString& a_file_path,
- UString& a_absolute_path);
- bool find_absolute_path_or_ask_user (const UString& a_file_path,
- UString& a_absolute_path,
- bool a_ignore_if_not_found = true);
bool ask_user_to_select_file (const UString &a_file_name,
UString& a_selected_file_path);
bool append_visual_breakpoint (SourceEditor *editor,
@@ -1140,6 +1135,80 @@ struct DBGPerspective::Priv {
a_buffer);
}
+ bool
+ is_asm_title (const UString &a_path)
+ {
+ return (a_path.raw () == DISASSEMBLY_TITLE);
+ }
+
+ void
+ build_find_file_search_path (list<UString> &a_search_path)
+ {
+ if (!prog_path.empty ())
+ a_search_path.insert (a_search_path.end (),
+ Glib::path_get_dirname (prog_path));
+
+ if (!prog_cwd.empty ())
+ a_search_path.insert (a_search_path.end (), prog_cwd);
+
+ if (!session_search_paths.empty ())
+ a_search_path.insert (a_search_path.end (),
+ session_search_paths.begin (),
+ session_search_paths.end ());
+
+ if (!global_search_paths.empty ())
+ a_search_path.insert (a_search_path.end (),
+ global_search_paths.begin (),
+ global_search_paths.end ());
+ }
+
+ bool
+ find_file (const UString &a_file_name,
+ UString &a_absolute_file_path)
+ {
+ list<UString> where_to_look;
+ build_find_file_search_path (where_to_look);
+ return env::find_file (a_file_name, where_to_look,
+ a_absolute_file_path);
+ }
+
+ /// Lookup a file path and return true if found. If the path is not
+ /// absolute, look it up in the various directories we know about
+ /// then return the absolute location at which it we found it.
+ /// \param a_file_path the file path to look up.
+ /// \param a_absolute_path the returned absolute location at which the
+ /// file got found, iff the function returned true.
+ /// \param a_ignore_if_not_found if true and if the file wasn't found
+ /// *after* we asked the user [e.g because the user clicked 'cancel'
+ /// in the dialog asking her to locate the file] subsequent calls to
+ /// this function will not ask the user to locate the file again.
+ /// \return true upon successful completion, false otherwise.
+ bool
+ find_file_or_ask_user (const UString &a_file_path,
+ UString &a_absolute_path,
+ bool a_ignore_if_not_found)
+ {
+ list<UString> where_to_look;
+ build_find_file_search_path (where_to_look);
+ return ui_utils::find_file_or_ask_user (a_file_path,
+ where_to_look,
+ session_search_paths,
+ paths_to_ignore,
+ a_ignore_if_not_found,
+ a_absolute_path);
+ }
+
+ bool
+ is_persistent_file (const UString &a_path)
+ {
+ if (is_asm_title (a_path))
+ return false;
+ UString absolute;
+ if (find_file (a_path, absolute))
+ return true;
+ return false;
+ }
+
};//end struct DBGPerspective::Priv
enum ViewsIndex
@@ -3948,44 +4017,6 @@ DBGPerspective::clear_session_data ()
m_priv->global_search_paths.clear ();
}
-bool
-DBGPerspective::find_absolute_path (const UString& a_file_path,
- UString &a_absolute_path)
-{
- return common::env::find_file_absolute_or_relative (a_file_path,
- m_priv->prog_path,
- m_priv->prog_cwd,
- m_priv->session_search_paths,
- m_priv->global_search_paths,
- a_absolute_path);
-}
-
-/// Lookup a file path and return true if found. If the path is not
-/// absolute, look it up in the various directories we know about
-/// then return the absolute location at which it we found it.
-/// \param a_file_path the file path to look up.
-/// \param a_absolute_path the returned absolute location at which the
-/// file got found, iff the function returned true.
-/// \param a_ignore_if_not_found if true and if the file wasn't found
-/// *after* we asked the user [e.g because the user clicked 'cancel'
-/// in the dialog asking her to locate the file] subsequent calls to
-/// this function will not ask the user to locate the file again.
-/// \return true upon successful completion, false otherwise.
-bool
-DBGPerspective::find_absolute_path_or_ask_user (const UString& a_file_path,
- UString& a_absolute_path,
- bool a_ignore_if_not_found)
-{
- return ui_utils::find_absolute_path_or_ask_user (a_file_path,
- m_priv->prog_path,
- m_priv->prog_cwd,
- m_priv->session_search_paths,
- m_priv->global_search_paths,
- m_priv->paths_to_ignore,
- a_ignore_if_not_found,
- a_absolute_path);
-}
-
void
DBGPerspective::append_source_editor (SourceEditor &a_sv,
const UString &a_path)
@@ -4117,7 +4148,8 @@ DBGPerspective::get_current_source_editor (bool a_load_if_nil)
if (path.empty ()) {
return 0;
}
- if (!find_absolute_path_or_ask_user (path, path))
+ if (!m_priv->find_file_or_ask_user (path, path,
+ /*ignore_if_not_found=*/false))
return 0;
SourceEditor *editor = open_file_real (path);
apply_decorations (editor,
@@ -4289,7 +4321,8 @@ DBGPerspective::get_or_append_source_editor_from_path (const UString &a_path)
SourceEditor *source_editor =
get_source_editor_from_path (a_path, actual_file_path);
if (source_editor == 0) {
- if (!find_absolute_path_or_ask_user (a_path, actual_file_path)) {
+ if (!m_priv->find_file_or_ask_user (a_path, actual_file_path,
+ /*ignore_if_not_found=*/false)) {
return 0;
}
source_editor = open_file_real (actual_file_path);
@@ -4724,7 +4757,7 @@ DBGPerspective::do_unmonitor_file (const UString &a_path)
// Disassembly result is composite content that doesn't come from
// any on-disk file. It's thus not monitored.
- if (is_asm_title (a_path))
+ if (m_priv->is_asm_title (a_path))
return true;
Priv::Path2MonitorMap::iterator it =
@@ -5469,9 +5502,17 @@ DBGPerspective::get_asm_title ()
}
bool
-DBGPerspective::is_asm_title (const UString &a_path)
+DBGPerspective::load_asm (const common::DisassembleInfo &a_info,
+ const std::list<common::Asm> &a_asm,
+ Glib::RefPtr<SourceBuffer> &a_source_buffer)
{
- return (a_path.raw () == DISASSEMBLY_TITLE);
+ list<UString> where_to_look_for_src;
+ m_priv->build_find_file_search_path (where_to_look_for_src);
+ return SourceEditor::load_asm (a_info, a_asm, /*a_append=*/true,
+ where_to_look_for_src,
+ m_priv->session_search_paths,
+ m_priv->paths_to_ignore,
+ a_source_buffer);
}
// If no asm dedicated tab was already present in the perspective,
@@ -5497,13 +5538,8 @@ DBGPerspective::open_asm (const common::DisassembleInfo &a_info,
source_buffer = source_editor->source_view ().get_source_buffer ();
source_buffer->erase (source_buffer->begin (), source_buffer->end ());
}
-
- if (!SourceEditor::load_asm (a_info, a_asm, /*a_append=*/true,
- m_priv->prog_path, m_priv->prog_cwd,
- m_priv->session_search_paths,
- m_priv->global_search_paths,
- m_priv->paths_to_ignore,
- source_buffer))
+
+ if (!load_asm (a_info, a_asm, source_buffer))
return 0;
if (!source_editor)
@@ -5565,11 +5601,7 @@ DBGPerspective::switch_to_asm (const common::DisassembleInfo &a_info,
asm_buf = a_source_editor->get_assembly_source_buffer ();
RETURN_IF_FAIL (asm_buf);
}
- if (!SourceEditor::load_asm (a_info, a_asm, /*a_append=*/true,
- m_priv->prog_path, m_priv->prog_cwd,
- m_priv->session_search_paths,
- m_priv->global_search_paths,
- m_priv->paths_to_ignore, asm_buf)) {
+ if (!load_asm (a_info, a_asm, asm_buf)) {
LOG_ERROR ("failed to load asm");
return;
}
@@ -5626,8 +5658,9 @@ DBGPerspective::switch_to_source_code ()
return;
}
UString absolute_path, mime_type;
- if (!find_absolute_path_or_ask_user (m_priv->current_frame.file_name (),
- absolute_path)) {
+ if (!m_priv->find_file_or_ask_user (m_priv->current_frame.file_name (),
+ absolute_path,
+ /*ignore_if_not_found=*/false)) {
LOG_DD ("Could not find file: "
<< m_priv->current_frame.file_name ());
return;
diff --git a/src/uicommon/nmv-source-editor.cc b/src/uicommon/nmv-source-editor.cc
index b471b19..d3bd89e 100644
--- a/src/uicommon/nmv-source-editor.cc
+++ b/src/uicommon/nmv-source-editor.cc
@@ -1409,10 +1409,8 @@ bool
SourceEditor::add_asm (const common::DisassembleInfo &/*a_info*/,
const std::list<common::Asm> &a_asm,
bool a_append,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_src_search_dirs,
list<UString> &a_session_dirs,
- const list<UString> &a_glob_dirs,
std::map<UString, bool> &a_ignore_paths,
Glib::RefPtr<SourceBuffer> &a_buf)
{
@@ -1429,7 +1427,7 @@ SourceEditor::add_asm (const common::DisassembleInfo &/*a_info*/,
// Write the first asm instruction into a string stream.
std::ostringstream first_os, endl_os;
- ReadLine reader (a_prog_path, a_cwd, a_session_dirs, a_glob_dirs,
+ ReadLine reader (a_src_search_dirs, a_session_dirs,
a_ignore_paths, &ui_utils::find_file_and_read_line);
bool first_written = write_asm_instr (*it, reader, first_os);
endl_os << std::endl;
@@ -1472,10 +1470,8 @@ bool
SourceEditor::load_asm (const common::DisassembleInfo &a_info,
const std::list<common::Asm> &a_asm,
bool a_append,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_src_search_dirs,
list<UString> &a_session_dirs,
- const list<UString> &a_glob_dirs,
std::map<UString, bool> &a_ignore_paths,
Glib::RefPtr<SourceBuffer> &a_buf)
{
@@ -1490,9 +1486,8 @@ SourceEditor::load_asm (const common::DisassembleInfo &a_info,
}
THROW_IF_FAIL (a_buf);
- add_asm (a_info, a_asm, a_append, a_prog_path, a_cwd,
- a_session_dirs, a_glob_dirs, a_ignore_paths,
- a_buf);
+ add_asm (a_info, a_asm, a_append, a_src_search_dirs,
+ a_session_dirs, a_ignore_paths, a_buf);
NEMIVER_CATCH_AND_RETURN (false)
return true;
diff --git a/src/uicommon/nmv-source-editor.h b/src/uicommon/nmv-source-editor.h
index a8453bd..37bcfbb 100644
--- a/src/uicommon/nmv-source-editor.h
+++ b/src/uicommon/nmv-source-editor.h
@@ -170,20 +170,16 @@ public:
static bool add_asm (const common::DisassembleInfo &/*a_info*/,
const std::list<common::Asm> &a_asm,
bool a_append,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_src_search_dirs,
list<UString> &a_session_dirs,
- const list<UString> &a_glob_dirs,
std::map<UString, bool> &a_ignore_paths,
Glib::RefPtr<SourceBuffer> &a_buf);
static bool load_asm (const common::DisassembleInfo &/*a_info*/,
const std::list<common::Asm> &a_asm,
bool a_append,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_src_search_dirs,
list<UString> &a_session_dirs,
- const list<UString> &a_glob_dirs,
std::map<UString, bool> &a_ignore_paths,
Glib::RefPtr<SourceBuffer> &a_buf);
diff --git a/src/uicommon/nmv-ui-utils.cc b/src/uicommon/nmv-ui-utils.cc
index 586a680..49a107c 100644
--- a/src/uicommon/nmv-ui-utils.cc
+++ b/src/uicommon/nmv-ui-utils.cc
@@ -205,25 +205,23 @@ ask_user_to_select_file (const UString &a_file_name,
}
bool
-find_absolute_path_or_ask_user (const UString& a_file_path,
- const UString &a_prog_path,
- const UString &a_cwd,
- list<UString> &a_session_dirs,
- const list<UString> &a_global_dirs,
- map<UString, bool> &a_ignore_paths,
- bool a_ignore_if_not_found,
- UString& a_absolute_path)
+find_file_or_ask_user (const UString& a_file_name,
+ const list<UString> &a_where_to_look,
+ list<UString> &a_session_dirs,
+ map<UString, bool> &a_ignore_paths,
+ bool a_ignore_if_not_found,
+ UString& a_absolute_path)
{
- if (!env::find_file_absolute_or_relative (a_file_path, a_prog_path,
- a_cwd, a_session_dirs, a_global_dirs,
- a_absolute_path)) {
- if (a_ignore_paths.find (a_file_path)
+ if (!env::find_file (a_file_name, a_where_to_look, a_absolute_path)) {
+ if (a_ignore_paths.find (a_file_name)
!= a_ignore_paths.end ())
- // We didn't find a_file_path but as we were previously
+ // We didn't find a_file_name but as we were previously
// requested to *not* ask the user to locate it, just
// pretend we didn't find the file.
return false;
- if (ask_user_to_select_file (a_file_path, a_cwd, a_absolute_path)) {
+ if (ask_user_to_select_file (a_file_name,
+ a_where_to_look.front (),
+ a_absolute_path)) {
UString parent_dir =
Glib::filename_to_utf8 (Glib::path_get_dirname
(a_absolute_path));
@@ -231,7 +229,7 @@ find_absolute_path_or_ask_user (const UString& a_file_path,
} else {
if (a_ignore_if_not_found)
// Don't ask the user to locate a_file_path next time.
- a_ignore_paths[a_file_path] = true;
+ a_ignore_paths[a_file_name] = true;
return false;
}
}
@@ -246,15 +244,9 @@ find_absolute_path_or_ask_user (const UString& a_file_path,
/// \param a_file_path the file path to consider. Not necessarily
/// absolute. If the file is not found, it will be searched for very hard
/// in many places.
-/// \param a_prog_path the path of to the current program. This can be
-/// useful to search for a_file_path in case we have to search for it
-/// very hard.
-/// \param a_cwd the current working directory. This can be useful to
-/// search for a_file_path.
-/// \param a_sess_dirs a list of directories where to search for if
-/// all other places we searched for failed.
-/// \param a_glob_dirs a list of directories where to seach for if
-/// anything else failed so far.
+/// \param a_where_to_look the list of directories where to look for files.
+/// \param a_sess_dirs if the user helps to find the a file,
+/// the directory given by the user will be added to this list.
/// \param a_ignore_paths a list of file paths to not search for. If
/// a_file_path is present in these, we will not search for it.
/// \param a_ignore_if_not_found if true and if we haven't found
@@ -265,12 +257,9 @@ find_absolute_path_or_ask_user (const UString& a_file_path,
/// \return true upon successful completion, false otherwise.
bool
find_file_and_read_line (const UString &a_file_path,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_where_to_look,
list<UString> &a_sess_dirs,
- const list<UString> &a_glob_dirs,
map<UString, bool> &a_ignore_paths,
- bool a_ignore_if_not_found,
int a_line_number,
string &a_line)
{
@@ -278,10 +267,11 @@ find_file_and_read_line (const UString &a_file_path,
return false;
UString path;
- if (!find_absolute_path_or_ask_user (a_file_path, a_prog_path,
- a_cwd, a_sess_dirs, a_glob_dirs,
- a_ignore_paths, a_ignore_if_not_found,
- path))
+ if (!find_file_or_ask_user (a_file_path,
+ a_where_to_look,
+ a_sess_dirs,
+ a_ignore_paths,
+ true, path))
return false;
return env::read_file_line (path, a_line_number, a_line);
diff --git a/src/uicommon/nmv-ui-utils.h b/src/uicommon/nmv-ui-utils.h
index 4489207..a878572 100644
--- a/src/uicommon/nmv-ui-utils.h
+++ b/src/uicommon/nmv-ui-utils.h
@@ -150,22 +150,18 @@ NEMIVER_API bool ask_user_to_select_file (const UString &a_file_name,
const UString &a_default_dir,
UString &a_selected_file_path);
-NEMIVER_API bool find_absolute_path_or_ask_user (const UString& a_file_path,
- const UString &a_prog_path,
- const UString &a_cwd,
- list<UString> &a_sess_dirs,
- const list<UString> &a_glob_dirs,
- map<UString, bool> &a_ignore_paths,
- bool a_ignore_if_not_found,
- UString& a_absolute_path);
+NEMIVER_API bool find_file_or_ask_user (const UString& a_file_path,
+ const list<UString> &a_where_to_look,
+ list<UString> &a_session_dirs,
+ map<UString, bool> &a_ignore_paths,
+ bool a_ignore_if_not_found,
+ UString& a_absolute_path);
+
bool find_file_and_read_line (const UString &a_file_path,
- const UString &a_prog_path,
- const UString &a_cwd,
+ const list<UString> &a_where_to_look,
list<UString> &a_sess_dirs,
- const list<UString> &a_glob_dirs,
map<UString, bool> &a_ignore_paths,
- bool a_ignore_if_not_found,
int a_line_number,
string &a_line);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]