summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com>2009-04-12 18:15:53 -0400
committerSøren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com>2009-04-12 18:15:53 -0400
commit21e1aecdc3fcb5e674b12d394f6066e898ce1cdf (patch)
treecdaf1a588408cd160528b5209e381e932601f3c6
parentde30d95d3f9f601ea2804547726e6d7ac3907dc4 (diff)
Add support for command line loading into empty window
-rw-r--r--siv.c35
-rw-r--r--siv.h17
-rw-r--r--window.c27
3 files changed, 58 insertions, 21 deletions
diff --git a/siv.c b/siv.c
index ea583b2..a7f7b7b 100644
--- a/siv.c
+++ b/siv.c
@@ -15,7 +15,7 @@ struct App
GtkWidget * chooser;
- GHashTable *windows_by_filename;
+ GPtrArray * windows;
};
void
@@ -89,6 +89,8 @@ app_register_window (App *app,
SivWindow *window)
{
++app->n_windows;
+
+ g_ptr_array_add (app->windows, window);
}
void
@@ -96,6 +98,8 @@ app_unregister_window (App *app, SivWindow *window)
{
if (--app->n_windows == 0)
gtk_main_quit ();
+
+ g_ptr_array_remove (app->windows, window);
}
GtkWidget *
@@ -366,14 +370,33 @@ open_file (App *app, const char *filename, GPtrArray *err_files)
{
SivWindow *window;
GError *err = NULL;
+ int i;
- if ((window = g_hash_table_lookup (app->windows_by_filename, filename)))
+ window = NULL;
+
+ for (i = 0; i < app->windows->len; ++i)
{
- /* FIXME: present the window here */
- return TRUE;
+ const char *f;
+
+ window = app->windows->pdata[i];
+
+ f = window_get_filename (window);
+
+ if (!f)
+ {
+ /* empty window */
+ break;
+ }
+
+ if (strcmp (f, filename) == 0)
+ {
+ window_show (window, GDK_CURRENT_TIME);
+ return TRUE;
+ }
}
- window = window_new (app);
+ if (!window)
+ window = window_new (app);
if (!window_load_file (window, filename, &err))
{
@@ -420,7 +443,7 @@ app_new (int argc, char **argv)
app = g_new0 (App, 1);
- app->windows_by_filename = g_hash_table_new (g_str_hash, g_str_equal);
+ app->windows = g_ptr_array_new ();
/* When a window is created, it increases the app->n_windows counter;
* when it is destroyed it decreases it. The problem is if the first
diff --git a/siv.h b/siv.h
index 0ec92c6..cfbafea 100644
--- a/siv.h
+++ b/siv.h
@@ -65,12 +65,15 @@ void app_show_could_not_open (GtkWidget *parent_window,
gchar **files);
/* SivWindow */
-SivWindow * window_new (App *app);
-gboolean window_load_file (SivWindow *window,
- const char *file,
- GError **err);
-void window_show (SivWindow *window,
- guint32 time);
-void window_free (SivWindow *window);
+SivWindow * window_new (App *app);
+gboolean window_load_file (SivWindow *window,
+ const char *file,
+ GError **err);
+void window_show (SivWindow *window,
+ guint32 time);
+void window_present (SivWindow *window);
+const char *window_get_filename (SivWindow *window);
+void window_free (SivWindow *window);
+
#endif
diff --git a/window.c b/window.c
index 9873952..0ab616b 100644
--- a/window.c
+++ b/window.c
@@ -1029,7 +1029,8 @@ canonicalize_filename (const char *filename)
{
memmove (p, p+1, strlen (p+1)+1);
}
- else if (p[0] == '.' && p[1] == '.' && (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
+ else if (p[0] == '.' && p[1] == '.' &&
+ (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2])))
{
q = p + 2;
/* Skip previous separator */
@@ -1124,25 +1125,29 @@ gboolean
window_load_file (SivWindow *window, const char *filename, GError **err)
{
GdkPixbuf *pixbuf;
+ gchar *canon;
- window->filename = canonicalize_filename (filename);
+ canon = canonicalize_filename (filename);
pixbuf = gdk_pixbuf_new_from_file (filename, err);
- if (!pixbuf)
- {
- return FALSE;
- }
- else
+ if (pixbuf)
{
window->original = pixbuf;
+ window->filename = canon;
- apply_meta_data (window, window->filename);
+ apply_meta_data (window, filename);
rebuild (window);
return TRUE;
}
+ else
+ {
+ g_free (canon);
+
+ return FALSE;
+ }
}
SivWindow *
@@ -1217,3 +1222,9 @@ window_show (SivWindow *window, guint32 time)
gtk_window_present_with_time (get_widget (window, "main_window"), time);
}
+
+const char *
+window_get_filename (SivWindow *window)
+{
+ return window->filename;
+}