static void
update_alert (GvcSoundThemeChooser *chooser,
              const char           *alert_id)
{
        GtkTreeModel *theme_model;
        GtkTreeIter   iter;
        char         *theme;
        char         *parent;
        gboolean      is_custom;
        gboolean      is_default;
        gboolean      add_custom;
        gboolean      remove_custom;

        theme_model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser->priv->combo_box));
        /* Get the current theme's name, and set the parent */
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (chooser->priv->combo_box), &iter) == FALSE) {
                return;
        }

        gtk_tree_model_get (theme_model, &iter,
                            THEME_IDENTIFIER_COL, &theme,
                            THEME_IDENTIFIER_COL, &parent,
                            -1);
        is_custom = strcmp (theme, CUSTOM_THEME_NAME) == 0;
        is_default = strcmp (alert_id, DEFAULT_ALERT_ID) == 0;

        /* So a few possibilities:
         * 1. Named theme, default alert selected: noop
         * 2. Named theme, alternate alert selected: create new custom with sound
         * 3. Custom theme, default alert selected: remove sound and possibly custom
         * 4. Custom theme, alternate alert selected: update custom sound
         */
        add_custom = FALSE;
        remove_custom = FALSE;
        if (! is_custom && is_default) {
                /* remove custom just in case */
                remove_custom = TRUE;
        } else if (! is_custom && ! is_default) {
                create_custom_theme (parent);
                save_alert_sounds (chooser, alert_id);
                add_custom = TRUE;
        } else if (is_custom && is_default) {
                save_alert_sounds (chooser, alert_id);
                /* after removing files check if it is empty */
                if (custom_theme_dir_is_empty ()) {
                        remove_custom = TRUE;
                }
        } else if (is_custom && ! is_default) {
                save_alert_sounds (chooser, alert_id);
        }

        if (add_custom) {
                gtk_list_store_insert_with_values (GTK_LIST_STORE (theme_model),
                                                   NULL,
                                                   G_MAXINT,
                                                   THEME_DISPLAY_COL, _("Custom"),
                                                   THEME_IDENTIFIER_COL, CUSTOM_THEME_NAME,
                                                   THEME_PARENT_ID_COL, theme,
                                                   -1);
                set_combox_for_theme_name (chooser, CUSTOM_THEME_NAME);
        } else if (remove_custom) {
                gtk_tree_model_get_iter_first (theme_model, &iter);
                do {
                        char *this_parent;

                        gtk_tree_model_get (theme_model, &iter,
                                            THEME_PARENT_ID_COL, &this_parent,
                                            -1);
                        if (this_parent != NULL && strcmp (this_parent, CUSTOM_THEME_NAME) != 0) {
                                g_free (this_parent);
                                gtk_list_store_remove (GTK_LIST_STORE (theme_model), &iter);
                                break;
                        }
                        g_free (this_parent);
                } while (gtk_tree_model_iter_next (theme_model, &iter));

                delete_custom_theme_dir ();

                set_combox_for_theme_name (chooser, parent);
        }

        update_alert_model (chooser, alert_id);

        g_free (theme);
        g_free (parent);
}
Exemplo n.º 2
0
ProjectManager::ProjectManager() {

	// load settings
	if (!EditorSettings::get_singleton())
		EditorSettings::create();


	EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came

	{
		int dpi_mode = EditorSettings::get_singleton()->get("global/hidpi_mode");
		if (dpi_mode==0) {
			editor_set_scale( OS::get_singleton()->get_screen_dpi(0) > 150 && OS::get_singleton()->get_screen_size(OS::get_singleton()->get_current_screen()).x>2000 ? 2.0 : 1.0 );
		} else if (dpi_mode==1) {
			editor_set_scale(0.75);
		} else if (dpi_mode==2) {
			editor_set_scale(1.0);
		} else if (dpi_mode==3) {
			editor_set_scale(1.5);
		} else if (dpi_mode==4) {
			editor_set_scale(2.0);
		}
	}

	FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"));

	set_area_as_parent_rect();
	set_theme(create_editor_theme());

	gui_base = memnew( Control );
	add_child(gui_base);
	gui_base->set_area_as_parent_rect();
	gui_base->set_theme(create_custom_theme());

	Panel *panel = memnew( Panel );
	gui_base->add_child(panel);
	panel->set_area_as_parent_rect();

	VBoxContainer *vb = memnew( VBoxContainer );
	panel->add_child(vb);
	vb->set_area_as_parent_rect(20*EDSCALE);
	vb->set_margin(MARGIN_TOP,4*EDSCALE);
	vb->set_margin(MARGIN_BOTTOM,4*EDSCALE);
	vb->add_constant_override("separation",15*EDSCALE);

	String cp;
	cp.push_back(0xA9);
	cp.push_back(0);
	OS::get_singleton()->set_window_title(_MKSTR(VERSION_NAME)+String(" - ")+TTR("Project Manager")+" - "+cp+" 2008-2016 Juan Linietsky, Ariel Manzur.");

	HBoxContainer *top_hb = memnew( HBoxContainer);
	vb->add_child(top_hb);
	CenterContainer *ccl = memnew( CenterContainer );
	Label *l = memnew( Label );
	l->set_text(_MKSTR(VERSION_NAME)+String(" - ")+TTR("Project Manager"));
	l->add_font_override("font", gui_base->get_font("doc","EditorFonts"));
	ccl->add_child(l);
	top_hb->add_child(ccl);
	top_hb->add_spacer();
	l = memnew( Label );
	l->set_text("v" VERSION_MKSTRING);
	//l->add_font_override("font",get_font("bold","Fonts"));
	l->set_align(Label::ALIGN_CENTER);
	top_hb->add_child(l);
	//vb->add_child(memnew(HSeparator));
	//vb->add_margin_child("\n",memnew(Control));

	tabs = memnew( TabContainer );
	vb->add_child(tabs);
	tabs->set_v_size_flags(SIZE_EXPAND_FILL);

	HBoxContainer *tree_hb = memnew( HBoxContainer);
	projects_hb = tree_hb;

	projects_hb->set_name(TTR("Project List"));

	tabs->add_child(tree_hb);

	VBoxContainer *search_tree_vb = memnew(VBoxContainer);
	search_tree_vb->set_h_size_flags(SIZE_EXPAND_FILL);
	tree_hb->add_child(search_tree_vb);

	HBoxContainer *search_box = memnew(HBoxContainer);
	search_box->add_spacer(true);
	project_filter = memnew(ProjectListFilter);
	search_box->add_child(project_filter);
	project_filter->connect("filter_changed", this, "_load_recent_projects");
	project_filter->set_custom_minimum_size(Size2(250,10));
	search_tree_vb->add_child(search_box);

	PanelContainer *pc = memnew( PanelContainer);
	pc->add_style_override("panel", gui_base->get_stylebox("bg","Tree"));
	search_tree_vb->add_child(pc);
	pc->set_v_size_flags(SIZE_EXPAND_FILL);

	scroll = memnew( ScrollContainer );
	pc->add_child(scroll);
	scroll->set_enable_h_scroll(false);

	VBoxContainer *tree_vb = memnew( VBoxContainer);
	tree_hb->add_child(tree_vb);
	scroll_childs = memnew( VBoxContainer );
	scroll_childs->set_h_size_flags(SIZE_EXPAND_FILL);
	scroll->add_child(scroll_childs);

	//HBoxContainer *hb = memnew( HBoxContainer );
	//vb->add_child(hb);

	Button *open = memnew( Button );
	open->set_text(TTR("Edit"));
	tree_vb->add_child(open);
	open->connect("pressed", this,"_open_project");
	open_btn=open;

	Button *run = memnew( Button );
	run->set_text(TTR("Run"));
	tree_vb->add_child(run);
	run->connect("pressed", this,"_run_project");
	run_btn=run;

	tree_vb->add_child(memnew( HSeparator ));

	Button *scan = memnew( Button );
	scan->set_text(TTR("Scan"));
	tree_vb->add_child(scan);
	scan->connect("pressed", this,"_scan_projects");

	tree_vb->add_child(memnew( HSeparator ));

	scan_dir = memnew( FileDialog );
	scan_dir->set_access(FileDialog::ACCESS_FILESYSTEM);
	scan_dir->set_mode(FileDialog::MODE_OPEN_DIR);
	scan_dir->set_title(TTR("Select a Folder to Scan")); // must be after mode or it's overridden
	scan_dir->set_current_dir( EditorSettings::get_singleton()->get("global/default_project_path") );
	gui_base->add_child(scan_dir);
	scan_dir->connect("dir_selected",this,"_scan_begin");


	Button* create = memnew( Button );
	create->set_text(TTR("New Project"));
	tree_vb->add_child(create);
	create->connect("pressed", this,"_new_project");

	Button* import = memnew( Button );
	import->set_text(TTR("Import"));
	tree_vb->add_child(import);
	import->connect("pressed", this,"_import_project");


	Button* erase = memnew( Button );
	erase->set_text(TTR("Remove"));
	tree_vb->add_child(erase);
	erase->connect("pressed", this,"_erase_project");
	erase_btn=erase;


	tree_vb->add_spacer();


	if (StreamPeerSSL::is_available()) {
		asset_library = memnew( EditorAssetLibrary(true) );
		asset_library->set_name("Templates");
		tabs->add_child(asset_library);
		asset_library->connect("install_asset",this,"_install_project");
	} else {
		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
	}


	CenterContainer *cc = memnew( CenterContainer );
	Button * cancel = memnew( Button );
	cancel->set_text(TTR("Exit"));
	cancel->set_custom_minimum_size(Size2(100,1)*EDSCALE);
	cc->add_child(cancel);
	cancel->connect("pressed", this,"_exit_dialog");
	vb->add_child(cc);

	//

	erase_ask = memnew( ConfirmationDialog );
	erase_ask->get_ok()->set_text(TTR("Remove"));
	erase_ask->get_ok()->connect("pressed", this,"_erase_project_confirm");

	gui_base->add_child(erase_ask);

	multi_open_ask = memnew( ConfirmationDialog );
	multi_open_ask->get_ok()->set_text(TTR("Edit"));
	multi_open_ask->get_ok()->connect("pressed", this, "_open_project_confirm");

	gui_base->add_child(multi_open_ask);

	multi_run_ask = memnew( ConfirmationDialog );
	multi_run_ask->get_ok()->set_text(TTR("Run"));
	multi_run_ask->get_ok()->connect("pressed", this, "_run_project_confirm");

	gui_base->add_child(multi_run_ask);

	multi_scan_ask = memnew( ConfirmationDialog );
	multi_scan_ask->get_ok()->set_text(TTR("Scan"));

	gui_base->add_child(multi_scan_ask);

	OS::get_singleton()->set_low_processor_usage_mode(true);

	npdialog = memnew( NewProjectDialog );
	gui_base->add_child(npdialog);

	npdialog->connect("project_created", this,"_load_recent_projects");
	_load_recent_projects();

	if ( EditorSettings::get_singleton()->get("global/autoscan_project_path") ) {
		_scan_begin( EditorSettings::get_singleton()->get("global/autoscan_project_path") );
	}

	//get_ok()->set_text("Open");
	//get_ok()->set_text("Exit");

	last_clicked = "";

	SceneTree::get_singleton()->connect("files_dropped", this, "_files_dropped");
}