diff --git a/reference/FileTabsExample/FileTabsExample.h b/reference/FileTabsExample/FileTabsExample.h new file mode 100644 index 000000000..aa490bea3 --- /dev/null +++ b/reference/FileTabsExample/FileTabsExample.h @@ -0,0 +1,52 @@ +#ifndef _FileTabsExample_FileTabsExample_h +#define _FileTabsExample_FileTabsExample_h + +#include +#include +using namespace Upp; + +#define LAYOUTFILE +#include + +class FileTabsExample : public WithFileTabsExampleLayout { +private: + FileTabs bar[4]; + String barbackup; + +public: + FileTabsExample(); + + // TabBar events + void OnCursor(); + bool OnCloseConfirm(Value v); + bool OnCloseAllConfirm(); + // Buttons + void OnAdd(); + void OnInsert(); + // Options + void OnGrouping(); + void OnGroupSort(); + void OnValueSort(); + void OnKeySort(); + void OnSeparators(); + void OnStacking(); + void OnStackSort(); + void OnIcons(); + void OnPrompt(); + void OnAllAlign(); + void OnInactive(); + // Ctrl overloads + virtual bool Key(dword key, int count); + virtual void DragAndDrop(Point p, PasteClip& d); + + struct MyValueOrder : public ValueOrder + { + virtual bool operator()(const Value& a, const Value& b) const { return (Random()%2); } + }; + + StdValueOrder vo; + MyValueOrder myvo; +}; + +#endif + diff --git a/reference/FileTabsExample/FileTabsExample.lay b/reference/FileTabsExample/FileTabsExample.lay new file mode 100644 index 000000000..6626faad1 --- /dev/null +++ b/reference/FileTabsExample/FileTabsExample.lay @@ -0,0 +1,23 @@ +LAYOUT(FileTabsExampleLayout, 660, 348) + ITEM(Upp::EditString, fileinput, HSizePosZ(8, 72).TopPosZ(44, 20)) + ITEM(Upp::Button, addfile, SetLabel(t_("Add")).RightPosZ(4, 64).TopPosZ(44, 20)) + ITEM(Upp::Option, grouping, SetLabel(t_("Group tabs")).LeftPosZ(8, 132).TopPosZ(84, 16)) + ITEM(Upp::Option, keysort, SetLabel(t_("Sort tabs by key")).LeftPosZ(416, 132).TopPosZ(104, 16)) + ITEM(Upp::Option, valuesort, SetLabel(t_("Sort tabs by value")).LeftPosZ(416, 132).TopPosZ(84, 16)) + ITEM(Upp::Option, stacksort, SetLabel(t_("Sort stacks")).LeftPosZ(144, 132).TopPosZ(104, 16)) + ITEM(Upp::Option, groupsort, SetLabel(t_("Sort tabs by group")).LeftPosZ(8, 132).TopPosZ(104, 16)) + ITEM(Upp::Option, separators, SetLabel(t_("Visually seperate groups")).LeftPosZ(8, 132).TopPosZ(124, 16)) + ITEM(Upp::Option, stacking, SetLabel(t_("Stack tabs")).LeftPosZ(144, 132).TopPosZ(84, 16)) + ITEM(Upp::Option, normalicons, SetLabel(t_("Icons for normal tabs")).LeftPosZ(144, 132).TopPosZ(124, 16)) + ITEM(Upp::Option, stackedicons, SetLabel(t_("Icons for stacked tabs")).LeftPosZ(144, 132).TopPosZ(144, 16)) + ITEM(Upp::Option, prompt, SetLabel(t_("Prompt before tab close")).LeftPosZ(280, 132).TopPosZ(84, 16)) + ITEM(Upp::Option, inactive, SetLabel(t_("Show inactive tabs")).LeftPosZ(280, 132).TopPosZ(124, 16)) + ITEM(Upp::Option, allalign, SetLabel(t_("Show all alignments")).LeftPosZ(280, 132).TopPosZ(104, 16)) + ITEM(Upp::LabelBox, dv___14, SetLabel(t_("Options")).HSizePosZ(4, 0).TopPosZ(68, 96)) + ITEM(Upp::Label, selection, HSizePosZ(4, 4).TopPosZ(184, 19)) + ITEM(Upp::Label, dv___16, SetLabel(t_("Selected file (form top bar only):")).HSizePosZ(4, 4).TopPosZ(164, 19)) + ITEM(Upp::LabelBox, dv___17, SetLabel(t_("Add Files")).HSizePosZ(4, 0).TopPosZ(0, 68)) + ITEM(Upp::Label, dv___18, SetLabel(t_("- Drag files onto this window\n- Enter full paths below (files do not need to exist)")).HSizePosZ(8, 4).TopPosZ(12, 32)) + ITEM(Upp::Button, insert, SetLabel(t_("Insert")).LeftPosZ(4, 64).BottomPosZ(5, 24)) +END_LAYOUT + diff --git a/reference/FileTabsExample/FileTabsExample.upp b/reference/FileTabsExample/FileTabsExample.upp new file mode 100644 index 000000000..1aed6f6ef --- /dev/null +++ b/reference/FileTabsExample/FileTabsExample.upp @@ -0,0 +1,14 @@ +description "TabBar and FileTabs example\377"; + +uses + CtrlLib, + TabBar; + +file + FileTabsExample.h, + main.cpp, + FileTabsExample.lay; + +mainconfig + "" = "GUI"; + diff --git a/reference/FileTabsExample/main.cpp b/reference/FileTabsExample/main.cpp new file mode 100644 index 000000000..455f88e76 --- /dev/null +++ b/reference/FileTabsExample/main.cpp @@ -0,0 +1,153 @@ +#include "FileTabsExample.h" + +#define FILE_LIMIT 5 +#define PACKAGE_LIMIT 5 + +FileTabsExample::FileTabsExample() +{ + CtrlLayout(*this, "FileTabs Example"); + Sizeable().Zoomable(); + + for (int i = 0; i < 4; i++) + bar[i].SetAlign((i+1) % 4); + AddFrame(bar[0]); + + bar[0].WhenAction << [=] { OnCursor(); }; + + addfile << [=] { + if (!fileinput.GetLength()) return; + for (int i = 0; i < 4; i++) + bar[i].AddFile(~fileinput); + }; + + insert << [=] { + for(FindFile ff(GetHomeDirFile("*")); ff; ff++) + for(int i = 0; i < 4; i++) + bar[i].AddFile(ff.GetPath().ToWString()); + }; + + grouping << [=] { + for (int i = 0; i < 4; i++) + bar[i].Grouping(~grouping); + }; + + groupsort << [=] { + if(~groupsort) + for (int i = 0; i < 4; i++) + bar[i].SortGroups(true); //or specify own TabSort + else + for (int i = 0; i < 4; i++) + bar[i].SortGroups(false); + }; + + separators << [=] { + for (int i = 0; i < 4; i++) + bar[i].GroupSeparators(~separators); + }; + + stacking << [=] { + for (int i = 0; i < 4; i++) + bar[i].Stacking(~stacking); + }; + + normalicons ^= stackedicons ^= [=] { + for (int i = 0; i < 4; i++) + bar[i].FileIcons(~normalicons, ~stackedicons); + }; + + prompt << [=] { + if (prompt) { + bar[0].ConfirmClose = [=](Value v) { return PromptOKCancel(Format("Close '\1%s\1'?", ~v)); }; + bar[0].ConfirmCloseAll = [=] { return PromptOKCancel("Close all tabs?"); }; + } + else { + bar[0].ConfirmClose.Clear(); + bar[0].ConfirmCloseAll.Clear(); + } + }; + + allalign << [=] { + if (allalign) { + for (int i = 1; i < 4; i++) + AddFrame(bar[i]); + } + else { + for (int i = 0; i < 4; i++) + bar[i].Remove(); + ClearFrames(); + AddFrame(bar[0]); + } + }; + + valuesort << [=] { + keysort = false; + if(~valuesort) + for (int i = 0; i < 4; i++) + bar[i].SortTabValues(vo); + else + for (int i = 0; i < 4; i++) + bar[i].SortTabs(false); + }; + + keysort << [=] { + valuesort = false; + if(~keysort) + for (int i = 0; i < 4; i++) + bar[i].SortTabKeys(vo); + else + for (int i = 0; i < 4; i++) + bar[i].SortTabs(false); + }; + + stacksort << [=] { + if(~stacksort) + for (int i = 0; i < 4; i++) + bar[i].SortStacks(true); + else + for (int i = 0; i < 4; i++) + bar[i].SortStacks(false); + }; + + inactive << [=] { + for (int i = 1; i < 4; i++) + bar[i].InactiveDisabled(~inactive); + }; + + grouping <<= true; + inactive <<= true; + normalicons <<= true; + + insert.WhenAction(); + + OnCursor(); +} + +void FileTabsExample::OnCursor() +{ + if (bar[0].HasCursor()) + selection = (String)~bar[0]; + else + selection = "No tab selected"; +} + +bool FileTabsExample::Key(dword key, int count) +{ + if (key == K_RETURN && fileinput.HasFocus()) { + addfile.PseudoPush(); + return true; + } + return false; +} + +void FileTabsExample::DragAndDrop(Point p, PasteClip& d) +{ + if (AcceptFiles(d)) + for (int i = 0; i < 4; i++) + bar[i].AddFiles(GetFiles(d)); +} + +GUI_APP_MAIN +{ + FileTabsExample().Run(); +} +