[gnome-commander] Store and open URI's for tabs instead of just using absolute path names, fixing #30
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Store and open URI's for tabs instead of just using absolute path names, fixing #30
- Date: Wed, 9 Feb 2022 20:27:29 +0000 (UTC)
commit d5c8ae7afc1bf68e59eb8fd8e969566730a1d36b
Author: Uwe Scholz <u scholz83 gmx de>
Date: Sun Jan 23 23:31:47 2022 +0100
Store and open URI's for tabs instead of just using absolute path names, fixing #30
src/gnome-cmd-data.cc | 42 +++++++++++++++++++-------------------
src/gnome-cmd-dir.cc | 2 +-
src/gnome-cmd-main-win.cc | 52 +++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 70 insertions(+), 26 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 22757142..2d125f5f 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1794,18 +1794,18 @@ static void save_tabs(GSettings *gSettings, const char *gSettingsKey)
if (gnome_cmd_data.options.save_tabs_on_exit)
{
auto fl = reinterpret_cast <GnomeCmdFileList*> (gtk_bin_get_child (GTK_BIN (i->data)));
- if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con))
+ if (GNOME_CMD_FILE_LIST (fl))
{
- gchar* realPath = GNOME_CMD_FILE (fl->cwd)->get_real_path();
- if (!realPath)
+ gchar* uriString = GNOME_CMD_FILE (fl->cwd)->get_uri_str();
+ if (!uriString)
continue;
g_variant_builder_add (&gVariantBuilder, GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING,
- realPath,
+ uriString,
(guchar) fileSelectorId,
fl->get_sort_column(),
fl->get_sort_order(),
fl->locked);
- g_free(realPath);
+ g_free(uriString);
}
}
else
@@ -1813,35 +1813,35 @@ static void save_tabs(GSettings *gSettings, const char *gSettingsKey)
if (gnome_cmd_data.options.save_dirs_on_exit)
{
auto fl = reinterpret_cast <GnomeCmdFileList*> (gtk_bin_get_child (GTK_BIN (i->data)));
- if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con) &&
(fl==gnomeCmdFileSelector.file_list() || fl->locked))
+ if (GNOME_CMD_FILE_LIST (fl) && (fl==gnomeCmdFileSelector.file_list() || fl->locked))
{
- gchar* realPath = GNOME_CMD_FILE (fl->cwd)->get_real_path();
- if (!realPath)
+ gchar* uriString = GNOME_CMD_FILE (fl->cwd)->get_uri_str();
+ if (!uriString)
continue;
g_variant_builder_add (&gVariantBuilder, GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING,
- realPath,
+ uriString,
(guchar) fileSelectorId,
fl->get_sort_column(),
fl->get_sort_order(),
fl->locked);
- g_free(realPath);
+ g_free(uriString);
}
}
else
{
auto fl = reinterpret_cast<GnomeCmdFileList*> (gtk_bin_get_child (GTK_BIN (i->data)));
- if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con) && fl->locked)
+ if (GNOME_CMD_FILE_LIST (fl) && fl->locked)
{
- gchar* realPath = GNOME_CMD_FILE (fl->cwd)->get_real_path();
- if (!realPath)
+ gchar* uriString = GNOME_CMD_FILE (fl->cwd)->get_uri_str();
+ if (!uriString)
continue;
g_variant_builder_add (&gVariantBuilder, GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING,
- realPath,
+ uriString,
(guchar) fileSelectorId,
fl->get_sort_column(),
fl->get_sort_order(),
fl->locked);
- g_free(realPath);
+ g_free(uriString);
}
}
}
@@ -2752,19 +2752,19 @@ void GnomeCmdData::load_tabs()
while ((tab = g_variant_iter_next_value (&iter)) != nullptr)
{
- gchar *path;
+ gchar *uriCharString;
gboolean sort_order, locked;
guchar fileSelectorId, sort_column;
g_assert (g_variant_is_of_type (tab, G_VARIANT_TYPE
(GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING)));
- g_variant_get(tab, GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING, &path, &fileSelectorId,
&sort_column, &sort_order, &locked);
- string directory_path(path);
- if (!directory_path.empty() && sort_column < GnomeCmdFileList::NUM_COLUMNS)
+ g_variant_get(tab, GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING, &uriCharString,
&fileSelectorId, &sort_column, &sort_order, &locked);
+ string uriString(uriCharString);
+ if (!uriString.empty() && sort_column < GnomeCmdFileList::NUM_COLUMNS)
{
- this->tabs[(FileSelectorID) fileSelectorId].push_back(make_pair(directory_path,
make_triple((GnomeCmdFileList::ColumnID) sort_column, (GtkSortType) sort_order, locked)));
+ this->tabs[(FileSelectorID) fileSelectorId].push_back(make_pair(uriString,
make_triple((GnomeCmdFileList::ColumnID) sort_column, (GtkSortType) sort_order, locked)));
}
g_variant_unref(tab);
- g_free(path);
+ g_free(uriCharString);
}
g_variant_unref(gvTabs);
}
diff --git a/src/gnome-cmd-dir.cc b/src/gnome-cmd-dir.cc
index 228ada89..eeb304aa 100644
--- a/src/gnome-cmd-dir.cc
+++ b/src/gnome-cmd-dir.cc
@@ -367,7 +367,7 @@ GnomeCmdDir *gnome_cmd_dir_new (GnomeCmdCon *con, GnomeCmdPath *path, gboolean i
{
if (error && !isStartup)
{
- gnome_cmd_show_message (*main_win, path->get_display_path(), error->message);
+ gnome_cmd_show_message (*main_win, uriString, error->message);
g_error_free(error);
}
g_object_unref(gFile);
diff --git a/src/gnome-cmd-main-win.cc b/src/gnome-cmd-main-win.cc
index c5d826fc..5e8f2689 100644
--- a/src/gnome-cmd-main-win.cc
+++ b/src/gnome-cmd-main-win.cc
@@ -1203,8 +1203,6 @@ gboolean GnomeCmdMainWin::key_pressed(GdkEventKey *event)
void GnomeCmdMainWin::open_tabs(FileSelectorID id)
{
- GnomeCmdCon *home = get_home_con ();
-
if (gnome_cmd_data.tabs[id].empty())
gnome_cmd_data.tabs[id].push_back(make_pair(string(g_get_home_dir ()),
make_triple(GnomeCmdFileList::COLUMN_NAME, GTK_SORT_ASCENDING, FALSE)));
@@ -1212,8 +1210,54 @@ void GnomeCmdMainWin::open_tabs(FileSelectorID id)
for (auto tab=gnome_cmd_data.tabs[id].begin(); tab!=last_tab; ++tab)
{
- auto *gnomeCmdDir = gnome_cmd_dir_new (home, gnome_cmd_con_create_path (home, tab->first.c_str()));
- fs(id)->new_tab(gnomeCmdDir, tab->second.first, tab->second.second, tab->second.third, TRUE);
+ auto uriString = tab->first;
+ auto uriScheme = g_uri_peek_scheme (uriString.c_str());
+ auto uriIsRelative = false;
+
+ if (!uriScheme)
+ {
+ g_warning("Stored URI is either not absolute or invalid: %s", uriString.c_str());
+ uriScheme = g_strdup("file");
+ uriIsRelative = true;
+ }
+
+ if (strcmp(uriScheme, "file") == 0 || uriIsRelative)
+ {
+ GnomeCmdCon *home = get_home_con ();
+ gchar *path = nullptr;
+ if (uriIsRelative)
+ {
+ path = g_strdup(tab->first.c_str());
+ }
+ else
+ {
+ auto gUri = g_uri_parse(tab->first.c_str(), G_URI_FLAGS_NONE, nullptr);
+ path = g_strdup(g_uri_get_path(gUri));
+ }
+ auto *gnomeCmdDir = gnome_cmd_dir_new (home, gnome_cmd_con_create_path (home, path));
+ fs(id)->new_tab(gnomeCmdDir, tab->second.first, tab->second.second, tab->second.third, TRUE);
+ g_free(path);
+ }
+ else
+ {
+ GError *error = nullptr;
+ gchar *path = nullptr;
+ auto gUri = g_uri_parse(tab->first.c_str(), G_URI_FLAGS_NONE, &error);
+ if (error)
+ {
+ g_warning("Stored URI is invalid: %s", error->message);
+ g_error_free(error);
+ // open home directory instead
+ path = g_strdup(g_get_home_dir());
+ }
+ path = path ? path : g_strdup(g_uri_get_path(gUri));
+
+ GnomeCmdConRemote *con = gnome_cmd_con_remote_new(nullptr, uriString);
+ auto gnomeCmdPath = gnome_cmd_con_create_path((GnomeCmdCon*) con, path);
+ auto gnomeCmdDir = gnome_cmd_dir_new((GnomeCmdCon*) con, gnomeCmdPath, true);
+ fs(id)->new_tab(gnomeCmdDir, tab->second.first, tab->second.second, tab->second.third, TRUE);
+ g_free(path);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]