我们考虑使用命令gedit toto1.txt
打开一个文件,新窗口显示toto1.txt
的内容。这听起来很熟悉,但是以下两种情况并非如此:(1)一个新命令(让我们说gedit toto2.txt
)在前一个窗口中打开一个新选项卡和(2)一个新命令(让我们看看)说gedit toto3.txt
)会在新窗口中打开一个新标签。
我的问题是:which
组件决定在案例(2)中打开新窗口,这样做的条件是什么?为什么在案例(1)中没有打开新窗口?
有什么想法吗?
答案 0 :(得分:3)
它的gedit本身做出了这个决定。我们来看看源代码。函数open_files将在找不到活动窗口时(或明确指定标志--new-window
时)打开一个新窗口。
static void
open_files (GApplication *application,
gboolean new_window,
...)
{
GeditWindow *window = NULL;
if (!new_window)
{
window = get_active_window (GTK_APPLICATION (application));
}
if (window == NULL)
{
gedit_debug_message (DEBUG_APP, "Create main window");
window = gedit_app_create_window (GEDIT_APP (application), NULL);
gedit_debug_message (DEBUG_APP, "Show window");
gtk_widget_show (GTK_WIDGET (window));
}
...
}
那是什么"活跃的窗口"?我们来看看get_active_window:
static GeditWindow *
get_active_window (GtkApplication *app)
{
GdkScreen *screen;
guint workspace;
gint viewport_x, viewport_y;
GList *windows, *l;
screen = gdk_screen_get_default ();
workspace = gedit_utils_get_current_workspace (screen);
gedit_utils_get_current_viewport (screen, &viewport_x, &viewport_y);
/* Gtk documentation says the window list is always in MRU order */
windows = gtk_application_get_windows (app);
for (l = windows; l != NULL; l = l->next)
{
GtkWindow *window = l->data;
if (GEDIT_IS_WINDOW (window) && is_in_viewport (window, screen, workspace, viewport_x, viewport_y))
{
return GEDIT_WINDOW (window);
}
}
return NULL;
}
所以答案是:如果屏幕上还没有gedit窗口,gedit会打开一个新窗口。
(好吧,当然可能存在错误。我看起来并不是非常密切。那些viewport_x/y
的东西看起来有点可疑,因为视口应该有四个坐标:top / bottom / left /对。代码可能会被多显示器设置混淆。)
答案 1 :(得分:1)
看起来这是由gedit本身完成的:) 但是,如果要在新窗口中打开文档,可以使用--new-window开关。尝试从命令行使用--help调用gedit。 如果您需要直接回答“gedit如何确定它是否可以使用现有窗口或必须打开一个新窗口?”我认为你必须在https://github.com/GNOME/gedit
看到gedit源代码