Пример #1
0
void TextFileWidget::ProcessTimePassed(const double TimePassed)
{
	// Check if the file has been changed externally, and if so, override this widget
	{
		auto NewContent = FromFileToString(m_Path);
		if (NewContent != m_TextFieldWidget->GetContent())
			// TODO: Make it so that a 'save' is not called in turn...
			m_TextFieldWidget->SetContent(NewContent);
	}

	FlowLayoutWidget::ProcessTimePassed(TimePassed);
}
Пример #2
0
ConceptionApp::ConceptionApp(InputManager & InputManager)
    : App(InputManager),
      m_CurrentProject(),
      m_TypingModule(new TypingModule())		// Gets cleaned up via unique_ptr when pushed back to m_Widgets
{
    PopulateConcepts();

    {
        auto MainCanvas = new Canvas(Vector2n(0, 0), true, true);
        //MainCanvas->MoveView(0, 336);
        MainCanvas->MoveView(1, -64);

#if 1
        {
            auto StdIncludesList = new ListWidget<ConceptId>(Vector2n::ZERO, m_CurrentProject.GetStdIncludes(), *m_TypingModule);
            StdIncludesList->m_TapAction = [=](Vector2n LocalPosition, std::vector<ConceptId> & m_List)
            {
                auto Entry = m_TypingModule->TakeString();

                if (!Entry.empty())
                {
                    auto ConceptId = FindOrCreateConcept(Entry);

                    //Insert(ConceptId);

                    // TEST
                    auto Spot = m_List.begin() + (LocalPosition.Y() / lineHeight);
                    m_List.insert(Spot, ConceptId);
                }
                else
                {
                    auto ListEntry = static_cast<decltype(m_List.size())>(LocalPosition.Y() / lineHeight);

                    if (ListEntry < m_List.size())
                    {
                        m_TypingModule->SetString(GetConcept(m_List[ListEntry]).GetContent());
                        m_List.erase(m_List.begin() + ListEntry);
                    }
                }
            };

            auto LabelledStdIncludesList = new FlowLayoutWidget(Vector2n(-280, -250), { std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("#include <"), LabelWidget::Background::None)),
                    std::shared_ptr<Widget>(StdIncludesList),
                    std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string(">"), LabelWidget::Background::None))
                                                                                      }, {});
            LabelledStdIncludesList->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelledStdIncludesList)));
            MainCanvas->AddWidget(LabelledStdIncludesList);
        }
#endif

        MainCanvas->AddWidget(new ButtonWidget(Vector2n(-100, -350), []() {
            std::cout << "Hi from anon func.\n";
        } ));
        MainCanvas->AddWidget(new ButtonWidget(Vector2n(-60, -350), []() {
            std::cout << "Second button.\n";
        } ));
        MainCanvas->AddWidget(new ToggleWidget(Vector2n(-20, -350), [](bool State) {
            std::cout << "Testing this toggle widget! It's now set to " << State << ".\n";
        }, true));
        MainCanvas->AddWidget(new LiveFunctionWidget(Vector2n(-100, 100), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveProgramWidget(Vector2n(-100, -300), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveProgramWidget(Vector2n(-100, -100), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveGofmtWidget(Vector2n(-460, 200), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new TextFieldWidget(Vector2n(-460, 160), *m_TypingModule));
        MainCanvas->AddWidget(new ShellWidget(Vector2n(-460, 60), *m_TypingModule));
        MainCanvas->AddWidget(new SayWidget(Vector2n(-460, -100), *m_TypingModule));

        MainCanvas->AddWidget(new ConceptStringBoxWidget(Vector2n(-400, 100 + 400), *m_TypingModule));

        // TEST: Modify some Concept
        {
            auto Widget = new TextFieldWidget(Vector2n(-320, 470), *m_TypingModule);
            Widget->SetContent(GetConcept(47).GetContent());
            Widget->m_OnChange = [=]() {
                static_cast<ConceptBasic &>(ModifyConcept(47)).SetContentTEST(Widget->GetContent());
            };
            Widget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*Widget)));
            MainCanvas->AddWidget(Widget);
        }

        // Label resizing test
        {
            auto SourceWidget = new TextFieldWidget(Vector2n::ZERO, *m_TypingModule);

            auto Content = [=]() -> std::string {
                return SourceWidget->GetContent();
            };
            auto LabelWidget = new class LabelWidget(Vector2n::ZERO, Content, LabelWidget::Background::Normal);

            MainCanvas->AddWidget(new FlowLayoutWidget(Vector2n(-100, -450), { std::shared_ptr<Widget>(SourceWidget), std::shared_ptr<Widget>(LabelWidget) }, {}));
        }

        // Time widget
        {
            auto Content = []() -> std::string {
                auto now = std::chrono::system_clock::now();

                auto duration = now.time_since_epoch();

                auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();

                return std::to_string(seconds);
            };
            auto LabelWidget = new class LabelWidget(Vector2n(360, -340), Content, LabelWidget::Background::Normal);
            LabelWidget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelWidget)));

            MainCanvas->AddWidget(LabelWidget);
        }

        MainCanvas->AddWidget(new TimeWidget(Vector2n(360, -360)));		// Time widget

