Enhancement: Fixes #298, Explorer - support address bar

This commit is contained in:
Rory Fewell
2024-05-15 00:53:44 +01:00
parent 8e619895ae
commit 021f624baf
19 changed files with 603 additions and 225 deletions

View File

@@ -23,9 +23,10 @@ static void wintc_cpl_view_printers_ishext_view_interface_init(
WinTCIShextViewInterface* iface
);
WinTCShextPathInfo* wintc_cpl_view_printers_activate_item(
gboolean wintc_cpl_view_printers_activate_item(
WinTCIShextView* view,
WinTCShextViewItem* item,
WinTCShextPathInfo* path_info,
GError** error
);
@@ -46,12 +47,14 @@ const gchar* wintc_cpl_view_printers_get_display_name(
WinTCIShextView* view
);
const gchar* wintc_cpl_view_printers_get_parent_path(
WinTCIShextView* view
void wintc_cpl_view_printers_get_parent_path(
WinTCIShextView* view,
WinTCShextPathInfo* path_info
);
const gchar* wintc_cpl_view_printers_get_path(
WinTCIShextView* view
void wintc_cpl_view_printers_get_path(
WinTCIShextView* view,
WinTCShextPathInfo* path_info
);
//
@@ -104,15 +107,16 @@ static void wintc_cpl_view_printers_ishext_view_interface_init(
//
// INTERFACE METHODS
//
WinTCShextPathInfo* wintc_cpl_view_printers_activate_item(
gboolean wintc_cpl_view_printers_activate_item(
WINTC_UNUSED(WinTCIShextView* view),
WINTC_UNUSED(WinTCShextViewItem* item),
WINTC_UNUSED(WinTCShextPathInfo* path_info),
GError** error
)
{
WINTC_SAFE_REF_CLEAR(error);
g_critical("%s Not Implemented", __func__);
return NULL;
return FALSE;
}
void wintc_cpl_view_printers_refresh_items(
@@ -157,18 +161,26 @@ const gchar* wintc_cpl_view_printers_get_display_name(
return "Printers and Faxes";
}
const gchar* wintc_cpl_view_printers_get_parent_path(
WINTC_UNUSED(WinTCIShextView* view)
void wintc_cpl_view_printers_get_parent_path(
WINTC_UNUSED(WinTCIShextView* view),
WinTCShextPathInfo* path_info
)
{
return wintc_sh_get_place_path(WINTC_SH_PLACE_CONTROLPANEL);
path_info->base_path =
g_strdup(
wintc_sh_get_place_path(WINTC_SH_PLACE_CONTROLPANEL)
);
}
const gchar* wintc_cpl_view_printers_get_path(
WINTC_UNUSED(WinTCIShextView* view)
void wintc_cpl_view_printers_get_path(
WINTC_UNUSED(WinTCIShextView* view),
WinTCShextPathInfo* path_info
)
{
return wintc_sh_get_place_path(WINTC_SH_PLACE_PRINTERS);
path_info->base_path =
g_strdup(
wintc_sh_get_place_path(WINTC_SH_PLACE_PRINTERS)
);
}
//

View File

@@ -739,9 +739,16 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkComboBoxText">
<object class="GtkComboBoxText" id="combo-address">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="has-entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
</child>
</object>
</child>
</object>
@@ -755,7 +762,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="button-nav-go">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="receives-default">False</property>

View File

@@ -33,10 +33,28 @@ static void wintc_explorer_window_set_property(
GParamSpec* pspec
);
static void prepare_new_location(
const gchar* specified_path,
WinTCShextPathInfo* current_path_info
);
static void on_browser_location_changed(
WinTCShBrowser* self,
gpointer user_data
);
static void on_button_nav_go_clicked(
GtkButton* self,
gpointer user_data
);
static void on_button_nav_up_clicked(
GtkButton* self,
gpointer user_data
);
static void on_combo_address_entry_activate(
GtkEntry* self,
gpointer user_data
);
//
// GTK OOP CLASS/INSTANCE DEFINITIONS
@@ -60,7 +78,9 @@ struct _WinTCExplorerWindow
WinTCShIconViewBehaviour* behaviour_icons;
GtkWidget* iconview_browser;
GtkWidget* button_nav_go;
GtkWidget* button_nav_up;
GtkWidget* combo_address;
};
//
@@ -126,6 +146,10 @@ static void wintc_explorer_window_init(
self->iconview_browser =
GTK_WIDGET(gtk_builder_get_object(builder, "browse-view"));
self->combo_address =
GTK_WIDGET(gtk_builder_get_object(builder, "combo-address"));
self->button_nav_go =
GTK_WIDGET(gtk_builder_get_object(builder, "button-nav-go"));
self->button_nav_up =
GTK_WIDGET(gtk_builder_get_object(builder, "button-nav-up"));
@@ -134,12 +158,24 @@ static void wintc_explorer_window_init(
// Link up UI
// FIXME: This is temp, use GActions!
//
g_signal_connect(
self->button_nav_go,
"clicked",
G_CALLBACK(on_button_nav_go_clicked),
self
);
g_signal_connect(
self->button_nav_up,
"clicked",
G_CALLBACK(on_button_nav_up_clicked),
self
);
g_signal_connect(
gtk_bin_get_child(GTK_BIN(self->combo_address)),
"activate",
G_CALLBACK(on_combo_address_entry_activate),
self
);
}
//
@@ -149,7 +185,7 @@ static void wintc_explorer_window_constructed(
GObject* object
)
{
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(object);
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(object);
if (!wnd->shext_host)
{
@@ -161,6 +197,13 @@ static void wintc_explorer_window_constructed(
//
wnd->browser = wintc_sh_browser_new(wnd->shext_host);
g_signal_connect(
wnd->browser,
"location-changed",
G_CALLBACK(on_browser_location_changed),
wnd
);
// Link up with UI
//
wnd->behaviour_icons =
@@ -172,21 +215,23 @@ static void wintc_explorer_window_constructed(
// Navigate to desktop
// FIXME: Need to check if we were initialised with a path in future!
//
gchar* desktop_path = g_strdup_printf("::{%s}", WINTC_SH_GUID_DESKTOP);
GError* error = NULL;
GError* error = NULL;
WinTCShextPathInfo path_info = { 0 };
wintc_sh_browser_set_location(
wnd->browser,
desktop_path,
&error
);
path_info.base_path = wintc_sh_path_for_guid(WINTC_SH_GUID_DESKTOP);
if (error)
if (
!wintc_sh_browser_set_location(
wnd->browser,
&path_info,
&error
)
)
{
wintc_display_error_and_clear(&error);
}
g_free(desktop_path);
wintc_shext_path_info_free_data(&path_info);
(G_OBJECT_CLASS(wintc_explorer_window_parent_class))->constructed(object);
}
@@ -243,9 +288,185 @@ GtkWidget* wintc_explorer_window_new(
);
}
//
// PRIVATE FUNCTIONS
//
static void prepare_new_location(
const gchar* specified_path,
WinTCShextPathInfo* current_path_info
)
{
GError* error = NULL;
const GRegex* regex_uri_scheme = wintc_regex_uri_scheme(&error);
if (!regex_uri_scheme)
{
wintc_nice_error_and_clear(&error);
return;
}
// If the path starts with '::' then assume it's a GUID and shouldn't be
// touched
//
if (g_str_has_prefix(specified_path, "::"))
{
wintc_shext_path_info_free_data(current_path_info);
current_path_info->base_path = g_strdup(specified_path);
return;
}
// If the path starts with a leading slash '/' then assume an absolute file
// system path
//
if (g_str_has_prefix(specified_path, "/"))
{
wintc_shext_path_info_free_data(current_path_info);
current_path_info->base_path =
g_strdup_printf("file://%s", specified_path);
return;
}
// If the path is a URL, handle it here
// FIXME: For now we just pass it on, in future we'll need to handle the
// scheme for cases like HTTP(S)
//
if (
g_regex_match(
regex_uri_scheme,
specified_path,
0,
NULL
)
)
{
wintc_shext_path_info_free_data(current_path_info);
current_path_info->base_path = g_strdup(specified_path);
return;
}
// Here we assume it's a relative path
// FIXME: When HTTP(S) is supported, we will need to check the current path
//
g_free(current_path_info->extended_path);
current_path_info->extended_path = g_strdup(specified_path);
}
//
// CALLBACKS
//
static void on_browser_location_changed(
WinTCShBrowser* self,
gpointer user_data
)
{
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(user_data);
// Just update the address bar for now
//
GtkWidget* entry;
WinTCShextPathInfo path_info = { 0 };
entry =
gtk_bin_get_child(
GTK_BIN(wnd->combo_address)
);
wintc_sh_browser_get_location(self, &path_info);
if (path_info.extended_path)
{
gtk_entry_set_text(
GTK_ENTRY(entry),
path_info.extended_path
);
}
else
{
// Special case for file:// address, we only want to display the actual
// filesystem path - kinda cheeky bunging it in here but it does get
// the job done
//
if (g_str_has_prefix(path_info.base_path, "file://"))
{
gtk_entry_set_text(
GTK_ENTRY(entry),
path_info.base_path + strlen("file://")
);
}
else
{
gtk_entry_set_text(
GTK_ENTRY(entry),
path_info.base_path
);
}
}
wintc_shext_path_info_free_data(&path_info);
}
static void on_button_nav_go_clicked(
WINTC_UNUSED(GtkButton* self),
gpointer user_data
)
{
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(user_data);
GtkWidget* entry;
GError* error = NULL;
WinTCShextPathInfo path_info = { 0 };
const gchar* target_path;
entry =
gtk_bin_get_child(
GTK_BIN(wnd->combo_address)
);
target_path =
gtk_entry_get_text(GTK_ENTRY(entry));
// Don't bother navigating if there's nowhere to go!
//
if (g_strcmp0(target_path, "") == 0)
{
return;
}
// Retrieve new location
//
wintc_sh_browser_get_location(
wnd->browser,
&path_info
);
prepare_new_location(
target_path,
&path_info
);
// Attempt the navigation
//
if (
!wintc_sh_browser_set_location(
wnd->browser,
&path_info,
&error
)
)
{
wintc_nice_error_and_clear(&error);
}
wintc_shext_path_info_free_data(&path_info);
}
static void on_button_nav_up_clicked(
WINTC_UNUSED(GtkButton* self),
gpointer user_data
@@ -255,3 +476,15 @@ static void on_button_nav_up_clicked(
wintc_sh_browser_navigate_to_parent(wnd->browser);
}
static void on_combo_address_entry_activate(
WINTC_UNUSED(GtkEntry* self),
gpointer user_data
)
{
WinTCExplorerWindow* wnd = WINTC_EXPLORER_WINDOW(user_data);
gtk_widget_activate(
GTK_WIDGET(wnd->button_nav_go)
);
}