This code places an Elementary file selector button widget on a window, along with some other checkboxes and a text entry.

Those are there just as knobs on the file selector button\textquotesingle{}s state and to display information from it.

Here\textquotesingle{}s how we instantiate it\+:  
\begin{DoxyCodeInclude}
   ic = elm_icon_add(win);
   elm_icon_standard_set(ic, \textcolor{stringliteral}{"file"});
   evas\_object\_size\_hint\_aspect\_set(ic, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);

   \textcolor{comment}{/* file selector button */}
   fs\_bt = elm_fileselector_button_add(win);
   elm_fileselector_path_set(fs\_bt, \textcolor{stringliteral}{"/tmp"});
   elm\_object\_text\_set(fs\_bt, \textcolor{stringliteral}{"Select a file"});
   elm_object_part_content_set(fs\_bt, \textcolor{stringliteral}{"icon"}, ic);

   elm_box_pack_end(vbox, fs\_bt);
   evas\_object\_show(fs\_bt);

\end{DoxyCodeInclude}


Note that we set on it both icon and label decorations. It\textquotesingle{}s set to list the contents of the {\ttfamily \char`\"{}/tmp\char`\"{}} directory, too, with \hyperlink{group__File__Selector__Button_ga201be50a20b315235ad58d6e6f177133}{elm\+\_\+fileselector\+\_\+button\+\_\+path\+\_\+set()}. What follows are checkboxes to exercise some of its A\+P\+I funtions\+:  
\begin{DoxyCodeInclude}
   ck = elm_check_add(win);
   elm\_object\_text\_set(ck, \textcolor{stringliteral}{"editable selection"});
   elm_check_state_set(ck, elm_fileselector_is_save_get(fs\_bt));
   evas\_object\_smart\_callback\_add(ck, \textcolor{stringliteral}{"changed"}, \_current\_sel\_toggle, fs\_bt);
   elm_box_pack_end(hbox, ck);
   evas\_object\_show(ck);

   ck = elm_check_add(win);
   elm\_object\_text\_set(ck, \textcolor{stringliteral}{"\(\backslash\)"inwin\(\backslash\)" mode"});
   elm_check_state_set(ck, elm_fileselector_button_inwin_mode_get(fs\_bt));
   evas\_object\_smart\_callback\_add(ck, \textcolor{stringliteral}{"changed"}, \_inwin\_mode\_toggle, fs\_bt);
   elm_box_pack_end(hbox, ck);
   evas\_object\_show(ck);

   ck = elm_check_add(win);
   elm\_object\_text\_set(ck, \textcolor{stringliteral}{"folders only"});
   elm_check_state_set(ck, elm_fileselector_folder_only_get(fs\_bt));
   evas\_object\_smart\_callback\_add(ck, \textcolor{stringliteral}{"changed"}, \_folder\_only\_toggle, fs\_bt);
   elm_box_pack_end(hbox, ck);
   evas\_object\_show(ck);

   ck = elm_check_add(win);
   elm\_object\_text\_set(ck, \textcolor{stringliteral}{"expandable"});
   elm_check_state_set(ck, elm_fileselector_expandable_get(fs\_bt));
   evas\_object\_smart\_callback\_add(ck, \textcolor{stringliteral}{"changed"}, \_expandable\_toggle, fs\_bt);
   elm_box_pack_end(hbox, ck);
   evas\_object\_show(ck);

   lb = elm_label_add(win);
   elm\_object\_text\_set(lb, \textcolor{stringliteral}{"Last selection:"});
   elm_box_pack_end(vbox, lb);
   evas\_object\_show(lb);

   en = elm_entry_add(win);
   elm_entry_line_wrap_set(en, EINA\_FALSE);
   elm_entry_editable_set(en, EINA\_FALSE);
   evas\_object\_smart\_callback\_add(fs\_bt, \textcolor{stringliteral}{"file,chosen"}, \_file\_chosen, en);
   elm_box_pack_end(vbox, en);
   evas\_object\_show(en);

\end{DoxyCodeInclude}


The checkboxes will toggle whether the file selector button\textquotesingle{}s internal file selector\+:
\begin{DoxyItemize}
\item must have an editable text entry for file names (thus, be in \char`\"{}save dialog mode\char`\"{})
\item is to be raised as an \char`\"{}inner window\char`\"{} (note it\textquotesingle{}s the default behavior) or as a dedicated window
\item is to populate its view with folders only
\item is to expand its folders, in its view, {\bfseries in place}, and not repainting it entirely just with the contents of a sole directory.
\end{DoxyItemize}

The entry labeled {\ttfamily \char`\"{}\+Last selection\char`\"{}} will exercise the {\ttfamily \char`\"{}file,chosen\char`\"{}} smart event coming from the file selector button\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \textcolor{comment}{/* hook on the sole smart callback */}
\_file\_chosen(\textcolor{keywordtype}{void}            *data,
             Evas\_Object *obj,
             \textcolor{keywordtype}{void}            *event\_info)
\{
   Evas\_Object *entry = data;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *file = event\_info;
   \textcolor{keywordflow}{if} (file)
     \{
        elm\_object\_text\_set(entry, file);
        printf(\textcolor{stringliteral}{"File chosen: %s\(\backslash\)n"}, file);
     \}
   \textcolor{keywordflow}{else}
     printf(\textcolor{stringliteral}{"File selection canceled.\(\backslash\)n"});
\}

\textcolor{comment}{/* toggle inwin mode */}

\end{DoxyCodeInclude}


Whenever you dismiss or acknowledges the file selector, after it\textquotesingle{}s raised, the {\ttfamily event\+\_\+info} string will contain the last selection on it (if any was made).

This is how the example, just after called, should look like\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/fileselector_button_example_00}}
\end{DoxyImageNoCaption}


Click on the file selector button to raise its internal file selector, which will be contained on an {\bfseries \char`\"{}inner window\char`\"{}}\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/fileselector_button_example_01}}
\end{DoxyImageNoCaption}


Toggle the \char`\"{}inwin mode\char`\"{} switch off and, if you click on the file selector button again, you\textquotesingle{}ll get {\bfseries two} windows, the original one (note the last selection there!)

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/fileselector_button_example_02}}
\end{DoxyImageNoCaption}


and the file selector\textquotesingle{}s new one

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/fileselector_button_example_03}}
\end{DoxyImageNoCaption}


Play with the checkboxes to get the behavior changes on the file selector button. The respective A\+P\+I calls on the widget coming from those knobs where shown in the code already.

See the full \hyperlink{fileselector_button_example_c}{source code} for this example. 