#if 0
        // "./GenProgram.go" file contents displayed (in real-time) in this Label Widget
        {
            auto Content = []() -> std::string {
                //return FromFileToString("./GenProgram.go");
                return FromFileToString("/Users/Dmitri/Desktop/goproj_play/src/gist.github.com/4670289.git/gistfile1.go");
            };
            auto LabelWidget = new class LabelWidget(Vector2n(-546, -186), Content, LabelWidget::Background::Normal);
            LabelWidget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelWidget)));

            MainCanvas->AddWidget(LabelWidget);
        }
#endif

#if 1
        {
            MainCanvas->AddWidget(new ListWidget<Concept *>(Vector2n(-730 - 450, -250), Concepts, *m_TypingModule));
        }
#endif

        m_Widgets.push_back(std::unique_ptr<Widget>(m_TypingModule));

        m_Widgets.push_back(std::unique_ptr<Widget>(MainCanvas));

        m_Widgets.push_back(std::unique_ptr<Widget>(new DebugOverlayWidget()));		// DEBUG: Print debug info
    }

    // Prepare and start the thread
    {
        m_CurrentProject.StartBackgroundThread();
    }

    {
        // Load program
        m_CurrentProject.LoadSampleGenProgram(*static_cast<Canvas *>(m_Widgets[0].get()));
    }
}
Пример #3
0
TextFileWidget::TextFileWidget(Vector2n Position, std::string Path, TypingModule & TypingModule)
	: FlowLayoutWidget(Position, {
		std::shared_ptr<Widget>(new FlowLayoutWidget(Vector2n::ZERO, {
			std::shared_ptr<Widget>(m_FileMinimizeToggle = new ToggleWidget(Vector2n::ZERO, Vector2n(12, 12), [](bool State) { if (!State) g_InputManager->RequestTypingPointer(*static_cast<GestureRecognizer *>(nullptr)); }, true)),
			std::shared_ptr<Widget>(new LabelWidget(Vector2n(0, -lineHeight - 2), Path, LabelWidget::Background::Normal))
		}, {})),
		std::shared_ptr<Widget>(m_TextFieldWidget = new TextFieldWidget(Vector2n::ZERO, TypingModule))
	}, { std::shared_ptr<Behavior>(new DraggablePositionBehavior(*this)) }, FlowLayoutWidget::LayoutType::Vertical),
	  m_Path(Path)
{
	m_TextFieldWidget->SetContent(FromFileToString(Path));
	m_OnChange = [=]()		// Saving takes place in TextFileWidget when it gets its NotifyChange() from the contained TextFieldWidget
	{
		//PlayBeep();
		//printf("Saving '%s'.\n", Path.c_str());

		// Write to file
		WriteToFile(Path, m_TextFieldWidget->GetContent());
	};

	const std::string Folder = ParsePath(Path, 0);
	const std::string Filename = ParsePath(Path, 1);

	auto CopyPath = [this, &TypingModule]() {
#if DECISION_USE_CLIPBOARD_INSTEAD_OF_TypingModule
		glfwSetClipboardString(this->m_Path);
#else
		TypingModule.SetString(this->m_Path);
#endif
	};
	ModifyGestureRecognizer().AddShortcut(GestureRecognizer::ShortcutEntry('I', PointerState::Modifiers::Super, CopyPath, "Copy Path"));

	// TEST: Line Gutters
#if 0
	//if ("./Gen/5086673/gistfile1.go" == Path)
	m_TextFieldWidget->m_GetLineGutters = [=](uint32 LineNumber) -> std::string
	{
#if 0
		std::string x = "."; Ls(x);
		return std::to_string(LineNumber + 1);
#endif
		// HACK: Pass file folder and name info
		if (0 == LineNumber)
			return Folder;
		else if (1 == LineNumber)
			return Filename;
		else
			throw 0;
	};
#endif

	if (IsFileTrackedByGit(Path)) {
		auto GitDiff = new GitDiffWidget(Vector2n::ZERO, TypingModule, this);
		GitDiff->RemoveAllBehaviors();
		AddWidget(GitDiff);

		auto GitCommit = new ButtonWidget(Vector2n(-160, -350), [=, &TypingModule]() {
				auto Shell = std::unique_ptr<ShellWidget>(new ShellWidget(Vector2n::ZERO, TypingModule));
				std::string Command = "cd \'" + Folder + "\'\ngit commit --allow-empty-message -m '' -- \'" + Filename + "\'";
				Command += "\ngit push origin master";
				Shell->m_CommandWidget->SetContent(Command);
				Shell->m_ExecuteWidget->GetAction()();
				this->NotifyExternalChange();		// Do this to triger potential GitDiffWidget, GitStatusWidget, etc.

				//std::cerr << "Commit & Push: '" << Folder << "' folder and '" << Filename << "' file.\n";
				std::cerr << Shell->m_OutputWidget->GetContent() << endl;
			},
			"Commit & Push");
		AddWidget(GitCommit);
	}

	m_TextFieldWidget->m_MinimizeToggle = m_FileMinimizeToggle;
}