Skip to content

Commit

Permalink
Merge pull request #68 from Falcion/feature/multifile-support
Browse files Browse the repository at this point in the history
Add multifile modals support
  • Loading branch information
Falcion authored Jun 22, 2024
2 parents afbd91a + b65bffd commit b2ff6fc
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 6 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.3.0](https://github.com/mokkapps/changelog-generator-demo/compare/v2.2.1...v2.3.0) (2024-06-22)


### Features

* **files-modal:** add modal to change extension of batch of files ([#62](https://github.com/Falcion/UNITADE.md/issues/62)) ([875ce27](https://github.com/mokkapps/changelog-generator-demo/commits/875ce2782071d25e4b9c30dc95bc118645cbeee8))
* **files-rename:** add modal to rename multiple files ([#62](https://github.com/Falcion/UNITADE.md/issues/62)) ([e535c36](https://github.com/mokkapps/changelog-generator-demo/commits/e535c364691381ca56890155538886d1126d9751))


### Build system

* **clone:** add .BAT script to clone dev-plugin in test-vault directly ([f6233fc](https://github.com/mokkapps/changelog-generator-demo/commits/f6233fce6bae9ef1665673cb1dcdf25ef59e54a5))

### [2.2.1](https://github.com/mokkapps/changelog-generator-demo/compare/v2.2.0...v2.2.1) (2024-05-14)


Expand Down
16 changes: 16 additions & 0 deletions clone.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off

REM Define the source and destination file paths
SET ""
SET ""

REM Copy the file
COPY "%source_file%" "%target_file%" /Y

REM Check if the copy operation was successful
IF ERRORLEVEL 0 (
ECHO File copied successfully.
) ELSE (
ECHO Error: File copy failed.
EXIT /B 1
)
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "unitade",
"name": "UNITADE.md",
"version": "2.2.1",
"version": "2.3.0",
"minAppVersion": "1.0.0",
"description": "Effortlessly treat any file extension as note, organize diverse file formats in your vault and take advancements in control of extension system even with custom modals.",
"author": "Falcion",
Expand Down
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "unitade",
"displayName": "UNITADE.md",
"private": true,
"version": "2.2.1",
"version": "2.3.0",
"description": "A plugin for note-taking app Obsidian™ which allows you to treat any file extension as markdown note-file",
"main": "main.ts",
"markdown": "github",
Expand Down Expand Up @@ -55,7 +55,7 @@
"release:major": "standard-version --release-as major",
"generate-version-json": "node scripts/js/generate-version-json.js",
"cli": ".\\gh.cli.sh",
"build": "tsc -noEmit -skipLibCheck --esModuleInterop source/main.ts && node esbuild.config.mjs production"
"build": "tsc -noEmit -skipLibCheck --esModuleInterop source/main.ts && node esbuild.config.mjs production && clone.bat"
},
"repository": {
"type": "git",
Expand Down
167 changes: 167 additions & 0 deletions source/components/files-edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* MIT License
*
* Copyright (c) 2023-2024
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Any code and/or API associated with OBSIDIAN behaves as stated in their distribution policy.
*/

import {
Modal,
ButtonComponent,
TextComponent,
TAbstractFile,
Setting,
} from "obsidian";

import UNITADE_PLUGIN from "./../main";
import MODALES_LOCALE from "./../locales/modals.text";

export class TFilesEdit extends Modal {
private _new_extension: string = 'md';

private _integration: boolean;

constructor(
private plugin: UNITADE_PLUGIN,
private target: TAbstractFile[]
) {
super(plugin.app);

this.target ??= [this.plugin.app.vault.getRoot()];

this._integration = false;
}

onOpen(): void {
const { contentEl } = this;

const form = contentEl.createEl("div");
const disp = contentEl.createEl("span");

const input = new TextComponent(form);

contentEl.style.cssText =
`
display: flex;
align-items: center;
flex-direction: column;
`;
disp.style.cssText =
`
flex-grow: 1;
font-weight: bold;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 5px;
text-align: center;
`;
form.style.cssText =
`
display: flex;
align-items: center;
`;
input.inputEl.style.cssText =
`
flex-grow: 1;
margin-right: 10px;
`;

disp.innerHTML = this.__generateDisplayInfo();

input.inputEl.addEventListener("keypress", (e) => {
if (e.key === "Enter") {
this.__submit();
} else if (e.key === "Escape") {
this.close();
}
});

input.setValue(this._new_extension);
input.onChange((value) => {
this._new_extension = value.startsWith(".") ? value.slice(1) : value;

disp.innerHTML = this.__generateDisplayInfo();
});

new ButtonComponent(form)
.setCta()
.setIcon('pencil')
.setButtonText("Edit")
.onClick(() => (this.__submit()));

new Setting(contentEl)
.setName(MODALES_LOCALE.gtToggle1().name)
.setDesc(MODALES_LOCALE.gtToggle1().desc)
.addToggle(toggle => {
toggle
.setValue(this._integration)
.onChange(async (value) => {
this._integration = value;
});

return toggle;
});
}

onClose() {
const { contentEl } = this;

contentEl.empty();
}

private async __submit() {
this.close();

if (this._integration) {
let next = {
...this.plugin.settings,
};

next.extensions += `;${this._new_extension}`;

this.plugin.uptSettings(next);
}

this.target.forEach(async (file) => {
const filename = file.path.split('/').last()!
const filepath = file.path.split('/').slice(0, -1).join('/');

const name = filename.split('.').first()!;

await this.app.vault.rename(file, this.__pathgen(filepath, name));
});
}

private __pathgen(path: string, name: string): string {
return path + "/" + name + (!!this._new_extension ? "." : "") + this._new_extension;
}

private __generateDisplayInfo(): string {
return this.target.map(file => {
const filename = file.path.split('/').last()!;
const filepath = file.path.split('/').slice(0, -1).join('/');
const extension = filename.split('.').slice(1).join('.')!;
const name = filename.split('.').first()!;
return `<div>${filepath}/${name}.${this._new_extension}</div>`;
}).join('');
}
}
Loading

0 comments on commit b2ff6fc

Please sign in to comment.